\magnification 1900 \parindent 0pt \parskip 10pt \pageno=1 \hsize 7.2truein \hoffset -0.35truein \voffset -0.3truein \vsize 10truein \def\u{\vskip -10pt} \def\v{\vfill} \def\s{\vskip -5pt} \def\r{\vskip -4pt} \def\t{\vskip 10pt} \def\Z{\cal Z} \def\hb{\hfil \break} \def\hr{\vskip 5pt \hrule } \def\S5{\Sigma_{n=1}^5} \underbar{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 no person receives their own gift. Let the set of friends = $\{p_1, ..., p_n\}$ where $p_j = $ person $j$. \hb Let the set of gifts = $\{g_1, ..., g_n\}$ where $g_j$ = the gift brought by person $j$. Suppose $f: \{p_1, ..., p_n\} \rightarrow \{g_1, ..., g_n\}$, \hb $f(p_k) = g_j$ iff person $p_k$ receives give $g_j$, the gift brought by person $j$. \hb If no person receives their own gift. Then $f(p_j) \not= g_j$. In simpler notation, \hb $f: \{1, ..., n\} \rightarrow \{1, ..., n\} $ such that $f(j) \not = j$ Recall: \hb a permutation on $ \{1, ..., n\} $ is a bijection $f\{1, ..., n\} \rightarrow \{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 {\it derangement} of $\{1, ..., n\}$ is a permutation $i_1 i_2 ... i_n$ such that $i_j \not = j$. I.e, $j$ is not in the $j$th place. In function notation: $f(j) = i_j$, then if $i_1 i_2 ... i_n$ is a derangement, $f(j) \not= j$ In yet other wording, recall a permuation corresponds to the placement of $n$ non-attacking rooks on an $n \times n$ chessboard. Ex: The permutation 1 3 2 corresponds to the following rook placement: \v A derangment 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 \times 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$. \v Thus the derangements of $\{1, 2, 3\}$ are 2 3 1, 2 1 3, 3 1 2, 3 2 1. \eject Let $D_n$ = the number of derangements of $\{1, ..., n\}$. Thm 6.3.1: For $n \geq 1$, $D_n = n!( 1 - {1 \over 1!} + {1 \over 2!} - {1 \over 3!} + ... + (-1)^n{1 \over n!})$ Pf: Use the inclusion and exclusion principle: If $A_i \subset S$, \line{$\overline{\cup A_i} = |S| - \Sigma_{j = 1}^n |A_j| + \Sigma_{i, j} |A_i \cap A_j| - ... + (-1)^n |A_{1} \cap A_{2} \cap ... \cap 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 derangments = $\overline{\cup A_j}$. \hb Let $A_j$ = set of permutations such that $j$ is in the $j$th spot. Note: $|A_j| = (n-1)!$ since their is only one choice for the $j$th spot (namely j), leaving $n-1$ terms to permute in the remaining $n-1$ places. $|A_i \cap A_j| = (n-2)!$ $|A_{i_1} \cap A_{i_2} \cap ... \cap A_{i_k}| = (n-k)!$. Thus $D_n = n! - \Sigma_{j = 1}^n (n-1)! + \Sigma_{i, j}(n-2)! - ... + (-1)^n (n -n)!$ $= \left(\matrix{n \cr 0}\right) n! - \left(\matrix{n \cr 1}\right) (n-1)! + \left(\matrix{n \cr 2}\right) (n-2)! - ... + \left(\matrix{n \cr n}\right) (-1)^n 0!$ $= n! - {n! \over 1!} + {n! \over 2!} + ... + (-1)^n {n! \over n!}$ $= n!(1 - {1 \over 1!} + {1 \over 2!} + ... + (-1)^n {1 \over n!})$ Recall $\left(\matrix{n \cr k}\right) =$ number of ways to choose $k$ $A_i$'s. \eject 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 the probability that the hats are returned so that no one received their own hat. Recall: If $E \subset S$, then the probability of $E$ = $P(E) = {|E| \over |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: ${D_4 \over 4!} = 1 - 1 + {1 \over 2} - {1 \over 6} = {1 \over 3}$ The probability that a permutation of $\{1, ..., n\}$ is a derangement = ${D_n \over n!} = 1 - {1 \over 1!} + {1 \over 2!} + ... + (-1)^n {1 \over n!}$ Recall from Taylor's expansion from Calculus I, the if $f(x) = $ Recall from Calculus I (Taylor's exp), the $e^{-1} = \Sigma_{j = 0}^\infty (-1)^j {1 \over j!}$. Thus $e^{-1}$ is a good approximation for the probability of a derangement for $n$ (slightly) large. Thus the probability that if floor, ceiling. 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 \geq 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 ${\cal D}_n =$ the set of derangements of $\{1, ..., n\}$. $D_n = $ the number of derangements of $\{1, ..., n\} = |{\cal 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 ${\cal 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 ($n$th) position of our derangement can be anything except $n$. Thus there are $n-1$ choices for the last ($n$th) position. Note the factor $n-1$ appears in our formula. Let ${\cal R}_k$ = the set of derangements of $\{1, ..., n\}$ where $k$ is in the $n$th position for $k = 1, ..., n-1$. Then ${\cal D}_n = \cup_{j=0}^{n-1} {\cal R}_n$ Let $r_k$ = $|{\cal R}_k|$ the number of derangments such that $k$ is in the $n$th 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 derangments such that $n-1$ is in the $n$th position. We need to partition the permutations in ${\cal 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 derangment of $\{1, ..., n-2\}$. In ${\cal R}_{n-1}$, $n-1$ appears in the last position. We can take a look at the derangements in ${\cal R}_{n-1}$, such that $n$ appears in the $(n-1)$st position. If we remove the $n$th and $(n-1)$st entries, we obtain a derangement in ${\cal D}_{n-2}$. Thus $D_{n-2}$ = the number of derangments of ${\cal R}_{n-1}$ (such that $n-1$ is in the $n$th position and) $n$ is in the $(n-1)$st position. We can now look at the remaining derangements in ${\cal R}_{n-1}$ where $n$ is not in the $(n-1)$st position. Note $r_{n-1} - D_{n-2} =$ the number of derangments such that $n-1$ is in the $n$th position and $k$ is in the $(n-1)$st position for some $k \not= n, n-1$ (I.e, $k \leq n-2$). We would like to show that $D_{n-1} =$ the number of derangments of $\{1, ..., n-1\}$ such that $n-1$ is in the $n$th position and $k$ is in the $(n-1)$st position for some $k \leq n-2$. Let ${\cal P}_{n}$ the set of derangement where $n-1$ is in the $n$th position and $k$ is in the $(n-1)$st position for some $k \leq n-2$. Let ${\cal D}_{n-1}$ = the set of derangments of $\{1, ..., n-1\}$. We would like to create a bijection from ${\cal P}_{n}$ to ${\cal D}_{n-1}$ Note that the differences between ${\cal P}_{n}$ and ${\cal D}_{n-1}$. A derangement in ${\cal P}_{n}$ has $n$ terms, while a derangement in ${\cal D}_{n-1}$ has $n-1$ terms. Thus we need to remove a term to go from ${\cal P}_{n}$ to ${\cal D}_{n-1}$. If $i_1i_2... i_n \in {\cal P}_{n}$, then $i_n = n-1$ and $i_{n-1} = k$ for some $k \leq n-2$. Also $i_j = n$ for some $j$. In ${\cal D}_{n-1}$, $i_{n-1} = k$ for some $k \leq 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 ${\cal P}_{n}$ and ${\cal D}_{n-1}$: \hb $i_1i_2... i_n$ has $n$ terms and \hb $n$ appears somewhere in $i_1i_2... i_n$, and \hb $i_n = n-1$, so the placement of $n-1$ doesn't vary. \hb We can fix this by removing the $n$th term and replacing $i_j = n$ with $i_j = n-1$ Let $i_1i_2... i_n \in {\cal P}_{n}$. Then $i_n = n-1$ and $i_{n-1} = k$ for some $k \leq n-2$. Create $a_1 a_2 ... a_{n-1}$, a derangment of $\{1, ..., n-1\}$ by let $a_l = \cases{ i_l & if $i_l \not= n$, $1 \leq l \leq n-1$ \cr n-1 & if $i_l = n$ } $ Ex: If $n = 5$, $25314 \rightarrow 2431$ Another (simpler) recurrance relation: Lemma B: $D_n = nD_{n-1} + (-1)^n$ for $n \geq 2$ Proof by induction on $n$. $n = 2$: $D_2 = 1$ (use definition or Thm 6.3.1) \hb $2D_1 + (-1)^2 = 2(0) + 1 = 1$. \hb 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} = k D_{k-1} + (-1) (-1)^{k-1} = k D_{k-1} + (-1)^{k} $ \underbar{6.4 Permutations with Forbidden Positions} {\bf Goal:} To {\bf 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 derangment 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 \subset \{1, ..., n\}$ for $j = 1, ..., n$. Defn: $P(X_1, X_2, ..., X_n) =$ the set of permutations $i_1i_2...i_n$ of $\{1, ..., n\}$ such that $i_j \not\in 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 \times 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 = \emptyset$. $P(X_1, X_2, ..., X_n) = P(\{1, 2\}, \{2, 3\}, \{3, 4\}, \emptyset) = \{3124, 3412, 3421, 4123\}$. $p(X_1, X_2, ..., X_n) = p(\{1, 2\}, \{2, 3\}, \{3, 4\}, \emptyset) = |\{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| - \Sigma_{j = 1}^n |A_j| + \Sigma_{i, j} |A_i \cap A_j| - ... + (-1)^n |A_{1} \cap A_{2} \cap ... \cap A_{n}|$ where Let $S =$ the set of permutations of $\{1, ..., n\}$. Then $|S| = n!$. Let $A_j$ = set of permutations $i_1i_2...i_n$ such that $i_j in X_j$ (for a fixed $j$). Note there are $|X_j|$ ways to place a rook in the $j$th 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)!$. Thus $\Sigma_{j = 1}^n |A_j| = \Sigma_{j = 1}^n |X_j|(n-1)!= (n-1)!\Sigma_{j = 1}^n |X_j| = r_1(n-1)!$ where $r_1 = \Sigma_{j = 1}^n |X_j|$. Note $r_1 =$ number of ways to place $1$ nonattacking rooks on an $n \times n$ chessboard so that the rook is in a forbidden position. Let's now look at $A_j \cap A_k$. $i_1i_2...i_n \in A_j \cap A_k$, then $i_j \in A_j$ and $i_k \in A_k$. Thus there are $|X_j|$ ways to place a rook in the $j$th position and $|X_k|$ ways to place a rook in the $k$th position. There are $(n-2)!$ ways to place the remaining $n-1$ rooks so that the permutation belongs to $A_j \cap A_k$. Thus $|A_j \cap A_k| = |X_j||X_k|(n-2)!$. $\Sigma_{i, j} |A_i \cap A_j| = \Sigma_{i, j} |X_j||X_k|(n-2)! = (n-2)! \Sigma_{i, j} |X_j||X_k|$. Let $r_2 = \Sigma_{i, j} |X_j||X_k|$. Note $r_2 =$ number of ways to place $2$ nonattacking rooks on an $n \times 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 \times n$ chessboard so that each of the $k$ rooks is in a forbidden position. Then $\Sigma |A_{i_1} \cap A_{i_2} \cap ... \cap A_{i_k}| = r_k(k-1)!$. Thm 6.4.1: $p(X_1, X_2, ..., X_n) = n! - r_1(n-1)! + r_2(n-2)! - ... + (-1)^nr_n$. \end