Tail Bounds for Algorithms
Markov, Chebyshev and Chernoff: from “on average” to “with high probability”.
Flip a fair coin 100 times. Markov's inequality says that 75 or more heads has probability at most 0.67, Chebyshev's says at most 0.04, and a Chernoff–Hoeffding bound says at most ; the truth is . Each step uses more about the random variable (its mean, its variance, then the independence of its parts), and that is exactly what turns "fast on average" into "fast with high probability".
What you’ll learn
- Prove Markov's and Chebyshev's inequalities, and apply Chebyshev's with only pairwise independence.
- Derive the multiplicative Chernoff bounds with the moment-generating-function method, state Hoeffding's additive bound, and know which one is tight in which regime.
- Combine tail bounds with the union bound to prove high-probability results: comparisons for randomized quicksort, maximum load for balls into bins, and with two choices.
- Use the probabilistic method (Erdős's Ramsey bound) and derandomize with conditional expectations and pairwise-independent sample spaces.
Markov and Chebyshev
An expected running time of does not rule out a rare run that takes steps. A tail bound caps the probability of such runs. The weakest needs only the mean: Markov's inequality, for , proved in Randomized Algorithms. The next one also uses the variance.
For a sum , the variance is , and the covariances vanish as soon as the are pairwise independent; full independence is not needed. That is why Chebyshev's inequality is the tool for algorithms whose randomness comes from pairwise-independent hash functions, which need only random bits.
Here is how the bounds compare on = the number of heads in 100 fair flips (, ):
| Bound | Uses | ||
|---|---|---|---|
| Markov | the mean | 0.833 | 0.667 |
| Chebyshev | the variance | 0.25 | 0.04 |
| Chernoff, multiplicative form | independence | 0.391 | 0.0045 |
| Hoeffding, | independence and boundedness | 0.135 | |
| Exact | the whole distribution | 0.0284 |
Chernoff bounds
For any , the map is increasing, so apply Markov's inequality to :
Independence turns the expectation of a product into a product of expectations; then removes the individual :
Take and the best , namely :
For , calculus shows , which gives . For , bound :
The lower tail is proved the same way with . The only lossy step is , which is nearly tight when the are small: the multiplicative bound is the right tool for sums of rare events, such as balls landing in one bin. For fair coins, Hoeffding's inequality (1963) is sharper: if the are independent and take values in , then , the in the table. Optimizing the same method exactly for fair coins gives , within a factor of 10 of the truth.
A Monte Carlo test is correct with probability . You run it times independently and take the majority answer. The Chernoff lower-tail bound gives an error of at most (with and ). How large must be for this bound to reach ?
Show the answer
664
The majority is wrong only if at most runs are correct, so the bound is , and : 664 runs. The exact binomial tail is already below at . Chernoff's constants are loose, but the shape, error falling exponentially in , is exactly right.
With high probability: quicksort and balls into bins
The second tool is the union bound, , which needs no independence at all. The standard pattern: bound each of bad events by with a tail bound, and conclude that none of them happens with high probability, at least .
Fix a key and follow the subarrays that contain it. Call a partition step good if its pivot's rank lies in the middle half of the subarray, so that both parts have at most of its size. Whatever happened before, a step is good with probability at least about . After good steps the subarray has at most keys, so is finished once
Among steps, the number of good ones dominates a binomial variable with . The key takes part in more than steps only if with , and the lower-tail Chernoff bound gives
By the union bound over the keys, with probability at least , every key takes part in at most partition steps. Each comparison involves one non-pivot key in one step, so the total is at most
Balls into bins. Throw balls into bins independently and uniformly, the model of hashing with chaining and a random hash function. The average load is 1, but the fullest bin is larger. A fixed bin receives at least balls with probability at most , the union over the -sets of balls. With this is at most for every , so by the union bound over bins, no bin holds more than balls with probability at least . The true maximum is with high probability (Raab & Steger, 1998, give sharp bounds).
One million balls go into one million bins, each into the less loaded of two random bins. About how many balls does the fullest bin hold?
Show the answer
4
, plus a constant: in five simulated runs the maximum was exactly 4 every time, against 8 to 10 with a single random choice.
The probabilistic method and derandomization
Randomness also proves that objects exist: if a random object has a property with positive probability, some object has it. Erdős's 1947 argument for Ramsey numbers is the classic example. The union bound again does the work.
Color each edge red or blue independently with probability . A fixed set of vertices spans edges, all red or all blue with probability . The union bound over all sets gives
If this is below 1, some coloring has no monochromatic . For , use :
For and , a random coloring has on average only about monochromatic copies of , so almost every coloring of avoids them. Yet no one knows how to write down such colorings efficiently for large : explicit constructions of Ramsey graphs remain far weaker than random ones.
Derandomization by conditional expectations. A random cut, each vertex on a random side, cuts each edge with probability , so some cut has at least edges. To find one deterministically, place the vertices one at a time on the side that cuts more edges to the vertices already placed. The conditional expectation of the final cut, given the choices so far, is the average over the two options for the next vertex, so the better option never lowers it: it starts at and ends as the actual cut.
def derandomized_cut(n, edges):
"""Method of conditional expectations for MAX-CUT: always cuts at least m/2 edges."""
adj = [[] for _ in range(n)]
for u, v in edges:
adj[u].append(v); adj[v].append(u)
side = [None] * n
for v in range(n): # E[cut | sides fixed so far] never decreases
to0 = sum(1 for w in adj[v] if side[w] == 0)
to1 = sum(1 for w in adj[v] if side[w] == 1)
side[v] = 1 if to0 >= to1 else 0 # join the side opposite most placed neighbors
return sum(1 for u, v in edges if side[u] != side[v]), side
print(derandomized_cut(3, [(0, 1), (1, 2), (0, 2)])) # (2, [1, 0, 1]): 2 of 3 triangle edgesChecked on 400 random graphs: always at least , never above the true maximum. The same method gives Johnson's (1974) algorithm satisfying of the clauses of a 3-CNF formula whose clauses have three distinct variables, and Håstad (2001) proved that beating is NP-hard, so this simple derandomized coin flip is optimal unless P = NP.
Small sample spaces. The cut analysis needs only that the two endpoints of each edge get independent sides: pairwise independence. Label the vertices , pick a random of bits, and put vertex on side . Any two distinct labels then get independent uniform sides, and the sample space has fewer than points, few enough to try them all: a deterministic algorithm that again guarantees .
Key takeaways
- Markov uses only the mean; Chebyshev adds the variance, which needs only pairwise independence; Chernoff and Hoeffding use full independence to get exponentially small tails.
- The Chernoff method: apply Markov to , factor the expectation by independence, optimize . The multiplicative bounds and suit sums of rare events; Hoeffding's suits bounded variables such as fair coins.
- Tail bound per element plus a union bound over elements gives "with high probability": randomized quicksort makes comparisons with probability , and balls in bins leave no bin above , while two choices cut the maximum to .
- The probabilistic method proves existence (), and conditional expectations or small pairwise-independent sample spaces turn random guarantees, such as a cut with edges, into deterministic algorithms.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
An analysis needs to apply Chebyshev's inequality. Which assumption is enough?
- The are mutually independent; nothing weaker works
- The are pairwise independent
- The are identically distributed
- The are nonnegative
Show the answer
B. The are pairwise independent
The variance of a sum adds the covariances of all pairs, and pairwise independence makes each of them 0. This is why pairwise-independent hash functions, which cost few random bits, suffice for Chebyshev-based analyses, while Chernoff bounds need more independence.
counts heads in 100 fair coin flips. Which bound on is the smallest?
- Markov:
- Chebyshev:
- Hoeffding:
- Multiplicative Chernoff with : about
Show the answer
C. Hoeffding:
Hoeffding's bound uses that each flip lies in and is sharp for fair coins. The multiplicative Chernoff bound loses in the step , which is poor for , and at this small deviation it is even weaker than Chebyshev. The exact value is about 0.028.
Each of bins receives more than balls with probability at most , but the bins' loads are dependent. What can you conclude about the event "some bin receives more than balls"?
- Nothing, because the events are not independent
- Its probability is at most
- Its probability is at most
- Its probability is exactly
Show the answer
B. Its probability is at most
The union bound needs no independence: . This is how per-element tail bounds become "with high probability" statements about all elements at once.
balls are placed one by one, each into the less loaded of two bins chosen uniformly at random. What is the maximum load, with high probability?
- , as with one choice
- At most 2
- About half the one-choice maximum
Show the answer
B.
This is Azar, Broder, Karlin and Upfal's theorem. Roughly, the number of bins with load at least shrinks doubly exponentially in once it is small, because a ball reaches load only if both its bins already have load . That squaring is what turns into .
Further reading
- H. Chernoff, "A measure of asymptotic efficiency for tests of a hypothesis based on the sum of observations," Annals of Mathematical Statistics 23(4) (1952), 493–507.
- W. Hoeffding, "Probability inequalities for sums of bounded random variables," Journal of the American Statistical Association 58(301) (1963), 13–30.
- Y. Azar, A. Z. Broder, A. R. Karlin & E. Upfal, "Balanced allocations," SIAM Journal on Computing 29(1) (1999), 180–200.
- P. Erdős, "Some remarks on the theory of graphs," Bulletin of the American Mathematical Society 53 (1947), 292–294.
- M. Mitzenmacher & E. Upfal, Probability and Computing, 2nd ed. (Cambridge University Press, 2017), chapters 3–6.