Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Interpreting Dijkstra's Algorithm

Graph

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)

like image 907
i_use_the_internet Avatar asked Apr 20 '15 18:04

i_use_the_internet


People also ask

What is the significance of Dijkstra's algorithm explain clearly with an example?

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.

What do you understand by Dijkstra's shortest path algorithm explain with an example?

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.

What is the purpose of Dijkstra's algorithm?

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.


2 Answers

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

like image 104
Thellimist Avatar answered Sep 18 '22 18:09

Thellimist


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:

  1. Start with an empty queue <>
  2. Then, starting from the root 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)>
  3. Pop the minimum priority path 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)>
  4. Repeat, popping the minimum priority path 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)>
  5. Keep going... pop 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)>
  6. pop 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)>
  7. pop A->D->C - however, we've already reached C with a lower cost path so can ignore it.
  8. pop A->B->C and ignore it.
  9. pop 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)>
  10. pop 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)>
  11. pop A->B->F->H->G->F and ignore it.
  12. pop A->C->A and ignore it.
  13. pop A->B->F->H->G->E and we've reached the goal (with a cost of 11)!
like image 43
MT0 Avatar answered Sep 19 '22 18:09

MT0