TExcelTAD
Home › Randomized Algorithms & Probabilistic Analysis › The Union Bound at Work: Max Load, Rounding and Set Balancing

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 A1,…,AmA_1, \ldots, A_m, dependent or not,

Pr⁡[⋃i=1mAi]≤∑i=1mPr⁡[Ai].\Pr\Bigl[\bigcup_{i=1}^m A_i\Bigr] \le \sum_{i=1}^m \Pr[A_i] .

It follows from additivity: the union is the disjoint union of Ai∖(A1∪⋯∪Ai−1)A_i \setminus (A_1 \cup \cdots \cup A_{i-1}), each a subset of AiA_i. 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:

  1. Name the bad events A1,…,AmA_1, \ldots, A_m, one per bin, row, constraint or vertex.
  2. Prove Pr⁡[Ai]≤1/mc+1\Pr[A_i] \le 1/m^{c+1} for each, usually with a Chernoff bound. This is where independence is needed, inside each event.
  3. Conclude Pr⁡[some Ai]≤1/mc\Pr[\text{some } A_i] \le 1/m^c: with high probability nothing goes wrong.

Maximum load

Throw nn balls into nn bins independently and uniformly. The load of a fixed bin is a sum of nn independent indicators with mean μ=1\mu = 1. Choose any kk balls: they all land in the bin with probability n−kn^{-k}, so by a union bound over the (nk)\binom{n}{k} choices,

Pr⁡[load of bin i≥k]≤(nk)1nk≤1k!≤(ek)k.\Pr[\text{load of bin } i \ge k] \le \binom{n}{k} \frac{1}{n^k} \le \frac{1}{k!} \le \left(\frac{e}{k}\right)^k .

(The Chernoff upper tail with μ=1\mu = 1 and 1+δ=k1 + \delta = k gives the same ek−1kk\frac{e^{k-1}}{k^k} up to a factor ee.) For k=3ln⁡nln⁡ln⁡nk = \frac{3 \ln n}{\ln \ln n} one checks that (e/k)k≤n−2(e/k)^k \le n^{-2} for large enough nn, and a second union bound over the nn bins gives

Pr⁡[max load≥3ln⁡nln⁡ln⁡n]≤n⋅1n2=1n.\Pr\Bigl[\text{max load} \ge \frac{3 \ln n}{\ln \ln n}\Bigr] \le n \cdot \frac{1}{n^2} = \frac{1}{n}.

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 m≥6nln⁡nm \ge 6n \ln n, then μ=m/n≥6ln⁡n\mu = m/n \ge 6 \ln n and the corollary with δ=1\delta = 1 gives Pr⁡[load≥2μ]≤e−μ/3≤n−2\Pr[\text{load} \ge 2\mu] \le e^{-\mu/3} \le n^{-2}, so every bin is within a factor 2 of the average with probability at least 1−1/n1 - 1/n. Heavy loading makes loads concentrated; light loading does not.

The program measures how often the fullest bin reaches kk and compares that with the union bound n/k!n/k!.

python · try it yourself
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 kk (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 xj∈[0,1]x_j \in [0, 1]. Randomized rounding (Raghavan and Thompson, 1987) sets each variable to 1 independently with probability xjx_j. 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 mm machines and JJ 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 LL. Rounding sends each job to one of its two machines with probability 1/21/2. A machine's integral load is a sum of independent indicators with mean LL, so Chernoff with δ=6ln⁡m/L\delta = \sqrt{6 \ln m / L} (assuming L≥6ln⁡mL \ge 6 \ln m, so δ≤1\delta \le 1) gives Pr⁡[load≥(1+δ)L]≤e−δ2L/3=m−2\Pr[\text{load} \ge (1 + \delta)L] \le e^{-\delta^2 L/3} = m^{-2}, and the union bound over machines makes the maximum load at most L+6Lln⁡mL + \sqrt{6 L \ln m} with probability at least 1−1/m1 - 1/m.

python · try it yourself
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 n×nn \times n matrix AA with entries in {0,1}\{0, 1\} describes nn subsets of nn people (row ii = the people with a feature ii). Split the people into two groups, encoded as a vector b∈{−1,+1}nb \in \{-1, +1\}^n, so that every feature is shared about equally: the goal is a small ∥Ab∥∞=max⁡i∣∑jaijbj∣\lVert Ab \rVert_\infty = \max_i \lvert \sum_j a_{ij} b_j \rvert.

Theorem. If bb is chosen uniformly at random, then Pr⁡[∥Ab∥∞≥4nln⁡n]≤2n\Pr\bigl[\lVert Ab \rVert_\infty \ge \sqrt{4n \ln n}\bigr] \le \frac{2}{n}.

Proof. Fix row ii with kk ones. If k≤4nln⁡nk \le \sqrt{4n \ln n}, the row sum cannot reach the bound. Otherwise the row sum ZiZ_i is a sum of kk independent uniform ±1\pm 1 variables, and the fair-coin Chernoff bound Pr⁡[Z≥a]≤e−a2/(2k)\Pr[Z \ge a] \le e^{-a^2/(2k)} (Chernoff Bounds and Their Proofs) applied to both tails gives

Pr⁡[∣Zi∣≥4nln⁡n]≤2e−4nln⁡n/(2k)≤2e−2ln⁡n=2n2,\Pr\bigl[\lvert Z_i \rvert \ge \sqrt{4n \ln n}\bigr] \le 2e^{-4n\ln n/(2k)} \le 2e^{-2\ln n} = \frac{2}{n^2},

using k≤nk \le n. A union bound over the nn rows finishes the proof. □\square

A random split is therefore within O(nlog⁡n)O(\sqrt{n \log n}) on every row, with no search at all. This is not optimal: Spencer (1985) proved that a split with discrepancy at most 6n6\sqrt n always exists, and Bansal (2010) and later Lovett and Meka (2012) gave efficient algorithms that find splits of discrepancy O(n)O(\sqrt n). The random split loses only the log⁡n\sqrt{\log n} factor, which comes precisely from the union bound over nn rows.

python · try it yourself
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.

cpp · try it yourself
#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 A1,…,AmA_1, \ldots, A_m?

  1. Mutual independence
  2. Pairwise independence
  3. Nothing: it holds for any events
  4. That they are disjoint

Each of nn bad events has probability at most n−3n^{-3}. What does the union bound give for the probability that none happens?

  1. At least 1−n−31 - n^{-3}
  2. At least 1−n−21 - n^{-2}
  3. At least 1−1/n1 - 1/n
  4. Nothing useful

In random set balancing of an n×nn \times n 0/1 matrix, where does the ln⁡n\sqrt{\ln n} factor in the bound 4nln⁡n\sqrt{4n \ln n} come from?

  1. From the variance of one row
  2. From making each row's failure probability small enough to survive a union bound over nn rows
  3. From the number of columns
  4. From Markov's inequality

Randomized rounding sets each variable xjx_j to 1 with probability equal to its fractional value. What does this preserve exactly?

  1. Every constraint, always
  2. The expectation of every linear function of the variables
  3. The optimal value, always
  4. Integrality of the LP