Combinatorics Web
Combinatorics Web
Mark Wildon
Contents
Introduction page 1
References 169
Index 171
Introduction
Outline
[This is not necessarily close to the final form of this section, but should give
an idea of the planned content.]
[Estimated page count at most 420 pages: 200 pages for the main text, 30 pages
for Appendices A, B and D, 180 pages, but probably less, for Appendix C
(solutions to exercises).]
2 Introduction
Part A: Enumeration
We begin with bijections and adding and multiplying choices: the building blocks
of combinatorial enumeration.
• The derangements problem: enumerating permutations with no fixed points.
This problem is solved eight times in the book, each solution illustrating a
different combinatorial technique.
• Binomial coefficients, emphasising memorable bijective proofs of the key
identities.
• Principle of Inclusion and Exclusion with applications to Euler’s f function
and counting
• Rook polynomials. Applications including the Problème des Ménages.
Acknowledgements
I gratefully acknowledge the significant contribution made by Eugenio Giannelli,
who did much of the initial work in preparing the first two chapters of this book.
Website
Corrections or comments sent by email to [email protected] are very
welcome. Errata will be collected on the web at www.ma.rhul.ac.uk/~uvah099/.
PART ONE
ENUMERATION
1
The Derangements Problem
1.1 Derangements
We begin with the Derangements Problem. Later we will develop techniques that
can be used to solve this problem in a routine way. Our first solution is necessarily
somewhat ad-hoc. Along the way we will see three basic counting principles that
are fundamental to combinatorial enumeration.
Recall that if X and Y are sets then a function f : X ! Y is a bijection if for every
y 2 Y there exists a unique x 2 X such that f (x) = y.
Definition 1.1.1 A permutation s of a set X is a bijection s : X ! X.
Usually we will consider permutations of {1, 2, . . . , n} for some natural number
n 2 N. It is often useful to represent permutations by diagrams. For example, the
diagram below shows the permutation s : {1, 2, 3, 4, 5} ! {1, 2, 3, 4, 5} defined by
s (1) = 2, s (2) = 1, s (3) = 4, s (4) = 5, s (5) = 3.
1 2 3 4 5
1 2 3 4 5
s (2) s (1) s (5) s (3) s (4)
More briefly, we may write s in one-line form as 21453. You might also have
seen two-line form; later in §9.2 we will see the disjoint cycle decomposition of
permutations.
As a starting point, consider the following questions:
(a) How many permutations are there of {1, 2, . . . , n}?
(b) How many of these permutations s satisfy s (1) = 1?
For (a), we construct a permutation s : {1, 2, . . . , n} ! {1, 2, . . . , n} step-by-step.
Let X = {1, 2, . . . , n}. We may choose any element of X for s (1). For s (2) we
8 The Derangements Problem
may choose any element of X except s (1). Continuing in this way, for s (r) we
may choose any element of X except s (1), . . . , s (r 1). Finally for s (n) we have
a unique choice. Thus there are n (r 1) choices for each s (r). Multiplying
choices, we see that there are n(n 1) . . . 1 = n! permutations of {1, 2, . . . , n}.
For (b), we have only 1 choice for s (1). Then as before, and for the same rea-
sons, we have n 1 choices for s (2), n 2 choices for s (3), and so on. So there are
1(n 1)(n 2) . . . 1 = (n 1)! permutations s of {1, 2, . . . , n} such that s (1) = 1.
This principle of multiplying numbers of choices is very powerful.
Note that in (a), the choices we have for s (r) depend on our earlier choices of
s (1), . . . , s (r 1). But it was still correct to apply BCP1 because the number
of choices for s (r) is always n (r 1). In the special case where we make two
choices, and one choice does not affect the next, so we first choose an element of
a set A, then an element of a set B, BCP1 simply says that |A ⇥ B| = |A||B|. (See
Appendix A if any of this notation is unfamiliar to you.)
1 2 3 1 2 3
The solution to this exercise given in Appendix B uses a further counting prin-
ciple.
Our final basic counting principle is arguably the most basic of all.
Both principles should seem obvious. For instance, when r = 2, BCP2 says that if
X is a finite set and X = A [ B where A \ B = ?, then |X| = |A| + |B|.
Exercise 1.1.4 You are a shepherd with a flock of several hundred sheep. You are
an expert on sheep, but have never learned to count above 5. How can you work
out how many sheep were killed by wolves over Winter?
The previous exercise shows that we cannot hope to solve the derangements
problem just by multiplying choices. Instead we shall find a recurrence for the
numbers dn .
that, after the swap, Parcel x has now gone to Person t(x). An example is
shown below.
1 2 3 4 5
s, before swap
1 2 3 4 5
1 2 3 4 5
t, after swap
1 2 3 4 5
Since s (2) 6= 1, Parcel 2 was not sent to Person 1. Hence, after Persons 1
and 2 swap parcels, Person 2 does not have Parcel 2. Therefore t(2) 6= 2.
The swap does not affect the parcels sent to Persons 3, . . . , n, so t(3) 6= 3,
. . . , t(n) 6= n. Clearly the swap can be undone: just repeat it! So swapping
parcels defines a bijection
8 9
( ) > permutations t of {1, 2, . . . , n} >
< =
derangements s of {1, 2, . . . , n}
! such that t(1) = 1, t(2) 6= 2, .
such that s (1) = 2, s (2) 6= 1 >
: >
;
t(3) 6= 3, . . . , t(n) 6= n
Since there are dn 1 derangements of {2, 3, . . . , n}, the set on the right-hand
side has size dn 1 . By BCP0 so does the set on the left-hand side.
Now add up the numbers of choices for the ‘either’ and ‘or’ cases using BCP2.
Exercise 1.1.7 Let f be the ‘swapping parcels’ bijection defined in the proof of
Lemma 1.1.6. Consider Figure 1.1 overleaf. Apply f to the permutation s on the
left, and apply f 1 = f to the permutation t on the right. Check in each case the
image is in the expected set. Check also that f ( f (s )) = s and f ( f (t)) = t.
It is often useful to see how proofs work by trying them out on particular exam-
ples. In the early sections of this book some exercises are included to encourage
you to get into this habit.
The proof of the next theorem is modelled on the solution to Exercise 1.1.3.
Theorem 1.1.8 If n 2 then dn = (n 1)(dn 2 + dn 1 ).
Proof Let D be the set of derangements of {1, 2, . . . , n}. For each x 2 {1, 2, . . . , n}
let Dx = {s 2 D : s (1) = x}. By Lemma 1.1.6 we have |D2 | = dn 2 + dn 1 . There
is nothing special about 2 in this context, except that 2 6= 1. Hence
|D2 | = |D3 | = . . . = |Dn | = dn 2 + dn 1 .
1.1 Derangements 11
1 2 3 4 5 1 2 3 4 5
1 2 3 4 5 1 2 3 4 5
s (4) s (1) s (2) s (5) s (3)
f f 1
1 2 3 4 5 1 2 3 4 5
1 2 3 4 5 1 2 3 4 5
t (1) t (3) t (2) t (5) t (4)
as required.
Using this recurrence relation it is easy to find values of dn for much larger n.
For example, you can easily compute d5 = (5 1)(d3 + d4 ) = 4 ⇥ (2 + 9) = 44.
Compare this with the effort required to find the 44 derangements of {1, 2, . . . , 5}
by listing all 5! permutations of {1, 2, . . . , 5}.
Whenever one meets a new combinatorial sequence, it is a good idea to look it up
in N. J. A. Sloane’s Online Encyclopedia of Integer Sequences: see oeis.org. You
will usually find it there, along with references and often other combinatorial in-
terpretations. The derangement numbers d0 , d1 , d2 , . . . are sequence A000166. The
terms for n 10 are
1, 0, 1, 2, 9, 44, 265, 1854, 14833, 133496, 1334961, . . .
(See the answer to Exercise 1.1.3 if you are surprised that d0 = 1.) We also find
a formula: a(n) = n!*Sum((-1)^k/k!, k=0..n). Knowing the answer, it is not
hard to prove by induction that it is correct.
Corollary 1.1.9 For all n 2 N0 ,
1 1 1 ( 1)n
dn = n! 1+ +···+ .
1! 2! 3! n!
Proof When n = 0 both sides are 1 and when d = 1 both sides are 0. Let n 2 and
12 The Derangements Problem
suppose, inductively, that the formula holds for dn 2 and dn 1 . By Theorem 1.1.8
and the inductive hypothesis we have
dn (n 1)(dn 2 + dn 1 )
=
n! n!
dn 2 n 1 dn 1
= +
n(n 2)! n (n 1)!
1 1 1 ( 1)n 2
= 1 + ···+
n 1! 2! (n 2)!
1 1 1 ( 1)n 2 ( 1)n 1
+ 1 1 + ···+ + .
n 1! 2! (n 2)! (n 1)!
k
1 ( 1)k
Each term 1n ( k!1) in the first summand is cancelled by a corresponding n k!
from the second summand. We are left with
A more systematic way to derive Corollary 1.1.9 from Theorem 1.1.8 will be
seen in Part 2. We will later prove Corollary 1.1.9 in many other ways, none of
which require knowing the answer in advance.
The proof of Corollary 1.1.9 shows that it is helpful to consider the probability
dn /n! that a permutation of {1, 2, . . . , n} is a derangement. (This assumes that each
probability is chosen uniformly at random, that is, with equal probability 1/n!.)
Before reading further, please take a moment to think about the next question.
Question 1.1.10 Let n be large. Suppose that n parcels are delivered uniformly
at random to n people, so that each person gets one parcel. Roughly, what is the
probability that no-one gets the right parcel?
Of course this probability is dn /n!. Since all n people have to be unlucky, one
reasonable guess is ‘nearly 0’. On the other hand, the chance a particular parcel
(say Parcel 1) is wrongly delivered is 1 1/n, which is very close to 1. So another
reasonable guess is ‘nearly 1’. This line of thought is continued in Exercise 1.8.
In fact, by the following theorem, the probability is close to 1/e = 0.36788 . . .,
and on average, exactly one person gets their own parcel.
1.1 Derangements 13
as required.
(ii) We define a set of ordered pairs
n s is a permutation of {1, 2, . . . , n},o
P = (s , x) : .
x 2 {1, 2, . . . , n}, s (x) = x
(See Appendix A if you need a reminder of the notation for ordered pairs.) Count-
ing P by summing over all n! permutations s of {1, 2, . . . , n} we get
|P| = Â x 2 {1, 2, . . . , n} : s (x) = x .
s
Hence the mean number of fixed points is |P|/n!. On the other hand, counting |P|
by summing over x 2 {1, 2, . . . , n} we get
n
|P| = Â permutations s of {1, 2, . . . , n} : s (x) = x .
x=1
We saw on page 8 that there are exactly (n 1)! permutations of {1, 2, . . . , n} fix-
ing 1. In this context there is nothing special about 1. Hence every summand above
is (n 1)!. Therefore |P| = n(n 1)! = n! and the mean number of fixed points is
n!/n! = 1.
The double-counting technique used in (ii) is often useful in combinatorial prob-
lems. A group theoretic generalization of (ii) is given in Exercise 1.11 below. It
should be admitted that the proof of (ii) is far from the shortest possible: we will
14 The Derangements Problem
use probabilities and expectations to give a ‘one-line proof’ of a more general result
in §9.2.
Exercises
Exercises 1.1 to 1.6 are core exercises intended to give you some practice in apply-
ing the Basic Counting Principles.
1.1 A menu has 3 starters, 4 main courses and 6 desserts.
(a) How many ways are there to order a three course meal, consisting of a starter,
main course and dessert? [Hint: multiply choices using BCP1]
(b) How many ways are there to order a two course meal, including exactly one
main course?
1.2 Let
T = {(x1 , x2 , x3 ) : 1 x1 , x2 , x3 10, x1 , x2 , x3 distinct},
S = {X : X ✓ {1, . . . , 10}, |X| = 3}.
Define a function f : T ! S by f (x1 , x2 , x3 ) = {x1 , x2 , x3 }. For example,
(3, 2, 5) 2 T and f (3, 2, 5) = {3, 2, 5} = {2, 3, 5} 2 S.
(a) Find |T |.
(b) Find the number of tuples (x1 , x2 , x3 ) 2 T such that f (x1 , x2 , x3 ) = {2, 3, 5}.
(c) By generalizing the idea in (b), find |S|.
[Hint: the point of this question is to show the ideas in one proof of the
formula for binomial coefficients. So please do not assume this formula is
true in (c). For a reminder of the difference between tuples and sets, see Ap-
pendix A.]
1.3 Fix n 2 N. Let X = {(a, b) : 1 a b n}. Find a simple formula for |X| in
terms of n.
1.4 For each n 2 N, how many subsets are there of {1, 2, . . . , n}? [Hint: work out
the answer for n = 1, 2, 3, . . . by writing down all the subsets in each case. Do
not forget the empty set! Now explain the pattern using BCP1.]
1.5 Let
nplacements of 4 indistinguishable balls into 7 o
A= ,
numbered urns so that each ball is in a different urn
n ways to walk 4 blocks East and 3 blocks South o
B= ,
on a New York grid, moving only East and South
C = X ✓ {1, 2, . . . , 7} : |X| = 4 .
Exercises 15
E E
S
E end
1 2 3 4 5 6 7
Exercises 1.7 to 1.11 extend the results so far on permutations and derangements.
1.7 Let pn = dn /n! be the probability that a permutation of {1, 2, . . . , n}, chosen
uniformly at random, is a derangement. Using only the recurrence in Theo-
rem 2.4, prove by induction that pn pn 1 = ( 1)n /n!; hence give an alter-
native proof of Corollary 1.1.9.
16 The Derangements Problem
1.8 As in Question 1.1.10, suppose that n parcels are delivered uniformly at ran-
dom to n people, so that each person gets one parcel.
(a) Let x 2 {1, . . . , n}. Show that the probability that Parcel x is wrongly delivered
is 1 1/n.
(b) Assuming the events that parcels are wrongly delivered are independent, show
that the probability that no-one gets their own parcel is (1 1/n)n .
(c) Show that (1 1/n)n ! 1/e as n ! •.
(d) Show, regrettably, that the independence assumption in (b) is false whenever
n 2.
(Despite the bad news in (d), this line of reasoning can still be modified to
give a rigorous proof that dn /n! ! 1/e as n ! •: see Exercise 11.4.)
1.9 Use the formula for dn in Corollary 1.1.9 to prove that if n > 0 then dn is the
nearest integer to n!/e.
1.10
(a) Let an (t) be the number of permutations of {1, 2, . . . , n} with exactly t fixed
points. Note that dn = an (0). Prove that
n! ⇣ 1 1 ( 1)n t ⌘
an (t) = 1 + ···+ .
t! 1! 2! (n t)!
Hence, or otherwise, give a simple expression for an (0) an (1).
(b) Use (a) to give an alternative proof of Theorem 2.6(ii), that the mean number
of fixed points of a permutation of {1, 2, . . . , n} is 1.
(c) (?) Let en be the number of derangements of {1, 2, . . . , n} that are even per-
mutations, and let on be the number that are odd permutations. By evaluating
the determinant of the matrix
0 1
0 1 1 ... 1
B1 0 1 . . . 1C
B C
B1 1 0 . . . 1C
B C
B. . . .
@ .. .. .. . . ... A
C
1 1 1 ... 0
Exercises 1.12 to 1.15 are more challenging. They can all be solved by elementary
arguments, but you will have to think hard. Try looking at small cases to get started.
1.12 (?) The hare and the tortoise—both of them capable mathematicians—play
a game. The umpire places evenly many coins in a row: a possible starting
position for a six coin game is shown below.
'$
'$'$
'$'$
'$
The players then alternately take coins from either end, until none are left.
The winner is the player who ends up with the most money. If the players get
equal amounts, the game is a draw. Tradition dictates that the tortoise starts.
Show that the tortoise can guarantee never to lose. Find a reasonably general
sufficient condition for the tortoise to win.
1.13 (?) There are 12 numbered locked safes that can be unlocked by 12 numbered
keys. Before you arrive, the keys are randomly distributed so that each safe
contains one key, and the safes are shut. When you arrive, the referee unlocks
the first r safes using her master key. What is the probability that you can now
open all the safes? (Once you have unlocked a safe, you may take and use the
key it contains.)
1.14 [American Mathematical Monthly Problem 11573] (?) A square matrix of
order n2 is said to be a Sudoku permutation matrix if all its entries are either
0 or 1, and it has exactly one 1 in each row, each column, and each of the n2
submatrices obtained by dividing the matrix into an n ⇥ n array of n ⇥ n sub-
matrices. For each n 2 N, find the number of Sudoku permutation matrices of
order n2 .
Challenge problems for MT4540 Combinatorics
Here are four hopefully interesting problems embodying combinato-
rial ideas. I will happily give £5 per problem to any person (or team of
people) that solves a problem and presents their solution at the board.
If you solve the first problem before 31st December you could send in
your solution to the American Mathematical Monthly; they publish
18 the names of solvers,Theand
Derangements Problem
the best solution.
(See below for an example when n = 2. If n = 3 then the 1s in a completed
Problem 1 (American Mathematical Monthly, Problem 211520). Let A
Sudoku
be grid
a setform a Sudoku
of n real permutation
numbers. For each imatrix
2 {1, 2,of
. . .order 3 .)
, n} define by
i
0i = 1 0max0X
0 X0 A 1 0
1 0X of0size0exactly i, and max X denotes
where the sum is over all subsets
the maximum element of the 0 subset
0 0 X.1 Express the k-th smallest
element of A as a linear combination of the i.
1.15 (?) Given a necklace with 168 beads, 84 black and 84 white, can it necessarily
be cut, and the 2new
Problem ends retied,
(Beads). Given aso that two
necklace necklaces
with 168 beads,each with 42
84 black andbeads
84 white, can it be cut, and the new ends retied, so that two necklaces
of either colour are obtained? (See below for one solution with an 8 bead
each with 42 beads of either colour are obtained? (See below for one
necklace.)
solution with an 8 bead necklace.)
£1 20p £1 £2 50p 1p
The players then alternately take coins from either end, until none are
left. The winner is the person who ends up with the most money.
Tradition dictates that the tortoise starts. Who wins? What can be
said if there are an odd number of coins?
2
Binomial coefficients
(z + w)m = (z + w)(z + w) · · · (z + w)
| {z }
m
The answer is 74 : each walking route has 7 steps, of which we must choose ex-
actly 4 to be East. Alternatively, we can compute iteratively. Let C be a street
junction. If C is due East or due South of A then there is a unique walking route
2.2 Basic binomial identities 23
1 1 1 1 1
A
1 2 3 4 5 D d
1 3 6 10 15 E C
e d+e
1 4 10 20 35
B
The numbers form a tilted version of Pascal’s Triangle: the number of routes going
to a junction k steps East and n k steps South of A is, as expected, nk .
n\k 0 1 2 3 4 5 6 7 8 9 10
0 1
1 1 1
2 1 2 1
✓ ◆ ✓ ◆
n 1 n 1 3 1 3 3 1
k 1 k
4 1 4 6 4 1
@
@@✓ ◆ 5 1 5 10 10 5 1
n 6 1 6 15 20 15 6 1
k
7 1 7 21 35 35 21 7 1
8 1 8 28 56 70 56 28 8 1
9 1 9 36 84 126 126 84 36 9 1
10 1 10 45 120 210 252 210 120 45 10 1
24 Binomial coefficients
We now prove some identities that come from summing adjacent entries in Pas-
cal’s Triangle. Consider row 8. Taking the alternating sum of the entries, we get
1 8 = 7 = 71 , 1 8 + 28 = 21 = 72 , 1 8 + 28 56 = 35 = 73 , and so
on. This suggests the following result.
m ✓ ◆ m 1 ✓ ◆ ✓ ◆
n k n m n
 ( 1) k =  ( 1) k + ( 1) m
k
k=0 k=0
✓ ◆ ✓ ◆
n 1 n
= ( 1)m 1 + ( 1)m
m 1 m
⇣✓ n ◆ ✓ n 1 ◆⌘
m
= ( 1)
m m 1
✓ ◆
n 1
= ( 1)m
m
where the final step uses the Fundamental Recurrence.
Perhaps surprisingly, there is no simple formula for the unsigned row sums
n
Âmk=0 k . But there are simple formulae for many, apparently more complicated,
sums along the rows. See for example Exercises 2.2 and 2.8.
Now consider the diagonals. Suppose we start at 40 = 1 and step right and down.
The sums are 1 + 5 = 6 = 61 , 1 + 5 + 15 = 21 = 72 , 1 + 5 + 15 + 35 = 56 = 83 ,
and so on. To see the reason for this pattern, think of the initial 1 not as 40 , but
as 50 , one position below. Then the sum 50 + 51 + 62 + 73 simplifies, by three
applications of the Fundamental Recurrence, to 61 + 62 + 73 = 72 + 73 = 84 .
This is a special case of the following result.
Proof Again we work by induction on m. If m = 0 then both sides are 1. For the
2.2 Basic binomial identities 25
For the column sums on Pascal’s Triangle see Exercise 2.3. For the other di-
agonal sum, see Exercise 2.6. For a bijective proof of Lemma 2.2.3, see Exer-
cise 2.13(e).
Incidentally, while it is common to credit Pascal with the triangle of binomial
coefficients, the Fundamental Recurrence and the Binomial Theorem were already
known around 1000 CE by the Iranian mathematician al-Karaji.
(i) I go into the petshop, announce to the surprised owner that I want m pets,
of any species. There are a + b pets on sale, so there are a+b m possible
purchases.
(ii) Alternatively, I first buy k alsatians for some k 2 {0, 1, . . . , m}, in ak ways,
and then buy m k budgies, in mb k ways. Multiplying choices, by BCP1,
there are ak mb k ways to do this. Summing over k, using BCP2, we count
a b
all Âm
k=0 k m k possible purchases.
a b a+b
Comparing (i) and (ii) we get Âm
k=0 k m k = m .
Note that there is no restriction on a, b and m, except that they are all in N0 . For
instance, if a < m then the summands in Vandermonde’s convolution for k > a are
all zero, because ak = 0; correspondingly, there is no way to buy k > a alsatians.
Corollary 2.2.8 ✓ ◆
m
m
(i) If m 2 N0 then  = 2m .
k=0 k
m ✓ ◆
k m
(ii) If m 2 N then  ( 1) = 0.
k=0 k
m k m k
Proof For (i) take z = 1 and w = 1 to get Âm
k=0 k 1 1 = (1+1)n = 2n . For (ii),
m m k n k
take z = 1 and w = 1 to get Âk=0 k ( 1) 1 = ( 1 + 1)m . Since m 1 the
right-hand side is 0.
An alternative proof of (i) was given in Exercise 1.4; (ii) is also a special case of
Lemma 2.2.2.
Corollary 2.2.9 For all m 2 N there are equally many subsets of {1, 2, . . . , m} of
even size as there are of odd size.
Proof Written out without the summation notation, Corollary 2.2.8(ii) states that
2.3 Balls and urns 27
m m
0 1+ m2 m m m
3 + · · · = 0. Add 1 + 3 + · · · to both sides. This cancels
the negative terms on the left-hand side, giving
✓ ◆ ✓ ◆ ✓ ◆ ✓ ◆ ✓ ◆ ✓ ◆
m m m m m m
+ + +··· = + + +··· .
0 2 4 1 3 5
The left-hand side is the number of subsets of {1, 2, . . . , m} of even size, and the
right-hand side is the number of subsets of {1, 2, . . . , m} of odd size.
Exercise 2.2.10 Find a bijective proof of Corollary 2.2.9 when m is odd. You may
find your bijection also works when m is even. If not, find a bijective proof that also
works in this case.
Exercise 2.15 gives some further identities involving alternating sums of bino-
mial coefficients that have bijective proofs.
1 2 2 1
1 2 3 4 1 2 3 4
Exercise 2.3.1 Using BCP1 find the number of ways to put k numbered balls
into n numbered urns that are (i) small, (ii) large.
1 2 3 4 1 2 3 4
28 Binomial coefficients
large urns nk
Exercise 2.3.2 Explain why there are number of placements of k numbered balls
into small urns is k! times the number of placements of k indistinguishable balls.
[Hint: compare the diagrams on the previous page. How many ways are there to
add labels to the indistinguishable balls?] Will the same result hold for large urns?
The final entry is revealed below. If you compute a few small cases by hand, and
compare the answers with Pascal’s Triangle (see page 23) you will discover it for
yourself.
Theorem 2.3.3 Let n 2 N and let k 2 N0 . The number of ways to place k indistin-
guishable balls into n numbered urns of unlimited capacity is n+kk 1 .
We give two proofs, one inductive, using the same idea as the proof of the Fun-
damental Recurrence (Lemma 2.1.7), and one bijective.
Inductive proof Let f (n, k) be the number of ways to place k indistinguishable
balls into n large urns. We consider two cases.
• Either urn n has a ball. Removing this ball gives a placement of k 1 balls
into n urns, and putting the ball back restores the original placement. Hence
there are f (n, k 1) such placements.
• Or urn n is empty. Then all the balls are in urns 1 up to n 1, and so there
are f (n 1, k) such placements.
By BCP2, we have
f (n, k) = f (n, k 1) + f (n 1, k) provided n 2 and k 1. (?)
The restriction in (?) is necessary for f (n, k 1) and f (n 1, k) to both be defined.
We want to assume that the claimed formula holds for f (n, k 1) and f (n 1, k).
But there is a problem: we cannot do induction on n, because we need to know
f (n, k 1). And we cannot do induction on k, because we need to know f (n 1, k).
2.3 Balls and urns 29
So how can we capture the sense that finding f (n, k 1) and f (n 1, k) are ‘smaller’
problems than finding f (n, k)?
The solution is to do induction n + k, the sum of the number of balls and urns.
The base cases come from the restriction in (?). When n = 1 we have f (1, k) = 1
for all k (we have to put all k balls in urn 1). This agrees with 1+kk 1 = kk = 1.
When k = 0 we have f (n, 0) = 1 for all n (the unique placement has no balls in any
urn). This agrees with n+00 1 = n 0 1 = 1. For the inductive step we use (?) to
get
✓ ◆ ✓ ◆ ✓ ◆
n+k 2 n+k 2 n+k 1
f (n, k) = f (n, k 1) + f (n 1, k) = + =
k 1 k k
where the final equality uses the Fundamental Recurrence.
Bijective proof Given a placement of k indistinguishable balls into n numbered
urns, perform the following procedure:
(1) Draw the balls and urns from left to right, starting with urn 1.
(2) Erase the left wall of urn 1 and all right urn walls, urn floors, urn numbers.
(3) Replace each ball with 0 and each remaining left urn wall with 1.
For example, when n = 4 and k = 3 we have
1 2 3 4
7 ! 7 ! 001101.
Exercise 2.4.3 Using Lemma 2.4.1, deduce the general form of Lemma 2.2.3,
z+k
namely Âmk=0 k = z+m+1
m , from Lemma 2.4.2.
Proof By Lemma 2.1.5 and Lemma 2.4.1, c+kc = c+kk = ( 1)k ck 1 and sim-
ilarly d+md k = d+m
m k
k
= ( 1)m k md k1 . Hence the left-hand side is
m ✓ ◆✓ ◆
c 1 d 1
( 1) m
 k m k
.
k=0
Exercise 2.14 asks for a bijective proof of this identity. To finish we prove a
tougher binomial identity.
Proof Our aim in each step is to reduce the number of appearances of the sum-
mation variable k. The 1/(k + 1) looks particularly troublesome, but it can easily
1 k+1 1 k
be removed using the identity k+1 `+1 = `+1 ` . (See Exercise 2.1 at the end of
this chapter for the combinatorial proof.) Hence the left-hand side is
✓ ◆✓ ◆✓ ◆
1 n n k n `+k k
 ( 1) k
` + 1 k=` k `
.
32 Binomial coefficients
Exercises
The core exercises are 2.1 to 2.4. Exercises 2.1 to 2.7 were used on the problem
sheet for this part of the course.
2.1 Prove that
✓ ◆ ✓ ◆
n n 1
k =n
k k 1
for n, k 2 N in two ways:
(a) using the formula for a binomial coefficient;
(b) bijectively.
2.2 Prove that if m, n 2 N0 then
n ✓ ◆✓ ◆ ✓ ◆
m n m+n 1
Âr r r =n n
.
r=0
[Hint: use Exercise 2.1 and then aim to apply Vandermonde’s convolution.]
2.3 Let n, k 2 N0 . Prove if n k then
✓ ◆ ✓ ◆ ✓ ◆ ✓ ◆ ✓ ◆
k k+1 k+2 n n+1
+ + +···+ =
k k k k k+1
in two ways:
Exercises 33
2.4 A lion tamer has n 2 N0 cages in a row. For k 2 {0, 1, . . . , n}, let g(n, k) be
the number of ways in which she may accommodate k indistinguishable lions
so that no cage contains more than one lion, and no two lions are housed in
adjacent cages.
(a) Show that g(n, k) = g(n 2, k 1) + g(n 1, k) if n 2 and k 1.
(b) Prove by induction that g(n, k) = n k+1
k for all n 2 N and k 2 N0 such that
k n. [Hint: the base cases are determined by the conditions n 2 and k 1
in (a).]
(c) (?) Find a bijective proof of the formula for g(n, k).
2.5 Let n, k 2 N. How many solutions are there to the equation u1 +u2 +· · ·+un =
k if the ur are strictly positive integers, that is ur 2 N for each r?
2.6 Define
✓ ◆ ✓ ◆ ✓ ◆
n n 1 n 2
bn = + + +···
0 1 2
for n 2 N0 .
(a) Find the first few terms of the sequence b0 , b1 , b2 , b3 , . . ..
(b) State and prove a recurrence relating bn+2 to bn+1 and bn . Hence identify the
numbers bn .
2.7
(a) What is 114 ? Explain the connection to binomial coefficients.
(b) Let m 2 N. Prove that
✓ ◆ ✓ ◆ ✓ ◆ ✓ ◆ ✓ ◆
2m 2m 2m 2m 2m
< ... < < > > ... >
0 m 1 m m+1 2m
and that
✓ ◆ ✓ ◆ ✓ ◆ ✓ ◆
2m + 1 2m + 1 2m + 1 2m + 1
< ... < = > ... > .
0 m m+1 2m + 1
(b) Show that X 4 X = ? for all X 2 S. Thus every element of S is its own additive
inverse.
(c) Let X, Y , Z 2 S. Show that
X 4 Y = Z () Y 4 Z = X () Z 4 X = Y.
[Hint: imagine X, Y and Z are numbers. How would you solve the equation
X +Y = Z for X?]
(d) Let X, Y , Z, W 2 S. Show that
X 4 Y = Z 4 W () X 4 Z = Y 4 W
{1, 2, 3}, {1, 2, 4}, {1, 3, 4}, {2, 3, 4}, {1, 2, 5}, {1, 3, 5}.
The following exercises use the generalized definition of binomial coefficients in-
troduced in §2.4
2.16
(a) Let h(z) = a0 + a1 z + · · · + ad zd be a polynomial in C[z]. Show that if there
exist distinct complex numbers c1 , c2 , . . . , cd+1 2 C such that h(ci ) = 0 for all
i 2 {1, 2, . . . , d + 1} then h = 0.
(b) Hence show that if f and g are polynomials of degree at most d that agree at
d + 1 distinct elements of C then f = g.
n
2.17 Let b 2 N and let n 2 N0 . Give a bijective proof that (b + 1)n = Âk k bk .
Deduce the Binomial Theorem using the previous exercise.
2.18 Show that if z 2 C and n 2 N0 then
m ✓ ◆ ✓ ◆
r z+1 m z 1
 ( 1)
r
r = ( 1)
m 1
(z + 1).
r=0
2.19 Let f (z) = z3 3z2 + 1. The table below has f (0), f (1), . . . , f (6) in its first
row. Each entry in each subsequent row is computed by taking the difference
between the two entries in the row above.
1 1 3 1 17 51 109
2 2 4 16 34 58
0 6 12 18 24
6 6 6 6
0 0 0
(a) Show that f (z) = 6 3z + 0 2z 2 1z + 0z . What is the connection with the
table? (The connection is proved in Exercise 2.21.)
Exercises 37
(b) Find a polynomial g(z) of small degree such that g(0), g(1), g(2), g(3), g(4)
equal 0, 1, 0, 1, 0, respectively.
2.20 Let an be the maximum number of regions inside a circle that can be formed
by taking n points on its circumference and joining every two distinct points
by a line. For example, counting regions in the diagram below shows that
a5 = 16.
(a) Find a1 , a2 , a3 , a4 .
(b) Conjecture (if you feel brave) a formula for an .
(c) Find a0 and a6 .
(d) Using the table method in Exercise 2.19 conjecture a formula for an .
(The formula given by (d) is in fact correct: this is proved in Exercise 6.1
using generating functions.)
2.21 Given a function f : C ! C, define D f : C ! C by (D f )(z) = f (z + 1) f (z).
Set D0 f = f and define Dk f = D(Dk 1 f ) inductively for k 2 N. For example,
if f (z) = z2 then (D f )(z) = (z + 1)2 z2 = 2z + 1 and hence (D2 f )(z) =
(2(z + 1) + 1) (2z + 1) = 2.
(a) Prove by induction on n that
8✓ ◆
✓ ◆ < z
z if 0 n r
Dn = r n
r :
0 otherwise.
(b) Let b(z) = rz . Let k 2 N0 . Show that (Dn b)(0) = 1 if k = n and (Dn b)(0) = 0
if k 6= r.
(c) Show that the binomial coefficients rz for r 2 N0 are a basis for C[z]. (Equiv-
alently, for each polynomial f (z) 2 C[z] of degree d, there exist unique coef-
ficients c0 , c1 , . . ., cd 2 C such that f (z) = Âdr=0 cr rz .)
(d) Using (b) and (c) show that if f (z) is a polynomial of degree at most d then
f (z) = Âdr=0 cr rz where cr = (Dr f )(0) and that the coefficients c0 , c1 , . . . , cd
are the entries on the diagonal of a table constructed as in Exercise 2.19.
(e) Show that (Dn f )(z) = Ânk=0 ( 1)k nk f (z + n k).
38 Binomial coefficients
Problem You are given three Fabergé eggs by the owner of a building with 100
floors. The owner wants to know the highest floor from which an egg will survive
being dropped. What is the smallest number of drops that guarantees to give the
correct answer?
(The eggs are identical in every respect. If an egg smashes it is gone for ever, if it
survives the fall then it is as good as new. It is possible that the eggs can survive
the drop from floor 100.)
Hints
Try simplifying the problem: take two eggs and a building with 10 floors.
• How many drops might be needed if the first egg is dropped from floor 5?
• How many drops might be needed if the first egg is dropped from floor 3?
• How is the optimal floor for the first drop related to the total number of
drops, in the worst case for your strategy?
Now solve the problem for some other small buildings and look for a pattern.
Solution
Following the hints, we start by looking at the smaller two egg problem. You should
have found that if there are 10 floors and the first egg is dropped from floor 4 then
4 drops always suffice:
• if the first drop smashes an egg then we drop the remaining egg from floor 1,
then floor 2 (if it survives), then floor 3 (if it survives again);
• if the egg survives the first drop then, after making the next drop from
floor 7, two more drops suffice.
40 Interlude I: The Egg Dropping Problem
Exercise Check the second claim above, and show, if you have not already done
so, that if the first drop is made from floor 5 or floor 3 then four more drops (making
five in total) may be necessary.
The analysis so far shows two key ideas:
(A) If we are down to one egg, because the other egg smashed when dropped
from floor r, and we have not made any drops from floors below r, then
there is nothing better than to make up to r 1 further drops working from
floor 1 upwards.
(B) If an egg survives a drop from floor r then we can ignore floors 1 up to r,
and think of the building as having n r floors.
Let f (n) be the number of drops needed, in the worst case, to find the highest
egg-safe floor in a building of n floors. Suppose we make the first drop from floor
r. If this smashes an egg then, by (A), we need at most r 1 further drops. If it
survives then, by (B), we need at most f (n r) further drops. (This is correct even
when r = n, provided we set f (0) = 0.) Hence
f (n) 1 + max r 1, f (n r) = max r, 1 + f (n r) (?)
for each r 2 N with r n. Moreover, the true value of f (n) is given by choosing r
to minimize the right-hand side of (?). Using (?) and computing iteratively, starting
with f (1) = 1, we get the table shown below.
n 0 1 2 3 4 5 6 7 8 9 10 11
f (n) 0 1 2 2 3 3 3 4 4 4 4 5
Proof Let n = d+1 2 . By the conjecture before this, d drops suffice to solve a
building of height n, and d drops do not suffice to solve a building of height n + 1,
since d+1
2 < n + 1.
Generalizing the definition of g, let ge (d) be the number of floors in the tallest
building that can be solved using at most d drops of e eggs. Clearly ge (1) = 1 for all
e 2 N and, by (A), g1 (d) = d for all d 2 N. We now run the argument proving the
first conjecture, thinking about ge . An instructive exercise is to prove the following
claim in the special case e = 2.
Claim For any d, e 2 N we have ge (d) = ge 1 (d 1) + ge (d 1) + 1.
Proof Let n = ge (d). Suppose an optimal strategy drops the first egg from floor r.
If it smashes, we are left with e 1 eggs and d 1 drops to deal with a building
of effective height r 1. Hence r 1 ge 1 (d 1). If the first egg survives, we
42 Interlude I: The Egg Dropping Problem
have e eggs and d 1 drops to deal with a building of effective height n r. Hence
n r ge (d 1). Adding these two inequalities implies that
ge (d) ge 1 (d 1) + ge (d 1) + 1. (??)
Moreover, taking r = ge 1 (d 1) + 1 we see that a building with ge 1 (d 1) +
ge (d 1) + 1 floors can be solved using d drops. Hence equality holds.
Using the recurrence (??) and the boundary conditions ge (1) = 1 and g1 (d) = d,
it is easy to calculate the following table of values for small d and e.
d\e 1 2 3 4 5 6
1 1 1 1 1 1 1
2 2 3 3 3 3 3
3 3 6 7 7 7 7
4 4 10 14 15 15 15
5 5 15 25 30 31 31
6 6 21 41 56 62 63
7 7 28 63 98 119 126
8 8 36 92 162 218 246
9 9 45 129 255 381 465
10 10 55 175 385 637 847
From the table we see that with 3 eggs, 8 drops do not suffice to solve a building
with 100 floors, but 9 drops are sufficient. (In fact 9 drops can solve a building with
129 floors.) This answers the original problem.
The values of g1 (d) and g2 (d) appearing in the first and second column and the
almost powers of 2 along the diagonal now suggest a final conjecture.
Conjecture For all d, e 2 N we have
✓ ◆ ✓ ◆ ✓ ◆
d d d
ge (d) = + +···+ .
1 2 e
Proof We work by induction on d. If d = 1 then we have ge (1) = 1, which agrees
with 11 + 12 + · · · + 1e = 1. Suppose inductively that the conjecture holds for
d 1. Then, by (??) and the Fundamental Recurrence (Lemma 2.1.7) we get
e 1✓ ◆ e ✓ ◆
d 1 d 1
ge (d) = ge 1 (d 1) + ge (d 1) + 1 = Â +Â +1
k=1 k k=1 k
e 1 ✓ ◆ ✓ ◆ ✓ ◆ e 1✓ ◆ e ✓ ◆
d 1 d 1 d 1 d d
=Â + + +1 = Â +d = Â
k=1 k k + 1 1 k=1 k + 1 k=1 k
Interlude I: The Egg Dropping Problem 43
as required.
Going back to the inverse function, we see that the minimum number of drops
of e eggs needed, in the worst case, to find the highest egg-safe floor in a building
with n floors is the minimum d such that d1 + d2 + · · · + de n.
Final discussion
After solving a problem, it is very tempting to (metaphorically) throw a quick party
with oneself as the guest of honour, and then forget all about it. But often the
greatest insights come from asking oneself further questions: “Is there an easier
solution?”, “Is the answer intuitive?”, “What techniques did I use that might be
applicable elsewhere?”, “Are there appealing generalizations or connections with
other areas of mathematics?” Here are some thoughts suggested by these questions.
• To get started we generalized the problem, by allowing buildings of arbitrary
height and any number of eggs, before simplifying it, by considering just two
eggs and small buildings. It is often useful, but humbling, to ask “What is the
simplest related problem that I still can’t solve?”
• One key idea was to switch from minimizing the number of drops, for a fixed
building height, to maximizing the building height, for a fixed number of drops.
This kind of ‘inversion’ is a common theme in mathematics. Jacobi, who made
important contributions to the theory of elliptic functions using inversion, fa-
mously said “man muss immer umkehren” (one must always invert).
• The proof of the recurrence ge (d) = ge 1 (d 1) + ge (d 1) + 1 shows that
when we drop the first egg from floor ge 1 (d 1) + 1 in a building with ge (d)
floors, we are indifferent to the outcome. If the egg smashes, we are left with
a building of effective height ge 1 (d 1), solvable in d 1 drops with the re-
maining e 1 eggs; if it survives we are left with a building of effective height
ge (d) (ge 1 (d 1) + 1) = ge (d 1), solvable in d 1 drops of the e eggs. This
feature, that with optimal play we are indifferent to our adversary’s response, of-
ten appears in the analysis of games.
• When we started, computing even the two-egg number f (10) was a non-trivial
problem. At the end, the explicit formula for ge (d) gives a fast algorithm for
finding the number of drops needed to solve any building, with any number of
eggs. As seen earlier for the derangement numbers, better understanding leads
to faster computation.
• Next we ask “Is the answer intuitive?” Suppose we make d drops. Interpreting
d
s as the number of ways to choose s of these drops to smash an egg, we see
that the number of different outcomes of a sequence of d drops is d1 + d2 +
44 Interlude I: The Egg Dropping Problem
• • •
B
• • • • • •
• , • • • , A • • • • • , ...
• • • • • •
• • • C
Let A, B, C be the three rhombic subsets of the m-th diagram, as indicated above
for h3 . By counting dots we see that |A| = m2 , |A \ B| = m and |A \ B \ C| = 1.
Hence, by symmetry and the final formula in Example 3.1.1,
hm = m2 + m2 + m2 m m m + 1 = 3m(m 1) + 1.
Observe that it was easier to find the sizes of the intersections of the three rhombi
than it was to find the size of their unions. Whenever intersections are easier to
think about than unions, the Principle of Inclusion and Exclusion may be helpful.
In the general result, we have subsets A1 , A2 , . . . , An ✓ W. For each non-empty
subset I ✓ {1, 2, . . . , n} we define
\
AI = Ai .
i2I
Thus AI is the set of elements which belong to each set Ai for i 2 I. (We deliberately
do not specify which other sets, if any, these elements lie in.) For example x 2 A{1,3}
if and only if x 2 A1 and x 2 A3 . More generally, if i, j 2 {1, 2, . . . , n} then A{i} = Ai
and A{i, j} = Ai \ A j . By convention the empty intersection is the universe set W.
Thus
A0/ = W.
Theorem 3.1.3 (Principle of Inclusion and Exclusion) If A1 , A2 , . . . , An are sub-
sets of a finite universe set W then
|A1 [ A2 [ · · · [ An | = Â ( 1)|I| |AI |.
I✓{1,2,...,n}
3.2 Counting derangements 47
Exercise 3.1.4 Check that you understand the AI notation by writing out the Prin-
ciple of Inclusion and Exclusion when n = 3 as a sum with eight summands and
comparing with Example 3.1.1.
We prove the Principle of Inclusion and Exclusion by generalizing the argument
in Example 3.1.1. We need the identity Âm k m
k=0 ( 1) k = 0 for m 2 N, proved in
Corollary 2.2.8(ii) by expanding ( 1 + 1)m using the Binomial Theorem. The spe-
cial case 30 3
1 + 2
3 3
3 = 0 may be seen in case (3) of this example.
Proof of Theorem 3.1.3 Let x 2 W. Suppose that x is not a member of any of the
sets A1 , A2 , . . . , An . Then x is counted once on the left-hand side. Since A0/ = W, on
the right-hand side x contributes 1 to |A0/ | and 0 to every other summand, giving an
overall contribution of 1, as required.
Now suppose that x 2 A j if and only if j 2 J, where J is a non-empty subset
of {1, 2, . . . , n}. On the right-hand side, x contributes to |AI | if and only if x lies
in Ai for every i 2 I, so if and only if I ✓ J. Hence the contribution from x to the
right-hand side is ÂI✓J ( 1)I . Since there are |J| k subsets of J of size k, this sum
is
|J| ✓ ◆
k |J|
 ( 1) k = 0
k=0
where the final equality is the case |J| = m of the identity just mentioned. Hence
the contribution of x to the right-hand side is 0, again as required.
Exercise 3.1.5 Deduce from Theorem 3.1.3 that
|A1 [ A2 [ · · · [ An | = Â ( 1)|I| 1 |AI |.
I✓{1,2,...,n}
I6=0/
Exercises 3.14 and 3.15 strengthen the Principle of Inclusion and Exclusion,
using a more formal argument in which a function from W to Z records the contri-
butions from each x 2 W to its right-hand side.
they fix i. (The permutation in Ai might have other fixed points too, but in the spirit
of the Principle of Inclusion and Exclusion, we use just one property to define Ai .)
Thus
Ai = {s 2 W : s (i) = i}
Lemma 3.2.1 Let s 2 W and let I ✓ {1, 2, . . . , n}. Then s 2 AI if and only if
s (i) = i for all i 2 I. Moreover |AI | = (n |I|)!.
We are now ready to apply the Principle of Inclusion and Exclusion to the right-
hand side in dn = |A1 [ . . . [ An |. It gives
n ✓ ◆
n
dn = Â ( 1) |AI | = Â ( 1) (n |I|)! = Â
|I| |I|
( 1)k (n k)!.
I✓{1,...,n} I✓{1,...,n} k=0 k
The final equality holds because there are nk subsets of {1, . . . , n} of size k, and for
each such subset I, we have ( 1)|I| (n |I|)! = ( 1)k (n k)!. Since nk (n k)! =
n!/k! by Lemma 2.1.4, it follows that
n
( 1)k
dn = n! Â
k=0 k!
as expected.
The answer is that CK is the set of hands with no King. (Again the hands in CK
might also be unwanted because they lack other cards.) The notation CK is chosen
to suggest ‘King complement’. Similarly, CA is the set of hands with no Ace, and
CQ is the set of hands with no Queen. A hand is in H if and only if it is in none of
CA , CK and CQ , hence H = CA [CK [CQ . Of the 52 cards in the pack, 48 are not
aces, so |CA | = 48 48
5 . Similarly |CK | = |CQ | = 5 . There are 44 cards that are not
Aces or Kings, so |CA \ CK | = 5 , and similarly |CA \ CQ | = |CK \ CQ | = 44
44
5 .
Finally |CA \CK \CQ | = 40 5 . By the Principle of Inclusion and Exclusion, in the
three subset case from Example 3.1.1, we get
You should now have no difficulty in counting the five card hands in Exercise 1.6(a)
with at least one Ace, King, Queen and Jack. The answer, from the Principle of
Inclusion and Exclusion applied with four sets, is 52 5 4 48
5 +6 5
44
4 40
5 +
36
5 = 10752.
Part of the strength of the Principle of Inclusion and Exclusion is that, once one
has grasped one application, it can often be adapted to solve similar problems. As
an example (see also Exercise 3.4), we count hands with at least one Ace, King and
Queen, and at least one of the two red Jacks. We redefine CJ to be those hands we do
not want to count, because they are missing both red Jacks. Thus |CJ | = 50 5 , and,
for instance, |CA \CJ | = 46 5 , and |CA \C K \C J | = 42
5 . The number of hands is
✓ ◆ ✓ ◆ ✓ ◆ ✓ ◆ ✓ ◆ ✓ ◆ ✓ ◆ ✓ ◆
52 48 50 44 46 40 42 38
3 +3 +3 3 + = 5504.
5 5 5 5 5 5 5 5
and 5. Any composite number in {1, 2, . . . , 48} is divisible by one of the primes 2,
3 or 5, so the uncrossed numbers are precisely the primes between 2 and 48. In
each subsequent step, a prime is circled, and there are no new crossings-out.
1 2 3 4 5 6 7 8 9 10
11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
31 32 33 34 35 36 37 38 39 40
41 42 43 44 45 46 47 48
We now interpret the diagram using the Principle of Inclusion and Exclusion.
Generally let W = {1, 2, . . . , M} and for m 2 N let
Example 3.4.1 Take W = {1, 2, . . . , 48}. We have seen that any composite number
in W is in the set D(2) [ D(3) [ D(5). Also this set contains 2, 3 and 5. The com-
plement of D(2) [ D(3) [ D(5) is therefore all the primes p 2 W such that p 7,
together with 1. (This appearance of 1 is annoying, but inevitable, since 1 is clearly
not in D(2) [ D(3) [ D(5).) In symbols,
Let Q be the size of either side. By the Principle of Inclusion and Exclusion,
Q = |W| |D(2)| |D(3)| |D(5)| + |D(2) \ D(3)|
+ |D(2) \ D(5)| + |D(3) \ D(5)| |D(2) \ D(3) \ D(5)|.
Either using Lemma 3.4.2 below, or by direct enumeration, one finds that Q =
48 24 16 9 + 8 + 4 + 3 1 = 13. For example, since a number is divisible
by 3 and 5 if and only if it is divisible by 15, D(3) \ D(5) = D(15) = {15, 30, 45}.
Reintroducing the primes 2, 3, and 5, and remembering to remove the non-prime 1,
we have shown that there are 13 + 3 1 = 15 primes in {1, 2, . . . , 48}. Observe that
we did this using only properties of 2, 3 and 5.
Lemma 3.4.2 Let M 2 N. There are exactly bM/dc numbers in {1, 2, . . . , M} that
are divisible by d.
We can now generalize Example 3.4.1 to a sieve over an arbitrary set of primes.
I✓{1,2,...,n}
Proof Let W = {1, 2, . . . , M}. The numbers in D(pi ) are those we do not want to
count, because they are divisible by pi . (Again, they might also be unwanted be-
cause they are divisible by other primes, but we define D(pi ) using pi only.) There-
fore S = D(p1 ) [ . . . [ D(pn ). Let I ✓ {1, . . . , n}. Since the pi are distinct primes, a
number is divisible by pi for all i 2 I if and only if it is divisible by ’i2I pi . Thus
T
i2I D(pi ) = D ’i2I pi . (When I = ? this holds by our convention that the empty
intersection is the universe W; by a standard convention, the empty product is 1.)
By Lemma 3.4.2 and the Principle of Inclusion and Exclusion, we get
⌫
\ M
|S| = Â ( 1) |I|
D(pi ) = Â ( 1) ’i2I pi
|I|
as required.
We say that natural numbers are coprime if they share no prime factors. Let
f (M) be the number of natural numbers in {1, 2, . . . , M} that are coprime to M.
For example, f (15) = 8 counts 1, 2, 4, 7, 8, 11, 13, 14.
Observe that if M has distinct prime factors p1 , p2 , . . . , pn then x 2 {1, 2, . . . , M}
is coprime to M if and only if x is not divisible by any of p1 , p2 , . . . , pn . Hence
f (M) = |S| where S is the set in Proposition 3.4.3. Since each product ’i2I pi
divides M exactly, we have
( 1)|I|
f (M) = M Â .
I✓{1,2,...,n} ’i2I i
p
More generally,
n ⇣
( 1)|I| 1⌘
f (M) = M Â = M’ 1
I✓{1,2,...,n} ’i2I i
p i=1 pi
since the summand ( 1)|I| / ’i2I pi in the middle is obtained by multiplying out
the product taking pi from 1 p1i if i 2 I and taking 1 if i 62 I.
Proposition 3.4.4 Let M 2 N have prime factorization pe11 pe22 . . . penn where ei 2 N
for each i. Then
n ⇣ 1⌘
f (pe11 pe22 . . . penn ) = ’ pei i 1 .
i=1 pi
Proof This is a restatement of the formula for f (M) just proved.
Euler’s f function is important in number theory and has applications in public
key cryptography: see Exercises 3.6 and 3.7.
By Proposition 3.4.4, we get |S| M ’ni=1 1 p1i + 2n . Since S contains all the
primes in {1, 2, . . . , M} other than p1 , p2 , . . . , pn , we have p(M) |S|+n. Therefore
n ⇣
1⌘
p(M) n + M ’ 1 + 2n .
i=1 pi
Exercises 53
(For details of the two inequalities above see Exercise 3.11.) We conclude that
’ni=1 1 p1i 1/ log pn and so p(M) n + M/ log pn + 2n .
Restated, this theorem says that if we choose a number in {1, 2, . . . , M} uni-
formly at random, the probability that it is prime is at most n/M + 1/ log pn + 2n /M.
To get a non-trivial bound, we need 2n to be smaller than M. More precisely, since
2n /M = en log 2 log M , we need n log M/ log 2.
Corollary 3.4.6 We have limM!• p(M)/M = 0.
Proof Take n = blog Mc in Theorem 3.4.5. Since pn n + 1 log M, we have
log pn log log M. Using 2blog Mc 2log M = M log 2 to bound the third summand,
we get
p(M) log M 1 M log 2
+ + .
M M log log M M
Now observe that each summand tends to 0 as M tends to infinity.
This makes precise the intuitive idea that as numbers get larger, they become
increasingly unlikely to be prime. In Exercise 3.10 you are asked to refine the
previous proof to show that p(M)/M 2/ log log M for all M sufficiently large.
Regrettably, this is still significantly weaker than the asymptotically correct result.
Known as the Prime Number Theorem, it states that
p(M)
lim = 1.
M!• M/ log M
While it seems that sieve methods cannot prove the Prime Number Theorem,
they are still very important in number theory. A sieve was used in Zhang’s break-
through proof in 2013 that there are infinitely many prime numbers p and q such
that q > p and q p 70 ⇥ 106 . Before Zhang’s theorem, no constant upper bound
was known. Thanks to the work of Maynard, Tao and the Polymath project (an
ad-hoc collaborative network of mathematicians) we now know that there are in-
finitely many pairs of primes differing by at most 246. It is conjectured, but as yet
unproved, that there are infinitely many primes p such that p + 2 is also prime.
Exercises
The core exercises are 3.1 to 3.4.
54 Principle of Inclusion and Exclusion
3.5 Let W be the set of all functions f : {1, 2, . . . , m} ! {1, 2, . . . , n}. For each
i 2 {1, 2, . . . , n} define
(d) Show that the above expression is the number of ways to put m numbered
balls into n numbered urns, so that each urn contains at least one ball.
(For the connection with Stirling Numbers of the Second Kind, see §?? and
Exercise 6.3.)
3.6 Recall that M and N are coprime if they share no common prime factor. Us-
ing Proposition 3.4.4, prove that if M and N are coprime then f (MN) =
f (M)f (N). Does this result hold for general M and N?
Exercises 55
3.7 In the RSA cryptosystem, Alice chooses two distinct primes p and q and
calculates M = pq. She chooses an encryption exponent a 2 N coprime to
f (M), and calculates a decryption exponent d such that ad ⌘ 1 mod f (M).
She publishes (M, a) as her public key and keeps p, q and d private. When Bob
sends a message to Alice, he looks up her public key (M, a), and encrypts his
message x 2 {0, 1, . . . , M 1} as xa mod M. When Alice receives an encrypted
message y, she decrypts by calculating yd mod M.
(Why this works to find x, and why, when p and q are large, it is believed that
an attacker cannot easily compute d, is explained in Exercise 3.9 below.)
In this toy example, we suppose that Alice takes p = 11 and q = 17 and a = 9.
She publishes (187, 9) as her public key.
(a) Encrypt the message 7 using Alice’s public key.
(b) Using Euclid’s Algorithm find d 2 N such that ad ⌘ 1 mod f (M).
(c) Alice has agreed with Bob that he will encrypt her exam mark using her
public key. She receives 51 from Bob. What is her exam mark?
(d) What are some problems with the scheme as described? [Hint: even if p and q
were far larger, there is a simple way for an attacker who observes Bob’s
encrypted message to deduce Alice’s exam mark.]
3.8 Suppose that M is the product of two distinct primes p and q. Show how to
find p and q given M and f (M).
3.9 (This exercise needs some basic group theory.) Let M = pq where p and q are
distinct primes. Let U = x 2 {0, 1, . . . , M 1} : x is coprime to p and q .
(a) Show that if x, y 2 U then xy mod M is also in U.
(b) Let x 2 U. Define fx : {0, 1, . . . , M 1} ! {0, 1, . . . , M 1} by fx (y) = xy
mod M. Show that fx is injective.
(c) Deduce from (b) that if x 2 U then there exists a unique x0 2 U such that
xx0 ⌘ 1 mod M.
(d) Hence show that U is a group under multiplication modulo M. What is the
order of U?
(e) Show that if a is coprime to f (M) then the function x 7! xa from U to itself is
invertible and find the inverse function. Can you compute the inverse function
knowing only a and M, but not f (M) or p or q?
3.10 The displayed equation in the proof of Corollary 3.4.6 implies that
p(M) log log M log M M log 2
log log M + 1 + log log M.
M M M
(a) Prove that if c 2 R and c > 0 then ye cy ! 0 as y ! •.
56 Principle of Inclusion and Exclusion
(b) Using (a) and the crude inequality log log M log M, or otherwise, show that
p(M)/M 2/ log log M for all sufficiently large M.
3.11 As in the proof of Theorem 3.4.5, let p1 , p2 , . . . , pn be the first n prime num-
bers.
(a) By the formula for the sum of a geometric progression,
⇣ 1⌘ 1 1 1
1 = 1+ + 2 +··· .
pi pi pi
Using that each natural number has a unique prime factorization, deduce that
n ⇣
1⌘ 1 pn
1
’ 1 pi  x.
i=1 x=1
R
S dt
(b) Show that ÂSx=1 1x 1 t = log S for any S 2 N.
(c) Deduce from (a) and (b) that there are infinitely many primes.
3.12 The Riemann z function is defined for z 2 C such that Re z > 1 by z (z) =
• z
m=1 1/m .
(a) Use |mz | = mRe z to show that the series converges absolutely when Re z > 1.
What happens when z = 1?
(b) By adapting the argument in Exercise 3.11(a), show that
• ⇣
1⌘ 1
z (z) = ’ 1
n=1 pzi
for z 2 C such that Re z > 1.
(c) For z 2 C such that Re z > 0, let h(z) = • m=1 ( 1)
m 1/mz . Show that if
Re z > 1 then
h(z)
z (z) = .
1 2 (z 1)
(d) Prove that h(z) converges if z 2 R and z > 0. (?) Prove that h(z) converges
whenever Re z > 0.
(The Prime Number Theorem was first proved in 1896, independently by
Hadamard and de la Vallée Poussin. Both proofs used complex analysis and
the Riemann z function extended, as the stronger result in (d) shows is possi-
ble, to the domain {z : Re z > 0, z 6= 1}. The Riemann Hypothesis, one of the
Clay Mathematics Institute’s million dollar open problems in mathematics,
states that if z (z) = 0 and Re z > 0 then z = 12 + it for some t 2 R.)
3.13 Given M 2 N, let p2 (M) be the number of numbers in {1, 2, . . . , M} that are
square-free; that is, they are not divisible by the square of any prime.
Exercises 57
p
(a) Let p1 , p2 , . . . , pn be the primes less than or equal to M. By adapting the
argument used to estimate p(M), show that
p2 (M) n
1⌘ 1
’
?
1 2
p .
M i=1 pi M
where ? denotes that all terms ±1/d 2 with d > M that arise when expanding
the product arepto be ignored. (This technicality is necessary to get the good
error bound 1/ M.)
(b) Deduce from (a) and Exercise 3.12(a) that
p2 (M)
lim = z (2).
M!• M
(c) Why does this sieve give a more precise result than the sieve used in Theo-
rem 3.4.5 to estimate p(M)?
2
(It is known that z (2) = p6 : you will easily find proofs using techniques
including real variable integration, contour integration, and Fourier series if
you search on the web.)
3.14 This question builds on the proof of the Principle of Inclusion and Exclusion
(Theorem 3.1.3). For r 2 {0, 1, . . . , n}, define gr : W ! Z by
(
( 1)|I| if x 2 AI
gr (x) = Â
I✓{1,2,...,n} 0 otherwise.
|I|r
where mx = j 2 {1, 2, . . . , n} : x 2 A j .
(c) By taking r = n in (b) deduce Theorem 3.1.3.
(d) Prove that if r is even then |A1 [ A2 [ . . . [ An | cr .
(e) Prove that if r is odd then cr |A1 [ A2 [ . . . [ An |.
(f) Prove that if r (n 1)/2 then cr cr+2 if r is odd and cr+2 cr if r is even.
58 Principle of Inclusion and Exclusion
(g) (?) In fact the bound on r in (f) can be slightly improved. Find the strongest
possible improvement.
(Thus the cr alternately under- and over-estimate the size of |A1 [ A2 [ . . . [ An |,
and the approximations get strictly better once r (n 1)/2.)
3.15 Again this question can be answered by adapting the proof of the Principle
of Inclusion and Exclusion in Theorem 3.1.3.
(a) Show there exist coefficients e1 , e2 , . . . , en 2 N such that the number of ele-
ments of W in exactly one of the sets A1 , A2 , . . . , An is
n
Â( 1)k 1 ek  |AI |.
k=1 I✓{1,2,...,n}
|I|=k
[Hint: suppose, as in (a) in the previous exercise, that the sum is truncated
to the terms for k = 1, . . . , r. By analogy with (b) in the previous exercise, the
formula should then be correct for elements lying in at most r of the sets A1 ,
A2 , . . . , An .]
(b) Prove a generalization of the Principle of Inclusion and Exclusion counting
the number of elements of W that lie in exactly t of the sets A1 , A2 , . . . , An ,
for each t 2 N0 .
(c) Fix t 2 {0, 1, . . . , n}. Check your result in (b) by counting the number of per-
mutations of {1, 2, . . . , n} that have exactly t fixed points. (See Exercise 1.10
for the answer.)
3.16 (?) Exercises 3.14 and 3.15 strengthen the Principle of Inclusion and Exclu-
sion in two different ways. Prove a still stronger version that implies both.
3.17 This question gives an alternative proof of the Principle of Inclusion and Ex-
clusion (Theorem 3.1.3). Fix a universe set W. For each X ✓ W, define a func-
tion 1X : W ! {0, 1} by
(
1 if x 2 X
1X (x) =
0 if x 62 X.
(d) By multiplying out the right-hand side in (c) and using (b), show that
1A1 [A2 [···[An = Â ( 1)|I| 1AI
I✓{1,2,...,n}
3.19 By applying the Principle of Inclusion and Exclusion to the set of functions
f : {1, 2, . . . , n} ! {1, 2, . . . , n} such that f has no fixed points, prove Ryser’s
formula for the number of derangements of {1, 2, . . . , n}:
n ✓ ◆
k n
dn = Â ( 1) (n k 1)k (n k)n k .
k=0 k
[Hint: Exercise 3.5 is related.] How does this use of the Principle of Inclusion
and Exclusion compare with its use in §3.2?
4
Rook Polynomials
For example, the rook polynomials of the four boards shown below
, , ,
R R R R R
R , R , , R , , R .
R R R
3 2 The diagram in the margin summarizes the enumeration above by counting num-
1 0 bers of placements according to the position of the top-left rook.
0
Exercise 4.1.2 Let B be a board. Show that r1 (B) is the number of squares in B.
What is r0 (B)?
Exercise 4.1.3 Show that the rook polynomial of the six-square board in the mar-
gin is 1 + 6z + 9z2 + 2z3 .
4.1 Introduction to rook polynomials 61
Exercise 4.1.4 Find the rook polynomial of the seven-square board in the margin.
[Hint: the non-attacking rook placements not having a rook in the top right are
counted by the previous exercise.]
Example 4.1.5 After the recent cutbacks, only four professor remain at the Uni-
versity of Erewhon. The basic course 1 can be lectured by Prof. W, Prof. X, or
Prof. Z, the trickier course 2 only by Prof. X, course 3 by Prof. Y or Prof. Z
and course 4 by Prof. W or Prof. Z. We model this timetabling problem using
the board B shown below, in which there is a square in row i and column P if and
only if Prof. P can lecture course i.
W X Y Z
1
2
3
4
R R
R R
R R
R R
R R
62 Rook Polynomials
Going back, the right rook placement corresponds to the derangement t such that
t(1) = 2, t(2) = 3, t(3) = 5, t(4) = 1 and t(5) = 4. We use rook polynomials to
calculate derangement numbers in §4.3 below.
Lemma 4.2.2 Let B be a board. Suppose that B can be partitioned into sub-
boards C and C0 so that no square in C lies in the same row or column as a square
of C0 . Then rk (B) = Âk`=0 r` (C)rk ` (C0 ) for each k 2 N and
We will see later that Lemma 4.2.2 is a special case of Theorem 8.0.1 on products
of generating functions.
We now show how the two previous lemmas are used in practice.
Example 4.2.3 Let B be the board in Example 4.1.5. Figure 4.2 overleaf shows
the four boards DD, DE, ED and EE given by applying Lemma 4.2.1 first to the
square s, then to the square u. By this lemma,
fB (z) = fD (z) + z fE (z) = fDD (z) + z fDE (z) + z fED (z) + z fEE (z) .
To calculate the rook polynomials on the right-hand side, we use Lemma 4.2.2:
In particular, rB (2) = 19 and rB (3) = 14. The squares s and u were chosen so that
Lemma 4.2.2 could be applied after two steps. Other choices are also sensible, and
are, of course, permitted.
u u
D E
DD DE ED EE
Figure 4.1 Lemma 4.2.1 applied to the board B in Examples 4.1.5 and 4.2.3, first
to the square s in position (3, 3), then the square u in position (4, 1).
To give another example, if B is the board split across the previous page and C
and C0 are the left and right subboards then, by symmetry, fC (z) = fC0 (z). Hence,
by Lemma 4.2.2, fB (z) = fC (z)2 . The simple algorithm based on Lemma 4.2.1
suggested in Exercise 4.9 takes about a minute to compute fC (z), and reveals that
fB (z) = (1 + 63z + 1544z2 + 18984z3 + · · · + 270000z8 + 23760z9 )2 .
By contrast, computing fB (z) directly by this algorithm, even on a supercomputer,
would not finish within the lifetime of our universe.
In this section we explore the surprisingly close connection between the non-
attacking rook placements on B and B.
Proof Given a rook placement in AI , colouring the rooks in the rows in I red
gives a rook placement with k black rooks on B and n k white rooks on either
B or B, such that all n rooks are non-attacking. Let Ck be the set of such coloured
rook placements. Going back, given a placement in C , the k black rooks identify
an indexing set I. Hence the left-hand side is |Ck |.
We may construct a rook-placement in Ck by putting k non-attacking black rooks
on B, in rk (B) ways, and a further n k non-attacking white rooks on the n k rows
and columns not yet used, in (n k)! ways. Hence |Ck | is the right-hand side.
This proof is more subtle than it might seem. For instance, except when k = 0,
S
the set Ck (which consists of coloured placements) is not I✓{1,2,...,n},|I|=k AI . As
ever, seeing how the proof works by trying it out on a particular example is helpful:
one relevant to derangements is suggested in Exercise 4.6 below. See Exercise 4.12
for another application of the colouring idea.
66 Rook Polynomials
Derangements
Fix n 2 N with n 2 and let B be the board of all diagonal squares in the n ⇥ n
grid, as shown by the shaded squares in the margin when n = 3. As seen in Exam-
ple 4.1.6, derangements of {1, 2, . . . , n} are in bijection with non-attacking place-
ments of n rooks on B. To apply Corollary 4.3.3 we need r0 (B), r1 (B), . . . , rn (B).
Note that any placement on B is non-attacking. Since there are nk to choose k
rows of B on which to put rooks, we have rk (B) = nk for each k. Hence, by Corol-
lary 4.3.3,
n ✓ ◆ n
k n n!
rn (B) = Â ( 1) (n k)! = Â ( 1)k
k=0 k k=0 k!
where the final equality uses Lemma 2.1.4. This is our usual formula for dn .
M1 5 1 M3 M3 5 1 M4
6 8 6 8
W3 7 W4 W1 7 W3
M2 M2
Observe that the women are either all sat in odd-numbered seats or all sat in
even-numbered seats. Suppose, as in the both examples above, the women are in
4.3 Complementary boards and the Problème des Ménages 67
M2
M4
M1
M3
In the first example, the board is the same, but since the permutation s is now
s (1) = 1, s (2) = 2, s (3) = 3, s (4) = 4, the row labels change to M1 , M2 , M3 , M4 .
The rook placements for the two examples above are shown below.
1 3 5 7 1 3 5 7
M1 R M2 R
M2 R M4 R
M3 R M1 R
M4 R M3 R
In general we label row i of the n ⇥ n grid by man Ms (i) . Then ways to seat the n
men correspond to placements of n non-attacking rooks on the complement of the
board Bn obtained by taking the staircase board S2n 1 with 2n 1 squares in the
sequence below and extending it by a square in the bottom-left corner.
, , , ,....
For example, B4 is the board of shaded squares seen three times above. It follows
from Lemma 4.2.1, taking the distinguished square to be one in the top-right corner,
that the rook polynomial of Bn is fS2n 1 (z) + x fS2(n 1) 1 (z).
Exercise 4.3.4 Using the formula fSm (z) = Ânk=0 m kk+1 , which you are asked to
discover in Exercise 4.5, prove that
n ✓ ◆
2n k 2n
fBn (z) = Â .
k=0 k 2n k
68 Rook Polynomials
Therefore, by Corollary 4.3.3, the number of ways to place the men is the ménage
number un defined by
n ✓ ◆
k 2n k 2n
un = Â ( 1) (n k)!.
k=0 k 2n k
n 0 1 2 3 4 5 6 7 8
un 2 1 0 1 2 13 80 579 4738
We could now apply Corollary 4.3.3 to find r7 (B). Instead, we motivate a more
general result by observing that g7 (z) = 1 + 14z + 77z2 + 210z3 + 294z4 + 196z5 +
49z6 + 2z7 . Since g3 (z) = 1 + 6z + 9z2 + 2z3 , it follows that
(In the second summand, we replaced k 4 with `.) By two more applications of
Corollary 4.3.3, this is u7 + u3 , or 579 + 1 = 580.
Proposition 4.3.6 Let `, m 2 N0 with ` m. Then g` (z)gm (z) = g`+m (z)+z2m g` m (z).
Proposition 4.3.6 is proved in Exercise 4.14. Using the proposition one can gen-
eralize Example 4.3.5 to arbitrary permutations s : see Exercise 4.16.
For example, to show why we defined u1 = 1, suppose that s has cycles of
lengths m + 1 and m. (Cycles are formally defined in §9.2: the permutation s in
Example 4.3.5 has cycles of lengths 5 and 2.) Defining B by analogy with Exam-
ple 4.3.5, so if m = 3 then B is as shown in the margin, Proposition 4.3.6 implies
that
fB (z) = gm+1 (z)gm (z) = g2m+1 (x) + z2m g1 (x) = g2m+1 (z) + z2m (1 + 2z).
By Corollary 4.3.3, the number of permutations discordant with both the identity
permutation and s is
2m 1
 rk (B2m+1 )( 1)k (2m + 1 k)! + r2m (B2m+1 ) + 1 1! r2m+1 (B2m+1 ) + 2 0!
k=0
2m+1
= Â rk (B)( 1)k (2m + 1 k)! + 1 2 = u2m+1 1 = u2m+1 + u1 .
k=0
The useful linearity property in Corollary 4.3.3 seen in this calculation general-
izes as follows. In practice the signs are often always +1: see Exercise 4.15(d).
70 Rook Polynomials
Exercise 4.3.7 Suppose that B is a board in the n ⇥ n grid such that fB (z) =
Ân`=0 a` zn ` g` . Show that rn (B) = Ân`=0 ( 1)n ` a` u` .
As motivation for our final result, fix m 2 N and observe that by repeatedly multi-
plying by gm using Proposition 4.3.6, we have g2m = g2m +2z2m , g3m = g3m +3z2m gm ,
g4m = g4m + 4z2m g2m + 6z4m and g5m = g5m + 5z3m g3m + 10z4m gm . The coefficients
should seem familiar.
Proposition 4.3.8 Fix m 2 N and c 2 N0 . Suppose that there are c circular tables,
each seating 2m diners, and that there are mc couples who must be seated obeying
the restrictions of the Problème des Ménages. The number of seating arrangements
is ✓ ◆ ✓ ◆
c c
2 (mc)! Â
c
um(c 2k) +
0k<c/2
k c/2
where again the final summand is regarded as 0 if c is odd. If c is even, with say
c = 2s, then multiplying the equation above by gm using Proposition 4.3.6, we get
s 1✓ ◆ ✓ ◆
2s 2mk 2s
gm (z)2s+1
=Â z 2m
gm(2s 2k+1) (z) + z gm(2s 2k 1) (z) + gm z2ms
k=0 k s
s 1 ✓ ◆ ✓ ◆ ✓ ◆ ✓ ◆
2s 2s 2s 2s
=Â + 2mk
z gm(2s+1 2k) (z) + + gm (z)z2ms
k=0 k k 1 s 1 s
s ✓ ◆
2s + 1 2mk
=Â z gm(2s+1 2k) (z)
k=0 k
where the final step uses the Fundamental Recurrence (Lemma 2.1.7). The induc-
tive step is similar if c is odd. Hence, by Exercise 4.3.7, the number of ways to seat
the men is ✓ ◆ ✓ ◆
c c
 k m(c 2k) c/2 .
u +
0k<c/2
To count all seating arrangements we must multiply this by 2c , counting the choices
of whether women are in even or odd seats at each table, and then by (mc)!, count-
ing the ways the women may choose seats of the chosen parity at each table.
Exercises 71
An alternative proof of the formula for gcm direct from the Binomial Theorem is
given in Exercise 4.15(e). We apply the results in this section to find the number
of permutations discordant with any two given permutations, and hence to count
3 ⇥ n Latin rectangles, in §9.4.
Exercises
The core exercises are 4.1 to 4.7.
✓ ◆✓ ◆
n
m n k
4.2 Show that the rook polynomial of the m ⇥ n grid is  k! z.
k=0 k k
(a) Explain why |T | is the number of ways to place 5 non-attacking rooks on the
board B formed by the unshaded squares below. (Include in your answer an
explicit example of how a permutation corresponds to a rook placement.)
(b) Find the rook polynomial of B, and hence find |T |. [Hint: consider the four
possibilities for the starred squares. For example, if both are occupied, the
contribution to the rook polynomial is z2 f1 (z) f2 (z) where fn (z) is the rook
polynomial of the n ⇥ n square board. You could also use Lemma 4.2.1.]
(c) Use Corollary 4.3.3 to find the number of ways to place 5 non-attacking rooks
on the shaded squares.
(d) (?) By adapting the argument used to prove Corollary 4.3.3, find the number
of ways to place 4 non-attacking rooks on the shaded squares. (See Exer-
cise 4.13 for a generalization.)
72 Rook Polynomials
4.4
(a) Show that permuting the rows or columns of a board does not change its rook
polynomial.
(b) Let B be the board in Example 4.1.5. Show that B and its complement B in
the 4 ⇥ 4 grid have the same rook polynomial.
4.5 Let Sm denote the staircase board with exactly m squares in the sequence
shown below.
, , , , ,....
4.6 Let n = 3 and let B be the board formed by the shaded squares below.
Draw the rook placements lying in each of the sets A? , A{1} , A{2} , A{3} ,
A{1,2} , A{1,3} , A{2,3} , A{1,2,3} in the proof of Lemma 4.3.2 and hence find
the set Ck of coloured rook placements for each k 2 {0, 1, 2, 3}. Check that it
has the expected size.
For instance you should find that C1 has the six coloured placements
r r R R R R
R R r r R R
R R R R r r
4.7 A Latin rectangle of order n is a rectangle in which every row contains each
of the numbers 1, 2, . . . , n exactly once and the entries in each column are
distinct. Let L be the Latin rectangle shown below
1 2 3 4 5 .
2 3 1 5 4
Let B be the board contained in the 5 ⇥ 5 grid with a square in position (i, j)
if and only if the number i can be put in row 3 and column j of L.
(a) Find the rook polynomial of B and hence find r5 (B).
(b) Explain why r5 (B) is the number of ways to extend L to a 3 ⇥ n Latin rectan-
gle.
(c) Use Proposition 4.3.6 and Exercise 4.3.7 to express r5 (B) as a sum of the
ménage numbers un .
4.8 Find the number of permutations s of {1, 2, 3, 4, 5, 6} such that s (m) 6= m for
any even number m.
(a) Representing boards as list of squares, implement this algorithm in the pro-
gramming language of your choice, choosing as the square s the first square
in the list. (One possibility is M ATHEMATICA: it has polynomial addition and
multiplication built-in and good support for lists and recursion.)
(b) Refine the algorithm by instead choosing the square on which a rook attacks
the maximum number of other squares.
(c) Refine the algorithm further by splitting boards using Lemma 4.2.2.
(d) Which, if any, of the algorithms in (a), (b), (c) can compute the rook poly-
nomial of the ‘coffee’ board on page 62 in a short time? (A M ATHEMATICA
notebook including the squares in this board may be downloaded from the
author’s website, see page 4.)
4.10 Given a board B contained in the n ⇥ n grid. Let M(B) be the matrix with
a 1 in each position where B has a square, and 0 in all other positions. Let
H(B) be the bipartite graph with adjacency matrix M(B). For example, if B
is the board in Example 4.1.5 with rows labelled by courses and columns by
74 Rook Polynomials
W X Y Z
0 1
1 1 1 1 0 W X Y Z
• • • •
2 B0 1 0 0C
!B
@0
C !
3 0 1 1A
• • • •
4 1 0 0 1 1 2 3 4
2 1 3 1
1 3 2 3 1 2 3 2
1 2 1 2 1 2 1 2
[Hint: Exercise 2.5 is relevant; you will need to swap the roles of n and k.]
(c) Deduce that nk is the number of ways to put n labelled balls into k unlabelled
tubes so that each tube is non-empty. (This is the usual definition of the Lah
Numbers.)
(d) (?) Give a bijective proof of (c).
Exercises 75
4.12 Fix n 2 N and let B be a board contained in the n ⇥ n grid. The hit number
ht (B) is the number of ways to put n non-attacking rooks on the n ⇥ n grid
so that exactly t rooks are on B. For example, if n = 4 and B is the board
of shaded squares in the margin then h0 (B) counts the 9 derangements and
h1 (B) = 8, h2 (B) = 6, h3 (B) = 0 and h4 (B) = 1.
(a) Show that
n ✓ ◆
t
 ht (B) k = rk (B)(n k)!.
t=k
[Hint: interpret each side as the number of ways to put k black rooks on B and
n k white rooks anywhere on the grid, so that all n rooks are non-attacking.]
n
(b) Deduce that Ât=0 ht (B)(1 + z)t = Ânk=0 rk (B)(n k)!zk and hence that
n n
 ht (B)wt =  rk (B)(n k)!(w 1)k .
t=0 k=0
• • • •
• • •
• • • • • • • • ...
C1 C2 C3 C4 C5
2 1+2z 1+3z 1+4z+z2 1+5z+5z2
p0 = 2 and note that, because of the self-loop on its unique vertex, p1 (z) = 1,
as shown above.
(a) Show that if n 2 then p2n (z) is the rook polynomial gn (z) of the board Bn
with 2n squares used in the Problème des Ménages.
m/2
(b) Show that rk (Cm ) = rk (Sm 1 )+rk 1 (Sm 3 ) and hence pm (z) = Âk=0 mk k mm k zk
for m 2 N, generalizing Exercise 4.3.4.
(c) Show that if m 2 then pm (z) = pm 1 (z) + zpm 2 (z). [Hint: the direct proof
from (b) is not hard. There is also a more enlightening bijective proof using
Exercise 4.18(e) below.]
(d) Show by induction on m that pm (z)p2 (z) = pm+2 (z) + z2 pm 2 (z) for m 2.
(e) For n 2 N let gen (w) = wn gn ( w 1 ). Thus gen (w) = Ânk=0 rBn (n k)( 1)n k wk
for n 2 and, because of our earlier definitions, ge0 (w) = 2, ge1 (w) = w 2.
Show that for all n 2 N,
gen (w)e
g1 (w) = gen+1 (w) + gen 1 (w).
(f) Deduce that there is an injective ring homomorphism q : C[w] ! C[t 1 ,t]
such that q gen (w) = t n + t n for all n 2 N0 . [Hint: do not be scared by the
ring theory. Since ge1 (w) = w 2 generates C[w], it suffices to prove that q
respects multiplication by ge1 (w); that is,
q gen (w)e
g1 (w) = q gen (w) q ge1 (w)
for all n 2 N. The details of this reduction are given in the answer.]
(g) Using (f) and the identity (t n + t n )2 = t 2n + 2 + t 2n prove that gn (z)2 =
g2n (z) + 2z2n for all n 2 N0 .
(h) Show more generally that g` (z)gm (z) = g`+m (z)+z2m g` m (z) for all `, m 2 N0
with ` m, as claimed in Proposition 4.3.6.
(i) (?) Is there a bijective proof of (g)?
4.15 Suppose that B is a board in the n ⇥ n grid such that fB (z) = g2 (z)c2 . . . gn (z)cn .
See Proposition 4.3.8 and the two following exerciss for cases where this
arises.
(a) Show that wn fB ( w 1 ) = ge2 (w)c2 . . . gen (w)cn , where gen (w) is as defined in
Exercise 4.14(e).
(b) Show that there are constants b` 2 N0 such that
(t 2
+ t 2 )c2 . . . (t n
+ t n )cn = Â b` (t (n 2`)
+ tn 2`
).
0`n/2
(c) Deduce from Exercise 4.14(f) that fB (z) = Â0`n/2 b` z2` gn 2` (z).
(d) Deduce from Exercise 4.3.7 that rB (n) = Â0`n/2 b` un 2` .
Exercises 77
(e) Use the Binomial Theorem applied to (t m + t m )c and (d) to give an alterna-
tive proof of Proposition 4.3.8.
(a) Express rB (9) as a sum of the ménage numbers un . [Hint: a very quick method
uses the machine developed in Exercise 4.15.]
(b) Express rC (10) as a sum of the ménage numbers un . [Hint: Exercise 4.15
generalizes to products with g1 (z); note that f (z) = 1 + z = (1 + 2z) z =
g1 (z) z.]
4.17
(a) Let s , t : {1, 2, . . . , n} ! {1, 2, . . . , n} be permutations. Give a bijection be-
tween permutations discordant with both s and t and permutations discor-
dant with both the identity permutation and s 1 t.
(b) For n 3 let Dn be the board of unshaded squares contained in the n ⇥ n
grid, shown below for D3 , D4 , D5 , D6 . Find the number of ways to put n non-
attacking rooks on Dn in terms of the ménage numbers un . (See Lemma 9.4.1
for the general result behind this.)
• • • •
• • •
• • • • • • •
• • • •
• • • •
are 1 + 5z + 6z2 + 4z3 , 1 + 5z, 1 + 6z + 9z2 + 2z3 and (1 + z)2 (1 + 3z + z2 ). The
name comes from graph theory: a subset of the vertices of G is independent
if it contains no two adjacent vertices.
(a) Find the independence polynomials of the graphs below.
•
• • • •
• • • • • •
• • • •
• • •
• •
• •
(b) State a generalization of Lemma 4.2.1 to independence polynomials. Does
the proof of this lemma also generalize?
(c) State a generalization of Lemma 4.2.2 to independence polynomials. Does
the proof of this lemma also generalize?
(d) Find the independence polynomial of the graph below by applying (b) and
then (c).
• •
• • • • •
t u v
• •
(e) Let G be a graph having vertices {t, u, v} such that the only edges involving
u are {t, u} and {u, v}. Let
• G/u be G with vertex u and its incident edges deleted and (unless it is
already an edge), a new edge {t, v} inserted;
• G//u be G with vertex v deleted and vertices u and w identified.
(If {t, v} is an edge of G then G//u has a self-loop on the vertex replacing t
and v.) For example, if G is the graph in (d) with t, u, v as marked, then G/u
and G//u are as shown below.
• • • •
• • • • • • •
• • • •
Show that fG (z) = fG/v (z) + z fG//v (z).
(f) Show that given a board B with m boxes there is a graph G(B) with m vertices
such that fB (z) = fG(B) (z).
(g) Which of the graphs in (a) are graphs of boards?
(h) (?) Give a necessary and sufficient condition for a graph to be the graph of a
board.
4.3 Complementary boards and the Problème des Ménages 79
4.19 [This ‘exercise’ and the answer in Appendix C are included for more expert
readers as in indication of how the machinery of Lemma 4.15 leads to a quick
proof of Riordan’s formula for the number of 3 ⇥ n Latin rectangles. It will
be part of the text in §9.4.]
Notation. For n 2 N let un be the ménage number defined in §4.3; this could
also have been defined as the number of permutations of {1, 2, . . . , n} discor-
dant with both the identity and an n-cycle. By definition, u0 = 2. (Alas, here
zn
u0 = 1 would be the better choice.) Let F(z) = • n=0 dn n! be the exponential
generating function of the derangement numbers dn .
(a) Show that if s is a permutation of {1, 2, . . . , n} with cycle type (2c2 , . . . , ncn )
then the number of permutations discordant with both the identity and s is
Â0`n/2 b` (s )un 2` where the coefficients b` (s ) are defined by
(t 2
+ t 2 )c2 . . . (t n
+ t n )cn = Â b` (s )(t (n 2`)
+ tn 2`
).
0`n/2
(c) Show that formally specializing the right-hand side in (b) by replacing t k +t k
with uk for each k 2 N gives the exponential generating function for 3 ⇥ n
Latin rectangles.
(d) Show that if 0 ` n/2 then the coefficient of znt n 2` /n! on the right-hand
side in (b) is n` d` dn ` and hence that the number of 3 ⇥ n Latin rectangles
with first row 1, 2, . . . , n is
✓ ◆
n
 ` d` dn ` vn 2`
`
1 2 3 4 1 2 3 4 1 2 3 4
1 2 3 4 1 2 3 4 1 2 3 4
Similarly, or by symmetry if you prefer, there are three derangements such that
s (1) = 3, and three derangements such that s (1) = 4. Hence d4 = 3 ⇥ 3 = 9.
Exercise 1.1.4 Before Winter sets in, walk around your land. For each sheep you
see, put a stone in your pocket. Keep the stones safe until Spring. At Spring, take
the stones and again walk around your land. For each sheep you see, throw away a
stone. The number of remaining stones is the number of lost sheep. If this number
is less than 10, you can count it. Otherwise, make another bijection between the
remaining stones and a subset of the remaining sheep to visualize how many sheep
were eaten by wolves. (This only fails if more than half the sheep were lost.)
Remark: Tally marks have been found carved on bones dating back to 30000BC
and clay tokens, such as the ones in Figure A.1 overleaf, were used to represent
sheep in neolithic times. More sophisticated recording devices, known as quipu,
using knots on cords, were made by the Incans.
Exercise 1.1.5 The two derangements s of {1, 2, 3, 4, 5} such that s (1) = 2 and
s (2) = 1 are shown overleaf.
112 Solutions to exercises
Figure A.1 Clay accounting tokens, Susa, Uruk period. Louvre Museum.
1 2 3 4 5 1 2 3 4 5
1 2 3 4 5 1 2 3 4 5
s (2) s (1) s (5) s (3) s (4) s (2) s (1) s (4) s (5) s (3)
We have s (3) 2 {4, 5} so there are two choices for s (3). On the other hand, the
three derangements of {1, 2, 3, 4, 5} such that s (1) = 2 and s (2) = 3 are 23154,
23451 and 23514 in one-line form, so now there are 3 choices for s (3).
Exercise 1.1.7 The missing diagrams in Figure 1.1.7 are shown below.
1 2 3 4 5 1 2 3 4 5
1 2 3 4 5 1 2 3 4 5
s (4) s (1) s (2) s (5) s (3)
f f 1
1 2 3 4 5 1 2 3 4 5
1 2 3 4 5 1 2 3 4 5
t (1) t (3) t (2) t (5) t (4)
Solutions to exercises 113
(b) The steps East are steps number 1, 3, 4, 7 so the element of C corresponding to
this walk is {1, 3, 4, 7}.
(c) Urns 2, 3, 4 and 6 have balls, so the corresponding element of C is {2, 3, 4, 6},
and the corresponding walking route is SEEESES.
7
(d) By definition |C| = 4 . The sets A and B are in bijection with C, so by BCP0
we have
✓ ◆
7
|A| = |B| = |C| = .
4
1.6 (a) See the table below. The ‘x-card’ in AKQJx stands for any ten or lower.
There are 52 16 = 36 such cards, and 4 of each royal card, so the number of
AKQJx hands is 4 ⇥ 4 ⇥ 4 ⇥ 4 ⇥ 36 = 9216.
(c) Fix a > 0. A sketch graph shows that e y 1 y for all y 0, and 1 y
e (1+a)y for all sufficiently small y. (These inequalities are surprisingly useful.)
Putting y = 1/n and taking nth powers we get
1 1/n n 1 n n
e = e 1 e (1+a)/n = e (1+a)
n
for all sufficiently large n. Since a was arbitrary, it follows that limn!• (1 1/n)n =
1/e, as required.
(d) Suppose Parcel 1 is correctly delivered. Then the probability that Parcel 2 is
correctly delivered is 1/(n 1), which is more than the usual 1/n chance. (In par-
ticular, if n = 2, then once Parcel 1 is correctly delivered, it is certain that Parcel 2
is correctly delivered.) The events that the parcels are correctly delivered are there-
fore not independent.
1.9 Corollary 1.1.9 states that
⇣ 1 1 ( 1)n ⌘
dn = n! 1 + ···+ .
1! 2! n!
116 Solutions to exercises
1 n n
1 ⇣ 1 1 ( 1)n k ⌘
Â
n! k=1
kan (k) = Â 1 + ···+ .
k=1 (k 1)! 1! 2! (n k)!
where s varies over all permutations of {1, 2, . . . , n}. Since Ais (i) = 1 if s (i) 6= i
and Ais (i) = 0 if s (i) = i, we have
(
n 1 if s is a derangement
’ Ais (i) = 0 otherwise.
i=1
Hence det A = en on .
Another way to find the determinant uses that det A is the product of the eigen-
values of A. Since A + I is the all-ones matrix, of rank 1, it has n 1 linearly
independent vectors in its kernel. Hence 1 is an eigenvalue of A with multiplicity
n 1. Another eigenvalue of A is n 1, since every column of A has sum n 1 and
so (1, . . . , 1)A = (n 1, . . . , n 1). Hence det A = ( 1)n (n 1). Comparing we get
en on = ( 1)n (n 1).
1.11 (a) We have defined P = {(s , x) : s 2 G, x 2 {1, 2, . . . , n}, s (x) = x}. Let
Fix s be the set of fixed points of s 2 G and let Stab x = {s 2 G : s (x) = x}.
Counting |P| by summing over s 2 G we get
|P| = Â |Fix s |.
s 2G
Recall that, by the orbit stabiliser theorem, if Orb x is the orbit of x under G then
|Orb x| = |G|/|Stab x|. Hence, counting |P| by summing over x 2 {1, 2, . . . , n}, we
get
n n
|G|
|P| = Â |Stab x| = Â |Orb x| .
x=1 x=1
Thus each x in an orbit of size r contributes |G|/r to the sum. Hence each orbit
contributes |G| to the sum, and |P|/|G| is the number of orbits of G on {1, 2, . . . , n}.
(b) Take a tetrahedron with faces labelled 1, 2, 3, 4. Any permutation of the faces
can be realised by a rotation that leaves the tetrahedron occupying the same position
118 Solutions to exercises
in space. Conversely, any rotation is clearly determined by what it does to the faces.
Thus the symmetry group of the tetrahedron is Sym({1, 2, 3, 4}).
The table below shows the number Cs of red-blue-green colourings fixed by an
element s of each cycle type. (See §9.2 for disjoint cycle notation.) For example,
the double-transposition s = (1, 2)(3, 4) fixes a colouring if and only if faces 1
and 2 have the same colour, and faces 3 and 4 have the same colour. So there are
C(1,2)(3,4) = 32 = 9 such colourings.
The bottom row shows the number of elements Ns with each cycle type. The num-
ber of coloured tetrahedra up to rotation is the number of orbits of Sym({1, 2, 3, 4})
on the set of all 34 coloured tetrahedra. By (a), it is
1 34 + 33 ⇥ 6 + 32 ⇥ 8 + 32 ⇥ 3 + 3 ⇥ 6
4! Â
Cs = = 15.
s 4!
(c) Attach labels 1, 2 to 3 to the three urns. We will ‘undo’ this labelling by counting
ball-urn placements up to the action of the symmetric group Sym({1, 2, 3}) on the
labels. For example, the ball and urn placement drawn below
1 2 3
is sent by the 3-cycle (1, 2, 3) to the placement with the same diagram, but with the
urns instead labelled 2, 3, 1 from left to right.
3+3 1 3+2 1 5 4
The total number of placements (into labelled urns) is 3 2 = 3 2 =
60, by BCP1 and Theorem 2.3.3.
A ball and urn placement is fixed by the transposition (1, 2) if and only if urns 1
and 2 have the same number of balls of each colour. Writing (w, b) for w white balls
and b black balls, the contents could be (0, 0), (1, 0), (0, 1) or (1, 1). Therefore there
are 4 placements fixed by each of the transpositions (1, 2), (1, 3) and (2, 3). Since
there are exactly 2 black balls, no placement is fixed by a three cycle. By (a), the
number of placements into indistinguishable urns is (60 + 3 ⇥ 4)/3! = 12.
1.12 Number the coins 1, 2, . . . , 2m from left to right. The tortoise can guarantee
to take all the odd coins (just do it!). Similarly the tortoise can guarantee to take
Solutions to exercises 119
all the even coins. So unless the value of the odd coins equals the value of the even
coins, the tortoise has a winning strategy.
Suppose that the even coins and the odd coins both have total value V . Let ci be the
value of coin i. Suppose that c1 > c2 and c1 > c2m . Let W = min(V c2 ,V c2m ).
Since V c1 < V c2 and V c1 < V c2m we have V c1 < W . Since V c2 =
c4 + · · · + c2m and V c2m = c2 + · · · + c2(m 1) , it follows that if the tortoise starts
by taking coin 1, and then switches to the even coins, he takes at least W + c1 > V .
By symmetry we see that the tortoise wins in the tied case whenever the coins at
each end are not equally valuable, and the more valuable one is worth more than
its neighbour.
1.13 The problem is no harder generalized to n safes. The keys can be distri-
bution uniformly at random as follows: start by putting key i in safe i, for each
i 2 {1, . . . , n}. Then for each k working from 1 up to n, choose a number j between
1 and k uniformly at random, and swap the keys in safes j and k. (If j = k then leave
the key in safe k where it is.) The first r swaps are irrelevant to the probability that
all safes can be opened. Then for each k > r, the key k in safe k must be moved
into an earlier openable safe. The probability this happens in every case is
k k+1 n 1 k
... = .
k+1 k+2 n n
This solution is due to Igors Stepanovs.
1.14 We build up a Sudoku permutation matrix one column at a time, starting
with column 1 and ending with column n2 . Let i, j 2 {0, 1, . . . , n 1}. When we
choose the row to contain the unique 1 in column ni + j + 1, there are j blocks,
each of n rows, that are barred because of the 1s in columns ni + 1, . . . , ni + j.
Let B be the n j-set of such rows. There are also ni rows that are barred because of
1s in columns 1, 2, . . . , ni. However, this double-counts any row containing a 1 in
columns 1, 2, . . . , ni whose number lies in B. In each block of columns nk + 1, . . . ,
nk + n for 0 k < i there are exactly j such rows. Hence there are
n2 nj ni + i j
possible positions for the 1 in column ni + j + 1. The total number of Sudoku
permutation matrices is therefore
n 1n 1 n 1
’ ’ (n i)(n j) = ’ n!(n j)n = n!n n!n = n!2n .
i=0 j=0 j=0
1.15 We give the start of one possible solution and invite the reader to complete
it.
120 Solutions to exercises
Working with a 4n-bead necklace, with 2n black beads and 2n white beads, number
the positions by integers, so m, m + 4n, m + 8n, . . . all label the same position. For
each m 2 {1, . . . , 4n}, let bm be the difference between the number of black beads
in positions {m, m + 1, . . . , m + 2n 1} and the number of black beads in positions
{m + 2n, . . . , m + 4n 1}. If bm = 0 then we may cut in position m to get two
necklaces, each with n black and white beads. Now consider how bm may vary
for m between 0 and 4m 1.
2. Binomial coefficients
Exercise 2.1.3 (a) The empty set ? is the unique subset of {1, 2, . . . , n} of size 0,
and {1, 2, . . . , n} is the unique subset of {1, 2, . . . , n} of size n. Hence n0 = nn = 1.
(If n = 0 then {1, 2, . . . , n} = ?; since ? ✓ ?, the empty set is the unique subset in
both cases.)
(b) Let n 2 N. The subsets of {1, 2, . . . , n} of size 1 are {1}, {2}, . . . , {n}. Clearly
the empty set ? has no subsets of size 1, so 01 = 0. Hence n1 = n for all n 2 N0 .
f : {1}, {2}, {3}, {4} ! {1, 2, 3}, {1, 2, 4}, {1, 3, 4}, {2, 3, 4}
is defined by f (X) = {1, 2, 3, 4}\X. Thus f ({1}) = {2, 3, 4}, f ({2}) = {1, 3, 4},
and so on. The inverse of f is
g : {1, 2, 3}, {1, 2, 4}, {1, 3, 4}, {2, 3, 4} ! {1}, {2}, {3}, {4}
1 2 3 4
1 2 3 4
1 2 3 4
1 2 3 4
Solutions to exercises 123
where the first and last equalities follow from Lemma 2.4.1 and the middle from
Lemma 2.4.2.
where the final step uses the Binomial Theorem. Substituting x = 1 we get Âr nr r
k =
n n k
k 2 and substituting x = 1 we get Âr ( 1)r nr kr = 0, provided n > k.
2.10 Again we use Lemma 2.2.4 to replace nr kr with nk nr kk . This gives
✓ ◆✓ ◆✓ ◆ n ✓ ◆✓ ◆✓ ◆ ✓ ◆ n ✓ ◆✓ ◆
r m n m n n k n m n k
 k r r  r k r k
= = Â r r k
k r=k
r r=k
✓ ◆ n ✓ ◆✓ ◆ ✓ ◆✓ ◆
n m n k n m+n k
= Â r n r = k
k r=k n
where the final step uses Vandermonde’s convolution (Lemma 2.2.6).
Solutions to exercises 127
when m < n/2. For this we use the team-and-leader combinatorial interpretation.
Take n people, all of different ages. Given a team X of r n/2 of these people,
say that Person x is paired with Person x? if Person x is the jth youngest person
in the team and Person x? is the jth youngest person not in the team. Say Person y
is a suitable leader for X if she is not in the team and is not paired with any team
member. The left-hand side of (†) counts the number of teams-and-suitable-leaders
where the team has size at most m.
The right-hand side of (†) counts the number of teams-and-leaders where the team
has size m. (The leader is not in the team, but need not be suitable.) Given such
a team X and a leader, either the leader is suitable, and we stop, or the leader is
paired with a unique team-member, say Person x. Sack the leader, and promote
Person x. If Person x is a suitable leader for the new team of size m 1, then stop.
Otherwise repeat this process. Since any leader is suitable for the empty team, the
process eventually stops with a team and suitable leader.
We illustrate the inverse by example. Take n = 6 and m = 3 and number the people
1, 2, 3, 4, 5, 6 in increasing seniority. Then Person 4 is a suitable leader for the team
with members Persons 1 and 5. This team must have been obtained by sacking an
unsuitable leader of a team with Persons 1, 4 and 5 and promoting Person 4. This
unsuitable leader was paired with Person 4. Since 4 is in the middle of {1, 4, 5}
and 3 is in the middle of {2, 3, 6}, this leader was Person 3.
2.12 (a) Since X 4 Y = Y 4 X and X \Y = Y \ X for all subsets X and Y , addition
and multiplication are commutative. The zero element is ?, since ? 4 X = X for
all subsets X and the one element is W since W \ X = X for all subsets X. Since
(X 4 Y ) 4 Z and X 4 (Y 4 Z) are both equal to
{w 2 W : w is in exactly one or exactly three of X, Y , Z, }
128 Solutions to exercises
1563715 whereas 24 9 < 1563715, this set has maximum element 25, and we now
27 24
need the set in position 107 10 9 = 256211 of the colexicographic order
on 8-subsets. Continuing in this way we arrive at {?, 5, 7, 10, 12, 14, 20, 22, 25, 28},
corresponding to
✓ ◆ ✓ ◆ ✓ ◆ ✓ ◆ ✓ ◆ ✓ ◆ ✓ ◆ ✓ ◆ ✓ ◆
27 24 21 19 13 11 9 6 4
107 = + + + + + + + + + 3.
10 9 8 7 6 5 4 3 2
3
The least entry, marked ? above, is therefore 3 = 1 .
(e) By (b), the set in position mr in the colexicographic order on m-subsets of
{1, 2, . . . , r} is {r m + 1, . . . , r}. Specifying this set by the ‘coding’ in (d), we get
✓ ◆ ✓ ◆ ✓ ◆ ✓ ◆
r 1 r m+1 r m+1 r
+···+ + = .
m 2 1 m
r 1 r r r
(The argument, as in (d), starts ‘since m < m whereas m m , the maxi-
r m+1
mum element is r, . . . ’.) Now rewrite 1 = r 1m + r 0m .
2.14 Let S(r, k) be the set of strings of 0s and 1s with exactly r 1s and k 0s.
There are r+k k ways to choose k positions in a string of length r + k to be zero, so
r+k
|S(r, k)| = k . The left-hand side of Claim 2.4.4 therefore counts the number of
pairs (s,t) where s 2 S(c, k) and t 2 S(d, m k), for some k 2 {0, 1, . . . , m}. Given
such a pair, we can form a new string s1t 2 S(c + d + 1, m) by inserting 1 between s
and t. Conversely, given a string in S(c + d + 1, m), split it at the (c + 1)th 1, and
discard this 1. This gives a left string in S(c, k) and a right string in S(d, m k),
where k is the number of 0s in the left string. Hence,
m
 |S(c, k)||S(d, m k)| = |S(c + d + 1, m)|.
k=0
 sgn(X,Y ) +  sgn(X,Y ).
(X,Y )2P (X,Y )2P
f ((X,Y ))=(X,Y ) f ((X,Y ))6=(X,Y )
Let Q = {(X,Y ) : f (X,Y ) = (X,Y )} be the set of summands in the first sum.
Note that f restricts to the identity map on Q and to a sign-reversing involution on
P\Q. Evaluating the second sum by applying f we get
for all z 2 C. To get the form in Theorem 2.1.8, replace z with z/w and multiply
through by wn . (A separate argument is required if w = 0.)
where the final equality uses Lemma 2.2.2. The required identity therefore holds
for all z 2 N0 . Since each side is a polynomial in z, it holds for all z 2 C.
2.19 (a) Starting with the right-hand side we have 6 3x 2 1x + 0x = 6x(x 1)(x
6
2)
x
2x + 1 = x(x 1)(x 2) 2x + 1 = x3 3x2 + 1. The coefficients of d for 0
d 3 are 1, 2, 0, 6; these are the numbers appearing on the diagonal of the table.
(b) Using 0, 1, 0, 1, 0 as the top row of a table gives
0 1 0 1 0
1 1 1 1
2 0 2
2 2
0
Motivated by (a), we take
✓ ◆ ✓ ◆ ✓ ◆
x x x x3 8x 1
g(x) = 2 2 + = 2x2 + = x(x 2)(x 4).
3 2 1 3 3 3
Clearly g has roots at 0, 2 and 4 and g(1) = 1, g(3) = 1, as required.
rare in combinatorial problems for the ‘empty’ case to be truly exceptional, so al-
ready this casts doubt on the conjecture. If you draw a sufficiently generic diagram
for n = 6 and carefully count the regions you should find that a6 = 31.
(d) The table below is constructed as in Exercise 2.19:
1 1 2 4 8 16 31
0 1 2 4 8 15
1 1 2 4 7
0 1 2 3
1 1 1
0 0
n n
We therefore conjecture (surely no more rashly than before) that an = 4 + 2 +1
for all n 2 N0 .
(Dn+1 f )(z)
= D Dn f (z)
n ✓ ◆ n ✓ ◆
k n k n
= Â ( 1) f (z + 1 + n k) Â ( 1) f (z + n k)
k=0 k k=0 k
n ✓ ◆ n+1 ✓ ◆
k n n
= Â ( 1) f (z + n + 1 k) Â ( 1) j 1
f (z + n (j 1))
k=0 k j=1 j 1
n+1 ✓✓ ◆ ✓ ◆◆
n n
= Â ( 1) k
+ f (z + n + 1 k)
k=0 k k 1
n+1 ✓ ◆
k n+1
= Â ( 1) f (z + n + 1 + k)
k=0 k
where again the final step uses the Fundamental Recurrence. This gives the induc-
tive step.
This agrees with Example 3.1.1 if we change the labels of the sets from A1 , A2 , A3
to A, B, C.
Exercise 3.1.5 Since |X| = |W| |X| for any subset X of W, we have |A1 [ A2 [
. . .[An | = |W| |A1 [ A2 [ . . . [ An |. Using the Principle of Inclusion and Exclusion
we get
By the convention that A? = W, the summand for I = ? is |W|; this cancels with
the first term. We are left with
3.1 We have A = {2, 4, 6, . . . , 2018} and B = {5, 10, 15, . . . , 2015}. Hence |A| =
2018/2 = 1009 and |B| = 2015/5 = 403. Clearly x 2 A \ B if and only if x 2 W
and x is divisible by 10. Hence A \ B = {10, 20, . . . , 2010} and |A \ B| = 201. It
follows from Example 3.1.1 that
The elements of A [ B are precisely those x 2 N such that x 2019 and x is an odd
number not divisible by 5, as shown in the Venn diagram below.
A A\B B
3.2 Let W = {1, 2, . . . , 100} and let D(m) = {x 2 {1, . . . , 100} : x is divisible by m}
as in §3.4. By adapting Example 3.4.1, we find |D(2) [ D(3) [ D(5) [ D(7)|. By the
Solutions to exercises 135
= Â ( 1)|P| D( ’ p)
P✓{2,3,5,7} p2P
⌫
100
= Â ( 1) |P|
’ p2P p
.
P✓{2,3,5,7}
3.3 As usual, for W ✓ N, let D(m) = {x 2 W : x is divisible by m}. For (a) we take
W = {1, 2, . . . , pq}. If x 2 W then
x is coprime to pq () x is not divisible by p and x is not divisible by q
() x 2 D(p) [ D(q).
Hence f (pq) = D(p) [ D(q) and so using the Principle of Inclusion and Exclusion
we get
f (pq) = |W| |D(p)| |D(q)| + |D(p) \ D(q)|
= |W| |D(p)| |D(q)| + |D(pq)|
pq pq pq
= pq +
p q pq
⇣ 1 ⌘⇣ 1⌘
= pq 1 1 .
p q
In (b) we take W = {1, 2, . . . , p2 q} and argue similarly that
x is coprime to p2 q () x is not divisible by p and x is not divisible by q
() x 2 D(p) [ D(q).
The conclusion is the same as (a), but now D(p) and D(q) are defined using
136 Solutions to exercises
{1, 2, . . . , p2 q}. (Note that it is correct to work with D(p) rather than D(p2 ), since
we have to rule out divisibility by p, not p2 .) The same calculation as (a) now gives
pq2 pq2 pq2 ⇣ 1 ⌘⇣ 1⌘
f (pq2 ) = pq2 + = pq2 1 1 .
p q pq p q
The three prime case in (c) is similar to (a): you should find that
⇣ 1 ⌘⇣ 1 ⌘⇣ 1⌘
f (pqr) = pqr 1 1 1 .
p q r
3.4 (a) This is similar to the second example in §3.3, replacing the ranks Ace,
King, Queen and Jack with the suits spades , hearts ~, diamonds } and clubs |.
As before, let W be all 52
5 hands of five cards. Let C be the hands we do not want
to count because they have no spades, and define C~ , C} and C| similarly. For
example, |C | = 5239 since there are 39 non-spades in the deck. By the Principle
of Inclusion and Exclusion, the number of five card hands with at least one card of
each suit is
|C \C~ \C} \C| |
= |W| |C | |C~ | |C} | |C| | + |C \C~ | + · · · + |C} \C| |
|C \C~ \C} | · · · |C~ \C} \C| | + |C \C~ \C} \C| |
✓ ◆ ✓ ◆ ✓ ◆ ✓ ◆ ✓ ◆
52 39 26 13 0
= 4 +6 4 +
5 5 5 5 5
= 682604.
1
(This is a bit over 4 of all hands.)
For (b) we use the sets above and also CA , CK , CQ , CJ from §3.3. As an example,
consider CA \ C \ C~ . Its elements are the five card hands built from a reduced
deck having no aces, spades or hearts. Using the Principle of Inclusion and Exclu-
sion in the case n = 2, there are 52 4 26+2 cards in the reduced deck. (The final
+2 accounts for the aces of spades and hearts.) Therefore |CA \ C \ C~ | = 24 5 .
More generally, a set AI defined by taking r of the rank sets CA ,CK ,CQ ,CJ and s of
the suit sets C ,C~ ,C} ,C| has size 52 13r5 4s+rs . Hence there are
4 4 ✓ ◆✓ ◆✓ ◆
r+s 4 4 52 13r 4s + rs
  ( 1) r s 5
= 2592
r=0 s=0
five card hands having at least one card of each suit and at least one Ace, King,
Queen and Jack. (The sum has 25 terms, so is most easily evaluated using computer
algebra.)
Solutions to exercises 137
Generalizing the argument in (a), there are n |I| possible choices for each f (t) so
|AI | = (n |I|)m .
(c) A function f 2 W is surjective if and only if f 62 A1 , f 62 A2 , . . . , f 62 An . Equiv-
alently, f 2 A1 [ A2 [ · · · [ An . By the Principle of Inclusion and Exclusion and (b)
we get
= Â ( 1)|I| (n |I|)m
I✓{1,2,...,n}
n ✓ ◆
k n
= Â( 1)
k
(n k)m
k=0
as required.
(d) Given a placement of m numbered balls into n numbered urns, define f 2 W by
3.6 Let the factorizations of M and N into distinct primes be M = pe11 pe22 . . . penn
and N = q1f1 q2f2 . . . qrfr . Since M and N are coprime, the pi and q j are distinct. Hence
Proposition 3.4.4 implies that
n ⇣ 1 ⌘ r fj⇣ 1⌘
f (MN) = ’ pei i 1
pi ’
q j 1
i=1 j=1 qj
3.9 (a) Since p is prime, and p does not divide x or y, p does not divide xy. (This is
less obvious than it might sound, but follows from unique factorization.) If xy ⌘ r
mod M then xy = kpq + r for some k 2 N0 , and so p does not divide r. Similarly q
does not divide r. Hence r is in U.
(b) Let y, y0 2 {0, 1, . . . , M 1} and suppose that fx (y) = fx (y0 ). Then xy ⌘ xy0 mod
M, so x(y y0 ) ⌘ 0 mod M. Hence p and q divide x(y y0 ). But since x 2 U is
coprime to p and q, pq must divide y y0 . Hence y ⌘ y0 mod M, and so y = y0 .
(c) By (a), each fx restricts to a function from U to U. Since 1 2 U and an injective
Solutions to exercises 139
function on a finite set is surjective, there exists x0 2 U such that fx (x0 ) = 1. That
is, xx0 ⌘ 1 mod M.
(d) By (a), U is closed under multiplication modulo M. The identity element is 1
and by (c) each element of U has an inverse. Multiplication is well known to be
associative. Therefore U is a group. The order of U is f (M), namely (p 1)(q 1).
(e) Suppose that a is coprime to f (M). There exists d such that ad ⌘ 1 mod f (M).
Suppose that ad = kf (M) + 1. By Lagrange’s Theorem, xf (M) ⌘ 1 mod M for all
x 2 U. Hence
3.10 (a) Using the Taylor series for the exponential function we have ecy > c2 y2 /2
for y > 0. Hence ye cy < 2/c2 y ! 0 as y ! •.
(b) Using log log M log M and (a) with y = log M, we get
(b) We have
Z x+1 Z x+1
dt dt 1
x t x x x
for each x 2 N. Hence
Z S S 1 Z x+1
dt dt S 1 1 S
1
t
 t
 Â
1 x=1 x x=1 x x=1 x
as required.
1
(c) If there are finitely many primes then ’ p 1 1p , where the product is over all
primes, is finite and so converges. This contradicts (b). (Of course Corollary 3.4.6
and Exercise 3.10 give a stronger result: the argument here is an even shorter
demonstration of the relevance of analytic methods to number theory.)
as required.
(c) Using h(z) to cancel summands 1/(2m + 1)z in z (z) we get
•
1
z (z) h(z) = 2 Â (2m) z
=2 (z 1)
z (z).
m=1
3.13 (a) Let W = {1, 2, . . . , M}. Since x 2 W is square-free if and only if x is not
divisible by any of p21 , p22 , . . . , p2n , we have
If we repeat the approximation in the proof of Theorem 3.4.5 we p get thepsame error
term of 2n . By the Prime
p Number Theorem, there arepabout M/ log M primes
less than or equal to M, so the error term is roughly M
p 2 . This is far larger than M
and p2 (M). Instead, we observe that if ’i2I pi > M then the summand p for I is
zero. We can therefore drop all these summands, leaving at most M non-zero
summands. Dividing by M and using the ? notation from the question to denote
that summands ±1/d with d > M are to be ignored, we get
p
p2 (M) 1 M
Â
? |I|
( 1) 2
.
M I✓{1,2,...,n} ’i2I pi M
(For this reason, the sieve used in this question is called the ‘convergent sieve’.)
3.14 (a) Using the definition of gr (x) and then swapping the sums over x 2 W and
I ✓ {1, 2, . . . , n}, we have
(
( 1)|I| if x 2 AI
cr = Â gr (x) = Â Â = Â ( 1)|I| |AI |
x2W I✓{1,2,...,n} x2W 0 otherwise I✓{1,2,...,n}
|I|r |I|r
as claimed.
(b) By hypothesis, x 2 A j if and only if j 2 J. As seen in the proof of the Principle
of Inclusion and Exclusion, x contributes to |AI | if and only if I ✓ J. Therefore we
can restrict the sum defining fr (x) to those I such that I ✓ J to get
gr (x) =
I✓J
Â( 1)|I| .
|I|r
Having guessed the formula it is not hard to prove it by the usual method. Suppose
that x 2 W lies in A j if and only if j 2 J. The contribution from x to the right-hand
side is then
|J| ✓ ◆
|J|
 ( 1) |I| =  ( 1) k k .
|I| 1 k 1
I✓J k=1
|J| |J| 1
By Exercise 2.1 we have k k = |J| k 1 . Hence, by Corollary 2.2.8(ii), the right-
hand side is
|J| ✓ ◆ (
|J| 1 1 if |J| = 1
|J| Â ( 1)k 1 =
k=1 k 1 0 otherwise,
as required.
(b) The argument used to discover the formula in (a) generalizes to suggest that the
144 Solutions to exercises
We now prove this. Suppose that x 2 W lies in A j if and only if j 2 J. Then the
contribution from x to the right-hand side is
✓ ◆ |J| ✓ ◆✓ ◆
|I| t |I| k t k |J|
 ( 1) t
= Â ( 1)
t k
.
I✓J k=t
|J| |J| t
By Lemma 2.2.4, kt |J|
k = t k t . Hence, by Corollary 2.2.8(ii), the right-
hand side is
✓ ◆ |J| ✓ ◆ (
|J| k t |J| t 1 if |J| = t
 ( 1)
t k=t k t
=
0 otherwise,
as required.
(c) Define the sets Ai as in §3.2, so Ai is the set of permutations of {1, 2, . . . , n} that
fix i. We saw in this section that |AI | = (n |I|)!. Therefore, by (b), the number of
permutations with exactly t fixed points is
n ✓ ◆✓ ◆ n
k t k n n!
 ( 1)
t k
(n k)! = Â ( 1)k t
(k t)!t!
.
k=t k=t
n t
This is n!
t! 1 1
1! + · · · + ((n1)t)! , as seen in Exercise 1.10.
3.16 This is left to you as an extended exercise on the method of counting contri-
butions.
3.17 (a) Since 1X (x) = 1 if x 2 X and 1X (x) = 0 if x 62 X, we have Âx2W 1X (x) = |X|.
(b) Again by definition of 1X , we have 1B (x)1C (x) = 1 () 1B (x) = 1 and 1C (x) =
1 () x 2 B and x 2 C () x 2 B \C () 1B\C (x) = 1. Therefore 1B 1C = 1B\C .
(c) As in (b), we check that the two sides agree on all x 2 W. Suppose that x 2
A1 [ A2 [ · · · [ An . Then x 2 A j for some j and (1W 1A j )(x) = 1 1 = 0. If x 62
A1 [ A2 [ · · · [ An then (1W 1A j )(x) = 1 for all j. Hence
x 2 A1 [ A2 [ · · · [ An () (1W 1A1 )(1W 1A2 ) . . . (1W 1An )(x) = 1
and so 1A1 [A2 [···[An = (1W 1A1 )(1W 1A2 ) . . . (1W 1An ).
(d) Multiplying out the right hand side above we get ( 1)|I| 1Ai1 . . . 1Aik by taking
Solutions to exercises 145
 1A [A [···[A (x) = Â
1 2 n  ( 1)|I| 1AI (x)
x2W x2W I✓{1,2,...,n}
= Â ( 1)|I| Â 1A (x)
I
I✓{1,2,...,n} x2W
= Â ( 1)I| |AI |
I✓{1,2,...,n}
3.18 (a) Following the hint, we let W be the collection of r-subsets of {1, . . . , m +
n} and aim to count the r-subsets not meeting {m + 1, . . . , m + n}. Let Ai be those
subsets we do not want to count because they contain m + i. Then A1 [ A2 [ . . . [ An
is the collection of r-subsets of {1, . . . , m}. By the Principle of Inclusion and Ex-
clusion, we have
✓ ◆
m
r
= Â ( 1)|I| |AI |.
I✓{1,2,...,n}
(c) Let S = {1, 2, . . . , n} ⇥ {1, 2, . . . , m} and let W be the set of all (n + 1)-subsets
of S. Say that X 2 W is admissible if for all i 2 {1, 2, . . . , n} there exists r 2
{1, 2, . . . , m} such that (i, r) 2 X. Let a be the number of admissible subsets. For
each i 2 {1, 2, . . . , n} let
Thus Ai is those subsets that are inadmissible (and we do not want to count) because
they contain no pair with first entry i. By the Principle of Inclusion and Exclusion
a = |A1 [ A2 [ · · · [ An | = Â ( 1)|I| AI
I✓{1,2,...,n}
f 2 Ai we have n 2 choices for f (x) for each x 6= i, and n 1 choices for f (i).
Therefore |Ai | = (n 2)n 1 (n 1). More generally, if |I| = k then
Since there are nk subsets I of size k, it follows from the Principle of Inclusion
and Exclusion that
n ✓ ◆
n
dn = Â (n k 1)k (n k)n k .
k=0 k
Here we started with a set of fixed-point-free functions, and threw out those that
were not injective (and so were not permutations); by comparison, in §3.2 we
started with a set of permutations and threw out those that had a fixed point.
4. Rook polynomials
Exercise 4.1.2 A single rook is always non-attacking so r1 (B) is the number of
squares in B. Since there is a unique rook placement with no rooks, r0 (B) = 1 for
any board B.
Exercise 4.1.3 By the previous exercise r0 (B) = 1 and r1 (B) = 6. The non-
attacking placements with two rooks are enumerated according to the position of
the highest rook in the left diagram below. For instance, the three placements with
the highest rook in the box in the middle of the top row are shown to the right.
3 3 R R R
2 1 R
R R
Therefore r2 (B) = 9. The two diagrams below show that rB (3) = 2. Hence fB (z) =
1 + 6z + 9z2 + 2z3 .
R R
R R
R R
Exercise 4.1.4 By Exercise 4.1.3, there are 9 placements of 2 rooks and 2 place-
ments of 3 rooks not having a rook in the top-left corner. If there is a rook in this
corner then the remaining rooks are on the board of unshaded squares in the margin.
Hence r2 (B) = 9 + 2 = 11 and r3 (3) = 2 + 1 = 3 and so fB (z) = 1 + 7z + 11z2 + 3z3 .
148 Solutions to exercises
Exercise 4.3.4 Applying Lemma 4.2.1 to Bn , using the square in the top-right
corner as instructed, we get
Exercise 4.3.7 Since g` (z) is the rook polynomial of the board B2` , the coefficient
of zk in zn ` g` is rk (n `) (B2` ) for each k 2 {n `, . . . , n}. Therefore Corollary 4.3.3
implies that
n n
rn (B) = Â a` Â ( 1)k rk (n `) (B2` )(n k)!
`=0 k=n `
n `
= Â a` Â ( 1) j+(n `)
r j (B2` )(` j)!
`=0 j=0
n
= Â a` ( 1)n ` r` (B2` )
`=0
n
= Â( 1)n ` u`
`=0
4.1 Using Exercise 4.1.2 and a direct count of the number of placements of 2
rooks we get f (z) = 1 + 3z + z2 , f (z) = 1 + 4z + 2z2 , f (z) = 1 + 5z + 4z2 .
The final board could also be done by a direct count, or by the method in Ex-
ercise 4.1.3, but instead we apply Lemma 4.2.1 to the square in the bottom-left
corner. Deleting this square gives the third board, while deleting its entire row and
Solutions to exercises 149
= 1 + 5z + 4z2 + z(1 + 3z + z2 )
= 1 + 6z + 7z2 + z3 .
4.2 To put k non-attacking rooks on the m ⇥ n grid we can choose k rows in mk
ways and k columns in nk ways. We must then put k rooks on the k ⇥ k subboard
of squares in the chosen rows and column; by the bijection between non-attacking
rook placements and permutations seen in Example 4.1.6, this can be done in k!
ways. Therefore the coefficient of zk is mk nk k!, as required.
4.3 (a) As seen in Example 4.1.6, there is a bijection between permutations of
{1, 2, 3, 4, 5} and ways to place five non-attacking rooks on the squares of a 5 ⇥ 5
grid: a permutation s corresponds to the rook placement with rooks in positions
(i, s (i)) for each i 2 {1, 2, 3, 4, 5}. Derangements correspond to rook placements
with no rooks on the diagonal. Moreover
• s (i) 6= i + 1 if 1 i 4 rules out the squares (1, 2), (2, 3), (3, 4), (4, 5), below
the diagonal,
• s (i) 6= i 1 if 2 i 5 rules out the squares (2, 1), (3, 2), (4, 3), (5, 4) above the
diagonal.
Therefore derangements in T are in bijection with non-attacking rook placements
of 5 rooks on the board of unshaded squares. For example, the permutation s
defined by s (1) = 3, s (2) = 4, s (3) = 5, s (4) = 2, s (5) = 1 corresponds to
the non-attacking placement shown below.
? R
R
R ?
R
R
(b) Suppose that neither starred square is occupied. Then all rooks lie in the un-
shaded squares below.
?
?
150 Solutions to exercises
No square in the bottom-left subboard lies in the same row or column as a square in
the top-right subboard. Hence, by Lemma 4.2.2 and Exercise 4.1, the contribution
to the rook polynomial from this case is
f (z) f (z) = (1 + 4z + 2z2 )(1 + 6z + 7z2 + z3 )
= 1 + 10z + 33z2 + 41z3 + 18z4 + 2z5 .
If the only starred square occupied is the one in position (1, 3) then all other rooks
are on the unshaded squares below.
?
Taking into account that one rook is already placed, the contribution to the rook
polynomial is
zf (z) f (z) = z(1 + 2z)(1 + 5z + 4z2 )
= z + 7z2 + 14z3 + 8z4 .
By symmetry we get the same contribution to the rook polynomial if the other
starred square is the only occupied starred square. Finally, as stated in the question,
if both starred squares are occupied, the contribution to the rook polynomial is
z2 f (z) f (z) = z2 (1 + z)(1 + 4z + 2z2 )
= z2 + 5z3 + 6z4 + 2z5 .
Adding up these four contributions shows that the rook polynomial of the original
board is
(1 + 10z + 33z2 + 41z3 + 18z4 + 2z5 ) + 2(z + 7z2 + 14z3 + 8z4 )
+ (z2 + 5z3 + 6z4 + 2z5 ) = 1 + 12z + 48z2 + 74z3 + 40z4 + 4z5 .
(c) By Corollary 4.3.3, the number of placements of five non-attacking rooks on
the shaded squares forming the complement B of B is
5!r0 (B) 4!r1 (B) + 3!r2 (B) 2!r3 (B) + 1!r4 (B) 0!r5 (B)
= 120 288 + 288 148 + 40 4 = 8.
(d) (?) Let Ai be the set of non-attacking placements of four rooks on the 5 ⇥ 5
grid in which there is a rook in row x and this rook is on a square in B. The sum
ÂI✓{1,...,n}:|I|=k |AI | of the sizes of all intersections of exactly k of the Ai is the
number of ways to put down k red rooks on squares in B and 4 k blue rooks
Solutions to exercises 151
2
anywhere on the grid. By the argument in Lemma 6.9, this quantity is 54 kk (4
k)! rk (B). Hence using 2(b) we find that there are
✓ ◆2 ✓ ◆2 ✓ ◆2 ✓ ◆2 ✓ ◆2
5 4 3 2 1
4! r0 (B) 3! r1 (B) + 2! r2 (B) 1! r3 (B) + 0! r4 (B)
4 3 2 1 0
= 52 .24.1 42 .6.12 + 32 .2.48 22 .1.74 + 40
= 600 1152 + 864 296 + 40 = 56
ways to put four non-attacking rooks on the shaded squares.
4.4 (a) If we take a board with a non-attacking rook placement and swap two
rows then each row still has at most one rook in it, as does each column. Hence the
rook placement on the new board is still non-attacking. Since any row permutation
can be obtained by repeated swapping of rows, this shows that permuting the rows
does not change the rook polynomial. Similarly for columns.
(b) The board B in Example 4.1.5 is formed from the unshaded squares in the
diagram left below.
We aim to permute the rows and column of B to obtain its complement B, shown
right above. Note that the rows of B have, from top to bottom, 3, 1, 2 and 2 unshaded
squares. So the only chance is to swap rows 1 and 2. This gives the board below.
Then we must move column 4 to column 2, since this is the only column to have a
shaded square in row 2. Swapping these columns we get the board below.
(c) Looking at the Pascal’s Triangle on page 23 one can spot the coefficients in
f5 and f6 on the southwest to northeast diagonals. For instance, the coefficients
of f6 are 1 = 70 , 6 = 61 , 10 = 52 , 4 = 43 . This suggests the conjecture that
rSn (k) = n k+1
k .
(d) The routine proof uses Lemma 4.2.1 to split the board on the bottom-left square.
As seen in (b), removing this square gives Sm 1 , while removing this square and all
squares in its row and column gives Sm 2 . Therefore by the lemma and induction
we have
fSm (z) = fSm 1 (z) + z fSm 2 (z)
✓ ◆ ✓ ◆
(m 1) k + 1 k (m 2) k + 1 k
= z +z z
k k k k
✓ ◆ ✓ ◆
m k k m k 1 k+1
=Â z +Â z
k k k k
⇣✓m k◆ ✓m k◆⌘
=Â + zk
k k k 1
✓ ◆
m k+1 k
=Â z
k k
where the final step uses the Fundamental Recurrence (Lemma 2.1.7). The base
cases fS1 (z) = 1 + z and fS2 (z) = 1 + 2z are easily checked.
Alternatively, observe that if we number the squares in the staircase board Sm from
Solutions to exercises 153
fB (z) = (1 + 6z + 9z2 + 2z3 )(1 + 4z + 2z2 ) = 1 + 10z + 35z2 + 50z3 + 26z4 + 4z5 .
Hence, by Corollary 4.3.3, the number of ways to put five non-attacking rooks on B
is 5! 10 ⇥ 4! + 35 ⇥ 3! 50 ⇥ 2! + 26 ⇥ 1! 4 ⇥ 0! = 12.
(b) Suppose we put down five non-attacking rooks on B, in positions (1, j1 ), (2, j2 ),
(3, j3 ), (4, j4 ), (5, j5 ). Then j1 62 {1, 2}, j2 62 {2, 3}, j3 62 {1, 3}, j4 62 {4, 5} and j5 62
{4, 5} and j1 , j2 , j3 , j4 , J5 are distinct. Therefore we can extend the Latin rectangle
to a 3⇥n Latin rectangle with third row j1 j2 j3 j4 j5 . Conversely, any allowable third
row corresponds to a way to put five non-attacking rooks on B. Therefore there are
12 extensions to a 3 ⇥ n Latin rectangle.
(c) Since fB (z) = g3 (z)g2 (z) = g5 (z) + z4 g1 (z) by Proposition 4.3.6, it follows from
Exercise 4.3.7 that r5 (B) = u5 + u1 .
RookPolynomial[{}] := 1
DS[{i_, j_}, bs__] := DeleteCases[bs, {i, j}]
ES[{i_, j_}, bs__]
:= DeleteCases[bs, {iP_, jP_} /; Or[iP == i, jP == j]]
RookPolynomial[{{i_, j_}, bs___}]
:= RookPolynomial[DS[{i, j}, List[bs]]]
+ z*RookPolynomial[ES[{i, j}, List[bs]]]
(b), (c) M ATHEMATICA code for these refined algorithms may be downloaded from
the author’s website (see page 4). An alternative implementation in the functional
programming language H ASKELL is also available.
(d) Using the algorithm in (c) that applies Lemma 4.2.2 where possible, the rook
polynomial of the ‘coffee’ board is computed in 86 seconds on a 2015 MacBook
Pro in M ATHEMATICA. The compiled Haskell code takes 12 seconds. The simpler
algorithms in (a) and (b) cannot compute this rook polynomial in a reasonable time.
4.10 (a) The summand ’ni=1 Mis (i) in per M is 0 unless Mis (i) = 1 for all i; if this
condition holds the summand is 1. Therefore the permanent counts the number of
ways to put n non-attacking rooks on the n ⇥ n grid so that every rook is in a square
(i, j) such that Mi j = 1. This is the coefficient of zn in fB (z).
(b) Choose notation so that H(B) has bipartition {1, . . . , n} [ {10 , . . . , n0 } where
vertices {1, . . . , n} to the rows and vertices {10 , . . . , n0 } correspond to the columns.
For instance, replacing Profs. W, X, Y, Z with 10 , 20 , 30 , 40 , the example graph and
matching are shown on the left below.
156 Solutions to exercises
10 20 30 40
10
•
20
•
30
•
40
•
1 R
!
2 R
• • • •
3 R
1 2 3 4 4 R
There is a bijection between placements of n non-attacking rooks on B and match-
ings in H(B) in which we choose the edge {i, j0 } if and only if there is a rook on
the square (i, j). The non-attacking rook placement corresponding to the matching
in the example is shown on the right above. Hence, by (a), per M(B) is the number
of matchings in H(B).
(c) A board B contained in the n ⇥ n grid given as a list of squares can be turned
into the n ⇥ n matrix M(B) with 0, 1 entries in time O(n2 ). Similarly one can go
turn such a matrix into a board, also in time O(n2 ). The problems of finding the
coefficient of zn in fB (z) and computing per M(B) are therefore polynomial time
equivalent. By Valiant’s result, both are in #P, the complexity class of counting the
number of accepting states of a non-deterministic Turing Machine that promises to
run in polynomial time.
Perhaps surprisingly, it is possible to decide in polynomial time if fB (z) is non-
zero. This is most easily seen using (b): there are algorithms that run in time poly-
nomial in n and return either a complete matching in the graph H(B), or a subset
X ✓ {1, 2, . . . , n} such that X has strictly fewer than |X| neighbours in {10 , . . . , n0 }.
See for instance the algorithmic proof of Hall’s Marriage Theorem on page 27 of
Bryant (1993). Alternatively one can apply the Ford–Fulkerson Algorithm (which
you might have seen used to prove the Max-flow Min-cut Theorem) to the network
version of H(B).
Therefore, unless P = NP, it is strictly harder to compute the coefficient of zn in
fB (z) than to decide if it is non-zero.
n 1 n
4.11 (a) By Exercise 4.2, the rook polynomial of the n 1⇥n grid is Ânk=0 k k k!.
Hence
✓ ◆✓ ◆ ✓ ◆
n n 1 n n 1 n!
= (n k)! =
k n k n k k 1 k!
as required.
(b) By Exercise 2.5, swapping the roles of k and n, there are nk 11 solutions to the
equation u1 + u2 + · · · + uk = n with ur 2 N for each r. Fix such a solution. We then
choose a permutation s : {1, 2, . . . , n} ! {1, 2, . . . , n} and put balls s (1), . . . , s (u1 )
into tube 1, balls s (u1 + 1), . . . , s (u1 + u2 ) into tube 2, and so on. This shows that
Solutions to exercises 157
there are nk 1
1 n! ways to put n labelled balls into k labelled tubes. By (a), this
n
number is k! k .
(c) Given a placement of n labelled balls into k unlabelled tubes so that each tube
is non-empty, we can distinguish the tubes using the balls at their bottoms, and so
label them in k! ways. This gives a placement of n labelled balls into k labelled
urns; by (b) there are k! nk such placements. Hence the number of placements into
unlabelled tubes is nk .
1 2 3 4 5 6 7
1 R
2 R 3 4
3
! 6 1
4
5 R 2 5 7
6 R 1 2 3
Note that the second scan finishes immediately since row 4 is empty. Therefore
tube 2 contains only ball number 5.
Constructing the inverse map from ball-and-tube placements to rook placements is
left as an exercise: for a detailed solution see pages 15 and 16 of Butler et al. (n.d.).
4.12 (a) Clearly ht (B) kt is the number of ways to put n non-attacking rooks on
the n ⇥ n grid so that exactly t on B and then to colour k of the rooks on B black.
Alternatively, we can construct such a coloured rook placement by first putting k
non-attacking black rooks on B and then n k white rooks on the rest of the grid,
so that all n rooks are non-attacking. As seen in the proof of Lemma 4.3.2, we can
do this in rk (B)(n k)! ways.
(b) By the Binomial Theorem,
n n t ✓ ◆
t
 ht (B)(1 + z) =   ht (B) k zk .
t
t=0 t=0 k=0
158 Solutions to exercises
t
The coefficient of zk on the right-hand side is Ât ht (B) k ; by (a) this is rk (B)(n
k)!. This proves the first identity. Now substitute w = z 1 to get the second.
(c) Substituting w = 0 the left-hand side is replaced with its constant term h0 (B),
so we have
n
h0 (B) = Â rk (B)(n k)!( 1)k
k=0
(e) Let Bn be the board contained in the n ⇥ n grid used to solve the Problème des
Ménages used in §4.3. By Exercise 4.12(b), we have
n n
 ht (B)wt =  rk (B)(n k)!(w 1)k .
t=0 k=0
2n k 2n
By Exercise 4.3.4, rk (B) = k 2n k . Hence taking the coefficient of wt as in the
previous exercise, we get
n ✓ ◆ ✓ ◆
2n k k
ht (B) = Â (n k)! ( 1)k t .
k=t k t
Now following the argument in §4.3, we seat the men in n! ways in the odd-
numbered seats, and the women in ht (B) ways in the even numbered seats, thus
putting t couples into adjacent seats. Multiplying by 2 as before to count the place-
ments with men in even-numbered seats we get 2n! Ânk=t 2nk k (n k)! kt ( 1)k t
placements.
4.13 Let Ai be those placements of m non-attacking rooks on the n ⇥ n grid that
we do not want to count because there is a rook in row i and this rook is on B.
Solutions to exercises 159
Generalizing the colouring argument used to prove Lemma 4.3.2, suppose that we
2
put k non-attacking black rooks on B. We then have mn kk (m k)! ways to put
m k white rooks on the grid so that all m rooks are non-attacking. Therefore
✓ ◆
n k 2
 |AI | = rk (B) m k (m k)!
I✓{1,2,...,n}
|I|=k
and using the Principle of Inclusion and Exclusion as in the proof of Corollary 4.3.3,
we get
✓ ◆
m
n k 2
rm (B) = Â ( 1) rk (B)
k
(m k)!
k=0 m k
as required.
1
1 2 8 •
• •2
3 4
7• •3
5 6
8 7 • •
6 • 4
5
Labelling the vertices of the graph C2n as shown on the right above for C8 , it is
clear the number of such placements is rk (C2n ).
(b) A similar argument to (a) shows that the graph corresponding to the staircase
board Sm is the line with m vertices, shown below.
• • ... •
1 2 m
(c) It is equivalent to show that rk (Cm 1 ) + rk 1 (Cm 2 ) = rk (Cm ). By (b), the left-
160 Solutions to exercises
hand side is
✓ ◆ ✓ ◆
m 1 k m 1 m 1 k m 2
+
k m 1 k k 1 m 1 k
✓ ◆
m k 1 (m 2k)(m 1) k(m 2)
= +
k m 1 k m k m k
✓ ◆
m k m (m 2k)(m 1) + k(m 2)
=
k m k m(m 1 k)
✓ ◆
m k m
=
k m k
which is rk (Cm ) by another application of (b). As mentioned in the question, there
is a much more enlightening proof using Exercise 4.18(e): if u is any vertex of Cm
then Cm /u is Cm 1 and Cm //u is Cm 2 , and so, by this exercise, pm (z) = pm 1 (z) +
zpm 2 (z).
(d) Using the given polynomials we have p2 (z)2 = (1 + 2z)2 = 1 + 4z + 4z2 =
(1 + 4z + 2z2 ) + 2z2 = p4 (z) + z2 p0 (z) and p3 (z)p2 (z) = (1 + 3z)(1 + 2z) = 1 +
5z + 6z2 = (1 + 5z + 5z2 ) + z2 = p5 (z) + z3 p1 (z). Using (c) to get the first and last
equalities below, and the inductive hypothesis for the second, we have
pm (z)p2 (z) = pm 1 (z)p2 (z) + zpm 2 p2 (z)
(f) Since ge1 (w) = w 2 generates the polynomial ring C[w], there is a unique
ring homomorphism C[w] ! C[t 1 ,t] that sends w 2 to t 1 + t and satisfies
q h(w)(w 2) = q h(w) q (w 2) for all h(w) 2 C[w]. Suppose, inductively,
that q gem (w) = t m + t m for m n. Then
q gen (w)(w 2) = q gen (w) q (w 2)
n n 1
= (t + t )(t + t) = t (n+1)
+ t n+1 + t (n 1)
+ t n 1.
Solutions to exercises 161
By (e), the left-hand side is q gen+1 (w) + gen 1 (w) , and since q is a ring homo-
morphism, this is q gen+1 (w) + q gen 1 (w) . Since q gen 1 (w) = t (n 1) + t n 1 ,
it follows that q gen+1 (w) = t (n+1) +t n+1 , as required for the inductive step. Since
a polynomial of degree d in C[w] is sent to a polynomial in C[t 1 ,t] with leading
term t d , the homomorphism q is injective.
(g) Since q is a ring homomorphism,
2
q gen (w)2 = q gen (w) = (t n
+ t n )2 = t 2n
+ 2 + t 2n = q ge2n (w) + w .
Since q is injective, it follows that gen (w)2 = ge2n (w) + 2, or equivalently, that
2
wn gn ( w 1 ) = w2n g2n ( w 1 ) + 2.
2
Replacing w 1 with z we get ( z 1 )n gn (z) = ( z 1 )2n g2n (z)+2. Multiplying
through by z2n we get gn (z)2 = g2n (z) + 2z2n .
(h) This follows in the same way as (g), using the identity
m
(t `
+ t ` )(t + t m) = t (`+m)
+ t `+m + t (` m)
+ t` m
.
(i) (?) Label the vertices of C2n by 1, 2, . . . , 2n as shown in (a) for the case n = 4.
Let k < n. Given a placement of k rooks on the vertices of C2n with no two rooks
adjacent, there exists j n such that neither j nor j + n has a rook. Choose j
minimal with this property, and split the cycle into two n-cycles with vertices
1, 2, . . . , j, j + n + 1, . . . , 2n and j + 1, . . . , j + n, keeping rooks on their chosen ver-
tices. Construction of the inverse map is left as an exercise: see Ilya Bogdanov’s
answer to MathOverflow Question 364978. Since rBm (m) = 2 for all m 2 N, this
bijection does all the work needed to prove that gn (z)2 = g2n (z) + 2.
4.15 (a) Since n = 2c2 + · · · + ncn , we have
wn fB ( w 1 ) = wn g2 ( w 1 )c2 . . . gn ( w 1 )cn
c2 cn
= (w2 g2 ( w 1 ) . . . (wn gn ( w 1 ) = gec22 . . . gecnn .
(b) The coefficient of t m in the right-hand side is the number of ways to write
m = 2c+
2 2c2 + 3c+
3 3c3 + · · · + nc+
n + ncn
Since q is injective and q Â0`n/2 b` gen 2` (w) is equal to the right-hand side,
we have wn fB ( w 1 ) = Â0`n/2 b` gen 2` (w). Now replace w with z 1 and use
gen 2` (w) = wn 2` gn 2` ( w 1 ) to get
( z 1 )n fB (z) = Â ( z)n 2`
b` gn 2` (z).
0`n/2
(f) Let B be the board contained in the mc ⇥ mc grid used in the proof of Proposi-
tion 4.3.8. By (d) we have rmc (B) = Â0`mc/2 b` umc 2` where the coefficients b`
are defined by
(t m
+ t m )c = Â b` (t (n 2`)
+ tn 2`
).
0`mc
c
Comparing coefficients, we see that rmc (B) = Â0kc/2 k um(c 2k) as required.
it follows from Exercise 4.15(d) that fB (z) = z8 g1 (z) + z6 g3 (z) + z4 g5 (z) + g9 (z)
and r9 (B) = u1 + u3 + u5 + u9 .
(b) Since (t 1 +t)(t 2 +t 2 )(t 3 +t 3 )(t 4 +t 4 ) = 2(t 2 +t 2 ) + 2(t 4 +t 4 ) + (t 6 +
t 6 ) + (t 8 + t 8 ) + (t 10 + t 10 ) the generalization of Exercise 4.15(d) to products
involving g1 (z) implies that
(1 + 2z) fB (z) = 2z8 g2 (z) + 2z6 g4 (z) + 4z4 g6 (z) + z2 g8 (z) + g10 (z).
Hence by Exercise 4.3.7, noting the signs, we get r10 (B) = u1 + 2u2 + u3 + 2u4 +
u5 + u6 + u8 + u9 + u10 .
Solutions to exercises 163
1 2 3 4 5 1 3 5 2 4
1 1
2 3
3 ! 5
4 2
5 4
Therefore fB (z) = gm (z)2 . By Proposition 4.3.6, fB (z) = g2m (z) + z2m g0 (z) and so,
by Exercise 4.3.7, rn (B) = un + u0 = un + 2.
4.18 (a) The independence polynomials are 1 + 4z + 3z2 + z3 , 1 + 4z + 3x2 , 1 +
4z + 2z2 , 1 + 5z + 5z2 and 1 + 5z + 4z2 + z3 , respectively.
(b) Given a vertex u 2 G, let G\u be G with u (and its incident edges) deleted,
and let G u be G with u and all the vertices adjacent to u deleted. Then fG (z) =
fG\u (z) + z fG u .
164 Solutions to exercises
The proof of Lemma 4.2.1 generalizes routinely: for instance, deleting u and its
adjacent vertices defines a bijection between non-attacking placements of k rooks
on G with a rook on u and non-attacking placements of k 1 rooks on G u.
(c) Suppose that G can be partitioned into subsets H and H 0 so that no vertex in
H is adjacent to a vertex of H 0 . Then rk (G) = Âk`=0 r` (H)rk ` (H 0 ) and fG (z) =
fH (z) fH 0 (z).
The proof of Lemma 4.2.2 generalizes almost word-for-word; again this is a special
case of Theorem 8.0.1.
(d) Applying (b) to vertex u we define the graphs G\u and G u shown below.
• • • •
• • • • • •
• • • •
· · R · R R · R R
If there is a rook on u (and so no rook on t or v), remove this rook to get a non-
attacking placement on G//u; if there are rooks on both t and v (and so no rook
on u), remove both these rooks and put a rook on the vertex, u0 say, identifying t
and v in G//u. Since there were rooks on t and v, the new placement on G//u is
non-attacking. As seen in the table on the right above, in both cases the number of
rooks is reduced by one.
It is clear from the tables that this procedure is bijective, therefore
fG (z) = fG/u (z) + z fG//u (z)
as required.
(f) Let G(B) have vertices all boxes (i, j) 2 G and edges between all two boxes in
the same row or column. Then non-attacking placements of k rooks on B are in
Solutions to exercises 165
(h) (?) As a hint, part of the argument for (g) generalizes to show that each vertex
is in at most two non-trivial cliques.
= F(z/t)F(zt)
where the final step uses that F(z) is the specialization of Polyá’s Cycle Index
j
Formula by setting x1 = 0 and x j = 1 for j 2 N, and so F(w) = ’•j=1 exp wj . By
166 Solutions to exercises
(c) This follows from (a): note that formally replacing t 0 + t 0 with u0 = 2 is cor-
rect, but this means that the zeroth power t 0 is replaced with v0 = 1.
n
(d) Since F(w) = • w
n=0 dn n! , we have
• n ✓ ◆
n zn
F(z/t)F(zt) = Â Â d` dn ` ` t n 2`
n!
.
n=0 `=0
Introduction
Whitehead: “Combinatorics is the slums of topology” is reported in Combinatorics
entering the third millennium, Peter J. Cameron, fourth draft, September 2011,
www.maths.qmul.ac.uk/~pjc/preprints/histcomb.pdf.
Gelfand: “The older I get, the more I believe that at the bottom of most deep
mathematical problems there is a combinatorial problem.”, lecture to Courant In-
stitute (1990), as reported in www-history.mcs.st-and.ac.uk/Quotations/
Gelfand.html.
1. Derangements
Exercise 1.11: the misattribution of Burnside’s Lemma is discussed in Peter M. Neu-
mann, A lemma that is not Burnside’s, The Mathematical Scientist, 4 (1979) 133–
141.
Exercise 1.14, Amer. Math. Monthly 118 (2011) 463, Problem 11573, proposed by
Rob Pratt, SAS Institute, Cary, NC.
2. Binomial coefficients
Al-Karaji: www-history.mcs.st-and.ac.uk/Biographies/Al-Karaji.html.
Exercise 2.10: Graham et al. (1994) (5.18).
Exercise 2.15(a): Jennifer J. Quinn, Tonight! Epic math battles: counting vs. match-
ing, Math Horizon (February 2015).
Exercise 2.22: A. C. Dixon, On the sum of the cubes of the coefficients in a certain
expansion by the binomial theorem, Messenger of Mathematics 20 (1891) 79–80.
168 End notes
4. Rook Polynomials
The exposition of the Problème des Ménages and Exercise 4.14 are based on Chap-
ter 8 of Riordan (2002). The formula for the number of 3 ⇥ n Latin rectangles in
Exercise 4.17 [which will be part of the text in §9.4] was first proved by Riordan
in Riordan (1946).
C. Solutions to exercises
Clay tokens, early numeracy and literacy: http://sites.utexas.edu/dsb/tokens/
tokens-and-writing-the-cognitive-development/.
Figure A.1.1: https://commons.wikimedia.org/wiki/File:Clay_accounting_
tokens_Susa_Louvre_n2.jpg, public domain.
References