Quick Read. A Gomory–Hu tree compresses the minimum-cut information of an undirected capacitated graph into a weighted tree on the same vertices. The beginner should learn the surprising claim: one tree can answer every pairwise minimum-cut value. The intermediate learner should understand why the minimum edge on the tree path between two vertices gives their minimum-cut value. The advanced learner should understand the n−1 max-flow construction and how partitions update parent relationships. The professional should understand undirected-only assumptions, flow-engine choices, cut recovery, complexity, validation and when the tree is worth building.
One-sentence answer
A Gomory–Hu tree is a cut-equivalent weighted tree for an undirected capacitated graph: for any vertices s and t, the minimum s–t cut value in the original graph equals the minimum edge weight on the unique s–t path in the tree, and the classical construction needs only n−1 minimum-cut/max-flow computations.
Why this is such a powerful algorithmic idea
An undirected graph with n vertices contains n(n−1)/2 unordered vertex pairs. If you want the minimum cut between every pair, the obvious approach is to run a separate max-flow/min-cut computation for every pair. That is quadratic many expensive flow problems.
Gomory and Hu showed something much stronger: the pairwise minimum-cut values contain enough structure that they can be represented by just n−1 weighted tree edges. The classical construction finds that tree with only n−1 flow computations. This is a beautiful example of algorithmic compression: not compressing the input data, but compressing the answers to a huge family of related optimization queries.
Level 1 — Beginner: understand the query the tree answers
Suppose a weighted tree contains vertices A, B, C and D. There is exactly one path between A and D. Imagine the edge weights along that path are 8, 3 and 7. The minimum edge weight is 3. In a Gomory–Hu tree, that number is the minimum A–D cut capacity in the original graph.
Even more is true. If you remove that minimum-weight tree edge, the tree splits into two vertex sets. Those two sets describe a minimum cut separating A and D in the original graph. Thus the tree can give both a cut value and, with the appropriate edge partition, a cut itself.
First exercise: query a tree before building one
- Draw any weighted tree with five vertices.
- Choose six different vertex pairs.
- For each pair, trace the unique tree path.
- Record the minimum edge weight on that path.
- Remove one minimum edge and write the two resulting vertex sets.
This exercise teaches the interface of the data structure. You should understand what a Gomory–Hu tree guarantees before learning how it is constructed.
Level 2 — Intermediate: connect minimum cuts to maximum flows
By the max-flow min-cut theorem, the minimum s–t cut value equals the maximum s–t flow value in a capacitated network. For undirected graphs, each Gomory–Hu construction step chooses two vertices, computes one minimum cut between them using a max-flow routine, and uses the resulting partition to reorganise a partially built tree.
The important mental shift is that the flow computation returns more than a number. It returns a partition: one side contains s, the other contains t. That partition is what lets one flow computation inform relationships involving many other vertices.
A useful parent-array view of the classical construction
One common implementation labels vertices 0 through n−1 and maintains a parent array. Initially, every vertex except 0 may use 0 as its parent. Then for each vertex s from 1 onward, let t = parent[s]. Compute a minimum s–t cut. Let S be the side of the cut containing s, and let the cut value be λ.
Now inspect later vertices whose current parent is t. If such a vertex lies on s’s side of the cut, redirect its parent to s. Additional parent/cut-value adjustments handle the case where t itself currently hangs below another vertex that also lies on s’s side. The exact bookkeeping varies between presentations, but the central invariant is stable: every flow partition refines the partially constructed cut-equivalent tree.
A simplified pseudocode shape
gomory_hu_tree(G):
n = number of vertices
parent[v] = 0 for v = 1..n-1
value[v] = 0
for s in 1..n-1:
t = parent[s]
(cut_value, S, T) = minimum_cut(G, s, t)
value[s] = cut_value
for v in s+1..n-1:
if parent[v] == t and v in S:
parent[v] = s
perform required parent/value correction
when parent[t] lies on the S side
return tree edges (v, parent[v], value[v])
Do not implement from this skeleton alone. Its purpose is to expose the repeated pattern: choose a parent pair, compute one cut, use the cut partition to update many parent relations, and finally output one weighted tree edge per non-root vertex.
Level 3 — Advanced: the path-minimum invariant
The completed tree must satisfy a remarkable condition. Pick any s and t. Along their unique tree path, let e be an edge of minimum weight. Removing e splits the tree into two components that separate s from t. The weight of e equals the minimum s–t cut capacity in the original graph.
That means one edge can serve as the certificate for many vertex pairs. The information is highly shared. A tree has only n−1 edges, yet those edges collectively encode all pairwise minimum-cut values.
Why n−1 flow computations are enough
The construction does not solve each pair independently. Each minimum-cut partition rearranges the parent structure so that one new tree edge captures a cut relationship while also constraining many future relationships. After processing n−1 non-root vertices, the tree has exactly n−1 edges and the required cut-equivalence property.
This is the kind of result that changes how professionals frame a problem. Before optimizing n² queries individually, ask whether the answers possess structure that admits a smaller shared representation.
Correctness: what should you try to prove?
- The structure produced is a tree on the same vertex set.
- Each stored tree-edge weight corresponds to a minimum cut found during construction.
- Parent redirections preserve previously established cut relationships.
- For any pair s,t, the smallest edge on their tree path gives a cut that separates them in the original graph.
- No s–t cut can have smaller capacity than that path-minimum value.
The full proof is more subtle than the query rule, so learn it in layers. First prove the tree-query property assuming the final cut-equivalent tree exists. Then study how one construction iteration preserves the necessary partition relationships. Finally connect all iterations by induction.
Level 4 — Professional: the max-flow engine dominates practical cost
The classical algorithm performs n−1 minimum-cut computations, so practical performance depends heavily on the chosen flow routine and graph structure. Sparse and dense graphs, integer capacity ranges, memory limits and implementation language can change the best engineering choice. A mature library may let you supply or select the flow function used inside the Gomory–Hu construction.
- Graph must be undirected for the classical tree guarantee. Do not silently apply the same contract to arbitrary directed graphs.
- Capacities need clear semantics. Missing, infinite, zero and negative capacities require explicit policy; standard flow models assume nonnegative capacities.
- Disconnected graphs need attention. Some APIs reject them or encounter effectively infinite/undefined relationships depending on conventions.
- Cut values versus cut partitions. If you need the actual partition repeatedly, preserve enough information or reconstruct it from the relevant tree edge.
- Flow implementation. Edmonds–Karp, Dinic, push–relabel and specialised methods can differ enormously in practice.
- Reuse. If you will answer many pairwise cut queries, preprocessing a Gomory–Hu tree can amortise the expensive construction. For one pair, simply run one min-cut.
Querying the finished tree efficiently
For occasional queries, walk the tree path from s to t and take the minimum edge weight. For a large number of online queries, preprocess the tree for path-minimum queries using binary lifting or another lowest-common-ancestor/path-aggregation structure. Then the expensive original graph disappears from the query hot path.
This creates a two-stage architecture: expensive graph optimisation during preprocessing, then cheap tree queries afterward. That separation is common in professional algorithm systems.
A concrete example of information compression
With 1,000 vertices there are 499,500 unordered vertex pairs. A Gomory–Hu tree still contains only 999 edges. Those 999 weighted edges do not list every minimum cut separately; instead, each pair derives its value from the weakest edge on a tree path. The saving is conceptual as well as computational: the output itself exposes shared bottlenecks in the original network.
Testing ladder
- Tiny graphs: enumerate every vertex pair, compute direct min-cuts and compare with tree path minima.
- Trees as input: the cut behaviour is easy to reason about and provides simple expected answers.
- Complete graphs with equal capacities: exploit symmetry to catch parent-update mistakes.
- Graphs with one obvious bridge bottleneck: many pairwise queries should share the same minimum tree edge.
- Random small weighted graphs: compare every pair against an independent max-flow/min-cut implementation.
- Large sparse graphs: benchmark construction time by separating flow time from parent-update overhead.
Common misconceptions
- “A Gomory–Hu tree is a minimum spanning tree.” No. Its weights encode minimum-cut values, not minimum total connection cost.
- “The tree edges must exist in the original graph.” The cut-equivalent tree is a representation on the same vertices; its edges are not required to be original graph edges.
- “One tree edge represents only one pair.” A single bottleneck edge can determine the minimum cut value for many pairs whose tree paths cross it.
- “The method needs all-pairs max flow first.” The classical result is valuable precisely because n−1 flow computations suffice.
- “This works unchanged for directed graphs.” The classical Gomory–Hu cut tree is an undirected-graph result.
A learning route from beginner to professional
- Beginner: answer path-minimum queries on an already-built weighted tree.
- Intermediate: solve individual max-flow/min-cut problems and record the cut partitions, not just the values.
- Advanced: trace the parent-array construction on a five-vertex graph.
- Implementation: build the tree using a trusted flow routine, then verify every pair against direct min-cut on small graphs.
- Professional: benchmark different flow engines, add fast path-minimum query preprocessing, and measure the break-even point where preprocessing pays for itself.
For learning, predict the cut side before inspecting a solver’s result, explain each parent redirection in words, and reconstruct one iteration from shuffled steps. This keeps the core structure visible rather than reducing the method to opaque library calls.
When should you build a Gomory–Hu tree?
Build one when you have a mostly static undirected capacitated graph and expect many minimum-cut queries between different vertex pairs, or when the cut-equivalent tree itself provides useful insight into network bottlenecks. Do not build one for a single s–t query. Also reconsider it if the graph changes frequently, because updates can invalidate the precomputed cut structure.
Authoritative sources and further reading
- R. E. Gomory and T. C. Hu, Multi-Terminal Network Flows, 1961.
- Current NetworkX Gomory–Hu tree documentation, including the n−1 minimum-cut computation property and path-minimum query rule.
- For broader combinatorial optimisation context, see the University of Oxford’s Combinatorial Optimisation course materials, which include Gomory–Hu trees for s–t minimum cuts.
- For programming pedagogy, see current computing-education work on Parsons problems and adaptive Parsons scaffolding.
Closing idea. Gomory–Hu trees teach a professional habit: when a problem asks for a huge number of related answers, search for shared structure before repeating the expensive computation. Sometimes half a million pairwise questions are really one small tree waiting to be discovered.
