Quant Memo
Foundational

The Hat-Check Problem and Expected Fixed Points

The classic derangement puzzle — n people randomly return n hats, what fraction get their own back — solved cleanly with indicator variables instead of the full derangement formula.

Prerequisites: Conditional Probability

The problem. nn people check their hats at a party. The coat-check attendant loses the tickets and hands hats back in a uniformly random order. In expectation, how many people get their own hat back? A related, harder question — what's the probability nobody gets their own hat back — is the classic "derangement" problem, and it's worth seeing why the expectation question is easy while that one is hard.

Setting it up with indicators

Label the people 11 through nn. Define Xi=1X_i = 1 if person ii receives their own hat, and 00 otherwise. The total number of people who get their own hat back is X=X1++XnX = X_1 + \cdots + X_n. By linearity of expectation, E[X]=i=1nE[Xi]E[X] = \sum_{i=1}^n E[X_i], and each E[Xi]=P(Xi=1)E[X_i] = P(X_i = 1), the probability person ii's hat happens to land back with them. Since the hats are returned in a uniformly random order, person ii is equally likely to receive any of the nn hats, so P(Xi=1)=1nP(X_i = 1) = \frac{1}{n}.

E[X]=i=1n1n=n1n=1.E[X] = \sum_{i=1}^n \frac{1}{n} = n \cdot \frac{1}{n} = 1.

In plain English: no matter how many people are at the party — 5 or 500 — the expected number who get their own hat back is exactly 1. This is the same skeleton as the card-shuffle fixed-point puzzle, because a random hat return and a random card shuffle are the same mathematical object: a uniformly random permutation of nn items.

Worked example: n = 4 by brute-force check

With n=4n=4 people, there are 4!=244! = 24 equally likely hat-return orders. Counting fixed points across all 24 permutations: the number of permutations with exactly kk fixed points is given by (4k)\binom{4}{k} times the number of derangements of the remaining 4k4-k items. Summing kk times that count over all permutations and dividing by 24 gives the average — and it comes out to exactly 2424=1\frac{24}{24} = 1, matching the indicator-variable answer without needing nn to be large for the result to hold. The clean value of 1 isn't an asymptotic approximation; it's exact for every n1n \geq 1.

Distribution · poisson
mean 1.00123456outcomes (k) →
mean 1.00std dev 1.00peak at k = 0

Drag the rate parameter to 1 on the explorer above: the number of fixed points in a large random permutation is well approximated by a Poisson(1) distribution — mean 1, but with real probability mass at 0, 1, 2, and beyond, illustrating that "expected value 1" does not mean "always exactly 1."

Why the harder question — nobody gets a match — needs more machinery

Asking for E[X]E[X] only needed P(Xi=1)P(X_i=1) for each ii individually — the indicators can be dependent and it still works. But asking P(X=0)P(X = 0), the probability of zero matches (a derangement), genuinely requires the joint structure: whether person 1 misses their hat is not independent of whether person 2 misses theirs, because they're drawing from the same shrinking pool. That probability converges to e136.8%e^{-1} \approx 36.8\% as nn grows, via inclusion-exclusion — a much heavier calculation than the one-line expectation. The contrast is the lesson: expectation questions often dissolve into simple indicator sums even when the corresponding probability question is hard.

The expected number of fixed points in a uniformly random permutation of nn items is exactly 1, for every nn, by the indicator-variable argument E[X]=P(Xi=1)=n1nE[X]=\sum P(X_i=1)=n\cdot\frac{1}{n}. This holds regardless of dependence between the indicators — only the exact-count and zero-count questions need the harder joint-dependence machinery.

Don't confuse "expected number of matches is 1" with "matches are common." As nn grows, the probability of exactly one match stays near 1/e1/e, but so does the probability of zero matches — the distribution is closer to Poisson(1) than to being tightly concentrated at 1. The mean being 1 doesn't mean 1 is the typical outcome for any given trial.

Related concepts

Practice in interviews

Further reading

  • Feller, An Introduction to Probability Theory, vol. 1, ch. 4
ShareTwitterLinkedIn