Algorithm Search⌘K

Proofs: Ford-Fulkerson algorithm

These are the human proofs of Ford-Fulkerson algorithm, at full length.

Ford-Fulkerson 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 G=(V,E)G = (V, E), c(e)≥0c(e) \ge 0 and s≠ts \ne t. For each edge e=(u,v)e = (u, v) the algorithm keeps two residual capacities: cf(e+)c_f(e^+) on the arc e+=(u,v)e^+ = (u, v) and cf(e−)c_f(e^-) on the arc e−=(v,u)e^- = (v, u). The residual graph GfG_f has the arcs with positive residual capacity. We write f(e)=cf(e−)f(e) = c_f(e^-), Sˉ=V∖S\bar S = V \setminus S, and ∣f∣=∑e out of sf(e)−∑e into sf(e)|f| = \sum_{e \text{ out of } s} f(e) - \sum_{e \text{ into } s} f(e).

Invariant (I). Before each test of line L2:

  1. cf(e+)≥0c_f(e^+) \ge 0, cf(e−)≥0c_f(e^-) \ge 0 and cf(e+)+cf(e−)=c(e)c_f(e^+) + c_f(e^-) = c(e) for each edge ee;
  2. ff satisfies flow conservation at each v≠s,tv \ne s, t;
  3. if all capacities are integers, all residual capacities are integers.

Part 1 says 0≤f(e)≤c(e)0 \le f(e) \le c(e), so with part 2, ff is an s-t flow.

Initialization. Line L1 sets cf(e+)=c(e)c_f(e^+) = c(e) and cf(e−)=0c_f(e^-) = 0. Part 1 holds, f=0f = 0 conserves at every vertex, and the values are integers when cc is.

Maintenance. Let P=x1,…,xkP = x_1, \ldots, x_k be the arcs of the path found in line L2, from ss to tt, and Δ=min⁡icf(xi)>0\Delta = \min_i c_f(x_i) > 0 (line L3). We may take PP simple: a depth-first search enters each vertex at most once, so the arcs on its current path form a simple path. Then PP uses at most one of e+,e−e^+, e^- for each edge ee, because using both would visit uu and vv in both orders.

Part 1. Lines L5 and L6 lower cf(xi)c_f(x_i) by Δ\Delta and raise the reverse arc by Δ\Delta. For an edge ee whose arc is on PP, the sum cf(e+)+cf(e−)c_f(e^+) + c_f(e^-) does not change, and the lowered arc stays ≥0\ge 0 since Δ≤cf(xi)\Delta \le c_f(x_i). Arcs of other edges do not change.

Part 2. If xi=e+x_i = e^+, then f(e)=cf(e−)f(e) = c_f(e^-) rises by Δ\Delta; if xi=e−x_i = e^-, then f(e)f(e) falls by Δ\Delta. Fix v≠s,tv \ne s, t on PP; it is the head of xix_i and the tail of xi+1x_{i+1} for one index ii, since PP is simple. The arc xix_i enters vv in GfG_f: either xi=e+x_i = e^+ for an edge ee into vv (flow in rises by Δ\Delta) or xi=e−x_i = e^- for an edge ee out of vv (flow out falls by Δ\Delta). Both raise the excess fin(v)−fout(v)f^{\text{in}}(v) - f^{\text{out}}(v) by Δ\Delta. In the same way xi+1x_{i+1} leaves vv, and either raises the flow on an edge out of vv or lowers the flow on an edge into vv; both lower the excess by Δ\Delta. So the excess of vv stays 0. A vertex not on PP is touched by no arc.

Part 3. Δ\Delta is the minimum of integers, so it is an integer, and lines L5 and L6 keep all values integral.

The value. The arc x1x_1 leaves ss and no later arc enters or leaves ss, since PP is simple. So x1x_1 either raises the flow on an edge out of ss or lowers the flow on an edge into ss, and ∣f∣|f| rises by exactly Δ\Delta.

Termination with integer capacities. By part 3, each Δ≥1\Delta \ge 1, so each round raises ∣f∣|f| by at least 1. For any s-t flow and the cut ({s},V∖{s})(\{s\}, V \setminus \{s\}), ∣f∣≤∑e out of sc(e)|f| \le \sum_{e \text{ out of } s} c(e), a finite integer bound. So the loop runs at most FF times, where FF is the maximum flow value (the value after the last round is at most FF and it starts at 0). The same argument with capacities scaled by a common denominator covers rational capacities.

The result is optimal. Suppose line L2 finds no path. Let SS be the set of line L7, the vertices reachable from ss in GfG_f. Then s∈Ss \in S and t∉St \notin S, so (S,Sˉ)(S, \bar S) is an s-t cut.

  • For an edge e=(u,v)e = (u, v) with u∈Su \in S and v∈Sˉv \in \bar S: if cf(e+)>0c_f(e^+) > 0, the arc (u,v)(u, v) would make vv reachable. So cf(e+)=0c_f(e^+) = 0 and f(e)=c(e)f(e) = c(e).
  • For an edge e=(v,u)e = (v, u) with v∈Sˉv \in \bar S and u∈Su \in S: if cf(e−)>0c_f(e^-) > 0, the arc e−=(u,v)e^- = (u, v) would make vv reachable. So f(e)=cf(e−)=0f(e) = c_f(e^-) = 0.

Summing the excess fin(w)−fout(w)f^{\text{in}}(w) - f^{\text{out}}(w) over w∈Sw \in S: the excess is 0 for w≠sw \ne s and −∣f∣-|f| for w=sw = s; each edge inside SS cancels, so −∣f∣=f(Sˉ,S)−f(S,Sˉ)-|f| = f(\bar S, S) - f(S, \bar S). With the two facts above, ∣f∣=c(S,Sˉ)−0=c(S,Sˉ)|f| = c(S, \bar S) - 0 = c(S, \bar S).

For any s-t flow gg and any s-t cut (X,Xˉ)(X, \bar X), the same sum gives ∣g∣=g(X,Xˉ)−g(Xˉ,X)≤c(X,Xˉ)|g| = g(X, \bar X) - g(\bar X, X) \le c(X, \bar X). Applied to gg and (S,Sˉ)(S, \bar S): ∣g∣≤c(S,Sˉ)=∣f∣|g| \le c(S, \bar S) = |f|, so ff is a maximum flow. Applied to ff and any cut (X,Xˉ)(X, \bar X): c(S,Sˉ)=∣f∣≤c(X,Xˉ)c(S, \bar S) = |f| \le c(X, \bar X), so (S,Sˉ)(S, \bar S) is a minimum cut. Line L8 returns ff and SS. ■\blacksquare

Remark. The optimality part does not use integrality. So whenever the loop stops, for any capacities, the answer is correct; only termination needs integer or rational capacities, or a rule for choosing PP such as shortest paths.

Back to Ford-Fulkerson algorithm