Dijkstra's Algorithm — Strings & Gravity

Build the graph out of string: every edge is a thread whose length is its weight, every vertex is a knot where the threads are tied together. The whole thing lies crumpled on the floor. Now grab the source s and pull it up. Gravity does the rest: each knot sinks as far as its threads allow, so the knot v ends up exactly d(v) below s, and the threads that end up taut are precisely the edges on shortest paths — they carry the load. Everything else dangles loose.

The pull height H is Dijkstra's clock: a knot leaves the ground at the very moment H = d(v), so the knots take off in exactly the order the priority queue settles them. Hover a knot to light up its shortest path, hover a thread to see why it is taut or slack.

0 / 0
24°
0.75
The string graph  ·  drag to turn the view
100%
taut & load-bearing (shortest-path tree)
taut, but a tie (alternative shortest path)
slack — hangs loose, carries nothing
never lifts off (unreachable)
 d(v): near → far
pull height H0.00
Physics  ⇌  Dijkstra
pull the source up to height Hthe key currently being extracted
a knot leaves the floordeleteMin: v is settled, dist[v] final
depth of v below the handdist[v]
thread u–v is tautdist[u] + w(u,v) = dist[v]  (tight)
thread u–v hangs slackdist[u] + w(u,v) > dist[v]  (no relaxation)
knot never leaves the floordist[v] = ∞ (unreachable)
Lift-off order  ·  the priority queue
Adjacency lists  ·  hover to highlight
Edit / paste a graph
Format (Sedgewick & Wayne EdgeWeightedGraph): first line the number of vertices V, second line the number of edges E, then E lines v w weight with weight ≥ 0. Vertices are 0 … V−1.

Strings have no direction, so every edge is read as undirected here; a digraph file (EdgeWeightedDigraph) still loads — the two directions of a pair are merged into one thread, keeping the smaller weight.

Optional fixed layout: after the edges, add exactly V more lines of x y — one pair per vertex, in order — to pin down how the graph lies on the floor. This is the same augmented format the graph editor writes, so prepared graphs carry over. Any numeric scale works; it is auto-centred and scaled, preserving relative position and aspect ratio.

Mixed-format tolerant: each edge occupies exactly one line; a missing weight defaults to 1.