Search code examples
algorithmgraphdijkstrapath-finding

How does Dijkstra's Algorithm find shortest path?


Example

How can the shortest path be A,C,E,B,D when there is no path between E and B?


Solution

  • Dijkstra's algorithm computes what is the lowest cost from the starting node in this case A to all other nodes in a typical implementation.

    To get the complete path from node A to some other node we follow the back pointers back to A. This, is not shown in this example.

    The nodes in S are arranged in the order of increasing cost from A. I am including a few resources on the topic, which might be helpful: