Memra

Shortest paths: the relaxation framework

◈ 4 cards

INITIALIZE-SINGLE-SOURCE and RELAX — the one primitive behind every shortest-path algorithm, plus the δ cases and key properties.

The single-source shortest-paths problem

Given a weighted directed graph and a source , find a minimum-weight path from to every vertex. The shortest-path weight is The third case matters: if you can loop through a negative cycle on the way to , you can make the path arbitrarily cheap, so is .

The two primitives

Every algorithm in this and the next two lessons is built from exactly two operations. Each vertex carries v.d (a shortest-path estimate — an upper bound on ) and v.π (its predecessor).

INITIALIZE-SINGLE-SOURCE(G, s): set v.d = ∞, v.π = NIL for every vertex, then s.d = 0.

RELAX(u, v, w): can we reach more cheaply by going through ?

That is the whole toolkit. Bellman-Ford, DAG-shortest-paths, and Dijkstra differ only in the order and number of times they relax edges.

Worked example of relaxation

Suppose u.d = 5, w(u,v) = 2, and v.d = 10. Then u.d + w(u,v) = 7 < 10, so RELAX sets v.d = 7 and v.π = u. If instead v.d were already 6, then and RELAX does nothing — estimates only ever decrease.

The properties that make it all work

  • Upper-bound: v.d ≥ δ(s,v) always, and once v.d = δ(s,v) it never changes again.
  • Triangle inequality: .
  • Convergence: if is a shortest path and u.d = δ(s,u) before RELAX(u,v,w), then v.d = δ(s,v) after it.
  • Path-relaxation: if you relax the edges of a shortest path in order — even with arbitrary other relaxations mixed in between — then v_k.d = δ(s,v_k).

The path-relaxation property is the linchpin of Bellman-Ford's correctness: after passes over all edges, every shortest path of edges has its correct value.

w = 2ud = 5vd 10→77 < 10, so v.d ← 7
RELAX(u, v, w) on the worked example. The test is v.d > u.d + w(u,v): 10 > 5 + 2, so v.d falls to 7 and v.π becomes u. Had v.d already been 6, the test would fail and nothing would change — an estimate never rises.
PropertyWhat it guaranteesLeaned on byUpper boundv.d ≥ δ(s,v); never risesevery algorithmTriangleδ(s,v) ≤ δ(s,u) + w(u,v)Dijkstra proofConvergenceu.d = δ before ⇒ v.d = δafterDijkstraPath relaxationrelax a path in order ⇒ v.d= δBellman-FordFour properties; every shortest-path proof uses them.
The four properties are the proof toolkit. Convergence is what lets Dijkstra freeze a vertex the moment it is extracted; path-relaxation is what makes |V|−1 Bellman-Ford passes enough.
NORMAL ~/memra/learn/comp-372/relaxation-framework utf-8 LF