The Union Bound at Work: Max Load, Rounding and Set Balancing
A randomized algorithm usually has to succeed in many places at once: every bin must stay small, every constraint must be nearly satisfied, every row must be balanced. The union bound reduces "everything goes right" to "each single thing goes wrong only rarely", and a Chernoff bound supplies that rarity. This lesson states the union bound, then works through three standard applications: the maximum load of balls in bins, a preview of randomized rounding, and set balancing.
The union bound
For any events , dependent or not,
It follows from additivity: the union is the disjoint union of , each a subset of . It is often called Boole's inequality. Its strength is that it needs no independence; its weakness is that it adds up overlaps, so it is loose when the bad events are likely to happen together.
The recipe that appears throughout the course:
- Name the bad events , one per bin, row, constraint or vertex.
- Prove for each, usually with a Chernoff bound. This is where independence is needed, inside each event.
- Conclude : with high probability nothing goes wrong.
Maximum load
Throw balls into bins independently and uniformly. The load of a fixed bin is a sum of independent indicators with mean . Choose any balls: they all land in the bin with probability , so by a union bound over the choices,
(The Chernoff upper tail with and gives the same up to a factor .) For one checks that for large enough , and a second union bound over the bins gives
The matching lower bound, and what happens with two choices per ball, are in Balls into Bins: The Maximum Load and The Power of Two Choices. With many more balls the picture changes: if , then and the corollary with gives , so every bin is within a factor 2 of the average with probability at least . Heavy loading makes loads concentrated; light loading does not.
The program measures how often the fullest bin reaches and compares that with the union bound .
import random
from math import factorial, log
rng = random.Random(10)
n, trials = 1000, 200
maxima = []
for _ in range(trials):
load = [0] * n
for _ in range(n):
load[rng.randrange(n)] += 1
maxima.append(max(load))
print(f"n = {n}: 3 ln n / ln ln n = {3 * log(n) / log(log(n)):.2f}")
print(" k measured Pr[max load >= k] union bound n/k!")
for k in range(4, 10):
measured = sum(m >= k for m in maxima) / trials
print(f"{k:2} {measured:26.3f} {min(1, n / factorial(k)):16.4f}")n = 1000: 3 ln n / ln ln n = 10.72
k measured Pr[max load >= k] union bound n/k!
4 1.000 1.0000
5 0.980 1.0000
6 0.415 1.0000
7 0.075 0.1984
8 0.005 0.0248
9 0.000 0.0028
The union bound is useless for small (it exceeds 1 and is printed capped at 1), where many bins are near the threshold at once and their bad events overlap, and becomes accurate in the far tail, where the bad events are rare and nearly disjoint.
A preview of randomized rounding
Many optimization problems are integer programs whose linear-programming relaxation can be solved efficiently, giving fractional values . Randomized rounding (Raghavan and Thompson, 1987) sets each variable to 1 independently with probability . Every linear quantity then has the right expectation, and Chernoff plus a union bound shows that every constraint is violated by at most a small factor simultaneously.
A toy load-balancing instance shows the idea. There are machines and jobs; each job may run on two specific machines, and the fractional solution splits each job in half, giving every machine the same fractional load . Rounding sends each job to one of its two machines with probability . A machine's integral load is a sum of independent indicators with mean , so Chernoff with (assuming , so ) gives , and the union bound over machines makes the maximum load at most with probability at least .
import random
from math import log, sqrt
rng = random.Random(12)
m, L = 50, 40
jobs = [] # each machine appears in exactly 2L job slots
slots = [i for i in range(m) for _ in range(2 * L)]
rng.shuffle(slots)
for j in range(0, len(slots), 2):
jobs.append((slots[j], slots[j + 1]))
frac = [0.0] * m
for a, b in jobs:
frac[a] += 0.5
frac[b] += 0.5
print(f"{len(jobs)} jobs on {m} machines; fractional max load {max(frac)}")
worst = []
for _ in range(100):
load = [0] * m
for a, b in jobs:
load[a if rng.random() < 0.5 else b] += 1
worst.append(max(load))
print(f"rounded max load over 100 roundings: mean {sum(worst) / len(worst):.2f}, largest {max(worst)}")
print(f"Chernoff + union bound guarantee (prob >= 1 - 1/m): L + sqrt(6 L ln m) = {L + sqrt(6 * L * log(m)):.2f}")2000 jobs on 50 machines; fractional max load 40.0
rounded max load over 100 roundings: mean 50.35, largest 56
Chernoff + union bound guarantee (prob >= 1 - 1/m): L + sqrt(6 L ln m) = 70.64
The full theory, including how the LP is set up and when rounding needs more care, is the subject of Approximation Algorithms and Linear Programming & Duality for Algorithms.
Set balancing
An matrix with entries in describes subsets of people (row = the people with a feature ). Split the people into two groups, encoded as a vector , so that every feature is shared about equally: the goal is a small .
Theorem. If is chosen uniformly at random, then .
Proof. Fix row with ones. If , the row sum cannot reach the bound. Otherwise the row sum is a sum of independent uniform variables, and the fair-coin Chernoff bound (Chernoff Bounds and Their Proofs) applied to both tails gives
using . A union bound over the rows finishes the proof.
A random split is therefore within on every row, with no search at all. This is not optimal: Spencer (1985) proved that a split with discrepancy at most always exists, and Bansal (2010) and later Lovett and Meka (2012) gave efficient algorithms that find splits of discrepancy . The random split loses only the factor, which comes precisely from the union bound over rows.
import random
from math import log, sqrt
rng = random.Random(13)
n, splits = 150, 60
rows = [[j for j in range(n) if rng.random() < 0.5] for _ in range(n)] # the columns with a 1
bound = sqrt(4 * n * log(n))
disc = []
for _ in range(splits):
b = [rng.choice((-1, 1)) for _ in range(n)]
disc.append(max(abs(sum(b[j] for j in row)) for row in rows))
print(f"n = {n}: bound sqrt(4 n ln n) = {bound:.1f}, sqrt(n) = {sqrt(n):.1f}")
print(f"{splits} random splits: discrepancy mean {sum(disc) / len(disc):.1f}, min {min(disc)}, max {max(disc)}")
print("splits at or above the bound:", sum(d >= bound for d in disc))n = 150: bound sqrt(4 n ln n) = 54.8, sqrt(n) = 12.2
60 random splits: discrepancy mean 20.7, min 14, max 33
splits at or above the bound: 0
In C++
Random set balancing in C++ with a fixed-seed std::mt19937 (one random bit per person, taken from the generator's output). The matrix and the splits are different random draws from the Python ones, so the numbers differ slightly, but the conclusion is the same.
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <random>
#include <vector>
int main() {
std::mt19937 rng(13);
const int n = 150, splits = 60;
std::vector<std::vector<int>> a(n, std::vector<int>(n));
for (auto& row : a)
for (int& x : row) x = rng() & 1;
double bound = std::sqrt(4.0 * n * std::log(n));
int lo = n, hi = 0, above = 0;
long long total = 0;
std::vector<int> b(n);
for (int s = 0; s < splits; ++s) {
for (int& x : b) x = (rng() & 1) ? 1 : -1;
int disc = 0;
for (const auto& row : a) {
int sum = 0;
for (int j = 0; j < n; ++j) sum += row[j] * b[j];
disc = std::max(disc, std::abs(sum));
}
total += disc;
lo = std::min(lo, disc);
hi = std::max(hi, disc);
above += disc >= bound;
}
std::printf("n = %d: bound %.1f; %d random splits: mean %.1f, min %d, max %d, at or above bound: %d\n",
n, bound, splits, double(total) / splits, lo, hi, above);
}n = 150: bound 54.8; 60 random splits: mean 21.2, min 13, max 35, at or above bound: 0
Test yourself
What does the union bound require of the events ?
- Mutual independence
- Pairwise independence
- Nothing: it holds for any events
- That they are disjoint
Each of bad events has probability at most . What does the union bound give for the probability that none happens?
- At least
- At least
- At least
- Nothing useful
In random set balancing of an 0/1 matrix, where does the factor in the bound come from?
- From the variance of one row
- From making each row's failure probability small enough to survive a union bound over rows
- From the number of columns
- From Markov's inequality
Randomized rounding sets each variable to 1 with probability equal to its fractional value. What does this preserve exactly?
- Every constraint, always
- The expectation of every linear function of the variables
- The optimal value, always
- Integrality of the LP