Derangement — Definition, Formula & Examples
A derangement is a rearrangement of a set of elements in which none of the elements end up in their original position. For example, if three people each grab a random hat, a derangement occurs when nobody gets their own hat back.
A derangement of a finite set is a permutation such that for every . The number of such permutations is denoted (also written , the subfactorial).
Key Formula
Where:
- = Number of derangements of $n$ elements (also written $!n$)
- = Total number of elements in the set
- = Summation index used in the inclusion-exclusion expansion
How It Works
To count derangements, apply the inclusion-exclusion principle to subtract out all permutations that fix at least one element. Let be the set of permutations fixing element . The number of permutations fixing no element is minus the size of , expanded via inclusion-exclusion. This yields the closed-form subfactorial formula. For large , approaches , so the probability that a random permutation is a derangement converges to .
Worked Example
Problem: Four friends exchange gifts randomly. In how many ways can the gifts be distributed so that nobody receives their own gift?
Apply the formula: Use the derangement formula with .
Expand the sum: Compute each term of the alternating sum.
Simplify: The numerator equals 9.
Answer: There are 9 ways to distribute the gifts so that nobody receives their own.
Why It Matters
Derangements appear in probability problems involving random matchings — secret Santa draws, shuffled exams, misdelivered letters. They also arise in algebraic combinatorics and the analysis of sorting algorithms where fixed points must be avoided.
Common Mistakes
Mistake: Confusing with , thinking you just remove the identity permutation.
Correction: Many permutations besides the identity fix at least one element. You must exclude all of them, which is exactly what the inclusion-exclusion formula does.
