Mathematics · Book 3 · Bachelor Year 1

University Mathematics — Year 1

University Mathematics — Year 1 · Bachelor Year 1

2Counting

Counting finite sets sounds elementary — and quickly becomes subtle. This chapter defines cardinality properly (through bijections, in the spirit of Chapter 1), establishes the handful of counting principles from which everything follows, and derives the classical counts: lists, permutations, subsets, binomial coefficients.

2.1 Cardinality of finite sets

Definition 2.1 (Finite set, cardinality)

For nNn \in \N^*, write [ ⁣[1,n] ⁣]={1,2,,n}\intint{1}{n} = \{1, 2, \dots, n\}. A set EE is finite when E=E = \emptyset or there is a bijection from [ ⁣[1,n] ⁣]\intint{1}{n} onto EE for some nNn \in \N^*; this nn is unique (Theorem 2.2) and is the cardinality of EE, written E\abs{E} (with =0\abs{\emptyset} = 0).

Theorem 2.2 (Cardinality is well defined)

If mnm \neq n, there is no bijection from [ ⁣[1,m] ⁣]\intint{1}{m} onto [ ⁣[1,n] ⁣]\intint{1}{n}. More precisely, if m>nm > n there is no injection from [ ⁣[1,m] ⁣]\intint{1}{m} into [ ⁣[1,n] ⁣]\intint{1}{n}.

Proof. We prove by induction on nn the statement: for all m>nm > n, there is no injection [ ⁣[1,m] ⁣][ ⁣[1,n] ⁣]\intint{1}{m} \to \intint{1}{n}. For n=0n = 0 the target is empty and m1m \geq 1: no map exists at all. Assume the statement for nn, and suppose f ⁣:[ ⁣[1,m] ⁣][ ⁣[1,n+1] ⁣]f \colon \intint{1}{m} \to \intint{1}{n+1} is an injection with m>n+1m > n + 1. If the value n+1n + 1 is not attained, ff is an injection into [ ⁣[1,n] ⁣]\intint{1}{n}, contradicting the induction hypothesis. Otherwise f(a)=n+1f(a) = n + 1 for exactly one aa; swap f(a)f(a) and f(m)f(m) (formally: compose with the transposition of the two values), so that the new injection gg has g(m)=n+1g(m) = n + 1. Then the restriction of gg to [ ⁣[1,m1] ⁣]\intint{1}{m-1} is an injection into [ ⁣[1,n] ⁣]\intint{1}{n} with m1>nm - 1 > n — contradiction again.

Corollary 2.3 (Pigeonhole principle)

If E>F\abs{E} > \abs{F}, no map f ⁣:EFf \colon E \to F is injective: some two elements of EE share their image.

Proof. Write E=m\abs E = m, F=n\abs F = n with m>nm > n, and choose bijections u ⁣:[ ⁣[1,m] ⁣]Eu \colon \intint1m \to E and v ⁣:F[ ⁣[1,n] ⁣]v \colon F \to \intint1n. If ff were injective, vfuv \circ f \circ u would be an injection from [ ⁣[1,m] ⁣]\intint1m into [ ⁣[1,n] ⁣]\intint1n (a composition of injections, Proposition 1.26), contradicting Theorem 2.2.

Remark 2.4 (Interlude: why the swap in the theorem’s proof?)

The proof of Theorem 2.2 contains the chapter’s first genuinely clever move, worth replaying slowly. The obstacle: to apply the induction hypothesis one wants to delete the last point mm of the source and the last point n+1n+1 of the target, but ff may send some other point aa to n+1n + 1, and then deleting the target point damages the map elsewhere. The cure: compose ff with the transposition of the two values f(a)f(a) and f(m)f(m) — a bijection of the target, so injectivity is preserved — after which the troublesome value n+1n + 1 sits at the harmless position mm, and both deletions are clean. This “normalize first, then cut” pattern recurs: it is how the derangement recurrence redirects σ1(n+1)\sigma^{-1}(n+1) in the weekend problem of this chapter, and how permutations are patched throughout Chapter 7’s problem on the symmetric group.

Proposition 2.5 (Injections, surjections and cardinality)

Let E,FE, F be finite sets with E=F\abs{E} = \abs{F}, and f ⁣:EFf \colon E \to F. Then

f injective    f surjective    f bijective.f \text{ injective} \iff f \text{ surjective} \iff f \text{ bijective}.

Proof. Suppose ff injective. Then ff is a bijection from EE onto f(E)f(E), so f(E)=E=F\abs{f(E)} = \abs{E} = \abs{F}. If f(E)f(E) missed a point y0y_0 of FF, then ff would be an injection of EE into F{y0}F \setminus \{y_0\}, a set of cardinality F1<E\abs{F} - 1 < \abs{E} — impossible by the pigeonhole principle. So f(E)=Ff(E) = F: ff is surjective, hence bijective.

Suppose ff surjective. Choose for each yFy \in F one preimage s(y)Es(y) \in E; then fs=idFf \circ s = \mathrm{id}_F, so ss is injective (Proposition 1.26). By the previous paragraph applied to ss (the cardinalities are equal), ss is bijective. From fs=idFf \circ s = \mathrm{id}_F we get f=idFs1=s1f = \mathrm{id}_F \circ s^{-1} = s^{-1}, so ff is bijective. Finally, a bijective map is by definition both injective and surjective, which closes the cycle of implications.

Example 2.6 (Finiteness is essential)

On a finite set, Proposition 2.5 is a powerful shortcut: any injective map from EE to itself is automatically a permutation of EE — half of bijectivity comes for free. Both implications collapse on infinite sets: nn+1n \mapsto n + 1 is injective from N\N to N\N but misses 00, and the map NN\N \to \N sending 000 \mapsto 0 and nn1n \mapsto n - 1 for n1n \geq 1 is surjective but not injective. Whenever this proposition is invoked, the finiteness hypothesis is doing real work — a theme that the weekend problem of Chapter 1 explores from the other side, where infinite sets are precisely those admitting such self-maps.

Example 2.7 (Half the work, for free)

Consider the map ff on {0,1,,6}\{0, 1, \dots, 6\} sending kk to the remainder of 3k3k upon division by 77; its table of values is

0, 3, 6, 2, 5, 1, 4.0,\ 3,\ 6,\ 2,\ 5,\ 1,\ 4 .

Is ff a bijection? Injectivity alone suffices (Proposition 2.5): if 3k3k and 3k3k' have the same remainder, 77 divides 3(kk)3(k - k'), and since 77 is prime and does not divide 33, it divides kkk - k' (Euclid’s lemma, used at High School level here and proved in Chapter 6); with kk6\abs{k - k'} \leq 6 this forces k=kk = k'. Surjectivity comes free — no need to solve 3kc3k \equiv c for each cc, though the table confirms every value appears exactly once. The shortcut is a workhorse: it proves the invertibility of modular multiplication (Chapter 6), powers the pairing in Wilson’s theorem, and returns in linear algebra as “an endomorphism of a finite-dimensional space is injective iff surjective” (Chapter 19).

2.2 The counting principles

Proposition 2.8 (Sum and product rules)

Let E,FE, F be finite sets.

  1. If EF=E \cap F = \emptyset, then EF=E+F\abs{E \cup F} = \abs{E} + \abs{F}; more generally, for a partition of EE into pieces E1,,EkE_1, \dots, E_k, E=iEi\abs{E} = \sum_i \abs{E_i}.
  2. In general, EF=E+FEF\abs{E \cup F} = \abs{E} + \abs{F} - \abs{E \cap F}.
  3. E×F=E×F\abs{E \times F} = \abs{E} \times \abs{F}.
  4. The set FEF^E of all maps from EE to FF satisfies FE=FE\abs{F^E} = \abs{F}^{\abs{E}}.
  5. P(E)=2E\abs{\mathcal{P}(E)} = 2^{\abs{E}}.

Proof. (1) Concatenate enumerations: if E={x1,,xm}E = \{x_1, \dots, x_m\} and F={y1,,yn}F = \{y_1, \dots, y_n\} with no repetition, then x1,,xm,y1,,ynx_1, \dots, x_m, y_1, \dots, y_n enumerates EFE \cup F without repetition (disjointness). Induction extends this to kk pieces.

(2) EFE \cup F is the disjoint union of EE and FEF \setminus E, and FF is the disjoint union of FEF \cap E and FEF \setminus E; so EF=E+FE=E+FEF\abs{E \cup F} = \abs{E} + \abs{F \setminus E} = \abs{E} + \abs{F} - \abs{E \cap F}.

(3) E×FE \times F is the disjoint union, over xEx \in E, of the sets {x}×F\{x\} \times F, each of cardinality F\abs{F}; apply (1).

(4) A map from E={x1,,xm}E = \{x_1, \dots, x_m\} to FF is exactly the choice of the mm-tuple (f(x1),,f(xm))Fm(f(x_1), \dots, f(x_m)) \in F^m; this correspondence is a bijection, and Fm=Fm\abs{F^m} = \abs{F}^m by (3) and induction.

(5) Subsets of EE correspond bijectively to maps E{0,1}E \to \{0, 1\} (send AA to its indicator function); apply (4).

Example 2.9 (Complement counting)

How many 44-digit PIN codes (digits 0099, order matters, repetition allowed) contain at least one repeated digit? Counting them directly means juggling the cases “exactly one pair, two pairs, a triple, a quadruple” — five overlapping configurations. Count the complement instead: all codes number 104=1000010^4 = 10\,000 (product rule), the codes with four distinct digits number 10×9×8×7=504010 \times 9 \times 8 \times 7 = 5\,040 (44-arrangements), so the answer is

10410987=100005040=4960.10^4 - 10 \cdot 9 \cdot 8 \cdot 7 = 10\,000 - 5\,040 = 4\,960 .

Nearly half of all PINs repeat a digit. The insight: whenever a count is phrased with “at least” or “not all”, try the complement first — the sum rule guarantees that A=EA\abs{A} = \abs{E} - \abs{\overline A}, and the complement is often a single clean configuration.

Example 2.10 (Lattice paths)

Count the shortest paths from the corner (0,0)(0,0) to the corner (4,3)(4, 3) of a grid, moving only one step right (R) or one step up (U) at a time. Every such path takes exactly 77 steps, of which 44 are R and 33 are U; conversely, any word of length 77 in the letters R, U with four R’s describes exactly one path. The paths therefore correspond bijectively to the choices of the positions of the R’s:

(74)=35.\binom{7}{4} = 35 .

The insight is the encoding: the count became trivial the moment each path was translated into a word, i.e. a subset of positions — one more instance of the slogan that a correct count is a disguised bijection (Method 2.19).

One of the 74 = 35 shortest paths from (0,0) to (4,3): the path shown encodes the word RURRURU, i.e. the choice of positions \1,3,4,6\ for the letter R among the seven steps.
One of the (74)=35\binom74 = 35 shortest paths from (0,0)(0,0) to (4,3)(4,3): the path shown encodes the word RURRURU, i.e. the choice of positions {1,3,4,6}\{1,3,4,6\} for the letter R among the seven steps.

2.3 Lists, permutations, subsets

Definition 2.11 (Arrangements, permutations, combinations)

Let EE be a set with E=n\abs{E} = n and let 0kn0 \leq k \leq n.

  • A kk-arrangement of EE is an injective kk-tuple of elements of EE (an ordered selection without repetition);
  • a permutation of EE is a bijection from EE to itself — equivalently, an nn-arrangement;
  • a kk-combination is a subset of EE with kk elements (an unordered selection without repetition). Their number is written (nk)\binom{n}{k}, read “nn choose kk” .

Theorem 2.12 (The three counts)

With n=En = \abs{E} and 0kn0 \leq k \leq n:

  1. the number of kk-arrangements of EE is n(n1)(nk+1)=n!(nk)!n (n-1) \cdots (n-k+1) = \dfrac{n!}{(n-k)!};
  2. the number of permutations of EE is n!n!;
  3. (nk)=n!k!(nk)!\dbinom{n}{k} = \dfrac{n!}{k!\,(n-k)!}.

Proof. (1) Choose the first coordinate (nn ways), then the second (n1n - 1 remaining choices), …, then the kk-th (nk+1n - k + 1 choices). Formally, induct on kk. For k=1k = 1 there are nn one-term injective tuples. Assume the count for k1k - 1. Each kk-arrangement (x1,,xk)(x_1, \dots, x_k) is obtained from exactly one (k1)(k-1)-arrangement — its truncation (x1,,xk1)(x_1, \dots, x_{k-1}) — by appending a last coordinate outside {x1,,xk1}\{x_1, \dots, x_{k-1}\}, for which exactly n(k1)n - (k - 1) values are available. The kk-arrangements are thus partitioned, by truncation, into classes of common size nk+1n - k + 1 indexed by the (k1)(k-1)-arrangements, and the sum rule gives

n!(nk+1)!  (nk+1)=n!(nk)!.\frac{n!}{(n-k+1)!}\;(n - k + 1) = \frac{n!}{(n-k)!} .

(2) is (1) with k=nk = n.

(3) Each kk-subset orders into k!k! distinct kk-arrangements, and every kk-arrangement arises from exactly one subset: so n!(nk)!=(nk)k!\frac{n!}{(n-k)!} = \binom nk \cdot k!.

Example 2.13 (Round tables: quotienting by symmetry)

In how many ways can nn guests sit around a round table, two seatings being identical when each guest has the same left and right neighbors — i.e. up to rotation? Each circular seating corresponds to exactly nn linear seatings (cut the circle at any of the nn places), so the n!n! linear orders collapse in groups of nn:

n!n=(n1)!circular seatings.\frac{n!}{n} = (n-1)! \quad\text{circular seatings.}

Equivalently: seat one distinguished guest anywhere (killing the rotational freedom), then order the remaining n1n - 1 guests clockwise. For n=6n = 6: 120120 tables. The two solutions illustrate the two standard cures for overcounting: divide by the exact number of repetitions, or break the symmetry by pinning one object down. Both require the group-of-repetitions size to be the same for every configuration — which the proof of the formula (nk)=n!k!(nk)!\binom nk = \frac{n!}{k!\,(n-k)!} above used as well, with k!k! in place of nn.

Example 2.14 (Adding a constraint)

Continuing the round table: among the (n1)!(n-1)! tables of n3n \geq 3 guests, how many seat two given guests AA and BB apart (not adjacent)? Count the complement. Tables where AA and BB sit together: glue them into a single block — n1n - 1 objects around the table, i.e. (n2)!(n-2)! circular arrangements — then order the pair inside its block (22 ways): 2(n2)!2\,(n-2)! adjacent tables. Hence

(n1)!2(n2)!=(n2)!((n1)2)=(n3)(n2)!(n-1)! - 2\,(n-2)! = (n-2)!\,\bigl((n - 1) - 2\bigr) = (n-3)\,(n-2)!

tables keep them apart. Sanity checks: n=3n = 3 gives 00 (around a triangle, everyone touches everyone) and n=4n = 4 gives 22, easily listed by hand. The gluing trick — treat a forced block as one object, then count its internal arrangements — is the standard cure for adjacency constraints, linear or circular.

Proposition 2.15 (Basic identities)

For 0kn0 \leq k \leq n:

(nk)=(nnk),(nk)=(n1k1)+(n1k)(1kn1),k=0n(nk)=2n.\binom{n}{k} = \binom{n}{n-k}, \qquad \binom{n}{k} = \binom{n-1}{k-1} + \binom{n-1}{k} \quad (1 \leq k \leq n-1), \qquad \sum_{k=0}^{n} \binom{n}{k} = 2^n .

Proof. First identity: AEAA \mapsto E \setminus A is a bijection between kk-subsets and (nk)(n-k)-subsets. Pascal’s rule: fix an element aEa \in E; the kk-subsets split into those containing aa (choose the k1k - 1 others: (n1k1)\binom{n-1}{k-1}) and those avoiding aa ((n1k)\binom{n-1}{k}). Third identity: both sides count all subsets of EE, split by size on the left (Proposition 2.8 (1) and (5)).

Theorem 2.16 (Binomial theorem)

For all a,ba, b in a commutative ring (say R\R or C\C) and nNn \in \N:

(a+b)n=k=0n(nk)akbnk.(a + b)^n = \sum_{k=0}^{n} \binom{n}{k} a^k b^{\,n-k} .

Proof. Expanding (a+b)(a+b)(a+b)(a+b)(a+b)\cdots(a+b) distributively yields one term per choice, in each factor, of either aa or bb: the term akbnka^k b^{n-k} appears once for each way of choosing which kk of the nn factors contribute aa — that is, (nk)\binom nk times. (Alternatively: induct on nn using Pascal’s rule.)

Example 2.17

Two classical specializations: a=b=1a = b = 1 recovers k(nk)=2n\sum_k \binom nk = 2^n; a=1a = -1, b=1b = 1 gives k(1)k(nk)=0\sum_{k} (-1)^k \binom nk = 0 for n1n \geq 1: among the subsets of a nonempty set, exactly half have even cardinality.

Example 2.18 (One identity, two proofs)

The specialization a=2a = 2, b=1b = 1 of the binomial theorem reads

k=0n(nk)2k=3n.\sum_{k=0}^{n} \binom nk\,2^k = 3^n .

Here is the same identity with no algebra at all. The right side counts the words of length nn over the alphabet {0,1,2}\{0, 1, 2\} (product rule). Classify each word by the set KK of positions carrying a nonzero letter: choosing KK with K=k\abs K = k costs (nk)\binom nk, then each position of KK independently carries 11 or 22: 2k2^k ways. The sum rule over kk gives the left side. Beyond the pleasure of agreement, the two proofs have different virtues: the algebraic one generalizes to any value of aa, the combinatorial one explains the formula and adapts to constraints (forbid the letter 22 in the last position, say) that no substitution captures. Keeping both techniques active is the practical skill this chapter trains.

Method 2.19 (Which count applies?)

Before computing, answer two questions about the selection: does the order matter, and are repetitions allowed?

order mattersorder does not matter
no repetitionn!(nk)!\dfrac{n!}{(n-k)!}(nk)\dbinom{n}{k}
[6pt] repetition allowednkn^k(Exercise 2.10)

Then hunt for a bijection or a partition reducing the problem to these model counts; a correct count is a disguised bijection.

Remark 2.20 (Common pitfalls in counting)

  1. Summing non-disjoint cases. The sum rule requires a partition; if configurations can satisfy two cases at once, they are counted twice — the cure is inclusion–exclusion (Theorem 2.24) or a finer case split.
  2. Ordered versus unordered. Choosing “a committee of two” is (n2)\binom n2, not n(n1)n(n-1): decide before computing whether the selection carries an order, and if an ordered count is easier, divide by the number of orderings at the end — but only when every unordered object arises from the same number of ordered ones.
  3. Multi-stage choices that are not independent. The product rule needs the number of options at each stage to be independent of the previous choices. “Choose a captain, then a different vice-captain” is fine (n(n1)n(n-1)); “choose two players who get along” is not a two-stage product at all.
  4. Double-counting by construction. Building each object twice — e.g. counting hands with at least one ace as (choose an ace) ×\times (choose 44 more cards) — overcounts hands with two aces. “At least” almost always calls for the complement (Example 2.9).

Example 2.21 (Poker-style count)

From a 5252-card deck, the number of 55-card hands is (525)=2598960\binom{52}{5} = 2\,598\,960. Hands containing exactly one ace: choose the ace (44 ways) then 44 cards among the 4848 non-aces: 4(484)=7783204 \binom{48}{4} = 778\,320. The product rule applies because the choice splits into independent stages.

Method 2.22 (Double counting)

To prove an identity between two counting expressions, find a single finite set that both sides count — typically a set of pairs — and evaluate its cardinality in two different orders. The prototype is the handshake lemma: at a party, count the pairs (person, hand shaken). Summing over people gives pdp\sum_p d_p (each person pp’s number of handshakes); summing over handshakes gives twice the number of handshakes (each involves two people). Hence pdp\sum_p d_p is even — so the number of people who shook an odd number of hands is always even, a nontrivial conclusion obtained with no formula at all. The same engine runs Exercise 2.12 and several questions of the weekend problem below.

Example 2.23 (The average subset)

What is the average cardinality of a subset of an nn-element set EE, all 2n2^n subsets being equally likely? Double count the pairs (A,a)(A, a) with aAa \in A: summing over subsets gives AA\sum_A \abs A, the total we want; summing over elements gives n2n1n \cdot 2^{n-1} (each of the nn elements lies in exactly half of the subsets — pair each AA containing aa with A{a}A \setminus \{a\}). Hence

12nAEA=n2n12n=n2:\frac{1}{2^n}\sum_{A \subseteq E} \abs A = \frac{n\,2^{n-1}}{2^n} = \frac n2 :

subsets are, on average, half-full — as the symmetry AAA \leftrightarrow \overline A (which pairs sizes kk and nkn - k) also predicts. Two proofs, one answer, and both avoid the direct computation kk(nk)\sum_k k\binom nk of Exercise 2.5: a well-chosen pairing often replaces an identity.

2.4 Inclusion–exclusion

Theorem 2.24 (Inclusion–exclusion)

For finite sets A1,,ApA_1, \dots, A_p:

i=1pAi=I[ ⁣[1,p] ⁣](1)I+1iIAi.\Bigl|\, \bigcup_{i=1}^{p} A_i \,\Bigr| = \sum_{\emptyset \neq I \subseteq \intint{1}{p}} (-1)^{\abs{I}+1} \Bigl|\, \bigcap_{i \in I} A_i \,\Bigr| .

For p=3p = 3: ABC=A+B+CABACBC+ABC\abs{A \cup B \cup C} = \abs A + \abs B + \abs C - \abs{A \cap B} - \abs{A \cap C} - \abs{B \cap C} + \abs{A \cap B \cap C}.

Proof. Fix an element xx of the union and count its contribution to the right-hand side. Let J={i:xAi}J = \{i : x \in A_i\}, of cardinality m1m \geq 1. The element xx is counted once in iIAi\abs{\bigcap_{i \in I} A_i} exactly when IJ\emptyset \neq I \subseteq J, with sign (1)I+1(-1)^{\abs I + 1}; its total contribution is

k=1m(mk)(1)k+1=1k=0m(mk)(1)k=10=1\sum_{k=1}^{m} \binom{m}{k} (-1)^{k+1} = 1 - \sum_{k=0}^{m} \binom mk (-1)^k = 1 - 0 = 1

by Example 2.17. So each element of the union is counted exactly once.

Example 2.25 (Counting coprime integers)

How many integers of [ ⁣[1,120] ⁣]\intint1{120} are coprime to 120=23×3×5120 = 2^3 \times 3 \times 5? An integer shares a factor with 120120 exactly when it is divisible by 22, 33 or 55, so count the complement of A2A3A5A_2 \cup A_3 \cup A_5, where AdA_d collects the multiples of dd. Within [ ⁣[1,120] ⁣]\intint1{120}, the multiples of dd number 120/d120/d whenever dd divides 120120 — no floor functions needed — and A2A3=A6A_2 \cap A_3 = A_6, etc. Inclusion–exclusion:

A2A3A5=60+40+2420128+4=88,\abs{A_2 \cup A_3 \cup A_5} = 60 + 40 + 24 - 20 - 12 - 8 + 4 = 88 ,

so 12088=32120 - 88 = 32 integers are coprime to 120120. It is instructive to regroup the computation as a product:

12088=120(112)(113)(115)=120122345=32:120 - 88 = 120\Bigl(1 - \frac12\Bigr)\Bigl(1 - \frac13\Bigr)\Bigl(1 - \frac15\Bigr) = 120 \cdot \frac12 \cdot \frac23 \cdot \frac45 = 32 :

expanding the three parentheses reproduces exactly the eight signed terms of inclusion–exclusion, one per subset of {2,3,5}\{2, 3, 5\}. This product form defines Euler’s totient function, whose arithmetic role appears with Chapter 6’s congruences and is developed in the Year 2 volume.

Example 2.26 (Derangements)

A derangement is a permutation with no fixed point. Let AiA_i be the set of permutations of [ ⁣[1,n] ⁣]\intint{1}{n} fixing ii; then iIAi=(nI)!\abs{\bigcap_{i \in I} A_i} = (n - \abs I)!, and inclusion–exclusion counts the permutations with at least one fixed point; the derangements number

Dn=n!k=0n(1)kk!.D_n = n! \sum_{k=0}^{n} \frac{(-1)^k}{k!} .

Since (1)k/k!e1\sum (-1)^k / k! \to \eu^{-1} (see Chapter 17), about 37%37\% of all permutations are derangements, whatever nn is.

Remark 2.27 (Where this chapter is used)

Binomial coefficients are the most heavily reused objects of this chapter: they drive the binomial theorem in Chapter 8 (expansion of (X+a)n(X + a)^n), the Leibniz formula for the nn-th derivative of a product in Chapter 14, and the coefficients of Taylor expansions in Chapter 16. Permutations return as a group — with the signature built from counting inversions — in Chapter 7, and the signature in turn defines determinants in Chapter 22. Inclusion–exclusion and the counting principles are the finite backbone of discrete probability, developed in the Year 2 volume; the derangement numbers of Example 2.26 are studied in depth in the weekend problem below.

2.5 Exercises

Exercise 2.1

A license plate consists of two letters (A–Z), then three digits, then two letters. How many plates are possible? How many with no repeated letter among the four?

Solution

Solution of Exercise 2.1.

Independent stages and the product rule: 262×103×262=264×1000=45697600026^2 \times 10^3 \times 26^2 = 26^4 \times 1000 = 456\,976\,000 plates. With the four letters pairwise distinct, the letter stages form a 44-arrangement of the alphabet: 26×25×24×23=35880026 \times 25 \times 24 \times 23 = 358\,800 ways, so 358800×1000=358800000358\,800 \times 1000 = 358\,800\,000 plates.

Exercise 2.2

How many anagrams (rearrangements of the letters, meaningful or not) has the word orange? And banana?

Solution

Solution of Exercise 2.2.

orange has 66 distinct letters: 6!=7206! = 720 anagrams. banana has 66 letters with repetitions (33 a’s, 22 n’s, 11 b): each anagram is determined by the positions of the a’s ((63)\binom 63 choices), then of the n’s among the remaining 33 spots ((32)\binom 32), the b taking the last spot: (63)(32)=20×3=60\binom{6}{3}\binom{3}{2} = 20 \times 3 = 60 anagrams (equivalently 6!/(3!2!1!)=606!/(3!\,2!\,1!) = 60).

Exercise 2.3

A committee of 44 people is chosen from 77 women and 55 men. How many committees: in total? with exactly 22 women? with at least one man?

Solution

Solution of Exercise 2.3.

Total: (124)=495\binom{12}{4} = 495. Exactly 22 women: choose them ((72)=21\binom 72 = 21) and 22 men ((52)=10\binom 52 = 10): 210210 committees. At least one man: complement of “no man”, (124)(74)=49535=460\binom{12}{4} - \binom{7}{4} = 495 - 35 = 460.

Exercise 2.4

Prove that in any group of 1313 people, two share their birth month; and that among any n+1n + 1 integers chosen from [ ⁣[1,2n] ⁣]\intint{1}{2n}, two are consecutive. (Pigeonhole both times: name the boxes.)

Solution

Solution of Exercise 2.4.

Birthdays: the boxes are the 1212 months; 1313 people into 1212 boxes force two in the same box (Corollary 2.3).

Consecutive integers: the boxes are the nn pairs {1,2},{3,4},,{2n1,2n}\{1,2\}, \{3,4\}, \dots, \{2n-1, 2n\}, which partition [ ⁣[1,2n] ⁣]\intint{1}{2n}. Choosing n+1n + 1 integers puts two in the same pair, and the two elements of a pair are consecutive.

Exercise 2.5

Compute k=0nk(nk)\sum_{k=0}^{n} k \binom{n}{k}. Hint: differentiate (1+x)n(1 + x)^n, or use k(nk)=n(n1k1)k \binom nk = n \binom{n-1}{k-1} (prove it).

Solution

Solution of Exercise 2.5.

For 1kn1 \leq k \leq n,

k(nk)=kn!k!(nk)!=n(n1)!(k1)!(nk)!=n(n1k1).k \binom nk = k\,\frac{n!}{k!\,(n-k)!} = n\,\frac{(n-1)!}{(k-1)!\,(n-k)!} = n \binom{n-1}{k-1}.

Summing and reindexing with j=k1j = k - 1:

k=0nk(nk)=nj=0n1(n1j)=n2n1\sum_{k=0}^{n} k \binom nk = n \sum_{j=0}^{n-1} \binom{n-1}{j} = n\, 2^{n-1}

by Proposition 2.15. (Alternative: differentiate (1+x)n=k(nk)xk(1+x)^n = \sum_k \binom nk x^k and set x=1x = 1.)

Exercise 2.6 ★★

How many strictly increasing maps are there from [ ⁣[1,k] ⁣]\intint{1}{k} to [ ⁣[1,n] ⁣]\intint{1}{n}? Deduce the number of increasing (not necessarily strictly) maps. Hint for the second count: ff increasing \mapsto g(i)=f(i)+i1g(i) = f(i) + i - 1.

Solution

Solution of Exercise 2.6.

A strictly increasing map f ⁣:[ ⁣[1,k] ⁣][ ⁣[1,n] ⁣]f \colon \intint{1}{k} \to \intint{1}{n} is determined by its image, a kk-subset of [ ⁣[1,n] ⁣]\intint{1}{n} (list the subset in increasing order); conversely every kk-subset gives exactly one such map. Hence (nk)\binom nk strictly increasing maps.

If ff is merely increasing, set g(i)=f(i)+i1g(i) = f(i) + i - 1. Then gg is strictly increasing (between consecutive arguments, ff gains 0\geq 0 and i1i - 1 gains 11) with values in [ ⁣[1,n+k1] ⁣]\intint{1}{n + k - 1}; and f(i)=g(i)i+1f(i) = g(i) - i + 1 recovers ff from any strictly increasing gg into [ ⁣[1,n+k1] ⁣]\intint{1}{n+k-1}. This is a bijection, so there are (n+k1k)\binom{n + k - 1}{k} increasing maps.

Exercise 2.7 ★★

(Vandermonde) Prove, by counting kk-subsets of a set split into two blocks of sizes mm and nn:

(m+nk)=j=0k(mj)(nkj).\binom{m+n}{k} = \sum_{j=0}^{k} \binom{m}{j} \binom{n}{k-j} .

Deduce j=0n(nj)2=(2nn)\sum_{j=0}^{n} \binom nj^2 = \binom{2n}{n}.

Solution

Solution of Exercise 2.7.

Split a set EE with m+nm + n elements into blocks MM (mm elements) and NN (nn elements). A kk-subset of EE contains some jj elements of MM (0jk0 \leq j \leq k) and kjk - j of NN; for fixed jj there are (mj)(nkj)\binom mj \binom{n}{k-j} such subsets, and the cases j=0,,kj = 0, \dots, k partition the kk-subsets. The sum rule gives Vandermonde’s identity.

With m=n=km = n = k: (2nn)=j=0n(nj)(nnj)=j=0n(nj)2\binom{2n}{n} = \sum_{j=0}^{n} \binom nj \binom{n}{n-j} = \sum_{j=0}^{n} \binom nj^2, using (nnj)=(nj)\binom{n}{n-j} = \binom nj.

Exercise 2.8 ★★

How many integers in [ ⁣[1,1000] ⁣]\intint{1}{1000} are divisible by 22 or 33 or 55? (Inclusion–exclusion; 1000/6\lfloor 1000/6 \rfloor counts the multiples of 66, etc.)

Solution

Solution of Exercise 2.8.

Let AdA_d be the multiples of dd in [ ⁣[1,1000] ⁣]\intint{1}{1000}, so Ad=1000/d\abs{A_d} = \lfloor 1000/d \rfloor. Inclusion–exclusion (Theorem 2.24) with A2,A3,A5A_2, A_3, A_5, noting A2A3=A6A_2 \cap A_3 = A_6 etc.:

500+333+20016610066+33=734.500 + 333 + 200 - 166 - 100 - 66 + 33 = 734 .

So 734734 integers are divisible by 22, 33 or 55.

Exercise 2.9 ★★

Count the surjections from a set of 44 elements onto a set of 22 elements; then onto a set of 33 elements. Hint: count the non-surjective maps with inclusion–exclusion on the missed values.

Solution

Solution of Exercise 2.9.

Onto 22 elements: all 24=162^4 = 16 maps except the 22 constant maps: 1414 surjections.

Onto 33 elements: by inclusion–exclusion on the missed values, the number of maps from a 44-set to a 33-set missing at least one value is (31)24(32)14=483=45\binom 31 2^4 - \binom 32 1^4 = 48 - 3 = 45; total maps 34=813^4 = 81; surjections: 8145=3681 - 45 = 36. (Check: a surjection from 44 onto 33 elements doubles up exactly one value: choose the doubled value (33), the pair mapping to it ((42)=6\binom 42 = 6), and a bijection for the rest (22): 3×6×2=363 \times 6 \times 2 = 36.)

Exercise 2.10 ★★

(Stars and bars) Prove that the number of kk-selections of nn objects with repetition, order ignored — equivalently, the number of (x1,,xn)Nn(x_1, \dots, x_n) \in \N^n with x1++xn=kx_1 + \dots + x_n = k — is (n+k1k)\binom{n + k - 1}{k}. Hint: encode a solution as a row of kk stars and n1n - 1 bars.

Solution

Solution of Exercise 2.10.

A solution of x1++xn=kx_1 + \dots + x_n = k in Nn\N^n encodes as a row of kk stars and n1n - 1 bars: write x1x_1 stars, a bar, x2x_2 stars, a bar, …, ending with xnx_n stars. This is a bijection onto the words of length k+n1k + n - 1 using kk stars and n1n - 1 bars, and those words are determined by the positions of the stars: (n+k1k)\binom{n + k - 1}{k}. Selections with repetition correspond to solutions of the equation (xix_i = number of copies of object ii), so the count is the same.

Exercise 2.11 ★★★

Prove the formula of Example 2.26 for DnD_n in detail, and deduce n!=k=0n(nk)Dnkn! = \sum_{k=0}^{n} \binom{n}{k} D_{n-k} (also prove this identity directly by classifying permutations by their fixed-point set).

Solution

Solution of Exercise 2.11.

With Ai={σ:σ(i)=i}A_i = \{\sigma : \sigma(i) = i\}, a permutation in iIAi\bigcap_{i \in I} A_i fixes every iIi \in I and permutes the other nIn - \abs I points freely: iIAi=(nI)!\abs{\bigcap_{i \in I} A_i} = (n - \abs I)!. Inclusion–exclusion:

iAi=k=1n(1)k+1(nk)(nk)!=k=1n(1)k+1n!k!,\Bigl|\bigcup_i A_i\Bigr| = \sum_{k=1}^{n} (-1)^{k+1} \binom nk (n-k)! = \sum_{k=1}^{n} (-1)^{k+1} \frac{n!}{k!} ,

since there are (nk)\binom nk subsets II of size kk. Hence

Dn=n!iAi=n!(1k=1n(1)k+1k!)=n!k=0n(1)kk!.D_n = n! - \Bigl|\bigcup_i A_i\Bigr| = n!\Bigl(1 - \sum_{k=1}^{n} \frac{(-1)^{k+1}}{k!}\Bigr) = n! \sum_{k=0}^{n} \frac{(-1)^k}{k!} .

For the second identity: classify the permutations σ\sigma of [ ⁣[1,n] ⁣]\intint{1}{n} by their fixed-point set F(σ)F(\sigma). For a fixed kk-subset FF, the permutations with F(σ)=FF(\sigma) = F are exactly the derangements of the complement: DnkD_{n-k} of them. Summing over the (nk)\binom nk choices of FF for each kk: n!=k=0n(nk)Dnkn! = \sum_{k=0}^{n} \binom nk D_{n-k}.

Exercise 2.12 ★★★

For nNn \in \N^*, prove by a double count of pairs (subset, marked element):

k=1nk(nk)=n2n1,thenk=1nk2(nk)=n(n+1)2n2.\sum_{k=1}^{n} k \binom{n}{k} = n\, 2^{n-1}, \qquad\text{then}\qquad \sum_{k=1}^{n} k^2 \binom{n}{k} = n(n+1)\, 2^{n-2} .

For the second: count pairs of marked elements, equal or not.

Solution

Solution of Exercise 2.12.

First identity. Count the pairs (A,a)(A, a) where AEA \subseteq E (E=n\abs E = n) and aAa \in A. By size of AA: k(nk)k\sum_k \binom nk k pairs. By choosing the marked element first: nn choices for aa, then any subset of the remaining n1n - 1 elements to complete AA: n2n1n\,2^{n-1} pairs.

Second identity. Count the triples (A,a,b)(A, a, b) with a,bAa, b \in A (possibly a=ba = b). By size: kk2(nk)\sum_k k^2 \binom nk. Directly: either a=ba = b (n2n1n\,2^{n-1} triples, previous count) or aba \neq b (n(n1)n(n-1) ordered choices, then any subset of the other n2n - 2 elements: n(n1)2n2n(n-1)\,2^{n-2}). Total

n2n1+n(n1)2n2=n2n2(2+n1)=n(n+1)2n2.n\,2^{n-1} + n(n-1)\,2^{n-2} = n\,2^{n-2}\,(2 + n - 1) = n(n+1)\,2^{n-2} .

2.6 Problem: Derangements, or the misaddressed letters

Problem 2.1

A secretary puts nn letters into nn addressed envelopes at random: what is the chance that nobody receives the right letter? This classical question (Montmort, 1708) leads to the derangement numbers DnD_n of Example 2.26. The inclusion–exclusion formula is only the opening move: this problem develops the recurrences that compute DnD_n, two further independent proofs of the formula, the striking theorem that DnD_n is the integer nearest to n!/en!/\eu, the full distribution of fixed points of a random permutation, and the curious arithmetic of the sequence (Dn)(D_n). Throughout, DnD_n denotes the number of derangements (fixed-point free permutations) of [ ⁣[1,n] ⁣]\intint1n, with the convention D0=1D_0 = 1 (the empty permutation has no fixed point).

Part I — Small cases and the fixed-point census.

  1. Compute D1,D2,D3D_1, D_2, D_3 directly, and D4D_4 by listing the derangements of {1,2,3,4}\{1, 2, 3, 4\} grouped by the value of σ(1)\sigma(1). (You should find D4=9D_4 = 9.)
  2. For 0kn0 \leq k \leq n, show that the number Pk(n)P_k(n) of permutations of [ ⁣[1,n] ⁣]\intint1n with exactly kk fixed points is (nk)Dnk\binom nk D_{n-k}.
  3. Verify the census for n=4n = 4: compute P0(4),,P4(4)P_0(4), \dots, P_4(4) and check that they sum to 4!=244! = 24. Which is more likely for four letters: no match, or exactly one match?
  4. By double counting (Method 2.22) the pairs (σ,i)(\sigma, i) with σ(i)=i\sigma(i) = i, show that

    σFix(σ)=n!:\sum_{\sigma} \abs{\mathrm{Fix}(\sigma)} = n! :

    on average, a random permutation has exactly one fixed point, whatever n1n \geq 1 is.

Part II — Two recurrences and two new proofs of the formula.

  1. Prove combinatorially, for n1n \geq 1:

    Dn+1=n(Dn+Dn1).D_{n+1} = n\,(D_n + D_{n-1}) .

    (Classify the derangements σ\sigma of [ ⁣[1,n+1] ⁣]\intint1{n+1} by j=σ(n+1)j = \sigma(n+1), then by whether σ(j)=n+1\sigma(j) = n + 1; in the case σ(j)n+1\sigma(j) \neq n+1, build a bijection with the derangements of [ ⁣[1,n] ⁣]\intint1n by redirecting the preimage of n+1n + 1 to jj.) Check the recurrence numerically up to D6D_6.

  2. Setting un=DnnDn1u_n = D_n - n D_{n-1}, deduce from question 5 that un+1=unu_{n+1} = -u_n, and conclude the second recurrence:

    Dn=nDn1+(1)n(n1).D_n = n D_{n-1} + (-1)^n \qquad (n \geq 1).
  3. From question 6, prove by induction the formula of Example 2.26,

    Dn=n!k=0n(1)kk!,D_n = n! \sum_{k=0}^{n} \frac{(-1)^k}{k!},

    — a proof wholly independent of inclusion–exclusion.

  4. (Binomial inversion) Let (an)(a_n) and (bn)(b_n) be two sequences such that an=k=0n(nk)bka_n = \sum_{k=0}^n \binom nk b_k for all nn. Prove that

    bn=k=0n(1)nk(nk)ak(nN).b_n = \sum_{k=0}^{n} (-1)^{n-k} \binom nk a_k \qquad (n \in \N).

    (First establish the trinomial revision (nk)(kj)=(nj)(njkj)\binom nk \binom kj = \binom nj \binom{n-j}{k-j}, then use the alternating row sum of Example 2.17.)

  5. Apply question 8 to the identity n!=k(nk)Dnkn! = \sum_k \binom nk D_{n-k} of Exercise 2.11 to obtain a third proof of the formula for DnD_n.

Part III — The nearest integer to n!/en!/\eu. Admit for this part — the theory is built in Chapter 17 — that e1=limnsn\eu^{-1} = \lim_{n \to \infty} s_n where sn=k=0n(1)kk!s_n = \sum_{k=0}^{n} \frac{(-1)^k}{k!}, with the strict alternating-series bound e1sn<1(n+1)!\abs{\eu^{-1} - s_n} < \frac1{(n+1)!} for every nn.

  1. Show that Dnn!/e<1n+1\bigl| D_n - n!/\eu \bigr| < \frac1{n+1} for all nNn \in \N.
  2. Deduce the headline theorem: for every n1n \geq 1, DnD_n is the integer nearest to n!/en!/\eu. Why does the argument need n1n \geq 1?
  3. Determine the sign of the error: show that Dn>n!/eD_n > n!/\eu exactly when nn is even. (Locate the first neglected term of the alternating series.)
  4. Compute D7D_7 through D10D_{10} with the recurrence of question 5, then check D10D_{10} against 10!/e10!/\eu (10!=362880010! = 3\,628\,800, e2.718281828\eu \approx 2.718281828).
  5. (The hat-check probability) Let pn=Dn/n!p_n = D_n/n! be the probability that a uniformly random permutation is a derangement. Show pne1<1(n+1)!\abs{p_n - \eu^{-1}} < \frac1{(n+1)!} and compute p6p_6 to five decimal places. Comment: why is the answer to Montmort’s question essentially independent of nn — already for a dozen letters?

Part IV — The distribution of fixed points.

  1. Fix kNk \in \N. Show that the proportion of permutations of [ ⁣[1,n] ⁣]\intint1n with exactly kk fixed points satisfies

    Pk(n)n!=snkk!  n  e1k!.\frac{P_k(n)}{n!} = \frac{s_{n-k}}{k!} \;\xrightarrow[n \to \infty]{}\; \frac{\eu^{-1}}{k!} .

    (These limiting values, summing to 11, form the Poisson distribution of parameter 11, a central object of the probability course in the Year 2 volume.)

  2. By double counting the triples (σ,i,j)(\sigma, i, j) where iji \neq j are both fixed by σ\sigma, show that σFix(σ)(Fix(σ)1)=n!\sum_\sigma \abs{\mathrm{Fix}(\sigma)}\, (\abs{\mathrm{Fix}(\sigma)} - 1) = n! for n2n \geq 2. Combined with question 4: the average of Fix2\abs{\mathrm{Fix}}^2 is 22, so the “spread” (variance) of the number of fixed points equals 11 — again independent of nn, again matching the Poisson law.
  3. Compute the proportion of permutations having at least one fixed point for n=4,5,6n = 4, 5, 6 (as fractions and to four decimal places), and compare with 1e10.63211 - \eu^{-1} \approx 0.6321.
  4. Show directly — no limits needed — that sn+2sn=(1)n+1(1(n+1)!1(n+2)!)s_{n+2} - s_n = (-1)^{n+1}\bigl(\frac1{(n+1)!} - \frac1{(n+2)!}\bigr), and deduce that the probabilities pn=snp_n = s_n of question 14 oscillate: p0>p2>p4>p_0 > p_2 > p_4 > \dots and p1<p3<p5<p_1 < p_3 < p_5 < \dots, the even (resp. odd) values decreasing (resp. increasing) toward the common limit e1\eu^{-1}.
  5. (Secret Santa) nn people each draw one name from a hat; if anyone draws their own name, the whole drawing is restarted from scratch. Using the standard fact that an event of probability pp takes on average 1/p1/p attempts, estimate the average number of complete drawings needed, and conclude that the procedure costs about e2.72\eu \approx 2.72 drawings on average, essentially independently of nn.

Part V — The arithmetic of DnD_n, and a synthesis.

  1. Refine question 5: show that for fixed j[ ⁣[2,n] ⁣]j \in \intint2n, the derangements of [ ⁣[1,n] ⁣]\intint1n with σ(1)=j\sigma(1) = j number exactly Dn1+Dn2D_{n-1} + D_{n-2}, independently of jj. Deduce that n1n - 1 divides DnD_n for every n2n \geq 2.
  2. Prove that DnD_n is odd if and only if nn is even. (Work modulo 22 in the recurrence of question 6.)
  3. Prove that Dn(1)n(modn)D_n \equiv (-1)^n \pmod n for n1n \geq 1, and check the congruence on the last digit of D10D_{10}.
  4. Show from question 6 that DnDn1=n+(1)nDn1\dfrac{D_n}{D_{n-1}} = n + \dfrac{(-1)^n}{D_{n-1}} for n3n \geq 3, so the ratio of consecutive derangement numbers is almost exactly nn; explain in one sentence why this is consistent with Dnn!/eD_n \approx n!/\eu.
  5. Where exactly did this problem use: (i) the product and sum rules; (ii) double counting; (iii) the binomial theorem; (iv) the admitted alternating-series bound? One sentence each.
  6. Synthesis. The formula for DnD_n now has three proofs (inclusion–exclusion, recurrence plus induction, binomial inversion). In a short paragraph, compare what each proof explains: which one computes fastest, which one generalizes to other fixed-point counts, and which one reveals why e\eu appears in a problem about envelopes.
Solution

Solution of Problem 2.1.

1. D1=0D_1 = 0 (the only permutation fixes 11), D2=1D_2 = 1 (the swap), D3=2D_3 = 2 (in one-line notation: 231231 and 312312). For n=4n = 4, group by σ(1)\sigma(1): with σ(1)=2\sigma(1) = 2 the derangements are 21432143, 23412341, 24132413; with σ(1)=3\sigma(1) = 3: 31423142, 34123412, 34213421; with σ(1)=4\sigma(1) = 4: 41234123, 43124312, 43214321. Three in each group: D4=9D_4 = 9.

2. A permutation with exactly kk fixed points is determined by the choice of its fixed-point set FF ((nk)\binom nk ways) together with its restriction to the complement, which must be a permutation of nkn - k points with no fixed point (DnkD_{n-k} ways). The two choices are independent and the correspondence is bijective: Pk(n)=(nk)DnkP_k(n) = \binom nk D_{n-k}.

3. P0(4)=D4=9P_0(4) = D_4 = 9; P1(4)=(41)D3=4×2=8P_1(4) = \binom41 D_3 = 4 \times 2 = 8; P2(4)=(42)D2=6P_2(4) = \binom42 D_2 = 6; P3(4)=(43)D1=0P_3(4) = \binom43 D_1 = 0 (three fixed points force a fourth); P4(4)=1P_4(4) = 1. Sum: 9+8+6+0+1=24=4!9 + 8 + 6 + 0 + 1 = 24 = 4!. No match (99 cases) beats exactly one match (88 cases) — narrowly.

4. Count the pairs (σ,i)(\sigma, i) with σ(i)=i\sigma(i) = i. For fixed ii, the permutations fixing ii are the permutations of the other n1n - 1 points: (n1)!(n-1)! of them. Hence the number of pairs is n(n1)!=n!n \cdot (n-1)! = n!, and this number is also σFix(σ)\sum_\sigma \abs{\mathrm{Fix}(\sigma)}. Dividing by the number n!n! of permutations: the average number of fixed points is exactly 11, for every n1n \geq 1.

5. Let σ\sigma be a derangement of [ ⁣[1,n+1] ⁣]\intint1{n+1} and j=σ(n+1)[ ⁣[1,n] ⁣]j = \sigma(n+1) \in \intint1n: nn possible values. Case σ(j)=n+1\sigma(j) = n+1: the points jj and n+1n+1 swap, and σ\sigma restricted to the remaining n1n - 1 points is an arbitrary derangement of them: Dn1D_{n-1} possibilities. Case σ(j)n+1\sigma(j) \neq n+1: let i0=σ1(n+1)i_0 = \sigma^{-1}(n+1); here i0ji_0 \neq j and i0ni_0 \leq n. Define τ\tau on [ ⁣[1,n] ⁣]\intint1n by τ(i)=σ(i)\tau(i) = \sigma(i) for ii0i \neq i_0 and τ(i0)=j\tau(i_0) = j. Then τ\tau is a permutation of [ ⁣[1,n] ⁣]\intint1n (the value n+1n+1 has been replaced by the missing value jj), and it is a derangement: τ(i0)=ji0\tau(i_0) = j \neq i_0, and τ(i)=σ(i)i\tau(i) = \sigma(i) \neq i elsewhere. Conversely, from a derangement τ\tau of [ ⁣[1,n] ⁣]\intint1n and the value jj, one recovers σ\sigma by setting σ(n+1)=j\sigma(n+1) = j, σ(τ1(j))=n+1\sigma(\tau^{-1}(j)) = n+1 and σ=τ\sigma = \tau elsewhere: a bijection, giving DnD_n possibilities. Summing over jj: Dn+1=n(Dn+Dn1)D_{n+1} = n(D_n + D_{n-1}). Numerically: D5=4(9+2)=44D_5 = 4(9 + 2) = 44, D6=5(44+9)=265D_6 = 5(44 + 9) = 265.

6. From question 5, Dn+1=nDn+nDn1D_{n+1} = nD_n + nD_{n-1}, so

un+1=Dn+1(n+1)Dn=nDn+nDn1(n+1)Dn=(DnnDn1)=un.u_{n+1} = D_{n+1} - (n+1)D_n = nD_n + nD_{n-1} - (n+1)D_n = -(D_n - nD_{n-1}) = -u_n .

Since u1=D11D0=1u_1 = D_1 - 1 \cdot D_0 = -1, induction gives un=(1)nu_n = (-1)^n, i.e. Dn=nDn1+(1)nD_n = nD_{n-1} + (-1)^n for n1n \geq 1.

7. Induction on nn. Base: D0=1=0!s0D_0 = 1 = 0!\,s_0. Step: assuming Dn1=(n1)!sn1D_{n-1} = (n-1)!\,s_{n-1},

Dn=nDn1+(1)n=n!sn1+(1)n=n!(sn1+(1)nn!)=n!sn,D_n = nD_{n-1} + (-1)^n = n!\,s_{n-1} + (-1)^n = n!\Bigl(s_{n-1} + \frac{(-1)^n}{n!}\Bigr) = n!\,s_n ,

which is the formula. No inclusion–exclusion was used: only the combinatorial recurrence of question 5.

8. Trinomial revision, by factorials:

(nk)(kj)=n!k!(nk)!k!j!(kj)!=n!j!(nj)!(nj)!(kj)!(nk)!=(nj)(njkj).\binom nk \binom kj = \frac{n!}{k!\,(n-k)!} \cdot \frac{k!}{j!\,(k-j)!} = \frac{n!}{j!\,(n-j)!} \cdot \frac{(n-j)!}{(k-j)!\,(n-k)!} = \binom nj \binom{n-j}{k-j} .

Now substitute ak=j(kj)bja_k = \sum_j \binom kj b_j and exchange the two finite sums:

k=0n(1)nk(nk)ak=j=0nbj(nj)k=jn(1)nk(njkj)=j=0nbj(nj)i=0nj(1)(nj)i(nji).\sum_{k=0}^{n} (-1)^{n-k} \binom nk a_k = \sum_{j=0}^{n} b_j \binom nj \sum_{k=j}^{n} (-1)^{n-k} \binom{n-j}{k-j} = \sum_{j=0}^{n} b_j \binom nj \sum_{i=0}^{n-j} (-1)^{(n-j)-i} \binom{n-j}{i} .

The inner sum is the expansion of (1+(1))nj=0nj(1 + (-1))^{n-j} = 0^{n-j} (binomial theorem, Theorem 2.16): it vanishes for j<nj < n and equals 11 for j=nj = n. Only j=nj = n survives, and the right-hand side is bnb_n, as claimed.

9. By the symmetry (nk)=(nnk)\binom nk = \binom n{n-k}, the identity of Exercise 2.11 rewrites as n!=k=0n(nk)Dkn! = \sum_{k=0}^n \binom nk D_k. Apply question 8 with an=n!a_n = n! and bk=Dkb_k = D_k:

Dn=k=0n(1)nk(nk)k!=k=0n(1)nkn!(nk)!=n!j=0n(1)jj!,D_n = \sum_{k=0}^{n} (-1)^{n-k} \binom nk k! = \sum_{k=0}^{n} (-1)^{n-k} \frac{n!}{(n-k)!} = n! \sum_{j=0}^{n} \frac{(-1)^j}{j!} ,

reindexing by j=nkj = n - k: the formula a third time.

10. Dn=n!snD_n = n!\,s_n (question 7), so

Dnn!e=n!sne1<n!(n+1)!=1n+1.\Bigl| D_n - \frac{n!}{\eu} \Bigr| = n!\,\abs{s_n - \eu^{-1}} < \frac{n!}{(n+1)!} = \frac1{n+1} .

11. For n1n \geq 1, 1n+112\frac1{n+1} \leq \frac12, and the inequality of question 10 is strict: DnD_n lies at distance <12< \frac12 from n!/en!/\eu, so it is the unique nearest integer. For n=0n = 0 the bound only gives distance <1< 1, and indeed the claim fails there: 0!/e0.3680!/\eu \approx 0.368 has nearest integer 00, while D0=1D_0 = 1.

12. e1sn=kn+1(1)k/k!\eu^{-1} - s_n = \sum_{k \geq n+1} (-1)^k/k! is an alternating series with strictly decreasing terms, so its sign is the sign of its first term (1)n+1/(n+1)!(-1)^{n+1}/(n+1)!. Hence sne1s_n - \eu^{-1} has the sign of (1)n(-1)^n: for nn even, sn>e1s_n > \eu^{-1} and Dn=n!sn>n!/eD_n = n!\,s_n > n!/\eu; for nn odd, Dn<n!/eD_n < n!/\eu.

13. D7=6(265+44)=6×309=1854D_7 = 6(265 + 44) = 6 \times 309 = 1854; D8=7(1854+265)=7×2119=14833D_8 = 7(1854 + 265) = 7 \times 2119 = 14\,833; D9=8(14833+1854)=8×16687=133496D_9 = 8(14\,833 + 1854) = 8 \times 16\,687 = 133\,496; D10=9(133496+14833)=9×148329=1334961D_{10} = 9(133\,496 + 14\,833) = 9 \times 148\,329 = 1\,334\,961. Check: 10!/e=3628800/2.7182818281334960.9210!/\eu = 3\,628\,800 / 2.718281828 \approx 1\,334\,960.92, whose nearest integer is 13349611\,334\,961 — and D10>10!/eD_{10} > 10!/\eu, as question 12 predicts for even nn.

14. pne1=sne1<1(n+1)!\abs{p_n - \eu^{-1}} = \abs{s_n - \eu^{-1}} < \frac1{(n+1)!}. For n=6n = 6: p6=265/720=0.36806p_6 = 265/720 = 0.36806 (five decimals), against e1=0.36788\eu^{-1} = 0.36788; the gap is below 1/7!=1/5040<2×1041/7! = 1/5040 < 2 \times 10^{-4}. The bound 1/(n+1)!1/(n+1)! collapses so fast that the probability is fixed to many decimal places already for a dozen letters: the answer “about 36.8%36.8\%” is, for every practical purpose, independent of nn — the famous surprise of the problem.

15. By question 2 and Dm=m!smD_m = m!\,s_m:

Pk(n)n!=(nk)Dnkn!=Dnkk!(nk)!=snkk!    e1k!\frac{P_k(n)}{n!} = \frac{\binom nk D_{n-k}}{n!} = \frac{D_{n-k}}{k!\,(n-k)!} = \frac{s_{n-k}}{k!} \;\longrightarrow\; \frac{\eu^{-1}}{k!}

as nn \to \infty with kk fixed, since snke1s_{n-k} \to \eu^{-1}. The limit values e1/k!\eu^{-1}/k! (kNk \in \N) are the weights of the Poisson distribution of parameter 11.

16. Count the triples (σ,i,j)(\sigma, i, j) with iji \neq j, σ(i)=i\sigma(i) = i, σ(j)=j\sigma(j) = j. Choosing the ordered pair first: n(n1)n(n-1) ways; the permutations fixing both ii and jj are the permutations of the remaining n2n - 2 points: (n2)!(n-2)! of them. Total: n(n1)(n2)!=n!n(n-1)(n-2)! = n!. Summing instead over σ\sigma first counts, for each σ\sigma, the ordered pairs of distinct fixed points: Fix(σ)(Fix(σ)1)\abs{\mathrm{Fix}(\sigma)}(\abs{\mathrm{Fix}(\sigma)}-1). Hence the stated identity; dividing by n!n!, the average of Fix(Fix1)\abs{\mathrm{Fix}}(\abs{\mathrm{Fix}} - 1) is 11, so the average of Fix2\abs{\mathrm{Fix}}^2 is 1+1=21 + 1 = 2 and the variance is 212=12 - 1^2 = 1.

17. The proportions 1pn1 - p_n: for n=4n = 4, 1924=1524=0.62501 - \frac 9{24} = \frac{15}{24} = 0.6250; for n=5n = 5, 144120=76120=0.63331 - \frac{44}{120} = \frac{76}{120} = 0.6333; for n=6n = 6, 1265720=455720=0.63191 - \frac{265}{720} = \frac{455}{720} = 0.6319. All within a percent of 1e10.63211 - \eu^{-1} \approx 0.6321, oscillating around it.

18. Directly:

sn+2sn=(1)n+1(n+1)!+(1)n+2(n+2)!=(1)n+1(1(n+1)!1(n+2)!),s_{n+2} - s_n = \frac{(-1)^{n+1}}{(n+1)!} + \frac{(-1)^{n+2}}{(n+2)!} = (-1)^{n+1}\Bigl(\frac1{(n+1)!} - \frac1{(n+2)!}\Bigr),

and the parenthesis is >0> 0. For nn even the difference is negative: sn+2<sns_{n+2} < s_n, so p0>p2>p4>p_0 > p_2 > p_4 > \dots; for nn odd it is positive: p1<p3<p5<p_1 < p_3 < p_5 < \dots Combined with question 12 (evens above e1\eu^{-1}, odds below) and question 14 (distance to e1\eu^{-1} tends to 00): the two staircases squeeze e1\eu^{-1} between them.

19. One complete drawing is a uniform random permutation, valid when it is a derangement: probability pne1p_n \approx \eu^{-1}. By the quoted fact, the average number of drawings until success is 1/pn1/p_n, and question 14 gives 1/pne1/p_n \approx \eu up to an error that is negligible already for small nn. So a Secret Santa with restarts costs on average about e2.72\eu \approx 2.72 complete drawings — whether the office has 66 people or 600600.

20. Fix j2j \geq 2 and run question 5’s classification on the value σ(1)=j\sigma(1) = j. If σ(j)=1\sigma(j) = 1: the remaining n2n - 2 points carry an arbitrary derangement, Dn2D_{n-2} ways. If σ(j)1\sigma(j) \neq 1: redirect the preimage i0=σ1(1)i_0 = \sigma^{-1}(1) to jj exactly as in question 5; this is a bijection with the derangements of the n1n - 1 points {2,,n}\{2, \dots, n\}: Dn1D_{n-1} ways. Total Dn1+Dn2D_{n-1} + D_{n-2}, the same for every jj. Summing over the n1n - 1 values of jj: Dn=(n1)(Dn1+Dn2)D_n = (n-1)(D_{n-1} + D_{n-2}), which displays the factor n1n - 1: (n1)Dn(n-1) \mid D_n.

21. Claim: DnD_n is odd iff nn is even. Induction using Dn=nDn1+(1)nD_n = nD_{n-1} + (-1)^n, i.e. DnnDn1+1(mod2)D_n \equiv nD_{n-1} + 1 \pmod 2. Base: D1=0D_1 = 0 is even, n=1n = 1 odd: claim holds. If nn is even, nDn1nD_{n-1} is even and Dn1D_n \equiv 1: odd, as claimed. If nn is odd, then n1n - 1 is even, so Dn1D_{n-1} is odd by hypothesis, and DnDn1+10D_n \equiv D_{n-1} + 1 \equiv 0: even. The induction closes.

22. Reducing Dn=nDn1+(1)nD_n = nD_{n-1} + (-1)^n modulo nn kills the first term: Dn(1)n(modn)D_n \equiv (-1)^n \pmod n. For n=10n = 10: (1)10=1(-1)^{10} = 1, and indeed D10=1334961D_{10} = 1\,334\,961 ends in the digit 11.

23. For n3n \geq 3, Dn11D_{n-1} \geq 1 and division of question 6’s recurrence by Dn1D_{n-1} gives Dn/Dn1=n+(1)n/Dn1D_n/D_{n-1} = n + (-1)^n/D_{n-1}, with (1)n/Dn11\abs{(-1)^n/D_{n-1}} \leq 1 and rapidly tending to 00. Consistency: if Dnn!/eD_n \approx n!/\eu, then Dn/Dn1n!/(n1)!=nD_n/D_{n-1} \approx n!/(n-1)! = n — the factor e\eu cancels in the ratio, and the recurrence confirms it to accuracy 1/Dn11/D_{n-1}.

24. (i) The product and sum rules underlie every count: questions 2 and 5 partition sets of permutations into independent stages. (ii) Double counting gave the mean (question 4) and the variance (question 16) of the number of fixed points with no formula for DnD_n at all. (iii) The binomial theorem evaluated the alternating inner sum (11)nj(1-1)^{n-j} that makes binomial inversion work (question 8). (iv) The alternating-series bound converted the exact but opaque sum n!snn!\,s_n into the transparent statement “nearest integer to n!/en!/\eu” (questions 10–14).

25. Inclusion–exclusion (Example 2.26 and Exercise 2.11) is the conceptual proof: it explains the alternating sum as overcounting corrections, and it generalizes verbatim to counting elements avoiding any family of “bad” sets. The recurrence route (questions 5–7) computes fastest — linear time, exact integer arithmetic, no factorials — and is the source of the arithmetic facts of Part V. Binomial inversion (questions 8–9) places the formula inside a general transform that will reappear wherever two triangular systems of identities face each other. And the appearance of e\eu is best explained by the formula itself: the proportion of derangements is the partial sum sns_n of the series for e1\eu^{-1}, so Montmort’s envelopes were, three decades before Euler’s notation, already computing the number e\eu.