Derangements
Definition
A derangement is a permutation in which no element appears in its original position. In other words, for a permutation of denoted by , if , then is called a derangement of .
For example, the ternary derangements are and . The quaternary derangements are , , , , , , , , and . A derangement is a permutation with no fixed point, that is, with no cycle of length 1.
Computing with the Inclusion–Exclusion Principle
The universal set is the set of permutations of , so ; let be the permutations in which . Using complements and the inclusion–exclusion principle, the problem becomes finding:
Here the summation means choosing from the numbers such that . Therefore
This is the number of permutations in which the numbers satisfy , while the remaining positions can contain any permutation. Hence:
There are numbers, with possible choices, so summing gives:
Therefore, the number of derangements of elements is:
The first few terms of the derangement sequence are (OEIS A000166).
Computing by Recurrence
Let us make the derangement problem concrete by considering the following question:
distinct letters, numbered , are to be placed into envelopes numbered , with no envelope number matching the letter number. How many different placements are possible?
Suppose we consider the -th envelope and initially place the -th letter into the -th envelope temporarily. We then derive a recurrence from two cases:
- All of the first envelopes contain the wrong letters;
- Exactly one of the first envelopes contains the correct letter, and all the others contain the wrong letters.
In the first case, all of the first envelopes contain the wrong letters. Since the first envelopes are already all wrong, the -th letter only needs to be swapped with any one of the preceding positions, giving possibilities.
In the second case, exactly one of the first envelopes contains the correct letter, and all the others contain the wrong letters. We consider this case because if one of the first envelopes is correct, swapping that letter with the -th letter produces a derangement.
In all other cases, a single operation cannot turn the arrangement into a derangement of length .
Thus, the number of derangements satisfies the recurrence:
Here is another recurrence:
Other Relations
The number of derangements has a simple rounding formula, and its growth differs from the factorial by only a constant factor:
As the number of elements increases, the probability P of forming a derangement approaches: