Algorithm Search⌘K

Proofs: Push-relabel algorithm

These are the human proofs of Push-relabel algorithm, at full length.

The FIFO push-relabel algorithm returns a maximum flow in O(n^3 + nm) time full

This proof shows: correctness, termination, complexity.

Setting. G=(V,E)G = (V, E) is a directed graph with n≥2n \ge 2 vertices, mm edges, real capacities c(e)≥0c(e) \ge 0, a source ss and a sink t≠st \ne s. Self-loops are removed. The residual graph GfG_f has, for each edge e=(u,w)e = (u, w), a forward edge (u,w)(u, w) of capacity c(e)−f(e)c(e) - f(e) and a backward edge (w,u)(w, u) of capacity f(e)f(e), and contains the edges of positive residual capacity. A labeling hh is valid for ff if h(s)=nh(s) = n, h(t)=0h(t) = 0, and h(u)≤h(w)+1h(u) \le h(w) + 1 for each edge (u,w)(u, w) of GfG_f. A residual edge (u,w)(u, w) is admissible if h(u)=h(w)+1h(u) = h(w) + 1. A vertex v∉{s,t}v \notin \{s, t\} is active if e(v)>0e(v) > 0.

Lemma 1 (invariants). At all times, ff is a preflow and hh is valid for ff. Heights never decrease, and h(s)=nh(s) = n, h(t)=0h(t) = 0 throughout.

Proof. After lines L1 and L2, every edge out of ss is full, so GfG_f has no edge out of ss except backward edges of edges into ss, which carry no flow and so are absent. All other residual edges join vertices of height 0, or go into ss from height 0. So hh is valid, and e(v)≥0e(v) \ge 0 for v≠sv \ne s.

Push along an admissible r=(u,w)r = (u, w) by δ=min⁡(e(u),cf(r))\delta = \min(e(u), c_f(r)) keeps 0≤f≤c0 \le f \le c and e(u)≥0e(u) \ge 0, and raises e(w)e(w). It may add the residual edge (w,u)(w, u), for which h(w)=h(u)−1≤h(u)+1h(w) = h(u) - 1 \le h(u) + 1; it may remove (u,w)(u, w), which keeps validity.

Relabel of uu happens at line L8 only when the current edge has passed the end of the list. Claim: then uu has no admissible edge. Each edge was passed over at line L10 only when it was not admissible, and an edge (u,w)(u, w) can become admissible only if h(u)h(u) rises (only a relabel of uu does that, which resets the pointer) or if (u,w)(u, w) newly enters GfG_f or h(w)h(w) falls. Heights never fall; (u,w)(u, w) enters GfG_f only by a push along (w,u)(w, u), which needs h(w)=h(u)+1h(w) = h(u) + 1, after which (u,w)(u, w) is not admissible. So no admissible edge out of uu exists. By validity, h(u)≤h(w)+1h(u) \le h(w) + 1 for every residual (u,w)(u, w), and since none is admissible, h(u)≤h(w)h(u) \le h(w). Lemma 3 below shows that the set of residual edges out of uu is not empty. So the new value 1+min⁡h(w)1 + \min h(w) is larger than h(u)h(u), and it keeps h(u)≤h(w)+1h(u) \le h(w) + 1 for edges out of uu. Edges into uu, (x,u)(x, u), stay valid because h(u)h(u) only grew. The vertices ss and tt are never active, so they are never relabeled. □\square

Lemma 2 (no augmenting path). For a valid labeling, GfG_f has no ss-tt path.

Proof. A simple path has at most n−1n - 1 edges, each lowers hh by at most 1, and h(s)−h(t)=nh(s) - h(t) = n. □\square

Lemma 3 (active vertices reach the source). If e(v)>0e(v) > 0 for v≠sv \ne s, then GfG_f has a path from vv to ss.

Proof. Let UU be the set of vertices that vv reaches in GfG_f, and suppose s∉Us \notin U. No residual edge leaves UU, so edges from UU to V∖UV \setminus U are full and edges from V∖UV \setminus U to UU are empty. Summing excesses over UU, the edges inside UU cancel, and ∑x∈Ue(x)=f(V∖U,U)−f(U,V∖U)≤0\sum_{x \in U} e(x) = f(V \setminus U, U) - f(U, V \setminus U) \le 0. Every term is at least 0 since s∉Us \notin U, and e(v)>0e(v) > 0, a contradiction. □\square

Lemma 4 (height bound). Always h(v)≤2n−1h(v) \le 2n - 1 for every vv.

Proof. Heights change only by relabels of active vertices. When uu is relabeled it is active, so by Lemma 3 a simple residual path from uu to ss of at most n−1n - 1 edges exists. Validity after the relabel gives h(u)≤h(s)+n−1=2n−1h(u) \le h(s) + n - 1 = 2n - 1. □\square

Lemma 5 (operation counts). (a) There are at most (2n−1)(n−2)<2n2(2n - 1)(n - 2) < 2n^2 relabels, and each raises one height by at least 1. (b) There are at most 2nm2nm saturating pushes. (c) With the FIFO queue there are at most 4n24n^2 passes, and at most 4n34n^3 nonsaturating pushes.

Proof. (a) Only the n−2n - 2 inner vertices are relabeled, each starts at 0 and ends at most 2n−12n - 1 by Lemma 4.

(b) Fix an edge ee of GG with ends uu, ww, and consider the saturating pushes from uu to ww along a residual edge of ee. At such a push h(u)=h(w)+1h(u) = h(w) + 1. Before the next one from uu to ww, some push from ww to uu must restore residual capacity, which needs h(w)=h(u)+1h(w) = h(u) + 1 at that time; since heights never fall, h(w)h(w) has grown by at least 2 between the two pushes from uu to ww. At each such push h(w)=h(u)−1≤2n−2h(w) = h(u) - 1 \le 2n - 2. So there are at most nn saturating pushes from uu to ww, and at most nn from ww to uu, for each edge of GG: at most 2nm2nm in total.

(c) Pass 1 discharges the vertices in QQ after line L3, and pass i+1i + 1 discharges the vertices enqueued during pass ii. A vertex is in QQ at most once at a time, so each pass discharges each vertex at most once. A discharge ends when e(u)=0e(u) = 0, and only its last push can be nonsaturating; so each pass has at most nn nonsaturating pushes. Let Φ\Phi be the largest height of an active vertex, or 0 if there is none; Φ=0\Phi = 0 at the start. If a pass has no relabel, every vertex active at its start loses all excess to vertices one level lower, and heights do not change, so Φ\Phi falls by at least 1 over the pass. If a pass has relabels, Φ\Phi grows by at most the total height increase of that pass. By (a) the total height increase over the run is less than 2n22n^2. Hence there are fewer than 2n22n^2 passes with a relabel and at most 2n22n^2 passes without one, at most 4n24n^2 in all, and at most 4n34n^3 nonsaturating pushes. □\square

Lemma 6 (running time). The FIFO algorithm runs in O(n3+nm)O(n^3 + nm) time.

Proof. A push is O(1)O(1), so pushes cost O(nm+n3)O(nm + n^3) by Lemma 5. A relabel of uu scans its list in O(deg⁡u)O(\deg u); with at most 2n2n relabels per vertex this is O(n∑udeg⁡u)=O(nm)O(n \sum_u \deg u) = O(nm). Between two relabels of uu the current pointer advances at most deg⁡u\deg u times, which is O(nm)O(nm) in total. □\square

Theorem. The algorithm stops, and returns a maximum flow ff and a minimum cut SS.

Proof. By Lemma 5 the number of operations is finite, so the loop stops; then QQ is empty. Every vertex that becomes active is enqueued at that moment (line L9), and a dequeued vertex is discharged until its excess is 0; so when QQ is empty no vertex is active, and ff is a flow by conservation at every inner vertex. By Lemmas 1 and 2, GfG_f has no ss-tt path, so ff is maximum by the max-flow min-cut theorem, and the set SS of vertices that ss reaches in GfG_f satisfies t∉St \notin S and c(S)=∣f∣c(S) = |f|, so it is a minimum cut. ■\blacksquare

Back to Push-relabel algorithm