I understand how to find the shortest path from start to finish as explained by the Dijkstra's Algorithm, what I do not understand is the interpretation. Here, from the graph in the picture, order added to my known set from A to E is A,C,B,D,F,H,G,E
what I do not get is, how to get the path from A to E as shown in the picture (the mathematical aspect)
Dijkstra's algorithm is the iterative algorithmic process to provide us with the shortest path from one specific starting node to all other nodes of a graph. It is different from the minimum spanning tree as the shortest distance among two vertices might not involve all the vertices of the graph.
Dijkstra's algorithm (/ˈdaɪkstrəz/ DYKE-strəz) is an algorithm for finding the shortest paths between nodes in a graph, which may represent, for example, road networks. It was conceived by computer scientist Edsger W. Dijkstra in 1956 and published three years later.
Dijkstra's algorithm solves the shortest-path problem for any weighted, directed graph with non-negative weights. It can handle graphs consisting of cycles, but negative weights will cause this algorithm to produce incorrect results.
Every node has a parent node. When you reach 'E'
, you simply look at its parent and so on until you find 'A'
. This way you'll find the list in reverse order. Reverse the list it to find the path from 'A'
to 'E'
.
Your parent list will be 'E' 'G' 'H' 'F' 'B' 'A'
if you append in order.
NOTE: The "parent node" is the node indicated in the table's "path" column
Consider a minimum priority queue containing paths to be traversed where the path's priority on the queue is the cost of traversing the edges in the path from the root up to and including that edge. At each step of the algorithm pop the lowest cost path from the queue and, considering each of its incident edges, extend the path with that incident edge and push the new path back onto the queue in priority order. Repeat until the first path reaches the destination.
For example:
<>
A
, put all the incident edges (A->B
, A->C
and A->D
with costs 2, 1 and 4 respectively) into the queue and order by priority: <(A->C,1),(A->B,2),(A->D,4)>
A->C
from the front of the queue and then consider the edges incident to the end of the path C
and push those paths back onto the queue (maintaining the priority order): <(A->B,2),(A->D,4),(A->C->A,10),(A->C->E,12)>
A->B
off and extending the paths with incident edges: <(A->D,4),(A->B->F,4),(A->B->C,7),(A->C->A,10),(A->B->E,12),(A->C->E,12)>
A->D
and push more incident edges: <(A->B->F,4),(A->D->C,6),(A->B->C,7),(A->C->A,10),(A->B->E,12),(A->C->E,12)>
A->B->F
and push more incident edges: <(A->D->C,6),(A->B->C,7),(A->B->F->H,7),(A->C->A,10),(A->B->E,12),(A->C->E,12)>
A->D->C
- however, we've already reached C
with a lower cost path so can ignore it.A->B->C
and ignore it.A->B->F->H
and push more incident edges: <(A->B->F->H->G,8),(A->C->A,10),(A->B->E,12),(A->C->E,12)>
A->B->F->H
and push more incident edges: <(A->B->F->H->G->F,10),(A->C->A,10),(A->B->F->H->G->E,11),(A->B->E,12),(A->C->E,12)>
A->B->F->H->G->F
and ignore it.A->C->A
and ignore it.A->B->F->H->G->E
and we've reached the goal (with a cost of 11)!If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With