Step 0 / 0 · Comparisons: 0 · Swaps: 0
How this algorithm works
How it works
- Initialize distances to all nodes as infinity, except source = 0.
- Use a min-priority queue ordered by distance.
- Extract the node with the smallest known distance.
- For each neighbor, check if a shorter path is found through the current node.
- If yes, update the distance and add to the priority queue.
- Mark the node as visited (finalized).
- Repeat until all nodes are visited or the target is reached.
Key concepts
- Greedy algorithm
- Shortest path (single source)
- Requires non-negative edge weights
- Priority queue / min-heap for efficiency
When to use it
Finding shortest paths in graphs with non-negative weights. Used in GPS navigation, network routing, and game AI pathfinding.
Did you know
Named after Edsger Dijkstra, who invented it in 1956 in 20 minutes while shopping with his fiancée.