TExcelTAD
Home › Randomized Algorithms & Probabilistic Analysis › Pairwise Independence and Small Sample Spaces

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 m/2m/2 is unchanged, and pairwise independent bits for nn vertices can be generated from about lg⁡n\lg n truly random bits. A sample space of size O(n)O(n) 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 Y1,…,YnY_1, \ldots, Y_n are pairwise independent if every two of them are independent: Pr⁡[Yi=a,Yj=b]=Pr⁡[Yi=a]Pr⁡[Yj=b]\Pr[Y_i = a, Y_j = b] = \Pr[Y_i = a]\Pr[Y_j = b] for all i≠ji \ne j and all values. More generally, they are kk-wise independent if every kk of them are mutually independent. Two facts make this weaker notion useful:

  1. 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).
  2. 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 kk independent fair bits b1,…,bkb_1, \ldots, b_k. For every nonempty subset S⊆{1,…,k}S \subseteq \{1, \ldots, k\}, let YS=⨁i∈SbiY_S = \bigoplus_{i \in S} b_i. This gives 2k−12^k - 1 bits.

Claim: each YSY_S is a fair bit, and the YSY_S are pairwise independent. Proof. Pick i∈Si \in S: whatever the other bits are, bib_i flips YSY_S, so YSY_S is fair. For S≠TS \ne T, pick ii in one but not the other, say i∈T∖Si \in T \setminus S. Conditioned on all bits except bib_i, YSY_S is fixed and YTY_T is still a fair coin, so YTY_T is independent of YSY_S. □\square They are not 3-wise independent: Y{1}⊕Y{2}=Y{1,2}Y_{\{1\}} \oplus Y_{\{2\}} = Y_{\{1, 2\}} always.

From a field. For a prime pp, choose a,ba, b independently and uniformly from Zp\mathbb{Z}_p, and let Yi=(a+ib) mod pY_i = (a + ib) \bmod p for i=0,…,p−1i = 0, \ldots, p - 1. For i≠ji \ne j and any targets (u,v)(u, v), the system a+ib=ua + ib = u, a+jb=va + jb = v has exactly one solution modulo pp, so Pr⁡[Yi=u,Yj=v]=p−2\Pr[Y_i = u, Y_j = v] = p^{-2}. This gives pp pairwise independent values uniform on Zp\mathbb{Z}_p from 2lg⁡p2\lg p 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: 2k≈n2^k \approx n points for nn bits, or p2p^2 points for pp values, compared with 2n2^n or ppp^p for full independence.

Derandomizing MAX-CUT by enumeration

Give vertex vv the bit YSvY_{S_v}, where S0,S1,…S_0, S_1, \ldots are distinct nonempty subsets of {1,…,k}\{1, \ldots, k\} and k=⌈lg⁡(n+1)⌉k = \lceil \lg(n + 1) \rceil. Each edge is cut with probability exactly 12\frac12, by pairwise independence, so the average cut over the 2k≤2n+22^k \le 2n + 2 seeds is exactly m/2m/2, and some seed gives a cut of at least m/2m/2. Trying all seeds is a deterministic algorithm with O(n⋅m)O(n \cdot m) running time.

python · try it yourself
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 m/2m/2, 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 ff of "good" elements in Zp\mathbb{Z}_p, evaluate the indicator at ss pairwise independent sample points Y0,…,Ys−1Y_0, \ldots, Y_{s-1} from the field construction. The estimate f^\hat f has mean ff and, since variances add, variance f(1−f)s\frac{f(1-f)}{s}, so Chebyshev gives Pr⁡[∣f^−f∣≥ε]≤f(1−f)sε2\Pr[\lvert \hat f - f \rvert \ge \varepsilon] \le \frac{f(1 - f)}{s\varepsilon^2}, the same as for fully independent samples, using only 2lg⁡p2\lg p random bits instead of slg⁡ps \lg p. (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 p2p^2 seeds, for p=101p = 101.

python · try it yourself
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: k=10k = 10 seed bits, 1024 seeds, each evaluated in O(n+m)O(n + m). 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.

cpp · try it yourself
#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

  • kk-wise independence for nn variables can be generated from O(klog⁡n)O(k \log n) bits by evaluating a random polynomial of degree k−1k - 1 (Joffe, 1974), with a sample space of size about nkn^{k}; Alon, Babai and Itai (1986) showed that size about n⌊k/2⌋n^{\lfloor k/2 \rfloor} is necessary, so kk-wise independent spaces are only polynomial for constant kk.
  • Almost kk-wise independence and ε\varepsilon-biased spaces (Naor and Naor, 1990): if every parity of the bits is only ε\varepsilon-close to fair, O(log⁡n+log⁡(1/ε))O(\log n + \log(1/\varepsilon)) 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 BPP=P\text{BPP} = \text{P}.

Test yourself

How many pairwise independent fair bits can be made from 5 truly random bits with the XOR-of-subsets construction?

  1. 5
  2. 10
  3. 31
  4. 32

Why does a pairwise independent assignment of sides still give E[cut]=m/2\mathbb{E}[\text{cut}] = m/2?

  1. Because the graph is random
  2. Because each edge is cut with probability 1/21/2 as soon as its two endpoints get independent fair bits, and linearity of expectation does the rest
  3. Because pairwise independence implies full independence
  4. It does not

Which tail bound remains valid for a sum of pairwise independent indicators?

  1. Chernoff
  2. Hoeffding
  3. Chebyshev
  4. None

Why are kk-wise independent sample spaces useful only for small kk?

  1. Because they need knk^n seeds
  2. Because their size must be at least about n⌊k/2⌋n^{\lfloor k/2 \rfloor}, polynomial only for constant kk
  3. Because kk-wise independence implies pairwise independence
  4. Because they cannot be enumerated