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. 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 through . Define if person receives their own hat, and otherwise. The total number of people who get their own hat back is . By linearity of expectation, , and each , the probability person 's hat happens to land back with them. Since the hats are returned in a uniformly random order, person is equally likely to receive any of the hats, so .
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 items.
Worked example: n = 4 by brute-force check
With people, there are equally likely hat-return orders. Counting fixed points across all 24 permutations: the number of permutations with exactly fixed points is given by times the number of derangements of the remaining items. Summing times that count over all permutations and dividing by 24 gives the average — and it comes out to exactly , matching the indicator-variable answer without needing to be large for the result to hold. The clean value of 1 isn't an asymptotic approximation; it's exact for every .
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 only needed for each individually — the indicators can be dependent and it still works. But asking , 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 as 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 items is exactly 1, for every , by the indicator-variable argument . 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 grows, the probability of exactly one match stays near , 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.
Practice in interviews
Further reading
- Feller, An Introduction to Probability Theory, vol. 1, ch. 4