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: people check their hats, the hats get shuffled randomly, and everyone is handed one hat back — in how many of the 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 items, written , follows the pattern , and for large the fraction of all permutations that are derangements converges quickly to — meaning roughly 37% of random shuffles leave nobody with their own item back, a number that barely changes once is more than about 5 or 6.
For example, with hats there are derangements out of total permutations, a ratio of — already close to the limiting that larger converges to.
This fast convergence is what makes derangement questions a favorite trick in interviews: candidates often expect the answer to depend heavily on , 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 items is a derangement converges quickly to as 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