djikstras-algorithm
Dijkstra’s Algorithm
Algorithm for finding the shortest paths from a node to every other node
How Dijkstra's Algorithm Works
Dijkstras Shortest Path Algorithm Explained | With Example | Graph Theory

Set initial node as 0 and rest as ∞ tentatively
Repeat until all nodes explored
Update estimates
Choose next vertex
Choose the vertex with smallest edge
*Do not update path lengths of already visited vertices
Example

Explore node A :
path to C → 2
path to F → 3
Choose F to explore next as its has the smallest edge (arrow) of 2
Explore node F :
path to C →
4but it is >3 so ignore , we want shortestpath to E → 5
path to B → 8
path to G → 7
Choose C to explore next as its has the smallest edge (arrow) of 2
Explore node C :
path to D → 7
path to E → 4 (<5 previously , improvement ! we take it)
Choose E to explore next as its has the smallest edge (arrow) of 1
... so on until all nodes are explored and we find the minimum distance to each node
Last updated