A derangement has no fixed point
σ(i) ≠ i for every i. The hat-check problem: nobody gets their own hat.
A derangement moves every element. Inclusion and exclusion counts them, and the proportion of permutations that are derangements converges to 1/e almost immediately — it is already accurate at n = 7.
Core ideas
Derangements are the standard worked example of inclusion and exclusion, and their limit is genuinely surprising.
σ(i) ≠ i for every i. The hat-check problem: nobody gets their own hat.
Let Aᵢ be the permutations fixing i. Then |Aᵢ| = (n−1)! and the intersections are similarly clean, so the alternating sum closes.
Dₙ/n! is within 10⁻⁴ of 1/e by n = 7. The chance that nobody gets their own hat is essentially the same for 10 people and for 10 million.
The material
The derivation, the recurrence, and the limit.
A derangement of {1, …, n} is a permutation σ with σ(i) ≠ i for every i. Dₙ denotes the number of them.
Dₙ = n! Σ_{k=0}^{n} (−1)^k / k! = n! (1 − 1/1! + 1/2! − 1/3! + ⋯ + (−1)ⁿ/n!).
Let Aᵢ be the set of permutations fixing i. A permutation is a derangement exactly when it lies in none of the Aᵢ, so Dₙ = n! − |A₁ ∪ ⋯ ∪ A_n|.
Fixing a specified set of k elements leaves the other n − k free, so each k-fold intersection has (n−k)! members, and there are C(n,k) such intersections.
By inclusion and exclusion, Dₙ = Σ_{k=0}^{n} (−1)^k C(n,k)(n−k)! = Σ_{k=0}^{n} (−1)^k n!/k!, which is the stated formula.
□
The convergence is startlingly quick because the series for 1/e alternates with rapidly shrinking terms: the error after n terms is below 1/(n+1)!. By n = 7 that is under 1/40320.
Dₙ is the nearest integer to n!/e for every n ≥ 1, which follows from the same error bound.
Dₙ = (n−1)(Dₙ₋₁ + Dₙ₋₂) for n ≥ 3, with D₁ = 0 and D₂ = 1.
In a derangement, element 1 goes to some position j ≠ 1, and there are n − 1 choices of j. Split on what happens to j:
If j goes to position 1, the remaining n − 2 elements form a derangement among themselves: Dₙ₋₂ ways.
If j does not go to position 1, then treating "position 1" as the forbidden position for j makes the remaining n − 1 elements a derangement of n − 1 items: Dₙ₋₁ ways.
So Dₙ = (n−1)(Dₙ₋₂ + Dₙ₋₁).
□
Two derivations of the same numbers, by different techniques. The recurrence is a case split of the kind “Recurrence Relations” in Induction and Recursion taught; the formula came from inclusion and exclusion. Agreement between them is a genuine check, and both are worth having.
n people check hats and receive them back at random. The probability nobody gets their own is Dₙ/n!, which for n ≥ 7 is 0.3679 to four places whatever n is — at n = 5 it is still 0.3667 and at 6 it is 0.3681. Discrete Probability makes the division into a probability statement.
Interactive
Three routes to one number
Method
Recognise the "nothing in its own place" shape.
That is what makes it a derangement. More complicated forbidden patterns need the permanent of a matrix and are outside this course.
The recurrence is faster by hand for small n; the formula is what generalises.
"Exactly k fixed points" is C(n,k)·D_{n−k}: choose which stay, derange the rest.
Dₙ is the nearest integer to n!/e. It is a one-line verification of an answer computed another way.
Out of six people, how many outcomes fix exactly two?
The final check is the useful one: every permutation has exactly one number of fixed points, so summing over k must recover n!. D₀ = 1 — the empty permutation deranges vacuously — is what makes the last term come out right.
Compute the number of permutations of 7 elements with exactly three fixed points, then verify that summing your formula over all k from 0 to 7 gives 7! = 5040. The check is what confirms the setup.
Something to change about this lesson? Write it down, tick it off when it is handled, and export the list when you want to act on it. Kept in this browser only: nothing is sent anywhere, and nobody is notified.
No recommendations yet for this lesson.