Pairwise Independence and Small Sample Spaces
The random-cut argument for MAX-CUT looks at one edge at a time: all it needs is that the two endpoints of each edge get independent fair bits. It never looks at three vertices together. If the random bits are only pairwise independent, the expectation is unchanged, and pairwise independent bits for vertices can be generated from about truly random bits. A sample space of size can then be searched exhaustively, and the randomized algorithm becomes a deterministic one. This lesson builds pairwise independent sample spaces, uses them to derandomize MAX-CUT, and shows how Chebyshev's inequality works with them.
Pairwise independence
Random variables are pairwise independent if every two of them are independent: for all and all values. More generally, they are -wise independent if every of them are mutually independent. Two facts make this weaker notion useful:
- Linearity of expectation needs no independence at all, and many expectations only involve one or two variables at a time (an edge is cut, a pair collides).
- Variances add for pairwise independent variables (Markov and Chebyshev: A Short Recap), so Chebyshev's inequality applies to their sums exactly as for independent ones.
Two constructions
From bits. Take independent fair bits . For every nonempty subset , let . This gives bits.
Claim: each is a fair bit, and the are pairwise independent. Proof. Pick : whatever the other bits are, flips , so is fair. For , pick in one but not the other, say . Conditioned on all bits except , is fixed and is still a fair coin, so is independent of . They are not 3-wise independent: always.
From a field. For a prime , choose independently and uniformly from , and let for . For and any targets , the system , has exactly one solution modulo , so . This gives pairwise independent values uniform on from random bits, the same idea as the 2-wise independent hash family of Universal and k-Wise Independent Hash Families.
In both cases the sample space (the set of all seeds) is tiny: points for bits, or points for values, compared with or for full independence.
Derandomizing MAX-CUT by enumeration
Give vertex the bit , where are distinct nonempty subsets of and . Each edge is cut with probability exactly , by pairwise independence, so the average cut over the seeds is exactly , and some seed gives a cut of at least . Trying all seeds is a deterministic algorithm with running time.
import random
from itertools import product
rng = random.Random(180)
n = 40
edges = [(u, v) for u in range(n) for v in range(u + 1, n) if rng.random() < 0.15]
m = len(edges)
k = n.bit_length() # 2^k - 1 >= n subsets
masks = list(range(1, n + 1)) # vertex v uses the subset encoded by the bits of v + 1
def bit(seed, mask):
return bin(seed & mask).count("1") % 2 # XOR of the seed bits selected by the mask
cuts = []
for seed in range(2 ** k):
side = [bit(seed, masks[v]) for v in range(n)]
cuts.append(sum(side[u] != side[v] for u, v in edges))
print(f"n = {n}, m = {m}, k = {k} seed bits, {2 ** k} seeds")
print(f"average cut over all seeds: {sum(cuts) / len(cuts)} (exactly m/2 = {m / 2})")
print(f"best seed cuts {max(cuts)} edges; worst seed cuts {min(cuts)}")n = 40, m = 120, k = 6 seed bits, 64 seeds
average cut over all seeds: 60.0 (exactly m/2 = 60.0)
best seed cuts 72 edges; worst seed cuts 0
The average is exactly , not approximately: the sample space is uniform over seeds, and every edge is cut by exactly half of them. (The worst seed, 0, puts every vertex on the same side.)
Chebyshev with pairwise independent samples
To estimate the fraction of "good" elements in , evaluate the indicator at pairwise independent sample points from the field construction. The estimate has mean and, since variances add, variance , so Chebyshev gives , the same as for fully independent samples, using only random bits instead of . (Chernoff bounds do not apply; for exponentially small error, combine with the median trick of Amplification by Repetition, or use expander walks.) The program checks this exhaustively, over all seeds, for .
p, s, eps = 101, 30, 0.15
good = {x for x in range(p) if x % 3 == 0 or x % 7 == 0} # some fixed set
f = len(good) / p
bad_seeds = 0
for a in range(p):
for b in range(p):
est = sum(((a + i * b) % p) in good for i in range(s)) / s
bad_seeds += abs(est - f) >= eps
print(f"f = {f:.4f}, s = {s} samples, eps = {eps}")
print(f"fraction of the {p * p} seeds with error >= eps: {bad_seeds / p ** 2:.4f}")
print(f"Chebyshev bound f(1-f)/(s eps^2): {f * (1 - f) / (s * eps ** 2):.4f}")f = 0.4356, s = 30 samples, eps = 0.15
fraction of the 10201 seeds with error >= eps: 0.0540
Chebyshev bound f(1-f)/(s eps^2): 0.3642
In C++
MAX-CUT by enumerating a pairwise independent sample space in C++, for a random graph with 1000 vertices and 10 000 edges: seed bits, 1024 seeds, each evaluated in . The graph comes from a fixed-seed std::mt19937; the search itself is deterministic. std::popcount (C++20) computes the parity of the selected seed bits.
#include <bit>
#include <cstdio>
#include <random>
#include <utility>
#include <vector>
int main() {
std::mt19937 rng(181);
const int n = 1000, m = 10000;
std::vector<std::pair<int, int>> edges;
while ((int)edges.size() < m) {
int u = rng() % n, v = rng() % n;
if (u != v) edges.push_back({u, v});
}
const int k = std::bit_width((unsigned)n); // 2^k - 1 >= n
long long total = 0;
int best = -1, best_seed = 0;
std::vector<int> side(n);
for (unsigned seed = 0; seed < (1u << k); ++seed) {
for (int v = 0; v < n; ++v) side[v] = std::popcount(seed & unsigned(v + 1)) & 1;
int cut = 0;
for (auto [u, v] : edges) cut += side[u] != side[v];
total += cut;
if (cut > best) { best = cut; best_seed = seed; }
}
std::printf("k = %d, %d seeds: average cut %.1f (m/2 = %d), best cut %d at seed %d\n",
k, 1 << k, double(total) / (1 << k), m / 2, best, best_seed);
}k = 10, 1024 seeds: average cut 5000.0 (m/2 = 5000), best cut 5203 at seed 778
Small sample spaces in general
- -wise independence for variables can be generated from bits by evaluating a random polynomial of degree (Joffe, 1974), with a sample space of size about ; Alon, Babai and Itai (1986) showed that size about is necessary, so -wise independent spaces are only polynomial for constant .
- Almost -wise independence and -biased spaces (Naor and Naor, 1990): if every parity of the bits is only -close to fair, seed bits suffice, and many derandomizations only need that.
- Pseudorandom generators stretch a short seed into a long string that fools a whole class of algorithms. For space-bounded computation they exist unconditionally (Nisan, 1992); for polynomial time they follow from circuit lower bounds (Nisan and Wigderson, 1994; Impagliazzo and Wigderson, 1997), which is the main evidence for the conjecture .
Test yourself
How many pairwise independent fair bits can be made from 5 truly random bits with the XOR-of-subsets construction?
- 5
- 10
- 31
- 32
Why does a pairwise independent assignment of sides still give ?
- Because the graph is random
- Because each edge is cut with probability as soon as its two endpoints get independent fair bits, and linearity of expectation does the rest
- Because pairwise independence implies full independence
- It does not
Which tail bound remains valid for a sum of pairwise independent indicators?
- Chernoff
- Hoeffding
- Chebyshev
- None
Why are -wise independent sample spaces useful only for small ?
- Because they need seeds
- Because their size must be at least about , polynomial only for constant
- Because -wise independence implies pairwise independence
- Because they cannot be enumerated