AlgoScope

DAG Shortest Path

Relax each vertex's edges once, in topological order: one pass, negative weights allowed.

Shortest path, algorithm, intermediate
Edge 1 to 2: 2 against infinity. Improved.5362427-1-201022345u
Edge 1 to 2: 2 against infinity. Improved.5362427-1-201022345u

Shortest Paths: DAG in topological order, with a negative edge

Decision, step 4 of 15

Relax 1 to 2: 0 + 2 = 2 against 2's current infinity. Shorter, so 2 becomes 2 with 1 as its parent.

How shortest paths works

Cost

Best
O(V + E)
Average
O(V + E)
Worst
O(V + E)
Space
O(V)

Taught by the same lesson

Shortest Paths covers these too, in the same run.