The global minimum cut is the cheapest way to split a graph into two non-empty parts — minimised over all pairs, not a fixed and .
Naive: fix one endpoint
Fix any vertex ; the min cut separates from some . So max-flow runs suffice: . Correct, but wasteful.
Stoer-Wagner — the one to write
, deterministic, about 30 lines. See Stoer-Wagner.
The idea. Build a maximum adjacency ordering : repeatedly add the vertex most strongly connected to the already-chosen set. Then the cut vs the rest is a minimum - cut. Record its weight, merge and , and repeat times. The best cut seen is the global minimum.
// O(n^3) adjacency-matrix version; fine for n <= 500
pair<long long, vector<int>> stoerWagner(vector<vector<long long>> w) {
int n = w.size();
vector<vector<int>> group(n);
for (int i = 0; i < n; i++) group[i] = {i};
vector<int> alive(n); iota(alive.begin(), alive.end(), 0);
long long best = LLONG_MAX; vector<int> bestGroup;
while (alive.size() > 1) {
vector<long long> wsum(n, 0);
vector<bool> added(n, false);
int prev = -1, last = -1;
for (size_t i = 0; i < alive.size(); i++) {
int sel = -1;
for (int v : alive)
if (!added[v] && (sel == -1 || wsum[v] > wsum[sel])) sel = v;
added[sel] = true;
prev = last; last = sel;
for (int v : alive) if (!added[v]) wsum[v] += w[sel][v];
}
if (wsum[last] < best) { best = wsum[last]; bestGroup = group[last]; }
// merge last into prev
for (int v : alive) { w[prev][v] += w[last][v]; w[v][prev] = w[prev][v]; }
group[prev].insert(group[prev].end(), group[last].begin(), group[last].end());
alive.erase(find(alive.begin(), alive.end(), last));
}
return {best, bestGroup};
}The algorithms
| Algorithm | Time | Type |
|---|---|---|
| max flows | deterministic | |
| Stoer-Wagner | deterministic — use this | |
| Nagamochi-Ibaraki | deterministic | |
| Karger | randomized | |
| Karger-Stein | randomized | |
| Karger 2000 (tree packing) | randomized, near-linear | |
| Reif (planar) | planar graphs only |
Directed graphs
Everything above assumes undirected. For a directed global min cut, fix a vertex and compute over all — max-flow runs. Stoer-Wagner does not apply.
Gomory-Hu tree — all pairs at once
The Gomory-Hu tree is a weighted tree on the same vertices such that, for every pair , the minimum - cut equals the minimum edge weight on their tree path. It is built with only max-flow computations, and after that all pairwise min cuts are path-min queries — a remarkable compression.
Counting min cuts
Karger’s analysis implies a graph has at most distinct global minimum cuts, and this is tight (a cycle achieves it). More generally, the number of cuts within a factor of the minimum is .
Typical problems
- “Minimum cost to split a network into two pieces”
- Clustering / community detection
- Network reliability — the min cut is the bottleneck against failure
- Edge connectivity — the global min cut with unit capacities
See also: Minimum Cut · Stoer-Wagner · Gomory-Hu