I understand what is, but I do not understand why this works.
To check on top, why does Dijkstra's algorithm select one with small weight? Why not just choose one head arbitrarily, because the algorithm touches in the corner as well? You can think of Giscrust's algorithm as a water filling algorithm (i.e. a width ago search). In each step, the goal is to cover the entire graph with the lowest cost path. Let's say that you have the corners on the edge of the area that you have filled, and you list them in the context of distance:
v0
What could possibly be a cheap way to get the top v1
? If so, then go through the path should v0
, because any unwanted upper part can not be close, so if you type the v0
Any way through the cheap is cheap, so check out the heading v0
(one step away from another head) to check where you can get it.
If you peel this kind of problem, then you guarantee that your distance is all minimum, because you always check the top that can reach the path of the least You find that least route, or you rule it, and move on to the next top.
And you stop without doing any more work, because you stop when your destination head is "I am the smallest" then stop the V0
slot.
Let's take a brief example. Suppose we are trying to multiply the 1
to 12
, and the cost between the nodes is the number that you have to multiply (we have to corner the corner < Code> 1 to 12
numbers.)
We start with 1
, and we multiply that value You can get it on any other node. Therefore the cost of the code 2
is 2
, 3
the cost 3
, ... 12
If you move in a step then the value of 12
is the price.
Now, a way through 2
(without knowing about the structure) 12
fastest if there is 2
There was no free link on 12
, but if there was, it would be the fastest. So we check out 2
and we find that for the cost 4
for the cost 2
, 6
3
and so on. We have a table of costs like this:
3 4 5 6 7 8 9 10 11 12 // Vertex 3 4 5 5 7 6 7 7 8 8 The best cost so far
OK, now maybe we can be free from 12
to 3
! Better check and we feel that 3 * 2 == 6
therefore cost 6
is the cost 3
plus 2
, And 9
plus 3
and 12
plus 4
.
4 5 6 7 8 9 10 11 12 4 5 5 7 6 6 7 11 7
Sufficient enough now we can get the 4
, And we see that we can find an additional 2
for 8
and 12
for an additional 3
Again, the cost of getting 12
is 4
+ 3
= 7
:
Code> and 6
- There is no improvement yet. It leaves us with
7 8 9 10 11 12 7 6 8 7 11 7
Now, for the first time, we see that < Getting to 8
is at the cost of reaching less to 7
, so we were checking better that there is no free way to get here Not 12
to 8
. There is no - there is no way to get there with any integers - so we throw it away.
7 9 10 11 12 7 8 7 11 7
And now we see that 12
is as cheap as There is no way left, so the cost reaching 12
should be 7
. If we keep track of the cheapest path yet (it is strictly better when giving path to the place), we knew that the cheapest way to hit 3 * 4
is 12
.
Comments
Post a Comment