Max-Flow Min-Cut in Depth
Ford–Fulkerson, Edmonds–Karp, Dinic and the duality theorem.
Ford–Fulkerson's running time depends on the capacities: with integers it may need as many augmentations as the flow is large, and with irrational capacities it may never stop. Edmonds and Karp made the count by always taking a shortest path, Dinic batched shortest paths into blocking flows, Goldberg and Tarjan abandoned paths altogether with push-relabel, and in 2013 Orlin reached , the bound that path-based methods had aimed at for decades.
What you’ll learn
- Prove max-flow min-cut through linear-programming duality with threshold rounding, characterize when the minimum cut is unique, and prove the flow decomposition theorem.
- Prove that Edmonds–Karp performs augmentations: residual distances never decrease, and each arc is critical times.
- Analyze Dinic's algorithm: level graphs, blocking flows with current-arc pointers, in general and on unit networks.
- Explain push-relabel through its height invariant and bounds, and place the landmark algorithms from Ford–Fulkerson to Orlin's .
Duality, decomposition and the set of minimum cuts
The Optimized lesson proved max-flow min-cut with augmenting paths. A second proof explains why such a theorem exists: maximum flow is a linear program, and minimum cut is its dual, with an integral optimum.
Take an optimal dual solution and clip every potential into , which never increases a positive drop . Pick a threshold uniformly at random in and let : a cut, since .
An edge crosses from to its complement exactly when , which has probability at most the drop, and so at most :
By linearity of expectation, the average cut costs at most the dual optimum, so some cut does too. With LP strong duality (P = D), this is max-flow min-cut again:
Decomposition explains a barrier. There are networks where every maximum flow needs paths of length , so any algorithm that builds the flow path by path, writing each path down, spends time: the flow-decomposition barrier in the title of Goldberg and Rao's 1998 paper "Beyond the flow decomposition barrier". Orlin's meets it; going below requires algorithms that never list paths one at a time.
After computing a maximum flow, let be the vertices reachable from in the residual graph, and the vertices from which is reachable. When is the minimum cut unique?
- Always: a maximum flow determines its minimum cut
- Exactly when
- Exactly when every edge leaving is saturated
- Exactly when all capacities are distinct
Show the answer
B. Exactly when
is the source side of the minimum cut with the smallest source side, and the source side of the one with the largest; every minimum cut's source side lies between them. They coincide iff no vertex is left over, iff . On the widget's ladder network, many vertices are reachable from neither side, and it has 15 minimum cuts.
Edmonds–Karp: O(nm) augmentations
(a) Suppose an augmentation changes into and some distances shrink; let be such a vertex with the smallest new distance , and its predecessor on a shortest path in . Then , and by the choice of , .
If the arc was already in , then , a contradiction. So is new: the augmentation pushed flow along , which lay on a shortest path, so . Then
which contradicts . (b) When is critical it lies on a shortest path, so , and it disappears. It can reappear only after some later augmentation, with flow , pushes flow back along on a shortest path, and by (a):
So between two critical moments of , the distance of grows by at least 2, and it stays below while is reachable. Each arc is critical at most times; with at most arcs and one breadth-first search of per augmentation:
Which sequence of path lengths (numbers of arcs) can Edmonds–Karp not produce on any network?
- 3, 3, 4, 5
- 2, 2, 2, 2
- 3, 4, 3, 5
- 5, 7, 7
Show the answer
C. 3, 4, 3, 5
By part (a), the distance from to never decreases, and each augmenting path has exactly that length, so the lengths are non-decreasing. On the widget's classic network, Edmonds–Karp's lengths are 3, 3, 4, 5.
Other ways to tame the capacities: Edmonds and Karp also analyzed the fattest augmenting path, which needs augmentations for integer capacities up to , and capacity scaling augments only along paths of residual capacity at least , halving from the largest power of 2 down to 1, for in all. These bounds are weakly polynomial: they depend on . Edmonds–Karp's is strongly polynomial: it depends on and only.
Dinic: level graphs and blocking flows
(a) After the blocking flow, the only new residual arcs are back edges, which go one level up. A path in the new residual graph of the old length would have to use only level-increasing arcs of , so it would be a path of , and each of those contains a saturated arc. So the new distance exceeds .
(b) A depth-first search from advances along each vertex's current arc. If the search dead-ends at a vertex, the current arc into it is useless for the rest of the phase and the pointer moves on: at most such retreats per phase. Each search that reaches costs and saturates an arc, at most times:
(c) On a unit network each vertex carries at most one unit, so a residual flow decomposes into vertex-disjoint paths. After phases every augmenting path has more than vertices, so at most units remain, and each further phase adds at least one. A unit-capacity blocking flow takes , since every arc is used once:
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
using namespace std;
struct Dinic {
struct Edge { int to; long long cap; };
vector<Edge> e; // edge i and its reverse i ^ 1
vector<vector<int>> g;
vector<int> level, it;
Dinic(int n) : g(n), level(n), it(n) {}
void add_edge(int u, int v, long long c) {
g[u].push_back(e.size()); e.push_back({v, c});
g[v].push_back(e.size()); e.push_back({u, 0});
}
bool bfs(int s, int t) { // levels in the residual graph
fill(level.begin(), level.end(), -1);
queue<int> q; q.push(s); level[s] = 0;
while (!q.empty()) {
int u = q.front(); q.pop();
for (int id : g[u])
if (e[id].cap > 0 && level[e[id].to] < 0) {
level[e[id].to] = level[u] + 1; q.push(e[id].to);
}
}
return level[t] >= 0;
}
long long dfs(int u, int t, long long f) { // one path of the level graph
if (u == t) return f;
for (int &i = it[u]; i < (int)g[u].size(); ++i) { // current-arc pointer
Edge &ed = e[g[u][i]];
if (ed.cap > 0 && level[ed.to] == level[u] + 1) {
long long d = dfs(ed.to, t, min(f, ed.cap));
if (d > 0) { ed.cap -= d; e[g[u][i] ^ 1].cap += d; return d; }
}
}
return 0; // dead end: the pointer stays past it
}
long long max_flow(int s, int t) {
long long flow = 0;
while (bfs(s, t)) { // one phase per BFS
fill(it.begin(), it.end(), 0);
while (long long f = dfs(s, t, LLONG_MAX)) flow += f; // blocking flow
}
return flow;
}
};The contest standard. it[u] is the current-arc pointer: it is taken by reference, so arcs that lead nowhere are skipped for the rest of the phase. long long capacities avoid overflow when flows add up; on the classic network, max_flow returns 16.
Push-relabel, and seventy years of bounds
Push-relabel (Goldberg & Tarjan, 1988) drops the conservation constraint while it works. A preflow lets a vertex hold an excess of inflow over outflow. Each vertex has a height , with and fixed. An active vertex (one with excess) pushes along a residual arc that goes exactly one step down, ; if it has no such arc, it is relabeled to one more than its lowest residual neighbor. Start by saturating every edge out of , and stop when no vertex other than and has excess.
In practice, push-relabel with two heuristics, periodic global relabeling by a backward breadth-first search from and the gap heuristic, is among the fastest general max-flow codes (Cherkassky & Goldberg, 1997), while on the grid graphs of computer vision the Boykov–Kolmogorov augmenting-path algorithm is the usual choice.
| Year | Algorithm | Time |
|---|---|---|
| 1956 | Ford–Fulkerson (integer capacities) | |
| 1970 | Dinic: blocking flows | |
| 1972 | Edmonds–Karp: shortest augmenting paths | |
| 1974 | Karzanov: preflows | |
| 1981–83 | Sleator–Tarjan: blocking flows with dynamic trees | |
| 1986–88 | Goldberg–Tarjan: push-relabel with dynamic trees | |
| 1994 | King, Rao & Tarjan | |
| 1998 | Goldberg–Rao: binary blocking flows (capacities up to ) | |
| 2013 | Orlin | , strongly polynomial |
| 2022 | Chen, Kyng, Liu, Peng, Probst Gutenberg & Sachdeva | (polynomially bounded integer capacities) |
Key takeaways
- Maximum flow is a linear program whose dual is a fractional cut; threshold rounding of the dual potentials yields an integral cut, which is max-flow min-cut again. The minimum cut is unique iff every vertex is reachable from or reaches in the final residual graph.
- Every flow decomposes into at most paths and cycles, which is why path-by-path algorithms face an barrier.
- Edmonds–Karp: residual distances never decrease and each arc is critical at most times, so at most augmentations and time, whatever the capacities.
- Dinic: at most phases of blocking flows, ; on unit networks phases and . Push-relabel keeps a height invariant that forbids augmenting paths: , with FIFO order.
- The strongly polynomial record is Orlin's (2013); below it, only algorithms that do not build the flow path by path, such as the 2022 almost-linear-time algorithm, have broken through.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
In the analysis of Edmonds–Karp, why can a residual arc be critical (the bottleneck that empties it) only times?
- Because its capacity halves each time it is critical
- Because between two times it is critical, the distance from to grows by at least 2, and distances are below
- Because each vertex can be on at most augmenting paths
- Because breadth-first search visits each arc once
Show the answer
B. Because between two times it is critical, the distance from to grows by at least 2, and distances are below
When is critical, . It returns only after flow is pushed back along , on a shortest path, when . Distances never decrease and stay below while is reachable, so this happens at most about times.
Why does Dinic's algorithm need at most phases?
- Each phase saturates at least one edge of the original network for good
- Each phase settles one vertex, as in Dijkstra's algorithm
- Each phase at least halves the remaining flow
- After a blocking flow, the distance from to in the residual graph strictly increases, and it is at most
Show the answer
D. After a blocking flow, the distance from to in the residual graph strictly increases, and it is at most
Every shortest path of the old level graph contains a saturated arc, and the only new arcs are back edges that go up a level, so no path of the old length survives. Distances are integers between 1 and while is reachable.
Push-relabel keeps , and for every residual arc . What does that invariant guarantee?
- At every moment, the residual graph has no path from to
- Every push moves flow closer to in distance
- Every vertex's excess is at most 1
- The heights equal the residual distances to
Show the answer
A. At every moment, the residual graph has no path from to
A residual path from height down to height 0 would need at least arcs, one per unit of height, but a simple path has at most . So the preflow always has the property that defines a maximum flow; once the excesses are gone it is a flow, hence a maximum one. Push-relabel works from the opposite side of the theorem from augmenting paths.
Further reading
- E. A. Dinic, "Algorithm for solution of a problem of maximum flow in a network with power estimation," Soviet Mathematics Doklady 11 (1970), 1277–1280.
- J. Edmonds & R. M. Karp, "Theoretical improvements in algorithmic efficiency for network flow problems," Journal of the ACM 19(2) (1972), 248–264.
- A. V. Goldberg & R. E. Tarjan, "A new approach to the maximum-flow problem," Journal of the ACM 35(4) (1988), 921–940.
- J. B. Orlin, "Max flows in O(nm) time, or better," Proceedings of the 45th ACM Symposium on Theory of Computing (2013), 765–774.
- R. K. Ahuja, T. L. Magnanti & J. B. Orlin, Network Flows: Theory, Algorithms, and Applications (Prentice Hall, 1993).