Simple Algorithm
Algorithms & Data Structures · Optimal · 26 min

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 2/(n(n−1))2/(n(n-1)) 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 (n2)\binom{n}{2} 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 2/(n(n−1))2/(n(n-1)), deduce that a graph has at most (n2)\binom n2 minimum cuts, and compute the repetitions needed for a target error.
  • Analyze Karger and Stein's recursive contraction: O(n2log⁡n)O(n^2 \log n) per run, success Ω(1/log⁡n)\Omega(1/\log n), and O(n2log⁡3n)O(n^2 \log^3 n) 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 n−1n - 1 maximum-flow computations: fix a vertex ss 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, n−2n - 2 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 GG (a super-vertex is a set of original vertices), so contraction never creates a cut smaller than λ(G)\lambda(G). And a cut of GG survives as long as none of its edges has been contracted.

python
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: O(m)O(m) 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 (n=10n = 10, m=21m = 21), the bound proved next guarantees success with probability only 2/90≈0.0222/90 \approx 0.022. 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

DerivationProof
  1. km  ≤  knk/2  =  2n\frac{k}{m} \;\le\; \frac{k}{nk/2} \;=\; \frac{2}{n}

    Let k=∣C∣=λ(G)k = \abs{C} = \lambda(G). A single vertex against the rest is a cut, so every vertex has degree at least kk, and the graph has at least nk/2nk/2 edges. The first contraction picks an edge of CC with probability at most

  2. Pr⁡[contraction i+1 hits C ∣ C survived i]  ≤  2n−i\Pr\big[\text{contraction } i+1 \text{ hits } C \,\big|\, C \text{ survived } i\big] \;\le\; \frac{2}{n-i}

    Suppose CC has survived ii contractions. The current graph has n−in - i super-vertices, CC is still one of its cuts, and its minimum cut is still kk, so every super-vertex has degree at least kk and there are at least (n−i)k/2(n-i)k/2 edges. Hence

  3. Pr⁡[C survives]  ≥  ∏i=0n−3(1−2n−i)  =  ∏j=3nj−2j  =  (n−2)!n!/2  =  2n(n−1)\Pr[C \text{ survives}] \;\ge\; \prod_{i=0}^{n-3}\Big(1 - \frac{2}{n-i}\Big) \;=\; \prod_{j=3}^{n}\frac{j-2}{j} \;=\; \frac{(n-2)!}{n!/2} \;=\; \frac{2}{n(n-1)}

    Multiply the survival probabilities of the n−2n - 2 contractions; the product telescopes:

To succeed with high probability, repeat independently and keep the smallest cut found. With success probability p=(n2)−1p = \binom n2^{-1} per run and 1−p≤e−p1 - p \le e^{-p}, TT runs all fail with probability at most e−pTe^{-pT}; T=(n2)ln⁡nT = \binom n2 \ln n runs push that to 1/n1/n. At O(m)O(m) per run that is O(n2mlog⁡n)O(n^2 m \log n) time, up to O(n4log⁡n)O(n^4 \log n) on dense graphs: simple, but slow.

Predict before you look

For a graph with n=10n = 10 vertices, using (1−p)T≤e−pT(1 - p)^T \le e^{-pT} with p=1/(102)p = 1/\binom{10}{2}, how many independent runs guarantee a failure probability of at most 1/101/10?

Show the answer

104

p=1/45p = 1/45, so you need e−T/45≤1/10e^{-T/45} \le 1/10, that is T≥45ln⁡10≈103.6T \ge 45 \ln 10 \approx 103.6: 104 runs. (Solving (1−1/45)T≤1/10(1 - 1/45)^T \le 1/10 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 CC with probability at most 2/n2/n, the last one with probability up to 2/32/3. Repeating the whole run (n2)ln⁡n\binom n2 \ln n 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 n/2n/\sqrt2 vertices, then branch into two independent recursive runs on the smaller graph, and keep the better answer.

DerivationAnalysis of recursive contraction
  1. Pr⁡[C survives to t vertices]  ≥  ∏j=t+1nj−2j  =  t(t−1)n(n−1)  ≥  n2/2n2  =  12\Pr[C \text{ survives to } t \text{ vertices}] \;\ge\; \prod_{j=t+1}^{n}\frac{j-2}{j} \;=\; \frac{t(t-1)}{n(n-1)} \;\ge\; \frac{n^2/2}{n^2} \;=\; \frac12

    Stopping the product of the previous proof at tt vertices gives the survival probability of a fixed minimum cut down to tt vertices. With t=⌈1+n/2 ⌉t = \lceil 1 + n/\sqrt2\, \rceil, both tt and t−1t - 1 are at least n/2n/\sqrt2:

  2. T(n)  =  2 T(⌈1+n/2 ⌉)+O(n2)  =  O(n2log⁡n)T(n) \;=\; 2\,T\big(\lceil 1 + n/\sqrt2\,\rceil\big) + O(n^2) \;=\; O(n^2 \log n)

    Time. Contracting a graph on nn vertices to tt costs O(n2)O(n^2) (with an adjacency matrix of edge multiplicities). Recursion depth ii has 2i2^i calls on about n/2 in/\sqrt2^{\,i} vertices, which is O(n2)O(n^2) per level, over log⁡2n=2log⁡2n\log_{\sqrt2} n = 2\log_2 n levels:

  3. pd+1  =  1−(1−pd2)2  =  pd−pd24p_{d+1} \;=\; 1 - \Big(1 - \frac{p_d}{2}\Big)^2 \;=\; p_d - \frac{p_d^2}{4}

    Success. A call succeeds if the cut survives its contraction (probability at least 12\tfrac12) and the child call then succeeds, for at least one of the two children. Writing pdp_d for a lower bound on the success of a call dd levels above the base case, where p0=1p_0 = 1:

  4. Pr⁡[success]  =  Ω(1log⁡n),O(log⁡2n)⋅O(n2log⁡n)  =  O(n2log⁡3n)\Pr[\text{success}] \;=\; \Omega\Big(\frac{1}{\log n}\Big), \qquad O(\log^2 n) \cdot O(n^2 \log n) \;=\; O(n^2 \log^3 n)

    By induction pd≥1/(d+1)p_d \ge 1/(d+1): the map x↦x−x2/4x \mapsto x - x^2/4 is increasing on [0,1][0, 1], and 1d+1−14(d+1)2≥1d+2\frac{1}{d+1} - \frac{1}{4(d+1)^2} \ge \frac{1}{d+2} because 4(d+1)≥d+24(d+1) \ge d + 2. The depth is O(log⁡n)O(\log n), so one run succeeds with probability Ω(1/log⁡n)\Omega(1/\log n), and O(log⁡2n)O(\log^2 n) runs succeed with probability 1−1/nc1 - 1/n^{c}:

python
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 tt super-vertices and relabels them. On two complete graphs of 20 vertices joined by 3 edges (n=40n = 40, m=383m = 383, 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).

Check your understanding

Why does Karger–Stein contract to about n/2n/\sqrt2 vertices before branching, rather than to n/2n/2?

  1. Because n/2n/\sqrt2 is the largest size at which the graph still fits in memory
  2. Because then a fixed minimum cut survives the shared phase with probability at least 1/21/2, which two independent branches can compensate, while the work per recursion level stays O(n2)O(n^2)
  3. Because contracting to n/2n/2 would change the minimum cut
  4. Because 2\sqrt2 makes the recursion depth constant
Show the answer

B. Because then a fixed minimum cut survives the shared phase with probability at least 1/21/2, which two independent branches can compensate, while the work per recursion level stays O(n2)O(n^2)

Survival to tt vertices is about (t/n)2(t/n)^2, so t=n/2t = n/\sqrt2 gives 12\tfrac12: two branches then keep the success probability from collapsing (it falls only like 1/log⁡n1/\log n). Contracting to n/2n/2 would leave survival near 14\tfrac14, and two branches could not compensate: the success probability would shrink polynomially in nn.

Deterministic, near-linear, and open

AlgorithmKindTime
n−1n - 1 maximum flows from a fixed sourcedeterministicn−1n - 1 max-flow computations
Nagamochi & Ibaraki (1992); Stoer & Wagner (1997)deterministic, no flows: maximum-adjacency orderingsO(nm+n2log⁡n)O(nm + n^2 \log n)
Karger (1993): repeated contractionMonte CarloO(n2mlog⁡n)O(n^2 m \log n) for success 1−1/n1 - 1/n, as above
Karger & Stein (1996): recursive contractionMonte CarloO(n2log⁡3n)O(n^2 \log^3 n)
Karger (2000): tree packing and 2-respecting cutsMonte CarloO(mlog⁡3n)O(m \log^3 n)
Gawrychowski, Mozes & Weimann (2019)Monte CarloO(mlog⁡2n)O(m \log^2 n)
Kawarabayashi & Thorup (2015)deterministic, simple unweighted graphsnear-linear, O~(m)\tilde O(m)
Li (2021)deterministic, weightedm1+o(1)m^{1 + o(1)}
Henzinger, Li, Rao & Wang (2024)deterministic, weightednear-linear, O~(m)\tilde O(m)
O~\tilde O hides polylogarithmic factors. Karger's near-linear algorithm packs spanning trees so that some minimum cut crosses at most two edges of one of O(log⁡n)O(\log n) trees, then finds the best such cut in each tree; later work speeds up that second step.

Contraction also counts. Rerun the survival argument for cuts of size at most α λ(G)\alpha\,\lambda(G) and it shows there are only O(n2α)O(n^{2\alpha}) 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 ss–tt cut, by design: a random contraction may merge ss with tt. 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 ∏j=3n(1−2/j)=2/(n(n−1))\prod_{j=3}^{n}(1 - 2/j) = 2/(n(n-1)), because a graph with minimum cut kk has at least nk/2nk/2 edges; hence no graph has more than (n2)\binom n2 minimum cuts, and the cycle shows the bound is tight.
  • Karger–Stein contracts once to about n/2n/\sqrt2 vertices, where a minimum cut survives with probability at least 12\tfrac12, then recurses twice: O(n2log⁡n)O(n^2 \log n) per run, success Ω(1/log⁡n)\Omega(1/\log n), O(n2log⁡3n)O(n^2 \log^3 n) for high probability.
  • Global minimum cut now runs in near-linear time, randomized (O(mlog⁡2n)O(m \log^2 n)) and deterministic (Henzinger, Li, Rao & Wang, 2024); linear time and simple deterministic algorithms remain open, and ss–tt cuts still need flows.

Check yourself

In the interactive lesson these are scored with your confidence, and what you miss comes back for review.

Question 1

The proof needs at least nk/2nk/2 edges in a graph with minimum cut kk. Where does that come from?

  1. From Euler's formula for planar graphs
  2. Every vertex alone forms one side of a cut, so every degree is at least kk, and the degrees sum to 2m2m
  3. Every edge lies on some minimum cut
  4. 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 kk, and the degrees sum to 2m2m

The cut ({v},V∖{v})(\{v\}, V \setminus \{v\}) has size deg⁡(v)\deg(v), which cannot be below the minimum kk. Summing over all vertices, 2m=∑vdeg⁡(v)≥nk2m = \sum_v \deg(v) \ge nk. The same holds after contractions, with super-vertices in place of vertices.

Question 2

How many minimum cuts does the cycle on 6 vertices have?

  1. 6
  2. 15
  3. 30
  4. 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: (62)=15\binom62 = 15. That meets Karger's upper bound (n2)\binom n2 exactly, so the bound cannot be improved.

Question 3

You need the smallest cut separating a given source ss from a given sink tt. Is Karger's algorithm the right tool?

  1. Yes: run it until the two remaining super-vertices contain ss and tt
  2. No: a random contraction can merge ss with tt, and the global minimum cut may not separate them; use maximum flow
  3. Yes, after giving the edges at ss and tt infinite multiplicity
  4. No, because Karger's algorithm works only on simple graphs
Show the answer

B. No: a random contraction can merge ss with tt, and the global minimum cut may not separate them; use maximum flow

Karger's analysis is about the global minimum cut. The best ss–tt cut can be much larger than λ(G)\lambda(G), and contracting random edges gives it no special protection, so its survival probability has no useful bound. Max-flow min-cut solves the ss–tt 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.