Counting Done Right: From the Birthday Paradox to the Binomial Distribution

Order and repetition generate the four urn models β€” and from them the birthday paradox and the binomial distribution follow almost mechanically.

22 min Β· difficulty 2/5

Discrete probability rests on one sentence: if all outcomes are equally likely, P(A)=∣A∣/∣Ω∣P(A) = |A|/|\Omega|. Everything hard about it is therefore counting, and counting fails the moment you are vague about two questions β€” does order matter, and may an element repeat. Those two binary choices generate the four urn models, and from them the birthday paradox and the binomial distribution follow almost mechanically.

Counting by stages: the multiplication principle

Definition

Multiplication principle. If an object is built in kk stages and stage ii offers mim_i options regardless of the earlier choices, the number of distinct objects is m1m2β‹―mkm_1 m_2 \cdots m_k.

The clause "regardless of the earlier choices" is the entire content. Drawing kk balls from nn with replacement leaves mi=nm_i = n at every stage, giving nkn^k. Without replacement, the pool shrinks by a fixed amount, mi=nβˆ’i+1m_i = n-i+1, giving the falling factorial

nkβ€Ύ=n(nβˆ’1)β‹―(nβˆ’k+1)=n!(nβˆ’k)!n^{\underline{k}} = n(n-1)\cdots(n-k+1) = \frac{n!}{(n-k)!}

Both are ordered counts: the choice tree has nkn^k and nkβ€Ύn^{\underline{k}} leaves respectively, and each leaf is one sequence.

The four urn models

An urn holds nn distinguishable balls, and we draw kk. The two yes/no questions give exactly four counting problems.

ordered (sequence)unordered (set / multiset)
with replacementnkn^k(n+kβˆ’1k)\dbinom{n+k-1}{k}
without replacementnkβ€Ύ=n!(nβˆ’k)!n^{\underline{k}} = \dfrac{n!}{(n-k)!}(nk)=n!k! (nβˆ’k)!\dbinom{n}{k} = \dfrac{n!}{k!\,(n-k)!}

The bottom row is easy: every unordered selection of kk distinct balls has exactly k!k! orderings, so the ordered count over-counts by a constant factor, and (nk)=nkβ€Ύ/k!\binom{n}{k} = n^{\underline{k}}/k!. Dividing out the symmetry is the standard route from ordered to unordered β€” but only because that factor is the same for every selection.

Stars and bars: why one cell is different

For multisets the division fails: {a,a,b}\{a,a,b\} has 33 orderings, {a,b,c}\{a,b,c\} has 66, so no single divisor undoes the over-counting (nk/k!n^k/k! is not even an integer in general). Re-encode instead: an unordered draw with replacement is determined by the multiplicities x1+β‹―+xn=kx_1 + \cdots + x_n = k, xiβ‰₯0x_i \ge 0. Write kk stars and split the nn bins with nβˆ’1n-1 bars:

β‹†β‹†βŸx1=2β€…β€Šβˆ£β€…β€Šβ‹†βŸx2=0β€…β€Šβˆ£β€…β€Šβ‹†β‹†β‹†βŸx3=3⟹(n+kβˆ’1k)\underbrace{\star\star}_{x_1=2}\;\mid\;\underbrace{\phantom{\star}}_{x_2=0}\;\mid\;\underbrace{\star\star\star}_{x_3=3} \qquad\Longrightarrow\qquad \binom{n+k-1}{k}

Classic pitfall

Multisets are not an equally likely sample space. Two dice give (72)=21\binom{7}{2}=21 multisets, but {1,2}\{1,2\} comes from 22 of the 3636 ordered outcomes and {1,1}\{1,1\} from only 11. Laplace probability lives on the ordered model; stars and bars is a counting device, not a probability model.

Complement counting: the birthday paradox

Put kk people into n=365n = 365 equally likely birthdays. The sample space is ordered with replacement, ∣Ω∣=365k|\Omega| = 365^k; the event "all distinct" is ordered without replacement, 365kβ€Ύ365^{\underline{k}}. So

P(collision)=1βˆ’365kβ€Ύ365 k=1βˆ’βˆi=0kβˆ’1(1βˆ’i365)P(\text{collision}) = 1 - \frac{365^{\underline{k}}}{365^{\,k}} = 1 - \prod_{i=0}^{k-1}\Big(1 - \frac{i}{365}\Big)

xy12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879801k = 23P(at least one shared birthday)50 %
Exact values: 0.117 at k = 10, 0.507 at k = 23, 0.706 at 30, 0.903 at 41, 0.970 at 50, 0.9992 at 70.

The paradox is one of framing: intuition answers "who shares my birthday", i.e. kβˆ’1k-1 comparisons with P=1βˆ’(364/365)kβˆ’1P = 1-(364/365)^{k-1}, which needs a group of k=254k = 254. The question instead counts all (k2)\binom{k}{2} pairs, and at k=23k = 23 that is 253253 pairs β€” numerically the same 253253, by coincidence. Pretending those pairs were independent gives (1βˆ’1365)253β‰ˆ0.4995(1-\tfrac{1}{365})^{253} \approx 0.4995; it is close to the exact 0.49270.4927 but systematically overestimates non-collision, because the pair events are dependent (a shared birthday of A,BA,B and of B,CB,C forces one for A,CA,C).

Bernoulli trials and the binomial distribution

Repeat an experiment nn times independently, recording success (probability pp) or failure. One outcome is a word in {S,F}n\{S,F\}^n β€” ordered with replacement, but not equally likely: by independence a specific word with kk successes has probability pk(1βˆ’p)nβˆ’kp^k(1-p)^{n-k}. That value depends only on kk, not on where the successes sit, so we merely count the words β€” choosing which kk of nn slots succeed is unordered without replacement.

Definition

X∼Bin(n,p)X \sim \mathrm{Bin}(n,p) if β€…β€ŠP(X=k)=(nk)pk(1βˆ’p)nβˆ’k\;P(X=k) = \dbinom{n}{k} p^k (1-p)^{n-k} for k=0,…,nk=0,\dots,n, with E[X]=np\mathbb{E}[X] = np and Var(X)=np(1βˆ’p)\mathrm{Var}(X) = np(1-p).

The binomial coefficient is no fudge factor: it is the urn model appearing inside a probability. Normalisation is the binomial theorem, βˆ‘k(nk)pk(1βˆ’p)nβˆ’k=(p+(1βˆ’p))n=1\sum_k \binom{n}{k}p^k(1-p)^{n-k} = (p + (1-p))^n = 1. If instead we sample without replacement from NN items containing KK successes, independence fails and the count becomes hypergeometric, P(X=k)=(Kk)(Nβˆ’Knβˆ’k)/(Nn)P(X=k) = \binom{K}{k}\binom{N-K}{n-k}\big/\binom{N}{n} β€” three binomial coefficients, no pp at all.

Worked example: defective parts, with and without replacement

Step 1 β€” Fix the model. A crate holds N=12N = 12 components, K=4K = 4 defective; we inspect n=5n = 5. Inspection is without replacement and order is irrelevant, so Ξ©\Omega = all 55-subsets, ∣Ω∣=(125)=792|\Omega| = \binom{12}{5} = 792, equally likely.

Step 2 β€” Count the favourable sets. Exactly 22 defective means choosing 22 of 44 and 33 of 88: (42)(83)=6β‹…56=336\binom{4}{2}\binom{8}{3} = 6 \cdot 56 = 336.

Step 3 β€” Divide. P(X=2)=336792=1433β‰ˆ0.4242P(X=2) = \frac{336}{792} = \frac{14}{33} \approx 0.4242.

Step 4 β€” Compare with replacement. Testing and returning each part gives Bernoulli trials with p=4/12=1/3p = 4/12 = 1/3, hence P(Y=2)=(52)(13)2(23)3=10β‹…19β‹…827=80243β‰ˆ0.3292P(Y=2) = \binom{5}{2}\big(\tfrac13\big)^2\big(\tfrac23\big)^3 = 10 \cdot \tfrac{1}{9} \cdot \tfrac{8}{27} = \tfrac{80}{243} \approx 0.3292.

Step 5 β€” Read the difference. Both have mean np=5/3np = 5/3, but drawing without replacement is self-correcting, so the variance carries the finite-population correction Nβˆ’nNβˆ’1=711\frac{N-n}{N-1} = \frac{7}{11} and mass piles up near the mean.

Result

P(exactlyΒ 2Β defective)=1433β‰ˆ42.4 %P(\text{exactly 2 defective}) = \frac{14}{33} \approx 42.4\,\% (hypergeometric, the correct model) versus β‰ˆ32.9 %\approx 32.9\,\% under the binomial. With n/N=0.42n/N = 0.42 the crate is far too small for that approximation β€” use it only when nβ‰ͺNn \ll N (rule of thumb n≀0.05 Nn \le 0.05\,N).

Summary

  • Multiplication principle: independent stage-by-stage choices multiply; every formula here follows from it.
  • Four urn models: nkn^k, nkβ€Ύn^{\underline{k}}, (nk)\binom{n}{k}, (n+kβˆ’1k)\binom{n+k-1}{k} β€” classified by order and replacement.
  • Divide by k!k! only when the symmetry factor is constant; multisets need stars and bars.
  • Complement counting turns "at least one" into "none": k=23k = 23 birthdays suffice for P>12P > \tfrac12 because pairs grow like k2k^2.
  • The coefficient in Bin(n,p)\mathrm{Bin}(n,p) counts arrangements; the same count without replacement gives the hypergeometric law.

Questions & Answers

Why does dividing by k!k! fail for unordered sampling with replacement?

Answer

Dividing an ordered count by k!k! works only if every unordered object has exactly k!k! orderings, which requires all drawn items to be distinct. With repeats the factor varies β€” {a,a,b}\{a,a,b\} has 3!/2!=33!/2! = 3 orderings, {a,b,c}\{a,b,c\} has 66 β€” so no single divisor undoes the over-counting. Note also that nk/k!n^k/k! is usually not even an integer, the fastest sanity check that the model is wrong; stars and bars avoids the issue by encoding the multiset as multiplicities.

Why is the birthday result so counter-intuitive?

Answer

People silently answer an easier question. "Does anyone share my birthday?" involves only kβˆ’1k-1 comparisons, so a 50 % chance needs a group of k=254k = 254 (P=0.5004P = 0.5004; already 0.49910.4991 at 253253). The real question involves all (k2)\binom{k}{2} unordered pairs, which grows quadratically; at k=23k = 23 that is exactly 253253 pairs. That the two 253253s coincide is arithmetic accident, not a link β€” but it shows why the two readings cross 50 % at such different group sizes.

What does complement counting buy us technically?

Answer

"At least one collision" is a union of heavily overlapping events, so direct counting needs inclusion–exclusion over many terms. Its complement, "all birthdays distinct", is a single ordered-without-replacement count 365kβ€Ύ365^{\underline{k}}, i.e. one product. Whenever an event reads "at least one", test the complement first.

Where does independence enter the binomial formula?

Answer

Exactly when we assign pk(1βˆ’p)nβˆ’kp^k(1-p)^{n-k} to one specific success/failure word: independence licenses multiplying the per-trial probabilities, and identical distribution makes the product depend only on the number of successes, not their positions. That position-invariance is what lets us group the words and multiply by (nk)\binom{n}{k}.

Why (nk)\binom{n}{k} rather than nkβ€Ύn^{\underline{k}} in Bin(n,p)\mathrm{Bin}(n,p)?

Answer

We choose which kk of the nn trial slots are successes, and the successes are indistinguishable β€” slot 33 being a success is the same outcome no matter in which order we "selected" it. That is selection without order and without replacement, so (nk)\binom{n}{k}; using nkβ€Ύn^{\underline{k}} would count each word k!k! times.

When may I replace the hypergeometric by the binomial?

Answer

When the sample barely changes the population composition. The variances differ precisely by the finite-population correction Nβˆ’nNβˆ’1\frac{N-n}{N-1}, so the approximation is good when that factor is close to 11, i.e. nβ‰ͺNn \ll N; the usual rule of thumb is n≀0.05Nn \le 0.05N. In the worked example n/N=0.42n/N = 0.42, and the two answers differ by 9.59.5 percentage points.

How do I decide "ordered or unordered" in a word problem?

Answer

Ask whether two outcomes differing only by a permutation of the drawn items count as different. PIN codes, race podiums and toss sequences: order matters. Lottery tickets, committees and card hands: it does not. When unsure, model the ordered version: for uniform draws from an urn (with or without replacement) it is an equally likely space, and the event of interest is usually permutation-invariant, so the k!k! cancels in the ratio. This does not extend to non-uniform mechanisms — for Bernoulli trials with p≠12p \neq \tfrac12 the ordered words are not equiprobable and must be weighted.

What links the birthday paradox to computer science?

Answer

Hash collisions. With a hash space of size nn, about 2ln⁑2β‹…nβ‰ˆ1.177n\sqrt{2\ln 2 \cdot n} \approx 1.177\sqrt{n} random items give a 50 % collision chance β€” for n=365n = 365 that is 22.522.5, i.e. the k=23k = 23 found above. The expected number of items drawn before the first repeat is the larger Ο€n/2β‰ˆ1.25n\sqrt{\pi n/2} \approx 1.25\sqrt{n}, here 23.923.9; mean and median differ and must not be conflated. This birthday bound is why a 6464-bit hash falls at roughly 2322^{32} items and why cryptographic digests use 256256 bits.

The rest of the map

The four urn models are the entrance hall of discrete probability; here is what lies immediately beyond.

Advanced counting

  • Multinomial coefficients β€” n!k1!β‹―km!\frac{n!}{k_1!\cdots k_m!} counts arrangements with several item types; the binomial for mm outcomes per trial.
  • Inclusion–exclusion β€” the systematic count of unions; yields derangements and "at least one of several types".

Related distributions

  • Hypergeometric β€” the without-replacement counterpart of the binomial; quality control and capture–recapture.
  • Poisson β€” the limit nβ†’βˆžn \to \infty, pβ†’0p \to 0, np=Ξ»np = \lambda; the law of rare events.
  • Geometric / negative binomial β€” count trials until the rr-th success instead of successes in fixed nn.

Approximation and limits

  • Stirling's formula β€” n!∼2Ο€n (n/e)nn! \sim \sqrt{2\pi n}\,(n/e)^n; tames factorials and binomial coefficients asymptotically; the n\sqrt{n} of the birthday bound comes from (k2)β‰ˆn\binom{k}{2} \approx n, not from Stirling.
  • De Moivre–Laplace and the CLT β€” the normal approximation of the binomial; the bridge to continuous probability.

Suggested roadmap

  1. Drill the 2Γ—2 table until any word problem can be classified in one sentence.
  2. Prove (nk)=nkβ€Ύ/k!\binom{n}{k} = n^{\underline{k}}/k! and the stars-and-bars bijection from scratch.
  3. Practise complement counting on "at least one" problems: birthdays, hash collisions, lottery.
  4. Derive Bin(n,p)\mathrm{Bin}(n,p) from Bernoulli trials, then get E[X]\mathbb{E}[X] and Var(X)\mathrm{Var}(X) via indicator variables.
  5. Compare binomial and hypergeometric numerically until the finite-population correction feels obvious.
  6. Take the Poisson limit of the binomial, then close with the normal approximation and the CLT.

Counting, complement counting and independence are the three moves behind nearly every discrete distribution β€” master the urn table and the rest is bookkeeping.