learngraphtheory.org

Guest

Sign in to keep your graphs and progress.

Cover of the book Graph Theory Through Problems

Practice book

Graph Theory Through Problems

300 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.

Available inKindlePaperback

13 chapters

Also by the authorGraph Algorithms for Coding Interviews100 solved interview problems with visual explanations and Python solutions.View on Amazon
Algorithm Selection

Select an algorithm and generate steps to begin visualization

Push-Relabel Max Flow Algorithm Visualizer

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

Time: O(V³) (FIFO)
Space: O(V + E)
Use Case: Large flow networks, image segmentation, bipartite matching
Showing the example graph for this algorithm.
Algorithm Execution

Select an algorithm and generate steps to begin visualization

About Push-Relabel (Goldberg-Tarjan)

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.

How it works

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.

Applications

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.

Pseudocode

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 flow

The 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.

Worked example, step by step

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.

  1. Preflow. A rises to height 6 and floods its edges: B and C now hold 29 between them, more than they can pass on.
  2. First pushes. B is relabelled to height 1 and pushes 12 to D. B still overflows, has no lower neighbour, rises to 7 (above A) and returns 4 to the source.
  3. Towards the sink. C pushes 13 to E, D and E are relabelled to 1 and push 12 and 4 into the sink F.
  4. Back and forth. E cannot pass its remaining excess on and climbs, sending flow back to C, then to D. The heights of C and E rise step by step as they push excess around.
  5. Return. C finally rises to 7, above the source, and returns its last 2 units to A. No vertex overflows any more.

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.

Complexity, and where it comes from

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).

When to use Push-Relabel (Goldberg-Tarjan), and when not to

Maximum flow has several classic algorithms. They differ in how much they look at at once.

AlternativePrefer it whenCost
Edmonds-KarpSimple to write and explain: shortest augmenting paths by BFS.O(V·E²)
DinicBlocking 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)

Common pitfalls

  • Treating the preflow as a flow. Until no vertex overflows, flow is not conserved at every vertex. The flow value is only the excess of the sink once the queue is empty.
  • Pushing uphill or sideways. A push is allowed only when h(u) = h(v) + 1. Pushing to an equal or higher vertex breaks the height invariant and the proof of maximality.
  • Relabelling by the wrong amount. The new height is exactly one more than the lowest residual neighbour. Rising by 1 only wastes steps, rising further breaks the height rule.

Frequently asked questions

What is a preflow?
An assignment of flow to edges that respects capacities, where each vertex other than the source may receive more than it sends. The difference is its excess.
Why does excess go back to the source?
Excess that cannot reach the sink keeps relabelling its vertex until it is higher than the source (height n), and then it may be pushed back along the edges it came through.
Is push-relabel faster than Ford-Fulkerson?
In the worst case yes: its bounds do not depend on the capacities. In practice, well-tuned push-relabel codes are among the fastest for large networks.
How is the minimum cut found?
From the final residual graph: the vertices the source can still reach through spare capacity form one side. The edges leaving that side are saturated and add up to the flow value.

Related algorithms: Maximum Flow, Dinic's Algorithm, Minimum Cut, Min-Cost Max Flow, Hopcroft-Karp Matching

An example graph: you can change it, or start blank.

Zoom Controls

30%
Nodes: 6
Edges: 9