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 vertices and edges. The residual graph has at most arcs: and for each edge . Let be the number of arcs on a shortest path from to in , or if there is none.
Lemma 1 (distances never decrease). Let be the flow after one augmentation of the algorithm, from . Then for each vertex .
Proof. Let be the augmenting path, a shortest s-t path in . Each arc of has , since a prefix of a shortest path is shortest. The augmentation changes only in two ways: it can remove arcs of (those whose residual capacity becomes 0), and it can add the reverse of an arc of . Every arc of satisfies : for an arc already in this is the property of BFS distances; for a new arc it holds since . Now take a shortest path in , so . Summing over gives . If is not reachable in , the claim is trivial.
Lemma 2 (critical arcs). Call an arc of critical in a round if ; after the round and is not in . Each arc is critical in at most rounds.
Proof. Suppose is critical in the round with flow . Then . For 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 , in a round with some flow . That path is shortest in , so . By Lemma 1, . Hence
By Lemma 1 again, at the next round in which is critical the distance of is at least . So the distances of at the rounds where is critical form a sequence that grows by at least 2 each time. In each such round lies on a shortest s-t path and is not , so ; and . A sequence of integers in that grows by at least 2 has at most terms.
Theorem 2. The algorithm makes at most augmentations, and its running time is , which is when .
Proof. In each round the bottleneck is the residual capacity of some arc of , so each round has at least one critical arc. There are at most arcs, each critical at most times by Lemma 2, so there are at most rounds. Each round costs for the search and for the augmentation. The final search that fails costs more. Lines L1 and L11 cost .
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 be a flow network with real capacities and . Write for the residual capacities, , and for the residual graph of arcs with .
Claim 1 (each round is a Ford-Fulkerson round). Lines L2 to L7 are a breadth-first search in from : line L6 follows an arc only if . If it marks , the parent arcs give a path from to in , and each vertex on it is marked once, so the path is simple. Lines L9 and L10 augment along it by its bottleneck . By the invariant proved for Ford-Fulkerson (residual capacities stay nonnegative, , and conservation holds), stays an s-t flow, and its value grows by .
Claim 2 (termination). The number of rounds is at most . 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 unmarked. Then the loop of line L4 stopped because was empty, so the search ran to the end, and the marked vertices are exactly the vertices reachable from in .
Claim 4 (optimality). Let be the marked set of the last round, so and . Each edge with , has , so ; each edge with , has , so . By conservation, . Since every s-t flow has and every s-t cut has , the flow is maximum and the cut is minimum.