In combinatorial mathematics, a derangement is a permutation of the elements of a set in which no element appears in its original position. In other words, a derangement is a permutation that has no fixed points. The number of derangements of a set of size n is known as the subfactorial of n or the n-th derangement number or n-th de Montmort number (after Pierre Remond de Montmort). Notations for subfactorials in common use include !n, Dn, dn, or n¡. For n > 0, the subfactorial !n equals the nearest integer to n!/e, where n! denotes the factorial of n and e is Euler's number. The problem of counting derangements was first considered by Pierre Raymond de Montmort in his Essay d'analyse sur les jeux de hazard. in 1708; he solved it in 1713, as did Nicholas Bernoulli at about the same time. Suppose that a professor gave a test to 4 students – A, B, C, and D – and wants to let them grade each other's tests. Of course, no student should grade their own test. How many ways could the professor hand the tests back to the students for grading, such that no student received their own test back? Out of 24 possible permutations (4!) for handing back the tests, {| style="font:125% monospace;line-height:1;border-collapse:collapse;" |ABCD, |ABDC, |ACBD, |ACDB, |ADBC,
ADCB, |
---|
BACD, |
BADC, |
BCAD, |
BCDA, |
BDAC, |
BDCA, |
- |
CABD, |
CADB, |
CBAD, |
CBDA, |
CDAB, |
CDBA, |
- |
DABC, |
DACB, |
DBAC, |
DBCA, |
DCAB, |
DCBA. |
} |
there are only 9 derangements (shown in blue italics above). In every other permutation of this 4-member set, at least one student gets their own test back (shown in bold red). |
Another version of the problem arises when we ask for the number of ways n letters, each addressed to a different person, can be placed in n pre-addressed envelopes so that no letter appears in the correctly addressed envelope. |
Counting derangements of a set amounts to the hat-check problem, in which one considers the number of ways in which n hats (call them h1 through hn) can be returned to n people (P1 through Pn) such that no hat makes it back to its owner. |