Karger’s Min-Cut Algorithm
Random edge contractions, and the Karger–Stein speedup.
Pick a random edge, merge its two endpoints, and repeat until only two vertices remain. The edges still running between them form a cut, and with probability at least it is a minimum cut. That is Karger's whole algorithm (1993), and the same calculation proves something purely deterministic: no graph has more than minimum cuts.
What you’ll learn
- Define global minimum cuts and edge contraction in multigraphs, and implement one contraction run in near-linear time with a random edge order and union-find.
- Prove that a fixed minimum cut survives contraction with probability at least , deduce that a graph has at most minimum cuts, and compute the repetitions needed for a target error.
- Analyze Karger and Stein's recursive contraction: per run, success , and for high probability.
- Place the contraction algorithms among flow-based, deterministic and near-linear-time minimum-cut algorithms, up to the deterministic near-linear algorithm for weighted graphs (2024).
Global minimum cuts and contraction
With flows, a global minimum cut costs maximum-flow computations: fix a vertex and try every other vertex as the sink, since some sink lies on the other side of the best cut (max-flow min-cut). Karger's contraction algorithm uses no flows at all: contract a uniformly random edge, times, and return the edges between the two super-vertices that remain.
Two facts make it work. Every cut of a contracted graph is a cut of (a super-vertex is a set of original vertices), so contraction never creates a cut smaller than . And a cut of survives as long as none of its edges has been contracted.
import random
def contract(n, edges, t=2):
"""Contract uniformly random edges of a multigraph on 0..n-1 until t super-vertices remain.
Returns (t, the edges between super-vertices, relabeled 0..t-1)."""
parent = list(range(n))
def find(x): # union-find with path halving
while parent[x] != x:
parent[x] = parent[parent[x]]
x = parent[x]
return x
order = edges[:]
random.shuffle(order) # random order = a random remaining edge each time
groups = n
for u, v in order:
if groups <= t:
break
ru, rv = find(u), find(v)
if ru != rv: # an edge inside a super-vertex is a self-loop: skip
parent[ru] = rv
groups -= 1
label = {}
for x in range(n):
label.setdefault(find(x), len(label))
return len(label), [(label[find(u)], label[find(v)]) for u, v in edges if find(u) != find(v)]One run of Karger's algorithm is len(contract(n, edges)[1]). Processing the edges in a uniformly random order and skipping self-loops picks, at every step, a uniformly random remaining edge, so a run is Kruskal's algorithm with random weights, stopped at two components: for the shuffle plus near-linear union-find work.
How lucky must a run be? On a "barbell" of two complete graphs on 5 vertices joined by one bridge (, ), the bound proved next guarantees success with probability only . In 100,000 simulated runs the bridge survived about half the time: most edges lie inside the dense halves, so the bridge is rarely picked. The bound is a worst case, and the next step shows where it is tight.
Why a minimum cut survives
Let . A single vertex against the rest is a cut, so every vertex has degree at least , and the graph has at least edges. The first contraction picks an edge of with probability at most
Suppose has survived contractions. The current graph has super-vertices, is still one of its cuts, and its minimum cut is still , so every super-vertex has degree at least and there are at least edges. Hence
Multiply the survival probabilities of the contractions; the product telescopes:
To succeed with high probability, repeat independently and keep the smallest cut found. With success probability per run and , runs all fail with probability at most ; runs push that to . At per run that is time, up to on dense graphs: simple, but slow.
For a graph with vertices, using with , how many independent runs guarantee a failure probability of at most ?
Show the answer
104
, so you need , that is : 104 runs. (Solving exactly gives 103.) On a typical graph far fewer suffice, but the guarantee must hold for every graph, cycles included.
Karger–Stein: contract less, branch more
Look at where the risk is. The first contraction hits with probability at most , the last one with probability up to . Repeating the whole run times repeats the safe early phase as often as the dangerous late one. Karger and Stein (1996) share the early phase: contract once down to about vertices, then branch into two independent recursive runs on the smaller graph, and keep the better answer.
Stopping the product of the previous proof at vertices gives the survival probability of a fixed minimum cut down to vertices. With , both and are at least :
Time. Contracting a graph on vertices to costs (with an adjacency matrix of edge multiplicities). Recursion depth has calls on about vertices, which is per level, over levels:
Success. A call succeeds if the cut survives its contraction (probability at least ) and the child call then succeeds, for at least one of the two children. Writing for a lower bound on the success of a call levels above the base case, where :
By induction : the map is increasing on , and because . The depth is , so one run succeeds with probability , and runs succeed with probability :
import math
def karger_stein(n, edges):
if n <= 6: # small: try every bipartition
return min(sum(1 for u, v in edges if (mask >> u & 1) != (mask >> v & 1))
for mask in range(1, 1 << (n - 1)))
t = math.ceil(1 + n / math.sqrt(2)) # a fixed minimum cut survives to here w.p. >= 1/2
return min(karger_stein(*contract(n, edges, t)) for _ in range(2))Uses contract from above, which contracts to super-vertices and relabels them. On two complete graphs of 20 vertices joined by 3 edges (, , minimum cut 3), one plain contraction run succeeded about 50% of the time in simulation, and one Karger–Stein run 99.75% of the time (400 runs).
Why does Karger–Stein contract to about vertices before branching, rather than to ?
- Because is the largest size at which the graph still fits in memory
- Because then a fixed minimum cut survives the shared phase with probability at least , which two independent branches can compensate, while the work per recursion level stays
- Because contracting to would change the minimum cut
- Because makes the recursion depth constant
Show the answer
B. Because then a fixed minimum cut survives the shared phase with probability at least , which two independent branches can compensate, while the work per recursion level stays
Survival to vertices is about , so gives : two branches then keep the success probability from collapsing (it falls only like ). Contracting to would leave survival near , and two branches could not compensate: the success probability would shrink polynomially in .
Deterministic, near-linear, and open
| Algorithm | Kind | Time |
|---|---|---|
| maximum flows from a fixed source | deterministic | max-flow computations |
| Nagamochi & Ibaraki (1992); Stoer & Wagner (1997) | deterministic, no flows: maximum-adjacency orderings | |
| Karger (1993): repeated contraction | Monte Carlo | for success , as above |
| Karger & Stein (1996): recursive contraction | Monte Carlo | |
| Karger (2000): tree packing and 2-respecting cuts | Monte Carlo | |
| Gawrychowski, Mozes & Weimann (2019) | Monte Carlo | |
| Kawarabayashi & Thorup (2015) | deterministic, simple unweighted graphs | near-linear, |
| Li (2021) | deterministic, weighted | |
| Henzinger, Li, Rao & Wang (2024) | deterministic, weighted | near-linear, |
Contraction also counts. Rerun the survival argument for cuts of size at most and it shows there are only of them, a structural fact used to sparsify graphs while preserving all cuts approximately and to estimate the probability that a network with randomly failing links disconnects. And it parallelizes: Karger's 1993 paper put global minimum cut in the class RNC, randomized polylogarithmic time on polynomially many processors.
None of this finds an – cut, by design: a random contraction may merge with . For a prescribed source and sink, use maximum flow (see Max-Flow Min-Cut in Depth).
Key takeaways
- Karger's contraction algorithm merges the endpoints of random edges until two super-vertices remain; a run is Kruskal's algorithm on random weights stopped at two components, near-linear time with union-find.
- A fixed minimum cut survives with probability at least , because a graph with minimum cut has at least edges; hence no graph has more than minimum cuts, and the cycle shows the bound is tight.
- Karger–Stein contracts once to about vertices, where a minimum cut survives with probability at least , then recurses twice: per run, success , for high probability.
- Global minimum cut now runs in near-linear time, randomized () and deterministic (Henzinger, Li, Rao & Wang, 2024); linear time and simple deterministic algorithms remain open, and – cuts still need flows.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
The proof needs at least edges in a graph with minimum cut . Where does that come from?
- From Euler's formula for planar graphs
- Every vertex alone forms one side of a cut, so every degree is at least , and the degrees sum to
- Every edge lies on some minimum cut
- Contraction doubles the number of parallel edges
Show the answer
B. Every vertex alone forms one side of a cut, so every degree is at least , and the degrees sum to
The cut has size , which cannot be below the minimum . Summing over all vertices, . The same holds after contractions, with super-vertices in place of vertices.
How many minimum cuts does the cycle on 6 vertices have?
- 6
- 15
- 30
- 31
Show the answer
B. 15
The minimum cut has size 2, and removing any 2 of the 6 edges splits the cycle into two arcs, a different cut for each pair: . That meets Karger's upper bound exactly, so the bound cannot be improved.
You need the smallest cut separating a given source from a given sink . Is Karger's algorithm the right tool?
- Yes: run it until the two remaining super-vertices contain and
- No: a random contraction can merge with , and the global minimum cut may not separate them; use maximum flow
- Yes, after giving the edges at and infinite multiplicity
- No, because Karger's algorithm works only on simple graphs
Show the answer
B. No: a random contraction can merge with , and the global minimum cut may not separate them; use maximum flow
Karger's analysis is about the global minimum cut. The best – cut can be much larger than , and contracting random edges gives it no special protection, so its survival probability has no useful bound. Max-flow min-cut solves the – problem exactly in polynomial time.
Further reading
- D. R. Karger, "Global min-cuts in RNC, and other ramifications of a simple min-cut algorithm," Proceedings of the 4th ACM-SIAM Symposium on Discrete Algorithms (SODA) (1993), 21–30.
- D. R. Karger & C. Stein, "A new approach to the minimum cut problem," Journal of the ACM 43(4) (1996), 601–640.
- M. Stoer & F. Wagner, "A simple min-cut algorithm," Journal of the ACM 44(4) (1997), 585–591.
- D. R. Karger, "Minimum cuts in near-linear time," Journal of the ACM 47(1) (2000), 46–76.
- M. Henzinger, J. Li, S. Rao & D. Wang, "Deterministic near-linear time minimum cut in weighted graphs," Proceedings of SODA (2024), 3089–3139.