Dijkstra's
Dijkstra's
Dijkstra's algorithm finds the shortest path from one vertex to all other
vertices.
Dijkstra's algorithm does not work for graphs with negative edges. For graphs
with negative edges, the Bellman-Ford algorithm that is described on the
next page, can be used instead.
To find the shortest path, Dijkstra's algorithm needs to know which vertex is
the source, it needs a way to mark vertices as visited, and it needs an
overview of the current shortest distance to each vertex as it works its way
through the graph, updating these distances when a shorter distance is
found.
If the path length of the adjacent vertex is lesser than new path length, don't update it
Avoid updating path lengths of already visited vertices
After each iteration, we pick the unvisited vertex with the least path length. So we choose 5
before 7
Notice how the rightmost vertex has its path length updated twice
Repeat until all the vertices have been visited