Playground / Dijkstra's Shortest Path

Find the cheapest route

Dijkstra's Shortest Path

Interactive lab

Try it: Dijkstra's Shortest Path

How Dijkstra's algorithm finds shortest paths in a graph with non-negative edge weights by always finalising the closest unfinished node.

How it works

  1. Start with distance 0 at the source and ∞ everywhere else.
  2. Pick the unfinished node with the smallest distance; its distance is now final.
  3. Relax each edge: if going through this node is shorter, update the neighbour's distance and predecessor.
  4. Repeat; follow predecessors back from the target to read the path.

Default run (21 steps): Shortest paths from A. Every distance starts at ∞ except A = 0. … Shortest path A → H: A → B → C → F → H, total weight 11.

Simplified: Fixed 8-node undirected graph with integer weights 1–9. Draggable layout; weights and edges are editable.

Educational simulation

Loading the simulation…