Algorithm Search⌘K

Proofs: Edmonds-Karp algorithm

These are the human proofs of Edmonds-Karp algorithm, at full length.

Edmonds-Karp makes at most nm augmentations full

This proof shows: time.worst.

Fix the run of the algorithm on a network with nn vertices and mm edges. The residual graph GfG_f has at most 2m2m arcs: e+e^+ and e−e^- for each edge ee. Let δf(v)\delta_f(v) be the number of arcs on a shortest path from ss to vv in GfG_f, or ∞\infty if there is none.

Lemma 1 (distances never decrease). Let f′f' be the flow after one augmentation of the algorithm, from ff. Then δf′(v)≥δf(v)\delta_{f'}(v) \ge \delta_f(v) for each vertex vv.

Proof. Let PP be the augmenting path, a shortest s-t path in GfG_f. Each arc (x,y)(x, y) of PP has δf(y)=δf(x)+1\delta_f(y) = \delta_f(x) + 1, since a prefix of a shortest path is shortest. The augmentation changes GfG_f only in two ways: it can remove arcs of PP (those whose residual capacity becomes 0), and it can add the reverse (y,x)(y, x) of an arc (x,y)(x, y) of PP. Every arc (p,q)(p, q) of Gf′G_{f'} satisfies δf(q)≤δf(p)+1\delta_f(q) \le \delta_f(p) + 1: for an arc already in GfG_f this is the property of BFS distances; for a new arc (y,x)(y, x) it holds since δf(x)=δf(y)−1≤δf(y)+1\delta_f(x) = \delta_f(y) - 1 \le \delta_f(y) + 1. Now take a shortest path s=v0,v1,…,vk=vs = v_0, v_1, \ldots, v_k = v in Gf′G_{f'}, so k=δf′(v)k = \delta_{f'}(v). Summing δf(vi+1)≤δf(vi)+1\delta_f(v_{i+1}) \le \delta_f(v_i) + 1 over ii gives δf(v)≤δf(s)+k=k\delta_f(v) \le \delta_f(s) + k = k. If vv is not reachable in Gf′G_{f'}, the claim is trivial. □\square

Lemma 2 (critical arcs). Call an arc x=(u,v)x = (u, v) of PP critical in a round if cf(x)=Δc_f(x) = \Delta; after the round cf′(x)=0c_{f'}(x) = 0 and xx is not in Gf′G_{f'}. Each arc is critical in at most n/2n/2 rounds.

Proof. Suppose x=(u,v)x = (u, v) is critical in the round with flow ff. Then δf(v)=δf(u)+1\delta_f(v) = \delta_f(u) + 1. For xx to be critical again, it must first come back into the residual graph, and the only way is an augmentation along a path that uses the reverse arc (v,u)(v, u), in a round with some flow gg. That path is shortest in GgG_g, so δg(u)=δg(v)+1\delta_g(u) = \delta_g(v) + 1. By Lemma 1, δg(v)≥δf(v)\delta_g(v) \ge \delta_f(v). Hence

δg(u)=δg(v)+1≥δf(v)+1=δf(u)+2.\delta_g(u) = \delta_g(v) + 1 \ge \delta_f(v) + 1 = \delta_f(u) + 2.

By Lemma 1 again, at the next round in which xx is critical the distance of uu is at least δg(u)≥δf(u)+2\delta_g(u) \ge \delta_f(u) + 2. So the distances of uu at the rounds where xx is critical form a sequence that grows by at least 2 each time. In each such round uu lies on a shortest s-t path and is not tt, so δ(u)≤n−2\delta(u) \le n - 2; and δ(u)≥0\delta(u) \ge 0. A sequence of integers in [0,n−2][0, n - 2] that grows by at least 2 has at most ⌊(n−2)/2⌋+1≤n/2\lfloor (n - 2)/2 \rfloor + 1 \le n/2 terms. □\square

Theorem 2. The algorithm makes at most nmnm augmentations, and its running time is O(nm(n+m))O(nm(n + m)), which is O(nm2)O(nm^2) when m≥nm \ge n.

Proof. In each round the bottleneck Δ\Delta is the residual capacity of some arc of PP, so each round has at least one critical arc. There are at most 2m2m arcs, each critical at most n/2n/2 times by Lemma 2, so there are at most 2m⋅n/2=nm2m \cdot n/2 = nm rounds. Each round costs O(n+m)O(n + m) for the search and O(n)O(n) for the augmentation. The final search that fails costs O(n+m)O(n + m) more. Lines L1 and L11 cost O(n+m)O(n + m). ■\blacksquare

Neither lemma uses integrality, so the bound holds for all nonnegative real capacities, and in exact arithmetic the algorithm terminates on every input.

Edmonds-Karp returns a maximum flow and a minimum cut full

This proof shows: correctness, termination.

Let N=(G,c,s,t)N = (G, c, s, t) be a flow network with real capacities c(e)≥0c(e) \ge 0 and s≠ts \ne t. Write cfc_f for the residual capacities, f(e)=cf(e−)f(e) = c_f(e^-), and GfG_f for the residual graph of arcs with cf>0c_f > 0.

Claim 1 (each round is a Ford-Fulkerson round). Lines L2 to L7 are a breadth-first search in GfG_f from ss: line L6 follows an arc only if cf(x)>0c_f(x) > 0. If it marks tt, the parent arcs π\pi give a path from ss to tt in GfG_f, and each vertex on it is marked once, so the path is simple. Lines L9 and L10 augment along it by its bottleneck Δ>0\Delta > 0. By the invariant proved for Ford-Fulkerson (residual capacities stay nonnegative, cf(e+)+cf(e−)=c(e)c_f(e^+) + c_f(e^-) = c(e), and conservation holds), ff stays an s-t flow, and its value grows by Δ\Delta.

Claim 2 (termination). The number of rounds is at most nmnm. This is proved in the complexity proof, Theorem 2; it uses no property of the capacities other than being real and nonnegative. So the loop of line L2 ends.

Claim 3 (the search at the end is complete). In the last round line L8 finds tt unmarked. Then the loop of line L4 stopped because QQ was empty, so the search ran to the end, and the marked vertices are exactly the vertices reachable from ss in GfG_f.

Claim 4 (optimality). Let SS be the marked set of the last round, so s∈Ss \in S and t∉St \notin S. Each edge (u,v)(u, v) with u∈Su \in S, v∉Sv \notin S has cf(e+)=0c_f(e^+) = 0, so f(e)=c(e)f(e) = c(e); each edge (v,u)(v, u) with v∉Sv \notin S, u∈Su \in S has cf(e−)=0c_f(e^-) = 0, so f(e)=0f(e) = 0. By conservation, ∣f∣=f(S,Sˉ)−f(Sˉ,S)=c(S,Sˉ)|f| = f(S, \bar S) - f(\bar S, S) = c(S, \bar S). Since every s-t flow gg has ∣g∣≤c(S,Sˉ)|g| \le c(S, \bar S) and every s-t cut XX has c(X,Xˉ)≥∣f∣c(X, \bar X) \ge |f|, the flow is maximum and the cut is minimum. ■\blacksquare

Back to Edmonds-Karp algorithm