Sub topic 16
Where to Go Next: Dinic and Push-Relabel
This chapter assumes you know the residual graph, augmenting paths, and the O(V E^2) analysis of Edmonds-Karp from earlier chapters. It gives a short tour of two faster algorithms so you know when to use them and what to read next.
Why Look Beyond Edmonds-Karp?
Edmonds-Karp runs one BFS for each augmenting path, and each path may carry only a small amount of flow. On dense graphs or large contest inputs, O(V E^2) is too slow. Both algorithms below avoid paying for a separate search for each path.
Dinic's Algorithm
Dinic's algorithm keeps the Edmonds-Karp idea of shortest paths but handles all of them at the same length in one batch.
- Run BFS from the source in the residual graph to give each vertex a level, its distance from s.
- Keep only edges that go from level i to level i + 1. This is the level graph.
- Use DFS to push a blocking flow through the level graph. A blocking flow is a flow in which every s-t path in the level graph has at least one saturated edge.
- Repeat until BFS cannot reach the sink.
After each phase, the distance from s to t in the residual graph strictly increases. That distance can never exceed V - 1, so there are at most V - 1 phases. With a per-vertex "current edge" pointer, the DFS never retries an edge that has already failed. This makes one blocking flow cost O(V E), and the total is O(V^2 E).
Push-Relabel
Push-relabel (Goldberg-Tarjan) does not search for paths at all. It works locally on one vertex at a time.
- It keeps a preflow. A preflow may break conservation: a vertex can have more flow coming in than going out. The surplus is that vertex's excess.
- Each vertex has a height label. The source starts at height V and every other vertex at 0. The source saturates all of its outgoing edges at the start.
- Push: if vertex u has excess and a residual edge to a vertex v exactly one level lower, send min(excess, residual capacity) along that edge.
- Relabel: if u has excess but no such edge exists, raise u's height to one more than its lowest residual neighbor.
Excess flows downhill toward the sink. Any excess that cannot reach t eventually rises above height V and drains back to s. When no vertex other than s and t has excess, the preflow is a valid maximum flow.
The generic version runs in O(V^2 E). The FIFO selection rule gives O(V^3), and the highest-label rule gives O(V^2 √E). In practice, the global relabeling heuristic (periodically recomputing heights with a BFS backward from t) and the gap heuristic make push-relabel very fast on large, dense graphs.
Choosing an Algorithm
| Algorithm | Worst-case time | Good fit |
|---|---|---|
| Edmonds-Karp | O(V E^2) | Small graphs, teaching, simple code |
| Dinic | O(V^2 E); O(E √V) on unit networks | Contests, matching, most general use |
| Push-relabel (highest-label) | O(V^2 √E) | Large dense graphs, production solvers |
Further Reading
- CLRS, Introduction to Algorithms, the chapter on maximum flow, which covers push-relabel in detail.
- Dinic's original 1970 paper, and Even's account of the algorithm.
- Goldberg and Tarjan, "A New Approach to the Maximum-Flow Problem" (1988).
Exercise
In Dinic's algorithm, why can there be at most V - 1 phases?
Show answer
Each phase saturates at least one edge on every shortest s-t path in the level graph, so the next BFS finds a strictly longer shortest path. A simple path has at most V - 1 edges, so the s-t distance can increase at most V - 1 times before the sink becomes unreachable.
Exercise
In push-relabel, vertex u has excess 5 and height 3. Its residual edges go to v (height 3, residual capacity 4) and w (height 6, residual capacity 2). Which operation applies, and what is u's new state?
Show answer
No push is allowed, because neither neighbor is exactly one level lower than u. Relabel u to 1 + min(3, 6) = 4. Now u can push min(5, 4) = 4 units to v, which leaves u with excess 1.