← Back to Chapter 3 Study Guide | ← Course Home
Math Foundations — Ch.3

COMPX270 — Chapter 3 Supplement

Mathematical Foundations: Balls in Bins

The counting, distribution theory, and analytic techniques behind the birthday paradox, coupon collector, and load balancing.

Counting & Combinatorics

Definition — Binomial Coefficient

The number of ways to choose \(k\) items from \(n\) without regard to order:

\[\binom{n}{k} = \frac{n!}{k!\,(n-k)!}\]
Fact 20.1 — Key Bound on \(\binom{n}{k}\)

For all integers \(1 \leq k \leq n\):

\[\left(\frac{n}{k}\right)^k \;\leq\; \binom{n}{k} \;\leq\; \left(\frac{en}{k}\right)^k\]

The lower bound follows from \(\binom{n}{k} \geq \frac{n^k}{k^k}\) (each factor \(\frac{n-i}{k} \geq \frac{n}{k}\cdot\frac{k-i}{k}\)), and the upper bound from \(k! \geq (k/e)^k\) (Stirling).

Start from:

\[\binom{n}{k} = \frac{n(n-1)\cdots(n-k+1)}{k!} \leq \frac{n^k}{k!}\]

By Stirling's approximation, \(k! \geq \sqrt{2\pi k}\,(k/e)^k \geq (k/e)^k\). Therefore:

\[\binom{n}{k} \leq \frac{n^k}{(k/e)^k} = \left(\frac{en}{k}\right)^k \qquad \blacksquare\]

Multinomial Coefficients

The number of ways to partition \(n\) objects into groups of sizes \(k_1, k_2, \ldots, k_r\) (where \(\sum k_i = n\)):

\[\binom{n}{k_1, k_2, \ldots, k_r} = \frac{n!}{k_1!\, k_2!\, \cdots\, k_r!}\]

The binomial coefficient is the special case \(r = 2\).

Counting Pairs

The number of unordered pairs from \(m\) items appears constantly in birthday-type problems:

\[\binom{m}{2} = \frac{m(m-1)}{2}\]

For \(m\) balls thrown into bins, there are \(\binom{m}{2}\) pairs that could potentially collide.

Quick Check: What is \(\binom{10}{3}\)?
\(30\)
\(720\)
\(120\)
\(210\)

Stirling's Approximation

Stirling's Formula

For large \(n\):

\[n! \;\approx\; \sqrt{2\pi n}\left(\frac{n}{e}\right)^n\]

More precisely: \(n! = \sqrt{2\pi n}\left(\frac{n}{e}\right)^n \left(1 + O(1/n)\right)\).

Application to the Birthday Paradox

To show a collision is likely when \(m \approx \sqrt{n}\) balls land in \(n\) bins, we need to estimate the probability of no collision:

\[\Pr[\text{no collision}] = \prod_{i=0}^{m-1}\left(1 - \frac{i}{n}\right) = \frac{n!}{(n-m)!\,n^m}\]

Using Stirling to approximate the factorials converts this to a tractable exponential form.

Key Limit

For a constant \(c > 0\), as \(n \to \infty\):

\[\left(1 - \frac{c}{\sqrt{n}}\right)^{\!\sqrt{n}} \;\longrightarrow\; e^{-c}\]

This arises directly from the birthday analysis: with \(m = c\sqrt{n}\) balls, the probability of no collision converges to \(e^{-\binom{m}{2}/n} \approx e^{-c^2/2}\).

Take the logarithm:

\[\sqrt{n}\,\ln\!\left(1 - \frac{c}{\sqrt{n}}\right)\]

For small \(x\), \(\ln(1-x) = -x - x^2/2 - \cdots \approx -x\). With \(x = c/\sqrt{n}\):

\[\sqrt{n}\left(-\frac{c}{\sqrt{n}} - \frac{c^2}{2n} - \cdots\right) = -c - \frac{c^2}{2\sqrt{n}} - \cdots \;\to\; -c\]

Exponentiating: \(e^{-c}\). \(\blacksquare\)

Harmonic Numbers

Definition — \(H_n\)

The \(n\)-th harmonic number is:

\[H_n = \sum_{k=1}^{n} \frac{1}{k} = 1 + \frac{1}{2} + \frac{1}{3} + \cdots + \frac{1}{n}\]
Asymptotic Expansion
\[H_n = \ln n + \gamma + O\!\left(\frac{1}{n}\right)\]

where \(\gamma \approx 0.5772\) is the Euler–Mascheroni constant. In particular, \(H_n = \Theta(\ln n)\).

Connection to the Coupon Collector

To collect all \(n\) coupons, the expected time is:

\[\mathbb{E}[T] = n \sum_{k=1}^{n}\frac{1}{k} = n\,H_n = n\ln n + \gamma n + O(1)\]

Each "phase" (going from \(k-1\) distinct to \(k\) distinct) is geometric with success probability \((n-k+1)/n\), contributing \(\frac{n}{n-k+1}\) in expectation. Summing over all \(n\) phases gives \(n\,H_n\).

The Basel Problem

A related but different series:

\[\sum_{k=1}^{\infty} \frac{1}{k^2} = \frac{\pi^2}{6} \approx 1.6449\]

This converges (unlike the harmonic series) and appears in variance calculations for the coupon collector problem.

Quick Check: What is \(H_3 = 1 + \frac{1}{2} + \frac{1}{3}\)?
\(\frac{3}{2}\)
\(\frac{11}{6}\)
\(2\)
\(\frac{7}{4}\)

Geometric Distribution

Definition — Geometric(\(p\))

The number of independent Bernoulli trials until the first success, where each trial has success probability \(p\):

\[\Pr[T = k] = (1-p)^{k-1}\,p, \quad k = 1, 2, 3, \ldots\]

Mean & Variance

  • \(\mathbb{E}[T] = \dfrac{1}{p}\)
  • \(\operatorname{Var}[T] = \dfrac{1-p}{p^2}\)

Memorylessness

The geometric distribution is the only discrete memoryless distribution:

\[\Pr[T > s + t \mid T > s] = \Pr[T > t]\]

"Past failures don't change the future."

Connection to the Coupon Collector

The coupon collector decomposes into \(n\) phases. In phase \(i\) (already have \(i-1\) distinct coupons, waiting for the \(i\)-th new one), each trial succeeds with probability:

\[p_i = \frac{n - (i-1)}{n}\]

The waiting time \(T_i \sim \text{Geometric}(p_i)\) with \(\mathbb{E}[T_i] = \frac{n}{n-i+1}\). The total time is \(T = \sum_{i=1}^{n} T_i\), and by linearity:

\[\mathbb{E}[T] = \sum_{i=1}^{n} \frac{n}{n-i+1} = n \sum_{j=1}^{n} \frac{1}{j} = nH_n\]
Quick Check: If \(T \sim \text{Geometric}(1/4)\), what is \(\operatorname{Var}[T]\)?
\(12\)
\(4\)
\(16\)
\(3\)

Indicator Variables & Variance

Recall — Indicator Random Variables

For an event \(A\), define \(\mathbf{1}_A \in \{0,1\}\) with \(\mathbb{E}[\mathbf{1}_A] = \Pr[A]\).

Products of indicators give joint probabilities: \(\mathbb{E}[\mathbf{1}_A \cdot \mathbf{1}_B] = \Pr[A \cap B]\).

When Is Variance Additive?

For \(X = \sum_i X_i\):

\[\operatorname{Var}[X] = \sum_i \operatorname{Var}[X_i] + 2\sum_{i < j} \operatorname{Cov}[X_i, X_j]\]

The covariance terms vanish when \(X_i, X_j\) are pairwise independent (i.e., \(\mathbb{E}[X_i X_j] = \mathbb{E}[X_i]\mathbb{E}[X_j]\)).

Pairwise vs Full Independence

Pairwise independence: every pair is independent. Sufficient for \(\operatorname{Var}[\sum X_i] = \sum \operatorname{Var}[X_i]\) and for Chebyshev.

Full (mutual) independence: every subset factors. Required for Chernoff bounds and MGF factorization.

The "Magic Cancellation" in Collision Variance

Let \(C = \sum_{\{i,j\}} \mathbf{1}_{ij}\) count collisions among \(m\) balls in \(n\) bins, where \(\mathbf{1}_{ij}\) indicates balls \(i,j\) land in the same bin. There are \(\binom{m}{2}\) such indicators. Computing \(\operatorname{Var}[C]\) requires analyzing \(\mathbb{E}[\mathbf{1}_{ij}\,\mathbf{1}_{kl}]\) for all pairs of pairs. Three cases arise:

Case
Count
\(\mathbb{E}[\mathbf{1}_{ij}\cdot\mathbf{1}_{kl}]\)
Same pair \(\{i,j\} = \{k,l\}\)
\(\binom{m}{2}\) terms
\(\frac{1}{n}\) (since \(\mathbf{1}_{ij}^2 = \mathbf{1}_{ij}\))
Disjoint: \(\{i,j\}\cap\{k,l\}=\emptyset\)
\(\binom{m}{2}\binom{m-2}{2}/2\) terms
\(\frac{1}{n^2}\) (independent)
Overlapping: share exactly one ball
\(6\binom{m}{3}\) terms
\(\frac{1}{n^2}\) (both need the shared ball's bin)

The "magic": overlapping pairs have \(\mathbb{E}[\mathbf{1}_{ij}\mathbf{1}_{jk}] = 1/n^2 = \mathbb{E}[\mathbf{1}_{ij}]\cdot\mathbb{E}[\mathbf{1}_{jk}]\), so even though \(\mathbf{1}_{ij}\) and \(\mathbf{1}_{jk}\) share ball \(j\), they are uncorrelated! This makes the variance calculation much cleaner:

\[\operatorname{Var}[C] = \mathbb{E}[C^2] - \mathbb{E}[C]^2 \leq \mathbb{E}[C] = \binom{m}{2}\frac{1}{n}\]
Quick Check: What is the minimum independence condition for \(\operatorname{Var}\!\left[\sum X_i\right] = \sum \operatorname{Var}[X_i]\)?
Full mutual independence
Pairwise independence
No independence needed

Moment Methods

First Moment Method (Markov for integer r.v.)

If \(X\) is a non-negative integer-valued random variable:

\[\Pr[X \geq 1] \leq \mathbb{E}[X]\]

This is just Markov's inequality with \(t = 1\). It gives a quick upper bound on the probability that a count is nonzero.

Application — Birthday Lower Bound

Let \(C\) count collisions among \(m\) balls in \(n\) bins. Then \(\Pr[\text{collision}] = \Pr[C \geq 1] \leq \mathbb{E}[C] = \binom{m}{2}/n\).

So if \(m \ll \sqrt{n}\), collisions are unlikely. But this doesn't tell us when collisions become likely.

Second Moment Method

For a non-negative integer-valued random variable \(X\):

\[\Pr[X = 0] \leq \frac{\operatorname{Var}[X]}{\mathbb{E}[X]^2}\]

Equivalently: \(\Pr[X \geq 1] \geq 1 - \frac{\operatorname{Var}[X]}{\mathbb{E}[X]^2} = \frac{\mathbb{E}[X]^2 - \operatorname{Var}[X]}{\mathbb{E}[X]^2}\).

Chebyshev gives:

\[\Pr[|X - \mu| \geq \mu] \leq \frac{\operatorname{Var}[X]}{\mu^2}\]

Since \(\{X = 0\} \subseteq \{|X - \mu| \geq \mu\}\) (because \(X \geq 0\) and \(\mu > 0\)):

\[\Pr[X = 0] \leq \Pr[|X - \mu| \geq \mu] \leq \frac{\operatorname{Var}[X]}{\mu^2} \qquad \blacksquare\]
Application — Birthday Threshold

With \(m = c\sqrt{n}\) balls, \(\mathbb{E}[C] = \binom{m}{2}/n \approx c^2/2\) and \(\operatorname{Var}[C] \leq \mathbb{E}[C]\). So:

\[\Pr[\text{collision}] \geq 1 - \frac{\operatorname{Var}[C]}{\mathbb{E}[C]^2} \geq 1 - \frac{1}{\mathbb{E}[C]} = 1 - \frac{2}{c^2}\]

For \(c\) large (say \(c = 3\)), this gives \(\Pr[\text{collision}] \geq 7/9 \approx 78\%\).

Poisson Approximation

Poisson Limit Theorem

If \(X \sim \text{Bin}(n, \lambda/n)\) and \(n \to \infty\) with \(\lambda\) fixed, then:

\[X \xrightarrow{d} \text{Poisson}(\lambda)\]
Poisson PMF

For \(X \sim \text{Poisson}(\lambda)\) and integer \(k \geq 0\):

\[\Pr[X = k] = \frac{e^{-\lambda}\,\lambda^k}{k!}\]

Key facts: \(\mathbb{E}[X] = \lambda\), \(\operatorname{Var}[X] = \lambda\).

Independence after Poissonization

The key power of the Poisson model: if we throw \(\text{Poisson}(\lambda)\) balls (instead of exactly \(m\)) uniformly into \(n\) bins, then the bin loads \(B_1, B_2, \ldots, B_n\) are mutually independent, each distributed as \(\text{Poisson}(\lambda/n)\).

This makes the maximum load analysis tractable — we can analyze each bin separately and apply a union bound.

Application to Load Balancing

With \(m = n\) balls and \(n\) bins, Poissonize with \(\lambda = n\). Each bin has load \(B_i \sim \text{Poisson}(1)\). The probability a single bin has load \(\geq k\) is:

\[\Pr[B_i \geq k] = 1 - \sum_{j=0}^{k-1}\frac{e^{-1}}{j!} \leq \frac{1}{k!}\]

By union bound over \(n\) bins: \(\Pr[\max B_i \geq k] \leq n/k!\). Setting \(k = \Theta(\ln n / \ln\ln n)\) makes this vanish.

Quick Check: If \(X \sim \text{Poisson}(3)\), what is \(\operatorname{Var}[X]\)?
\(9\)
\(\sqrt{3}\)
\(3\)
\(6\)

Jensen's Inequality & MGF Trick

Jensen's Inequality

If \(f\) is convex: \(\;f(\mathbb{E}[X]) \leq \mathbb{E}[f(X)]\)

If \(f\) is concave: \(\;f(\mathbb{E}[X]) \geq \mathbb{E}[f(X)]\)

Key Instance: \(\mathbb{E}[\ln X] \leq \ln \mathbb{E}[X]\)

Since \(\ln\) is concave, Jensen gives \(\mathbb{E}[\ln X] \leq \ln(\mathbb{E}[X])\). Equivalently, by exponentiation:

\[\mathbb{E}[e^Y] \geq e^{\mathbb{E}[Y]}\]

for any random variable \(Y\) (using \(f(y) = e^y\), which is convex).

The MGF Trick: Max → Sum via Exponentiation

To bound the maximum of random variables, convert it to a sum using the exponential function. For any \(t > 0\):

\[\max_i X_i = \frac{1}{t}\ln\!\left(\max_i e^{tX_i}\right) \leq \frac{1}{t}\ln\!\left(\sum_i e^{tX_i}\right)\]

The inequality holds because \(\max \leq \sum\) for non-negative quantities.

Application to Load Balancing Upper Bound

Let \(M = \max_j B_j\) be the maximum bin load. For any \(t > 0\):

\[\mathbb{E}[e^{tM}] = \mathbb{E}\!\left[\max_j e^{tB_j}\right] \leq \sum_{j=1}^{n}\mathbb{E}[e^{tB_j}]\]

By Markov: \(\Pr[M \geq k] = \Pr[e^{tM} \geq e^{tk}] \leq \frac{\sum_j \mathbb{E}[e^{tB_j}]}{e^{tk}}\).

Each \(B_j \sim \text{Poisson}(1)\) has \(\mathbb{E}[e^{tB_j}] = e^{e^t - 1}\), giving:

\[\Pr[M \geq k] \leq n \cdot \frac{e^{e^t - 1}}{e^{tk}}\]

Free Parameter Optimization

The bound holds for all \(t > 0\), so we choose \(t\) to minimize \(e^{e^t - 1 - tk}\). Taking the derivative and setting to zero:

\[\frac{d}{dt}(e^t - 1 - tk) = e^t - k = 0 \implies t^* = \ln k\]

Substituting: the exponent becomes \(k - 1 - k\ln k \approx -k\ln k\) for large \(k\). Combined with the union bound factor \(n\), we get the maximum load is \(O(\ln n / \ln\ln n)\) with high probability — by balancing \(n \cdot e^{-k\ln k} \leq 1/n\).

Math quiz

Chapter math quizzes are in the Quiz Hub. Filter by this chapter and choose Study / Math / All.

Open Quiz Hub