Dijkstra's Algorithm

Dijkstra's shortest paths on a directed, weighted graph from a source vertex. Reads the EdgeWeightedDigraph format (V, then E, then v w weight lines). Watch the min-priority queue extract the closest unsettled vertex and relax its outgoing edges — edge length is drawn roughly to scale with its weight, and the exact weight is always labelled. Flip on Water mode to watch water released from the source flow at one edge-unit of length per one unit of time along every channel — since a longer (heavier) edge takes proportionally longer to fill, the water's visual speed looks uniform, and the moment it reaches a vertex is that vertex's shortest-path distance. A running clock and an arrival log record exactly when (and at what distance) each vertex is reached.

650ms
Digraph G (edge-weighted)
undiscovered
in priority queue
current (just extracted)
water (flowing)
buoy (reached)
distance: near → far
edge direction
Status
Press  Step  or  Play  to begin.
Priority Queue  ·  min-distance
min ▸
empty
◂ rest
Min (smallest tentative distance) is extracted next; relaxed neighbours get a key decrease. This greedy order is what makes Dijkstra correct.
Clock  ·  time / distance
t = 0.00
no arrivals yet
Adjacency lists  ·  iterators
Edit / paste a graph
Format (Sedgewick & Wayne EdgeWeightedDigraph): first line is the number of vertices V, second line is the number of edges E, then E lines each holding a directed edge v w weight (weight ≥ 0, decimals allowed). Vertices are 0 … V−1. Edges are one-way, v → w; include the reverse line too if you want a two-way connection. Adjacency lists keep the order edges were read.

Optional fixed layout: after the edges, add exactly V more lines of x y — one pair per vertex, in order — to pin down your own layout instead of the automatic one. Any numeric scale works; it's auto-centred and scaled to fit, preserving relative position and aspect ratio. Loading a graph always fills the box back in with its current layout's coordinates so you can nudge them; tick the box above to see the plain format instead.