6.3 Derangements

Suppose each person in a group of n friends brings a gift to a party. In how many ways can the n gifts be distributed so that each person receives one gift and no person receives their own gift.

Let the set of friends = {p_{1}, ..., p_{n}} where p_{j} = person j. Let the set of gifts = {g_{1}, ..., g_{n}} where g_{j} = the gift brought by person j.

Suppose f : {p_{1}, ..., p_{n}} → {g_{1}, ..., g_{n}}, f(p_{k}) = g_{j} iff person p_{k} receives give g_{j}, the gift brought by person j. If each person receives one gift, then f is a bijection. If no person receives their own gift. Then f(p_{j}) ≠ g_{j}.

In simpler notation, f : {1, ..., n} → {1, ..., n} such that f(j) ≠ j

Recall: a permutation on {1, ..., n} is a bijection f : {1, ..., n} → {1, ..., n}

Ex: The permutation 1 2 3 4 5 corresponds to the identity function.

Ex: The permutation 1 3 2 corresponds to the function f(1) = 1, f(2) = 2, f(3) = 2 Defn: A derangement of {1, ..., n} is a permutation i_{1}i_{2}...i_{n} such that i_{j} ≠ j. I.e, j is not in the jth place.

In function notation: f(j) = i_{j}, then if i_{1}i_{2}...i_{n} is a derangement, f(j) ≠ j.

In yet other wording, recall a permutation corresponds to the placement of n non-attacking rooks on an n × n chessboard.

Ex: The permutation 1 3 2 corresponds to the following rook placement:

A derangement corresponds to non-attacking rook placement with forbidden positions along the diagonal (j, j), for j = 1, ..., n.

Ex: If rooks are placed on the following 3 × 3 chessboard in non-attacking position, then the rook placement corresponds to a derangement if no rook is placed in a spot marked with an X.

Thus the derangements of {1, 2, 3} are 2 3 1 and 3 1 2.

Let D_{n} = the number of derangements of {1, ..., n}. Thus D_{3} = 2.

Thm 6.3.1: For n ≥ 1, D_{n} = n!(1 − \frac{1}{1!} + \frac{1}{2!} − \frac{1}{3!} + ... + (−1)^{n} \frac{1}{n!}) Pf: Use the inclusion and exclusion principle: If A_{i} ⊂ S, \overline{∪A_{i}} = |S|−Σ_{j=1}^{n}|A_{j}|+Σ_{i,j}|A_{i}∩A_{j}|−...+(−1)^{n}|A_{1}∩A_{2}∩...∩A_{n}|. Choose S. What can we count which contains the set of derangements? Let S = the set of permutations of {1, ..., n}. Then |S| = n!. Choose A_{j} such that the set of derangements = \overline{∪A_{j}}. Let A_{j} = set of permutations such that j is in the jth spot. |A_{j}| = (n − 1)! since there is only one choice for the jth spot (namely j), leaving n − 1 terms to permute in the remaining n − 1 places. |A_{i} ∩ A_{j}| = (n − 2)! since there is only one choice for the ith spot (namely i) and only one choice for the jth spot (namely j), leaving n−2 terms to permute in the remaining n−2 places. Similarly, |A_{i_{1}} ∩ A_{i_{2}} ∩ ... ∩ A_{i_{k}}| = (n − k)!. Thus D_{n} = n! − Σ_{j=1}^{n}(n − 1)! + Σ_{i,j}(n − 2)! − ... + (−1)^{n}(n − n)!

= ( \begin{matrix}n \\ 0 \end{matrix} ) n! − ( \begin{matrix}n \\ 1 \end{matrix} ) (n − 1)! + ( \begin{matrix}n \\ 2 \end{matrix} ) (n − 2)! − ... + ( \begin{matrix}n \\ n \end{matrix} ) (−1)^{n}0!

= n! − \frac{n!}{1!} + \frac{n!}{2!} + ... + (−1)^{n} \frac{n!}{n!} = n!(1 − \frac{1}{1!} + \frac{1}{2!} + ... + (−1)^{n} \frac{1}{n!})

Recall ( \begin{matrix}n \\ k \end{matrix} ) = number of ways to choose k A_{i}’s.

Sidenote: Finding the number of derangements is often called the hat check problem, because in the old days it was sometimes stated in the following terms: If n men check their hats, what is the probability that the hats are returned so that no one received their own hat.

Recall: If E ⊂ S, then the probability of E = P (E) = \frac{|E|}{|S|}

S = sample space, E = events.

Note: we assume each outcome is equally likely.

Suppose 4 customers at a restaurant order 4 meals. What is the probability that a waiter delivers these 4 orders to the 4 customers so that no customer receives what they ordered?

Answer: \frac{D_{4}}{4!} = 1 − 1 + \frac{1}{2} − \frac{1}{6} = \frac{1}{3}

The probability that a permutation of {1, ..., n} is a derangement = \frac{D_{n}}{n!} = 1 − \frac{1}{1!} + \frac{1}{2!} + ... + (−1)^{n} \frac{1}{n!}

Recall Taylor’s expansion from Calculus I, f(x) = Σ_{j=0}^{∞} \frac{f^{(j)}(a)}{j!}(x − a)^{j} (under appropriate hypothesis).

Thus e^{−1} = Σ_{j=0}^{∞}(−1)^{j} \frac{1}{j!} (let f(x) = e^{x}, x = −1, a = 0).

Thus e^{−1} is a good approximation for the probability of a derangement for n (slightly) large.

Thus the probability of a derangement is about the same when n = 5 as it is for n = 50000000000.

We can derive a recursive formula for D_{n} (we will look at many recursive formulas in chapter 7). Lemma A: D_{n} = (n − 1)(D_{n−2} + D_{n−1}) for n ≥ 3. Note the above formula is a recursive formula as we can determine D_{n} by calculating D_{k} for k < n. Note D_{1} = 0, D_{2} = 1 (as 2 1 is the only derangement of {1, 2}). Thus D_{3} = 2(0+1) = 2, D_{4} = 3(1+2) = 9, D_{5} = 4(2+9) = 44, etc. Combinatorial proof of lemma A: Let D_{n} = the set of derangements of {1, ..., n}. D_{n} = the number of derangements of {1, ..., n} = |D_{n}|. We need to show that D_{n} is a product of n−1 and D_{n−2}+D_{n−1}. If we can partition D_{n} into n − 1 subsets where each subset has D_{n−2} + D_{n−1} elements, we can use the multiplication principle to show D_{n} = (n − 1)(D_{n−2} + D_{n−1}). Let’s focus on one of the positions of a derangement. The last (nth) position of our derangement can be anything except n. Thus there are n − 1 choices for the last (nth) position. Note the factor n − 1 appears in our formula. Let R_{k} = the set of derangements of {1, ..., n} where k is in the nth position for k = 1, ..., n − 1. Then D_{n} = ∪_{j=0}^{n−1}R_{n} Let r_{k} = |R_{k}| the number of derangements such that k is in the nth position.

Note that r_{1} = r_{2} = ... = r_{n−1} (while r_{n} = 0).

Then D_{n} = r_{1} + ... + r_{n−1} = r_{n−1} + ... + r_{n−1} = (n − 1)r_{n−1}.

Thus we have (hopefully) simplified our problem to showing that D_{n−2} + D_{n−1} = r_{n−1} = the number of derangements such that n − 1 is in the nth position.

We need to partition the permutations in R_{n−1} into two sets, one with D_{n−2} elements and the other with D_{n−1} elements.

We can easily take care of D_{n−2}. The numbers n − 1 and n do not appear in any derangement of {1, ..., n − 2}. In R_{n−1}, n − 1 appears in the last position. We can take a look at the derangements in R_{n−1}, such that n appears in the (n − 1)st position. If we remove the nth and (n − 1)st entries, we obtain a derangement in D_{n−2}.

Ex: for n = 5, 23154 ∈ R_{n−1} → 231 ∈ D_{n−2}.

Thus D_{n−2} = the number of derangements of R_{n−1} (such that n − 1 is in the nth position and) n is in the (n − 1)st position.

We can now look at the remaining derangements in R_{n−1} where n is not in the (n − 1)st position.

Let P_{n} the set of derangement where n−1 is in the nth position and k is in the (n − 1)st position for some k ≠ n, n − 1 (I.e, k ≤ n − 2).

We would like to show that D_{n−1} = the number of derangements of {1, ..., n − 1} such that n − 1 is in the nth position and k is in the (n − 1)st position for some k ≤ n − 2 = |P_{n}|.

Let D_{n−1} = the set of derangements of {1, ..., n − 1}.

We would like to create a bijection from P_{n} to D_{n−1}

Note that the differences between P_{n} and D_{n−1}. A derangement in P_{n} has n terms, while a derangement in D_{n−1} has n−1 terms. Thus we need to remove a term to go from P_{n} to D_{n−1}.

If i_{1}i_{2}...i_{n} ∈ P_{n}, then i_{n} = n − 1 and i_{n−1} = k for some k ≤ n − 2. Also i_{j} = n for some j.

In D_{n−1}, i_{n−1} = k for some k ≤ n−2 (by definition of derangement of {1, ..., n−1}, so we have no problems with the (n−1)st term.

However, we have the following differences between P_{n} and D_{n−1}: i_{1}i_{2}...i_{n} has n terms and n appears somewhere in i_{1}i_{2}...i_{n}, and i_{n} = n − 1, so the placement of n − 1 doesn’t vary. We can fix this by removing the nth term and replacing i_{j} = n with i_{j} = n − 1

Let i_{1}i_{2}...i_{n} ∈ P_{n}. Then i_{n} = n − 1 and i_{n−1} = k for some k ≤ n − 2.

Create a_{1}a_{2}...a_{n−1}, a derangement of {1, ..., n − 1} by

let a_{l} = \{ \begin{matrix}i_{l} & if i_{l} ≠ n, 1 ≤ l ≤ n − 1 \\ n − 1 & if i_{l} = n \end{matrix}

Ex: For n = 5, 25314 ∈ |P_{n}| → 2431 ∈ |D_{n−1}|. This gives us a bijection between P_{n} and D_{n−1}. Thus D_{n−1} = |P_{n}|. Another (simpler) recurrance relation: Lemma B: D_{n} = nD_{n−1} + (−1)^{n} for n ≥ 2 Proof by induction on n. n = 2: D_{2} = 1 (use definition or Thm 6.3.1) 2D_{1} + (−1)^{2} = 2(0) + 1 = 1. Thus D_{n} = nD_{n−1} + (−1)^{n} holds for n = 2. Suppose D_{k−1} = (k − 1)D_{k−2} + (−1)^{k−1} for k < n By lemma A, D_{k} = (k − 1)D_{k−2} + (k − 1)D_{k−1} By the induction hypothesis, D_{k−1} = (k − 1)D_{k−2} + (−1)^{k−1}. Thus (k − 1)D_{k−2} = D_{k−1} − (−1)^{k−1} Thus D_{k} = D_{k−1}−(−1)^{k−1}+(k−1)D_{k−1} = kD_{k−1}+(−1)(−1)^{k−1} = kD_{k−1} + (−1)^{k} 6.4 Permutations with Forbidden Positions Goal: To derive a more general formula for counting the number of permutations with arbitrary forbidden positions. Recall in section 6.3, we looked at permutations with forbidden positions A derangement corresponds to non-attacking rook placement with forbidden positions along the diagonal (j, j), for j = 1, ..., n. In this section, we will cover arbitrary forbidden positions.

Let X_{j} ⊂ {1, ..., n} for j = 1, ..., n.

Defn: P (X_{1}, X_{2}, ..., X_{n}) = the set of permutations i_{1}i_{2}...i_{n} of {1, ..., n} such that i_{j} ∉ X_{j}.

Defn: p(X_{1}, X_{2}, ..., X_{n}) = |P (X_{1}, X_{2}, ..., X_{n})|

Ex: P (X_{1}, X_{2}, ..., X_{n}) corresponds to the set of derangements of {1, ..., n} if X_{j} = {j}. Thus D_{n} = |P ({1}, {2}, ..., {n}|

Recall, we can visualize permutations with forbidden positions via n × n chessboards.

Ex: Derangements of {1, 2, 3} : X_{j} = {j}.

Non-derangement example: n = 4, X_{i} = {j, j + 1}, j = 1, 2, 3, X_{4} = ∅.

P (X_{1}, X_{2}, ..., X_{n}) = P ({1, 2}, {2, 3}, {3, 4}, ∅)

= {3124, 3412, 3421, 4123}. p(X_{1}, X_{2}, ..., X_{n}) = p({1, 2}, {2, 3}, {3, 4}, ∅)

= |{3124, 3412, 3421, 4123}| = 4.

We can use the inclusion-exclusion principle to calculate p(X_{1}, X_{2}, ..., X_{n}) (although in many cases, the computation can be tediously long and beyond computer capabilities for large n).

Similar to the proof of Thm 6.3.1. By the inclusion-exclusion principle,

p(X_{1}, X_{2}, ..., X_{n}) = |S|−Σ_{j=1}^{n}|A_{j}|+Σ_{i,j}|A_{i}∩A_{j}|−...+(−1)^{n}|A_{1}∩ A_{2} ∩ ... ∩ A_{n}|

where

Let S = the set of permutations of {1, ..., n}. Then |S| = n!.

Let A_{j} = set of permutations i_{1}i_{2}...i_{n} such that i_{j} ∈ X_{j} (for a fixed j).

Note there are |X_{j}| ways to place a rook in the jth position. There are (n − 1)! ways to place the remaining n − 1 rooks so that the permutation belongs to A_{j}.

Thus |A_{j}| = |X_{j}|(n − 1)!. Σ_{j=1}^{n}|A_{j}| = Σ_{j=1}^{n}|X_{j}|(n − 1)! = (n − 1)!Σ_{j=1}^{n}|X_{j}| = r_{1}(n − 1)! where r_{1} = Σ_{j=1}^{n}|X_{j}|.

Note r_{1} = number of ways to place 1 nonattacking rooks on an n × n chessboard so that the rook is in a forbidden position.

Let’s now look at A_{j} ∩ A_{k}. i_{1}i_{2}...i_{n} ∈ A_{j} ∩ A_{k}, then i_{j} ∈ X_{j} and i_{k} ∈ X_{k}. Thus there are |X_{j}| ways to place a rook in the jth position and |X_{k}| ways to place a rook in the kth position. There are (n − 2)! ways to place the remaining n − 1 rooks so that the permutation belongs to A_{j} ∩ A_{k}.

Thus |A_{j} ∩ A_{k}| = |X_{j}||X_{k}|(n − 2)!. Σ_{i,j}|A_{i} ∩ A_{j}| = Σ_{i,j}|X_{j}||X_{k}|(n − 2)! = (n − 2)!Σ_{i,j}|X_{j}||X_{k}|. Let r_{2} = Σ_{i,j}|X_{j}||X_{k}|.

Note r_{2} = number of ways to place 2 nonattacking rooks on an n × n chessboard so that each of the 2 rooks is in a forbidden position.

Similarly, define r_{k} = number of ways to place k nonattacking rooks on an n × n chessboard so that each of the k rooks is in a forbidden position.

Then Σ|A_{i_{1}} ∩ A_{i_{2}} ∩ ... ∩ A_{i_{k}}| = r_{k}(k − 1)!.

Thus we have proved:

Thm 6.4.1: p(X_{1}, X_{2}, ..., X_{n}) = n! − r_{1}(n − 1)! + r_{2}(n − 2)! − ... + (−1)^{n}r_{n}.

Note that if there are many forbidden positions, then r_{k} may be difficult to calculate and it may be easier to calculate p(X_{1}, X_{2}, ..., X_{n}) directly. If there are few forbidden positions, Thm 6.4.1 is the easier method to compute p(X_{1}, X_{2}, ..., X_{n}).

Examples:

Let X = {1, 2, 3}. p({1, 2}, {1, 3}, {3}| =

Note in this case, it was easiest to count directly and not use Thm 6.4.1.

Examples:

Let X = {1, 2, 3, 4, 5}. p({1, 2}, {1, 3}, {3}| =

6.5 Another Forbidden Position Problem

Goal: To derive a formula for counting the number of permutations with relative forbidden positions.

Ex: Suppose children 1, 2, 3, 4, and 5 sit in a row in class. Children 1 and 2 cannot sit next to each other or they will cause trouble.

The order in which the children sit corresponds to a permutation of {1, 2, 3, 4, 5}. If 1 is in the ith spot, then 2 cannot be in the i − 1st spot or the i + 1th spot. Thus the pattern 21 or 12 cannot appear in our permutation. This is called a relative forbidden position as certain positions for the placement of 2 are forbidden, but these forbidden positions depend on the placement of 1.

We will focus on the relative forbidden position problem in which

Let Q_{n} = the number of permutations of {1, 2, ..., n} in which none of the patterns 12, 23, 34, ..., (n − 1)n occurs.

Thm 6.5.1 Q_{n} = n! − ( \begin{matrix}n − 1 \\ 1 \end{matrix} ) (n − 1)! + ( \begin{matrix}n − 1 \\ 2 \end{matrix} ) (n − 2)! −

... + ( \begin{matrix}n − 1 \\ n − 1 \end{matrix} ) (−1)^{n−1}1!

Proof: Use inclusion-exclusion principle. Let S = the set of permutations of {1, ..., n}. Then |S| = n!. Let A_{j} = set of permutations which contain the pattern j(j+1). Note: |A_{j}| = (n − 1)! |A_{i} ∩ A_{j}| = (n − 2)! |A_{i_{1}} ∩ A_{i_{2}} ∩ ... ∩ A_{i_{k}}| = (n − k)!.