Guest
Sign in to keep your graphs and progress.

Practice book
Graph Theory Through Problems300 Exercises with Hints, Worked Algorithms and Complete Solutions
By Mohammed Islam Hadjoudj
Learn graph theory by solving problems: 300 exercises, from routine checks to challenging proofs, each with a complete solution.
Also by the authorGraph Algorithms for Coding Interviews100 solved interview problems with visual explanations and Python solutions.View on AmazonSelect an algorithm and generate steps to begin visualization
Maximum flow, one edge and one height at a time
Maximum flow without augmenting paths: overflowing vertices push flow downhill one edge at a time and are lifted when they are stuck
Select an algorithm and generate steps to begin visualization
Push-relabel computes a maximum flow, like Ford-Fulkerson and Dinic, but it never looks for whole augmenting paths. Goldberg and Tarjan (1986) let vertices overflow: the source first floods every edge out of it, creating a preflow in which vertices may hold more than they pass on. Each vertex has a height, and flow only moves downhill, one level per edge. Overflowing vertices push their excess to lower neighbours, and when they have none they are lifted. When no vertex overflows any more, the preflow is a maximum flow.
The source starts at height n, every other vertex at 0, and every edge out of the source is saturated. While some vertex u other than the source and sink has excess, it looks for a residual edge u → v with h(u) = h(v) + 1. If there is one it pushes min(excess, residual capacity) along it. If not, it relabels: h(u) becomes one more than the lowest neighbour it still has spare capacity to. Excess that cannot reach the sink eventually climbs above the source and flows back to it. The FIFO version processes overflowing vertices in queue order and runs in O(V³). The visualizer shows each vertex's height (top right, with old → new on a relabel), its excess (bottom left) and its place in the queue (bottom right), and ends with the minimum cut.
Push-relabel is the method of choice in many practical max-flow codes, especially with heuristics such as global relabelling and gap detection. It is used for image segmentation by graph cuts, for bipartite matching and assignment, for network reliability and in scheduling. Because each operation is local to one vertex and its edges, it also parallelises better than augmenting-path methods.
A preflow first, then a queue of overflowing vertices that push or relabel until the queue is empty.
PushRelabel(G, s, t):
h[s] = n, h[v] = 0 for every other vertex
for each edge s → v: push its full capacity // the preflow
queue = vertices other than s, t with excess > 0
while queue is not empty:
u = front of queue
while excess[u] > 0:
if some residual edge u → v has h[u] == h[v] + 1:
push min(excess[u], residual(u, v)) along it
if v gained excess and v is not s or t: enqueue v
else:
h[u] = 1 + min h[v] over residual edges u → v // relabel
dequeue u
return excess[t] // the maximum flowThe heights are a valid labelling: a residual edge never goes down more than one level. That is why the source at height n has no path to the sink in the residual graph, and why the final flow is maximum.
The same network as the max-flow and Dinic pages, from A to F.
Example graph: Six vertices A to F, with capacities on the edges. The source A has edges of capacity 29 in all, more than the network can carry.
Maximum flow 23 after 13 pushes and 11 relabels, the same value as Edmonds-Karp and Dinic on this network. The highlighted edges form the minimum cut.
Time: O(V³) for the FIFO version · Space: O(V + E)
Heights never decrease and stay below 2V, so there are O(V²) relabels. Saturating pushes are O(V·E). The FIFO order bounds the non-saturating pushes by O(V³), which dominates. The generic version with any order is O(V²·E), and the highest-label rule gives O(V²·√E).
Maximum flow has several classic algorithms. They differ in how much they look at at once.
| Alternative | Prefer it when | Cost |
|---|---|---|
| Edmonds-Karp | Simple to write and explain: shortest augmenting paths by BFS. | O(V·E²) |
| Dinic | Blocking flows in a level graph. Very fast on unit-capacity graphs and bipartite matching. | O(V²·E) |
| Push-relabel (highest label) | Large dense networks, especially with global relabelling and gap heuristics. | O(V²·√E) |
Read the full article: Max-Flow Min-Cut Theorem & Network Flow
Read the full article: Max-Flow & Min-Cut Interview Questions
Related algorithms: Maximum Flow, Dinic's Algorithm, Minimum Cut, Min-Cost Max Flow, Hopcroft-Karp Matching