Quant Memo
Core

Derangements

A derangement is a way of rearranging a set of items so that none of them ends up in its original position — the classic example being the number of ways to return everyone's hat from a mixed-up coat check so that nobody gets their own hat back.

The classic "hat-check problem" asks: nn people check their hats, the hats get shuffled randomly, and everyone is handed one hat back — in how many of the n!n! possible ways of returning the hats does absolutely nobody get their own hat back? Such an arrangement, with no item in its original position, is called a derangement, and the count of derangements of nn items, written DnD_n, follows the pattern Dn=(n1)[Dn1+Dn2]D_n = (n-1)\left[D_{n-1} + D_{n-2}\right], and for large nn the fraction of all n!n! permutations that are derangements converges quickly to 1/e0.3681/e \approx 0.368 — meaning roughly 37% of random shuffles leave nobody with their own item back, a number that barely changes once nn is more than about 5 or 6.

For example, with n=4n=4 hats there are D4=9D_4 = 9 derangements out of 4!=244! = 24 total permutations, a ratio of 9/24=0.3759/24 = 0.375 — already close to the limiting 1/e0.3681/e \approx 0.368 that larger nn converges to.

This fast convergence is what makes derangement questions a favorite trick in interviews: candidates often expect the answer to depend heavily on nn, and are surprised that "what's the probability nobody gets their own item back, for a large group" has essentially the same answer (about 37%) whether the group has 10 people or 10,000.

A derangement is a permutation with no item left in its original position; the probability a random shuffle of nn items is a derangement converges quickly to 1/e0.3681/e \approx 0.368 as nn grows, a surprisingly fast and stable convergence that interview puzzles often exploit.

Related concepts

Practice in interviews

Further reading

  • Feller, An Introduction to Probability Theory and Its Applications, vol. 1
ShareTwitterLinkedIn