Skip to content
DSA Visualizerpreview

Dijkstra's shortest paths

Settle the closest unsettled node, then see if going through it shortens anything else.

O((V + E) log V) with a heap time · O(V) space

Weighted edgesA-B:4, A-C:1, C-B:2, B-D:1, C-D:5, D-E:3from A

Distance to A is 0; everything else starts at ∞.

Graph with nodes A, B, C, D, E and edges A–B (4), A–C (1), C–B (2), B–D (1), C–D (5), D–E (3).
  • compare
  • swap or write
  • settled

1 / 13

Speed

Space play · ← → step · Home End jump · drag the strip to scrub