ProofComplete

Pigeonhole and Inclusion-Exclusion - Key Proof

The derangement formula is one of the most elegant applications of the inclusion-exclusion principle, counting permutations where no element remains in its original position.

DefinitionDerangement

A derangement of a set {1,2,,n}\{1, 2, \ldots, n\} is a permutation σ\sigma such that σ(i)i\sigma(i) \neq i for all i{1,2,,n}i \in \{1, 2, \ldots, n\}. The number of derangements of nn objects is denoted DnD_n or !n!n.

Theorem: The number of derangements of nn objects is: Dn=n!k=0n(1)kk!D_n = n! \sum_{k=0}^{n} \frac{(-1)^k}{k!}

Proof using Inclusion-Exclusion:

Let SS be the set of all permutations of {1,2,,n}\{1, 2, \ldots, n\}, so S=n!|S| = n!.

For each i{1,2,,n}i \in \{1, 2, \ldots, n\}, let AiA_i be the set of permutations where element ii is in position ii (i.e., σ(i)=i\sigma(i) = i).

We want to count permutations where no element is fixed, which is: Dn=A1A2An=n!A1A2AnD_n = \left|\overline{A_1 \cup A_2 \cup \cdots \cup A_n}\right| = n! - |A_1 \cup A_2 \cup \cdots \cup A_n|

We apply the inclusion-exclusion principle to compute A1An|A_1 \cup \cdots \cup A_n|: A1An=k=1n(1)k+1S=kiSAi|A_1 \cup \cdots \cup A_n| = \sum_{k=1}^{n} (-1)^{k+1} \sum_{|S|=k} \left|\bigcap_{i \in S} A_i\right|

For any subset S{1,2,,n}S \subseteq \{1, 2, \ldots, n\} with S=k|S| = k, the intersection iSAi\bigcap_{i \in S} A_i consists of permutations where all elements in SS are fixed in their original positions. The remaining nkn-k elements can be arranged arbitrarily, giving (nk)!(n-k)! permutations.

The number of subsets SS with S=k|S| = k is (nk)\binom{n}{k}.

Therefore: iSAi=(nk)!\left|\bigcap_{i \in S} A_i\right| = (n-k)!

and: S=kiSAi=(nk)(nk)!\sum_{|S|=k} \left|\bigcap_{i \in S} A_i\right| = \binom{n}{k} (n-k)!

Substituting into the inclusion-exclusion formula: A1An=k=1n(1)k+1(nk)(nk)!|A_1 \cup \cdots \cup A_n| = \sum_{k=1}^{n} (-1)^{k+1} \binom{n}{k} (n-k)!

=k=1n(1)k+1n!k!(nk)!(nk)!=k=1n(1)k+1n!k!= \sum_{k=1}^{n} (-1)^{k+1} \frac{n!}{k!(n-k)!} (n-k)! = \sum_{k=1}^{n} (-1)^{k+1} \frac{n!}{k!}

Therefore: Dn=n!k=1n(1)k+1n!k!=n!k=1n(1)k+1n!k!D_n = n! - \sum_{k=1}^{n} (-1)^{k+1} \frac{n!}{k!} = n! - \sum_{k=1}^{n} \frac{(-1)^{k+1} n!}{k!}

=n!n!k=1n(1)k+1k!=n!(1k=1n(1)k+1k!)= n! - n! \sum_{k=1}^{n} \frac{(-1)^{k+1}}{k!} = n! \left(1 - \sum_{k=1}^{n} \frac{(-1)^{k+1}}{k!}\right)

=n!(1+k=1n(1)kk!)=n!k=0n(1)kk!= n! \left(1 + \sum_{k=1}^{n} \frac{(-1)^{k}}{k!}\right) = n! \sum_{k=0}^{n} \frac{(-1)^k}{k!}

This completes the proof. \square

ExampleComputing Small Derangements

For small values of nn:

  • D0=1D_0 = 1 (by convention, the empty permutation)
  • D1=0D_1 = 0 (element 1 must be in position 1)
  • D2=1D_2 = 1 (only the swap: (2,1)(2,1))
  • D3=2D_3 = 2 (permutations (2,3,1)(2,3,1) and (3,1,2)(3,1,2))
  • D4=9D_4 = 9

We can verify D3D_3 using the formula: D3=3!(11+1216)=613=2D_3 = 3! \left(1 - 1 + \frac{1}{2} - \frac{1}{6}\right) = 6 \cdot \frac{1}{3} = 2

Remark

As nn \to \infty, the sum k=0n(1)kk!\sum_{k=0}^{n} \frac{(-1)^k}{k!} converges to e1=1/ee^{-1} = 1/e. Therefore, Dnn!/eD_n \approx n!/e, and the probability that a random permutation is a derangement approaches 1/e0.3681/e \approx 0.368. This is the answer to the classic "hat check problem": if nn people check their hats and the hats are returned randomly, the probability that no one gets their own hat back approaches 1/e1/e, independent of nn for large nn. There's also a useful recurrence relation: Dn=(n1)(Dn1+Dn2)D_n = (n-1)(D_{n-1} + D_{n-2}) for n2n \geq 2.