TExcelTAD
Home › Streaming, Sketching & Sublinear Algorithms › Cut Sparsifiers: Benczúr-Karger

Cut Sparsifiers: Benczúr-Karger

Many graph questions are about cuts: the minimum cut, the sparsest cut, the max-flow value between two vertices (by max-flow min-cut). A dense graph can have Θ(n2)\Theta(n^2) edges, but Benczúr and Karger (1996) proved that its cut structure fits into a weighted graph with only O(nlog⁡n/ε2)O(n \log n / \varepsilon^2) edges: a cut sparsifier, which preserves every cut up to a factor 1±ε1 \pm \varepsilon. For streaming this is the key to cut problems in semi-streaming space: maintain a sparsifier of the edges seen, and answer any cut question from it at the end.

The definition

Let G=(V,E,w)G = (V, E, w) be a weighted graph and w(∂S)=∑e∈E(S,V∖S)wew(\partial S) = \sum_{e \in E(S, V \setminus S)} w_e the value of the cut defined by S⊆VS \subseteq V. A weighted graph HH on the same vertices is a (1±ε)(1 \pm \varepsilon) cut sparsifier of GG if

(1−ε) wG(∂S)  ≤  wH(∂S)  ≤  (1+ε) wG(∂S)for all S⊆V.(1 - \varepsilon)\, w_G(\partial S) \;\le\; w_H(\partial S) \;\le\; (1 + \varepsilon)\, w_G(\partial S) \qquad \text{for all } S \subseteq V .

There are 2n−1−12^{n-1} - 1 cuts, so this is a lot to ask of a small graph.

Uniform sampling works when the minimum cut is large

The natural construction keeps each edge independently with probability pp and gives the kept edges weight 1/p1/p. Every cut value is then preserved in expectation. Karger (1994) showed that, if the minimum cut cc is large enough, it is also preserved simultaneously for all cuts:

Theorem (Karger, 1994). If GG has minimum cut cc and p≥min⁡(1,Kln⁡nε2c)p \ge \min\bigl(1, \frac{K \ln n}{\varepsilon^2 c}\bigr) for a suitable constant KK, then with high probability every cut of the sampled graph, scaled by 1/p1/p, is within 1±ε1 \pm \varepsilon of its value in GG.

Proof sketch. Fix a cut with αc\alpha c edges (α≥1\alpha \ge 1). The number of its edges that are kept is a sum of independent indicators with mean pαc≥αKln⁡n/ε2p\alpha c \ge \alpha K \ln n / \varepsilon^2, so by a Chernoff bound it deviates by more than a factor 1±ε1 \pm \varepsilon with probability at most 2e−ε2pαc/3≤2n−αK/32e^{-\varepsilon^2 p \alpha c / 3} \le 2n^{-\alpha K/3}. A single cut is easy; the difficulty is that there are exponentially many. The rescue is cut counting: a graph with minimum cut cc has at most n2αn^{2\alpha} cuts of value at most αc\alpha c (Karger, 1993, from the analysis of the contraction algorithm). Group the cuts by α\alpha in ranges [α,α+1)[\alpha, \alpha + 1), apply the union bound to each group, and sum: with KK large enough the total failure probability is ∑αn2(α+1)⋅2n−αK/3=O(n−1)\sum_{\alpha} n^{2(\alpha+1)} \cdot 2n^{-\alpha K/3} = O(n^{-1}). □\square

The program takes K14K_{14} with every edge 20 times (1820 edges, minimum cut 260), samples it at three rates, and checks all 8191 cuts exhaustively. A Gray-code walk visits the cuts so that consecutive ones differ by one vertex, and the cut value is updated in O(n)O(n).

python · try it yourself
import math, random

def all_cut_values(n, W):
    """Values of all 2^(n-1) - 1 cuts (S containing vertex n-1 excluded), via a Gray code walk."""
    deg = [sum(row) for row in W]
    inS = [False] * n
    cut, vals = 0.0, []
    for g in range(1, 1 << (n - 1)):
        v = (g & -g).bit_length() - 1            # the bit that flips in the Gray code
        wv = sum(W[v][u] for u in range(n) if inS[u])
        if inS[v]:
            inS[v] = False
            cut -= deg[v] - 2 * wv
        else:
            cut += deg[v] - 2 * wv
            inS[v] = True
        vals.append(cut)
    return vals

rng = random.Random(1994)
n, mult = 14, 20                                  # K_14 with every edge 20 times: min cut 13 * 20 = 260
G = [[0 if i == j else mult for j in range(n)] for i in range(n)]
exact = all_cut_values(n, G)
m = n * (n - 1) // 2 * mult
print(f"graph: {m} edges, min cut {min(exact):.0f}, {len(exact)} cuts checked exhaustively")
for p in [0.5, 0.2, 0.05]:
    H = [[0.0] * n for _ in range(n)]
    kept = 0
    for i in range(n):
        for j in range(i + 1, n):
            k = sum(rng.random() < p for _ in range(mult))   # keep each parallel edge with probability p
            H[i][j] = H[j][i] = k / p                         # weight 1/p for each kept edge
            kept += k
    approx = all_cut_values(n, H)
    worst = max(abs(a / e - 1) for a, e in zip(approx, exact))
    print(f"p = {p:4}: {kept:4} edges kept (weight {1 / p:g} each); worst relative error over all cuts {worst:.3f}; "
          f"guide sqrt(3 ln n / (p c)) = {math.sqrt(3 * math.log(n) / (p * min(exact))):.3f}")
graph: 1820 edges, min cut 260, 8191 cuts checked exhaustively
p =  0.5:  937 edges kept (weight 2 each); worst relative error over all cuts 0.121; guide sqrt(3 ln n / (p c)) = 0.247
p =  0.2:  356 edges kept (weight 5 each); worst relative error over all cuts 0.231; guide sqrt(3 ln n / (p c)) = 0.390
p = 0.05:   99 edges kept (weight 20 each); worst relative error over all cuts 0.692; guide sqrt(3 ln n / (p c)) = 0.780

The worst error over all cuts tracks ln⁡n/(pc)\sqrt{\ln n / (pc)}, the quantity in the proof, with a smaller constant than the worst case. With only 99 edges kept (5% of the graph), some cut is off by 69%: the sampled graph has expected minimum cut pc=13pc = 13, too small for concentration.

In C++

The exhaustive check scales to 219=524 2872^{19} = 524\,287 cuts of a random 20-vertex multigraph in a fraction of a second.

cpp · try it yourself
#include <bit>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <random>
#include <vector>

// Evaluate all 2^(n-1) - 1 cuts of a weighted graph with a Gray-code walk: O(n) per cut.
std::vector<double> all_cuts(const std::vector<std::vector<double>>& W) {
    int n = (int)W.size();
    std::vector<double> deg(n, 0), toS(n, 0), out;
    for (int i = 0; i < n; ++i) for (double w : W[i]) deg[i] += w;
    std::vector<bool> inS(n, false);
    double cut = 0;
    for (std::uint32_t g = 1; g < (1u << (n - 1)); ++g) {
        int v = std::countr_zero(g);                      // the vertex that changes sides
        double delta = deg[v] - 2 * toS[v];
        int sign = inS[v] ? -1 : 1;
        cut += sign * delta;
        inS[v] = !inS[v];
        for (int u = 0; u < n; ++u) toS[u] += sign * W[u][v];   // weight from u into S
        out.push_back(cut);
    }
    return out;
}

int main() {
    const int n = 20;
    std::mt19937_64 rng(1994);
    // a random multigraph: each pair joined by 0..29 parallel edges
    std::vector<std::vector<double>> G(n, std::vector<double>(n, 0));
    long m = 0;
    for (int i = 0; i < n; ++i)
        for (int j = i + 1; j < n; ++j) { G[i][j] = G[j][i] = double(rng() % 30); m += (long)G[i][j]; }
    auto exact = all_cuts(G);
    double mincut = 1e18;
    for (double c : exact) mincut = std::min(mincut, c);
    std::printf("n = %d, %ld edges, min cut %.0f, %zu cuts\n", n, m, mincut, exact.size());
    for (double p : {0.3, 0.1, 0.03}) {
        std::vector<std::vector<double>> H(n, std::vector<double>(n, 0));
        long kept = 0;
        for (int i = 0; i < n; ++i)
            for (int j = i + 1; j < n; ++j) {
                int k = 0;
                for (int e = 0; e < (int)G[i][j]; ++e) k += (rng() >> 11) * 0x1.0p-53 < p;
                H[i][j] = H[j][i] = k / p;
                kept += k;
            }
        auto approx = all_cuts(H);
        double worst = 0;
        for (std::size_t s = 0; s < exact.size(); ++s) worst = std::max(worst, std::fabs(approx[s] / exact[s] - 1));
        std::printf("p = %.2f: %5ld edges kept, worst relative cut error %.3f\n", p, kept, worst);
    }
}
n = 20, 2812 edges, min cut 181, 524287 cuts
p = 0.30:   839 edges kept, worst relative cut error 0.213
p = 0.10:   304 edges kept, worst relative cut error 0.556
p = 0.03:    80 edges kept, worst relative cut error 0.550

Importance sampling: Benczúr-Karger

Uniform sampling fails when the graph has a small cut next to dense parts. Take two cliques joined by 3 edges: to keep the bridge cut within 1±ε1 \pm \varepsilon, the 3 bridges must be kept with probability near 1, but then the cliques are not sparsified at all. The answer is to sample each edge according to how well connected its endpoints are. Benczúr and Karger defined the strength kek_e of an edge, the largest kk such that ee lies in a kk-edge-connected induced subgraph, and sampled with

pe=min⁡(1,ρke),ρ=Θ(log⁡nε2),weight 1pe.p_e = \min\Bigl(1, \frac{\rho}{k_e}\Bigr), \qquad \rho = \Theta\Bigl(\frac{\log n}{\varepsilon^2}\Bigr), \qquad \text{weight } \frac{1}{p_e} .

Theorem (Benczúr and Karger, 1996). With this sampling, with high probability the result is a (1±ε)(1 \pm \varepsilon) cut sparsifier, and the expected number of edges is ∑epe≤ρ (n−1)=O(nlog⁡n/ε2)\sum_e p_e \le \rho\,(n - 1) = O(n \log n / \varepsilon^2).

The bound on the number of edges comes from the identity ∑e1/ke≤n−1\sum_e 1/k_e \le n - 1 (for unit weights), which holds because a graph's edges can be peeled off in "strength classes" that each form forests in the right accounting. The proof of the sparsifier property applies the uniform-sampling argument separately to each strength class, inside the kk-connected pieces where cut counting is available. Strengths can be computed (approximately) in near-linear time. Fung, Hariharan, Harvey and Panigrahi (2011) showed that the simpler edge connectivity λe\lambda_e (the minimum cut separating the two endpoints) can be used instead of the strength, at the cost of one more log⁡n\log n factor in the size.

The program builds the two-clique example (each clique K12K_{12} with multiplicity 10, three bridges), where the connectivity of each edge is easy to read off (110 inside a clique, 3 for a bridge). It samples with pe=min⁡(1,12/λe)p_e = \min(1, 12/\lambda_e) and, for comparison, uniformly with the same expected number of edges, and evaluates some cuts.

python · try it yourself
import random
from fractions import Fraction                      # exact weights, so the printed sums are exact

rng = random.Random(1996)
k, mult = 12, 10
A, B = list(range(k)), list(range(k, 2 * k))
edges = []                                         # (u, v, connectivity lambda_e)
for side in (A, B):
    for i in side:
        for j in side:
            if i < j:
                edges += [(i, j, (k - 1) * mult)] * mult  # inside a clique: lambda = 110
bridges = [(0, k, 3), (1, k + 1, 3), (2, k + 2, 3)]       # the only edges between the cliques: lambda = 3
edges += bridges
n, m = 2 * k, len(edges)

def cut(weights, S):
    return sum(w for (u, v, _), w in zip(edges, weights) if (u in S) != (v in S))

def sample(probs):
    return [1 / p if rng.random() < p else 0 for p in probs]

rho = Fraction(12)                                  # oversampling: p_e = min(1, rho / lambda_e)
imp = [min(Fraction(1), rho / lam) for _, _, lam in edges]
budget = sum(imp)                                   # expected number of kept edges
uni = [budget / m] * m                              # uniform sampling with the same expected size
tests = {"the bridge cut A | B": set(A), "one vertex {5}": {5}, "A plus one vertex of B": set(A) | {k + 5}}
for _ in range(3):
    tests[f"random cut {len(tests) - 2}"] = {v for v in range(n) if rng.random() < 0.5}
print(f"{m} edges; both samplers keep about {float(budget):.0f} edges in expectation")
print("cut                        exact   uniform (5 samples)               importance (5 samples)")
U = [sample(uni) for _ in range(5)]
I = [sample(imp) for _ in range(5)]
for name, S in tests.items():
    ex = cut([1] * m, S)
    print(f"{name:24} {ex:7}   " + " ".join(f"{float(cut(w, S)):6.0f}" for w in U) + "   "
          + " ".join(f"{float(cut(w, S)):6.0f}" for w in I))
1323 edges; both samplers keep about 147 edges in expectation
cut                        exact   uniform (5 samples)               importance (5 samples)
the bridge cut A | B           3        9      0      0      0      0        3      3      3      3      3
one vertex {5}               110      126     90     81     90    117      183    110    128     73     73
A plus one vertex of B       113      153     72    135     99    135      104    113    131    140     76
random cut 1                 711      720    747    765    783    666      725    789    661    826    744
random cut 2                 700      684    864    720    639    639      660    798    642    770    678
random cut 3                 632      720    675    738    657    675      644    625    607    763    524

Uniform sampling destroys the bridge cut: in four of five samples the two cliques are disconnected, an infinite relative error. Importance sampling keeps the three bridges with probability 1 and gets that cut exactly, while sparsifying the cliques by a factor of 9. The other cuts are noisy because ρ=12\rho = 12 is small for n=24n = 24; a real sparsifier would use ρ≈3ln⁡n/ε2\rho \approx 3\ln n/\varepsilon^2.

Sparsifiers in streams

  • Insertion-only, one pass (Ahn and Guha, 2009): sparsify as you go. Keep a sparsifier of the edges seen so far; when it grows, sparsify the sparsifier again (merge-and-reduce, as in mergeable summaries). Errors compound over O(log⁡n)O(\log n) levels, so each level uses ε/log⁡n\varepsilon / \log n; the space stays O(npolylog⁡n/ε2)O(n \operatorname{polylog} n / \varepsilon^2).
  • Dynamic streams (Ahn, Guha and McGregor, 2012): use AGM sketches at geometrically decreasing sampling rates to find, for each edge, the scale at which it stops being well connected, which estimates its connectivity, and sample accordingly.
  • Uses: approximate minimum cut, ss-tt min cut and max flow values, sparsest cut, all within 1±ε1 \pm \varepsilon from the sparsifier, in semi-streaming space.

Spectral sparsifiers strengthen the guarantee from cuts to all quadratic forms of the Laplacian.

Test yourself

What does a (1±ε)(1 \pm \varepsilon) cut sparsifier HH of GG guarantee?

  1. HH has the same minimum cut edges
  2. Every one of the 2n−1−12^{n-1} - 1 cuts has value in HH within 1±ε1 \pm \varepsilon of its value in GG
  3. HH is a spanning tree
  4. Shortest paths are preserved

In Karger's uniform sampling argument, what handles the exponentially many cuts?

  1. A single Chernoff bound
  2. Cut counting: at most n2αn^{2\alpha} cuts have value at most αc\alpha c, so a union bound per value range works because larger cuts are both rarer to fail and more numerous only polynomially
  3. Pairwise independence
  4. Linearity of expectation

Why does uniform sampling fail on two cliques joined by three edges?

  1. The cliques are too small
  2. The bridge cut has only 3 edges, so a sampling rate low enough to sparsify the cliques loses the bridges and disconnects the graph
  3. Uniform sampling is biased
  4. The graph is not connected

How many edges does a Benczúr-Karger sparsifier have in expectation?

  1. O(n2)O(n^2)
  2. O(nlog⁡n/ε2)O(n \log n / \varepsilon^2), from ∑epe≤ρ(n−1)\sum_e p_e \le \rho(n - 1) with ρ=Θ(log⁡n/ε2)\rho = \Theta(\log n/\varepsilon^2)
  3. O(n)O(n)
  4. O(mε)O(m \varepsilon)