algo·visual

Dijkstra (Graph)

Graphs
avgO(V²)worstO(V²)spaceO(V)
41258263719A0B∞C∞D∞E∞F∞G∞H∞

Every distance starts at ∞ except the source A, which is 0

1 / 33
Nodes8
Source
Target
Edgesweights 1 to 99

How it works

Dijkstra's algorithm grows a set of settled nodes outward from the source, always settling the unfinished node with the smallest tentative distance and then relaxing its edges. With non-negative weights a settled distance can never improve, so when it finishes every reachable node has its shortest distance. This version scans for the minimum, the classic O(V²) form that suits small dense graphs.

Complexity

Best
O(V²)
Average
O(V²)
Worst
O(V²)
Space
O(V)

Search algorithms

Jump to any algorithm or page