In
combinatorial
Combinatorics is an area of mathematics primarily concerned with counting, both as a means and an end in obtaining results, and certain properties of finite structures. It is closely related to many other areas of mathematics and has many ap ...
mathematics
Mathematics is an area of knowledge that includes the topics of numbers, formulas and related structures, shapes and the spaces in which they are contained, and quantities and their changes. These topics are represented in modern mathematics ...
, a derangement is a
permutation
In mathematics, a permutation of a set is, loosely speaking, an arrangement of its members into a sequence or linear order, or if the set is already ordered, a rearrangement of its elements. The word "permutation" also refers to the act or proc ...
of the elements of a
set
Set, The Set, SET or SETS may refer to:
Science, technology, and mathematics Mathematics
*Set (mathematics), a collection of elements
*Category of sets, the category whose objects and morphisms are sets and total functions, respectively
Electro ...
, such that 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. Notations for subfactorials in common use include !''n,'' ''D
n'', ''d
n'', or ''n''¡.
For ''n'' > 0, the subfactorial !''n'' equals the nearest integer to ''n''!/''e,'' where ''n''! denotes the
factorial
In mathematics, the factorial of a non-negative denoted is the product of all positive integers less than or equal The factorial also equals the product of n with the next smaller factorial:
\begin
n! &= n \times (n-1) \times (n-2) \t ...
of ''n'' and ''e'' is
Euler's number
The number , also known as Euler's number, is a mathematical constant approximately equal to 2.71828 that can be characterized in many ways. It is the base of a logarithm, base of the natural logarithms. It is the Limit of a sequence, limit ...
.
The problem of counting derangements was first considered by
Pierre Raymond de Montmort
Pierre Remond de Montmort was a French mathematician. He was born in Paris on 27 October 1678 and died there on 7 October 1719. His name was originally just Pierre Remond. His father pressured him to study law, but he rebelled and travelled to E ...
in 1708; he solved it in 1713, as did
Nicholas Bernoulli at about the same time.
Example
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,
:
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
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 ''h''
1 through ''h
n'') can be returned to ''n'' people (''P''
1 through ''P
n'') such that no hat makes it back to its owner.
Each person may receive any of the ''n'' − 1 hats that is not their own. Call the hat which the person ''P''
1 receives ''h
i'' and consider ''h
i''’s owner: ''P
i'' receives either ''P''
1's hat, ''h''
1, or some other. Accordingly, the problem splits into two possible cases:
# ''P
i'' receives a hat other than ''h''
1. This case is equivalent to solving the problem with ''n'' − 1 people and ''n'' − 1 hats because for each of the ''n'' − 1 people besides ''P''
1 there is exactly one hat from among the remaining ''n'' − 1 hats that they may not receive (for any ''P
j'' besides ''P
i'', the unreceivable hat is ''h
j'', while for ''P
i'' it is ''h''
1). Another way to see this is to rename ''h''
1 to ''h''
i, where the derangement is more explicit: for any ''j'' from 2 to ''n'', ''P''
j cannot receive ''h''
j.
# ''P
i'' receives ''h''
1. In this case the problem reduces to ''n'' − 2 people and ''n'' − 2 hats, because ''P''
1 received ''h
i''s hat and ''P''
i received ''h
1s hat, effectively putting both out of further consideration.
For each of the ''n'' − 1 hats that ''P''
1 may receive, the number of ways that ''P''
2, …, ''P
n'' may all receive hats is the sum of the counts for the two cases.
This gives us the solution to the hat-check problem: stated algebraically, the number !''n'' of derangements of an ''n''-element set is
:
for
,
where
and
.
The number of derangements of small lengths is given in the table below.
There are various other expressions for !''n'', equivalent to the formula given above. These include
:
for
and
:
for
where