Sub topic 16
Derangements: Nobody in Their Own Place
Prerequisites and the Core Idea
Assume you can use factorials, permutations, combinations, and the inclusion-exclusion principle. A derangement is an arrangement of \(n\) distinct objects in which no object remains in its original position.
For example, suppose three letters start as A, B, C. The arrangements ABC, ACB, and BAC are not derangements because at least one letter stays in its original position. The arrangements BCA and CAB are derangements:
- BCA: A, B, and C all move.
- CAB: A, B, and C all move.
The number of derangements of \(n\) objects is written as \(D_n\).
Recurrence Method
The most useful recurrence is:
\[ Dn=(n-1)(D{n-1}+D_{n-2}) \]
The starting values are:
\[ D0=1,\qquad D1=0 \]
To understand the recurrence, focus on the object originally in position 1. It can move to any of the other \(n-1\) positions.
After choosing its new position, there are two cases:
- The object originally in that position moves to position 1. The remaining \(n-2\) objects must be deranged, giving \(D_{n-2}\).
- That object does not move to position 1. The remaining arrangement behaves like a derangement of \(n-1\) objects, giving \(D_{n-1}\).
Therefore, each of the \(n-1\) choices contributes \(D{n-1}+D{n-2}\).
def derangements(n):
d = [1, 0] # D0 and D1
for i in range(2, n + 1):
d.append((i - 1) * (d[i - 1] + d[i - 2]))
return d[n]
print([derangements(n) for n in range(7)])
# [1, 0, 1, 2, 9, 44, 265]Thus, \(D_4=9\). Among all \(4!=24\) arrangements, 9 place nobody in the original position.
Inclusion-Exclusion Formula
Derangements can also be counted by excluding arrangements that leave one or more objects fixed:
\[ D_n=n!\left(1-\frac1{1!}+\frac1{2!}-\frac1{3!}+\cdots+\frac{(-1)^n}{n!}\right) \]
For \(n=4\):
\[ D_4=4!\left(1-1+\frac12-\frac16+\frac1{24}\right)=9 \]
This method is useful when a problem describes forbidden positions directly. The signs alternate because inclusion-exclusion adds and subtracts overlapping cases.
Common Errors
- Counting arrangements where at least one object moves instead of requiring every object to move.
- Using \(n!\) without removing arrangements with fixed positions.
- Starting the recurrence with \(D0=0\). The empty arrangement counts as one valid derangement, so \(D0=1\).
- Treating objects as identical. Derangements require distinct objects and identifiable original positions.
Exercise
Six people receive six sealed envelopes, one addressed to each person. How many assignments give nobody their own envelope?
Show answer
Use the derangement value D6. From the recurrence, D6 = 5(D5 + D4) = 5(44 + 9) = 265.