Dijkstra's Algorithm: Shortest Path Explorer
Follow Dijkstra's algorithm as it discovers the shortest paths from a source node across a weighted graph. Each step highlights the active line of pseudocode, the current node under consideration, the frontier held in the priority queue, and how tentative distances tighten as better routes are found.
Pseudocode
- function dijkstra(graph, source)
- for each vertex v: set dist[v] to ∞
- set dist[source] to 0
- push (0, source) onto priority queue
- while priority queue is not empty:
- (d, u) ← extract-min from queue
- if d > dist[u]: continue
- for each neighbor v of u with weight w:
- if dist[u] + w < dist[v]:
- update dist[v]
- insert (dist[v], v) into queue
- return dist
Graph Exploration
current node
in priority queue
settled shortest path
Press Play or Step Forward to begin the walk-through.