Toolkit 106

Derangements and Inclusion–Exclusion

A derangement is a permutation in which no element is in its original position.

πii(1in)\pi_i\ne i\qquad(1\le i\le n)

Let D_n denote the number of derangements of 1,2,\dots,n.

Dn=n!(10!11!+12!13!++(1)nn!)D_n=n!\left(\frac{1}{0!}-\frac{1}{1!}+\frac{1}{2!}-\frac{1}{3!}+\cdots+\frac{(-1)^n}{n!}\right)

Proof

Suppose the permutation is

π1,π2,,πn.\pi_1,\pi_2,\ldots,\pi_n.

For each ii, define

Ai={πi=i},i=1,2,,n.A_i=\{\pi_i=i\},\qquad i=1,2,\ldots,n.

A derangement has no fixed points, so

Dn=n!A1A2An.D_n=n!-|A_1\cup A_2\cup\cdots\cup A_n|.

By the Principle of Inclusion–Exclusion,

Dn=n!Ai+AiAjAiAjAk++(1)nA1A2An.D_n=n!-\sum |A_i|+\sum |A_i\cap A_j|-\sum |A_i\cap A_j\cap A_k|+\cdots+(-1)^n|A_1\cap A_2\cap\cdots\cap A_n|.

If kk specified elements are fixed, the remaining nkn-k elements can be permuted in (nk)!(n-k)! ways. Therefore,

Dn=n!n(n1)!+(n2)(n2)!(n3)(n3)!++(1)n(nn)0!.D_n=n!-n(n-1)!+\binom{n}{2}(n-2)!-\binom{n}{3}(n-3)!+\cdots+(-1)^n\binom{n}{n}0!.

Factoring out n!n! gives

Dn=n!(10!11!+12!13!++(1)nn!).D_n=n!\left(\frac{1}{0!}-\frac{1}{1!}+\frac{1}{2!}-\frac{1}{3!}+\cdots+\frac{(-1)^n}{n!}\right).
Dn=n!k=0n(1)kk!.D_n=n!\sum_{k=0}^{n}\frac{(-1)^k}{k!}.\quad\square