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 edges, but Benczúr and Karger (1996) proved that its cut structure fits into a weighted graph with only edges: a cut sparsifier, which preserves every cut up to a factor . 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 be a weighted graph and the value of the cut defined by . A weighted graph on the same vertices is a cut sparsifier of if
There are 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 and gives the kept edges weight . Every cut value is then preserved in expectation. Karger (1994) showed that, if the minimum cut is large enough, it is also preserved simultaneously for all cuts:
Theorem (Karger, 1994). If has minimum cut and for a suitable constant , then with high probability every cut of the sampled graph, scaled by , is within of its value in .
Proof sketch. Fix a cut with edges (). The number of its edges that are kept is a sum of independent indicators with mean , so by a Chernoff bound it deviates by more than a factor with probability at most . A single cut is easy; the difficulty is that there are exponentially many. The rescue is cut counting: a graph with minimum cut has at most cuts of value at most (Karger, 1993, from the analysis of the contraction algorithm). Group the cuts by in ranges , apply the union bound to each group, and sum: with large enough the total failure probability is .
The program takes 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 .
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 , 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 , too small for concentration.
In C++
The exhaustive check scales to cuts of a random 20-vertex multigraph in a fraction of a second.
#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 , 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 of an edge, the largest such that lies in a -edge-connected induced subgraph, and sampled with
Theorem (Benczúr and Karger, 1996). With this sampling, with high probability the result is a cut sparsifier, and the expected number of edges is .
The bound on the number of edges comes from the identity (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 -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 (the minimum cut separating the two endpoints) can be used instead of the strength, at the cost of one more factor in the size.
The program builds the two-clique example (each clique 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 and, for comparison, uniformly with the same expected number of edges, and evaluates some cuts.
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 is small for ; a real sparsifier would use .
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 levels, so each level uses ; the space stays .
- 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, - min cut and max flow values, sparsest cut, all within 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 cut sparsifier of guarantee?
- has the same minimum cut edges
- Every one of the cuts has value in within of its value in
- is a spanning tree
- Shortest paths are preserved
In Karger's uniform sampling argument, what handles the exponentially many cuts?
- A single Chernoff bound
- Cut counting: at most cuts have value at most , so a union bound per value range works because larger cuts are both rarer to fail and more numerous only polynomially
- Pairwise independence
- Linearity of expectation
Why does uniform sampling fail on two cliques joined by three edges?
- The cliques are too small
- The bridge cut has only 3 edges, so a sampling rate low enough to sparsify the cliques loses the bridges and disconnects the graph
- Uniform sampling is biased
- The graph is not connected
How many edges does a Benczúr-Karger sparsifier have in expectation?
- , from with