Proofs: Dinic's algorithm
These are the human proofs of Dinic's algorithm, at full length.
Dinic's algorithm runs in O(n^2 m) time full
This proof shows: time.worst.
Fix a run on a network with vertices and edges, and assume, as for every maximum flow bound stated in terms of , that after removing the vertices that no edge touches; otherwise add to each bound. Each arithmetic operation and comparison costs .
Theorem 1 (phases). There are at most runs of line L3. By Claim 5 of the correctness proof, grows by at least 1 in each phase, and it lies in while the loop continues, so there are at most phases and one final search.
Theorem 2 (one phase costs O(nm)). Line L1 costs once. Line L3 is a breadth-first search over at most arcs: . Line L5 costs . In the loop of lines L7 to L14:
- lines L12 and L14 each move a pointer one arc forward, and there are arcs, so they run at most times in all, at each;
- line L9 runs at most times (Claim 4 of the correctness proof) and costs each time, since ;
- line L11 adds an arc to , and each arc added to leaves it later by line L9 (at most arcs per run, already counted) or by line L14 (one arc per run). So line L11 runs at most times;
- line L13 runs once.
So the loop costs , and one phase costs .
Theorem 3 (total). By Theorems 1 and 2 the time is . The arrays , the adjacency lists, , , the queue and take space. Nothing in the count uses integrality, so the bound holds for real capacities.
Dinic's algorithm 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, , for the residual graph of arcs with , and for the value computed in line L3 of the current phase. The level graph is the set of arcs with and ; its arcs are tested with the residual capacities of the moment.
Claim 1 (each augmentation keeps a flow). When line L9 runs, is a walk from to built by line L11, so each arc of had and goes up one level. The levels along are , so is a simple path. Every arc of still has at line L9: an arc of loses residual capacity only through an augmentation, and an augmentation restarts the walk with empty. So , and by the invariant proved for Ford-Fulkerson (residual capacities stay nonnegative, , conservation holds) stays an s-t flow and its value grows by .
Claim 2 (level arcs only shrink in a phase). An augmentation adds residual capacity only to reverses of arcs of , which have , so they are not level arcs. The levels are fixed during the phase. Hence the set of arcs of with only loses members during the phase.
Claim 3 (dead vertices are dead). Call dead when has run past the last arc of . Invariant: no dead vertex has a path to in using arcs with , and every arc that a pointer has passed is either not a level arc, or has , or ends at a dead vertex. A pointer moves in line L12 only when the arc fails the test of line L10, that is, it is not a level arc or it has ; by Claim 2 it stays so. A pointer moves in line L14 past the arc just after was found dead. Every arc of a dead has been passed, so each one is useless or ends at a dead vertex, and by induction on the order in which vertices die, has no path to with positive level arcs. The sink never dies, because line L8 runs before lines L10 to L14 whenever .
Claim 4 (each phase ends and finds a blocking flow). Each pass of the loop runs one of lines L9, L11, L12, L14. Lines L12 and L14 move a pointer, at most times in all. Line L9 makes some arc of have , and by Claim 2 it stays so, so it is in no later ; has at most arcs, since the two arcs of one edge cannot both go up a level, so line L9 runs at most times. Line L11 runs at most times between two runs of lines L9 or L14, since each run raises the level of by 1. So the loop ends, and it ends only in line L13, with dead. By Claim 3, then has no s-t path with all : the flow added in this phase is a blocking flow of the level graph of the phase start.
Claim 5 (termination). By the lemma on blocking flows, adding a blocking flow of makes strictly larger. While the loop of line L2 continues, . So there are at most phases before line L4 leaves the loop.
Claim 6 (optimality). In the last run of line L3, is not reached, and is exactly the set of vertices reachable from in , with 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.