0% found this document useful (0 votes)
167 views222 pages

Wagner Notes-1

This document introduces the topic of enumeration in combinatorics. It discusses counting problems involving choices, lists, permutations, subsets and multisets. The document covers basic principles like inclusion-exclusion and generating functions. It provides examples like derangements, poker hands and the birthday problem. The overall document introduces foundational concepts in enumeration.

Uploaded by

jdn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
167 views222 pages

Wagner Notes-1

This document introduces the topic of enumeration in combinatorics. It discusses counting problems involving choices, lists, permutations, subsets and multisets. The document covers basic principles like inclusion-exclusion and generating functions. It provides examples like derangements, poker hands and the birthday problem. The overall document introduces foundational concepts in enumeration.

Uploaded by

jdn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 222

MATH 239/249

Introduction to Combinatorics
Hello World, and Thanks!


c 2022 David G. Wagner
Department of Combinatorics and Optimization
Faculty of Mathematics
University of Waterloo
Contents

I Introduction to Enumeration 9

1 Basic Principles of Enumeration. 13


1.1 The Essential Ideas. . . . . . . . . . . . . . . . . . . . . . . . . . 13
1.1.1 Choices – “AND” versus “OR”. . . . . . . . . . . . . . . 13
1.1.2 Lists, permutations, and subsets. . . . . . . . . . . . . . 15
1.1.3 Think of what the numbers mean. . . . . . . . . . . . . 18
1.1.4 Multisets. . . . . . . . . . . . . . . . . . . . . . . . . . . 20
1.1.5 Bijective proofs. . . . . . . . . . . . . . . . . . . . . . . . 21
1.1.6 Inclusion/Exclusion. . . . . . . . . . . . . . . . . . . . . 24
1.1.7 Combinatorial probabilities. . . . . . . . . . . . . . . . . 27
1.2 Examples and Applications. . . . . . . . . . . . . . . . . . . . . 28
1.2.1 The Vandermonde convolution formula. . . . . . . . . 28
1.2.2 Common birthdays. . . . . . . . . . . . . . . . . . . . . 29
1.2.3 An example with multisets. . . . . . . . . . . . . . . . . 31
1.2.4 Poker hands. . . . . . . . . . . . . . . . . . . . . . . . . 34
1.2.5 Derangements. . . . . . . . . . . . . . . . . . . . . . . . 36
1.3 Exercises. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

2 The Idea of Generating Series. 45


2.1 The Binomial Theorem and Binomial Series. . . . . . . . . . . . 46

3
2.2 The Theory in General. . . . . . . . . . . . . . . . . . . . . . . . 49
2.2.1 Generating series. . . . . . . . . . . . . . . . . . . . . . . 50
2.2.2 The Sum, Product, and String Lemmas. . . . . . . . . . 52
2.3 Compositions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
2.4 Subsets with Restrictions. . . . . . . . . . . . . . . . . . . . . . 60
2.5 Proof of Inclusion/Exclusion. . . . . . . . . . . . . . . . . . . . 63
2.6 Exercises. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65

3 Binary Strings. 71
3.1 Regular Expressions and Rational Languages. . . . . . . . . . 72
3.2 Unambiguous Expressions. . . . . . . . . . . . . . . . . . . . . 75
3.2.1 Translation into generating series. . . . . . . . . . . . . 76
3.2.2 Block decompositions. . . . . . . . . . . . . . . . . . . . 77
3.2.3 Prefix decompositions. . . . . . . . . . . . . . . . . . . . 80
3.3 Recursive Decompositions. . . . . . . . . . . . . . . . . . . . . 81
3.3.1 Excluded substrings. . . . . . . . . . . . . . . . . . . . . 82
3.4 Exercises. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85

4 Recurrence Relations. 91
4.1 Fibonacci Numbers. . . . . . . . . . . . . . . . . . . . . . . . . . 91
4.2 Homogeneous Linear Recurrence Relations. . . . . . . . . . . . 94
4.3 Partial Fractions. . . . . . . . . . . . . . . . . . . . . . . . . . . 99
4.3.1 The Main Theorem. . . . . . . . . . . . . . . . . . . . . . 103
4.3.2 Inhomogeneous Linear Recurrence Relations. . . . . . 105
4.4 Quadratic Recurrence Relations. . . . . . . . . . . . . . . . . . 108
4.4.1 The general binomial series. . . . . . . . . . . . . . . . . 109
4.4.2 Catalan numbers. . . . . . . . . . . . . . . . . . . . . . . 110
4.5 Exercises. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
II Introduction to Graph Theory 117

5 Graphs and Isomorphism. 121


5.1 Graphs. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
5.2 The Handshake Lemma. . . . . . . . . . . . . . . . . . . . . . . 122
5.3 Examples. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
5.4 Isomorphism. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
5.5 Some more Basic Concepts. . . . . . . . . . . . . . . . . . . . . 134
5.6 Multigraphs and Directed Graphs. . . . . . . . . . . . . . . . . 138
5.7 Exercises. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139

6 Walks, Paths, and Connectedness. 145


6.1 Walks, Trails, Paths, and Cycles. . . . . . . . . . . . . . . . . . . 145
6.2 Connectedness. . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
6.3 Euler Tours. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
6.4 Bridges / Cut-edges. . . . . . . . . . . . . . . . . . . . . . . . . 156
6.5 Exercises. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158

7 Trees. 163
7.1 Trees and Minimally Connected Graphs. . . . . . . . . . . . . . 163
7.2 Spanning Trees and Connectedness. . . . . . . . . . . . . . . . 166
7.3 Search Trees. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
7.4 Exercises. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174

8 Planar Graphs. 177


8.1 Plane Embeddings of Graphs. . . . . . . . . . . . . . . . . . . . 177
8.1.1 Stereographic projection. . . . . . . . . . . . . . . . . . 180
8.2 Kuratowski’s Theorem. . . . . . . . . . . . . . . . . . . . . . . . 181
8.3 Numerology of Planar Graphs. . . . . . . . . . . . . . . . . . . 183
8.3.1 The “Faceshaking” Lemma. . . . . . . . . . . . . . . . . 183
8.3.2 Euler’s Formula. . . . . . . . . . . . . . . . . . . . . . . 185
8.3.3 The Platonic solids. . . . . . . . . . . . . . . . . . . . . . 188
8.4 Planar Duality. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
8.5 Exercises. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194

9 Graph Colouring. 199


9.1 Chromatic Number. . . . . . . . . . . . . . . . . . . . . . . . . . 199
9.2 Colouring Planar Graphs. . . . . . . . . . . . . . . . . . . . . . 203
9.2.1 The Four Colour Theorem. . . . . . . . . . . . . . . . . 203
9.2.2 The Five Colour Theorem. . . . . . . . . . . . . . . . . . 203
9.3 Chromatic Number versus Girth. . . . . . . . . . . . . . . . . . 206
9.4 Exercises. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207

10 Bipartite Matching. 209


10.1 Matchings and Covers. . . . . . . . . . . . . . . . . . . . . . . . 210
10.2 König’s Theorem. . . . . . . . . . . . . . . . . . . . . . . . . . . 212
10.2.1 Anatomy of a bipartite matching. . . . . . . . . . . . . . 213
10.2.2 A bipartite matching algorithm. . . . . . . . . . . . . . 215
10.3 Hall’s Theorem. . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
10.4 Exercises. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218
Preliminaries.

MATH 239 is an introduction to two of the main areas in combinatorics –


enumeration and graph theory. MATH 249 is an advanced version of MATH
239 intended for very strong students. These courses are designed for stu-
dents in the second year of an undergraduate program in mathematics or
computer science.
The prerequisites required from first-year mathematics are as follows.
• From MATH 135. Abstract algebra I: sets and propositional logic, proofs,
mathematical induction, modular arithmetic, complex numbers, the
Fundamental Theorem of Algebra.
• From MATH 136. Linear algebra I: systems of linear equations, Gaus-
sian elimination, matrix algebra, vector spaces.
• From MATH 137. Calculus I: algebra with power series, open/closed
sets, continuous functions, differentiation (but not integration).
We use the following standard notation for various number systems.

natural numbers N = {0, 1, 2, 3, ...} including zero 0


integers Z = {..., −2, −1, 0, 1, 2, ...}
rational numbers Q
real numbers R
complex numbers C
integers (modulo n) Zn = {[0], [1], [2], ..., [n − 1]}
finite field of prime size Fp = Zp

The cardinality (size) of a set S is denoted by |S|.


For convenience, we use LHS and RHS as shorthand for “left-hand side”
and “right-hand side”, respectively.

7
Part I

Introduction to Enumeration

9
Overview.

Suppose I pay $5 for a lottery ticket – what is the chance that I win a share
of the top prize? It depends on the details, of course. There are a certain
number of ways to win, and a certain number of ways to lose. Enumeration
is the art and science of figuring out this kind of thing. This is the subject of
the first part of these course notes.
There are two broad principles of the subject. The combinatorial ap-
proach is to construct explicit one-to-one correspondences between sets to
show that they have the same size. The algebraic approach is to translate the
information about the problem from combinatorics into algebra, and then to
use algebraic techniques to determine the sizes of the sets. We will see many
examples of both approaches.
In Chapter 1 we begin by introducing the basic building blocks of the the-
ory: subsets, lists and permutations, multisets, binomial coefficients, and so
on. In Section 1.2 the use of these objects is illustrated by analyzing various
applications and examples.
In Chapter 2 we introduce the idea of generating series. This begins with
the Binomial Theorem and Binomial Series, which are of fundamental im-
portance for later results. The general theory of generating series is devel-
oped in Section 2.2, and its use is illustrated by analyzing “compositions”
in Section 2.3.
In Chapter 3 we consider the enumeration of various sets of binary strings,
namely those which can be described by regular expressions – the “rational
languages”. This provides an interesting and varied class of examples to
which the results of Chapters 2 and 4 apply.
In Chapter 4 we consider sequences which satisfy a homogeneous linear
recurrence relation with initial conditions, the sequences arising in Chapters

11
2 and 3 being examples. This technique allows us to calculate the numbers
which answer the various counting problems we have been considering.
By using Partial Fractions we can derive an even better solution to such
problems, although the calculations involved are also more complicated.
(We include a proof of Partial Fractions for completeness.) In Section 4.4 we
briefly discuss recurrence relations which are quadratic rather than linear.
Two additional topics are discussed in Chapters ?? and ??.
Chapter 1

Basic Principles of Enumeration.

1.1 The Essential Ideas.

1.1.1 Choices – “AND” versus “OR”.

In the next few pages we will often be constructing an object of some kind
by repeatedly making a sequence of choices. In order to count the total
number of objects we could construct we must know how many choices are
available at each step, but we must know more: we also need to know how to
combine these numbers correctly. A generally good guideline is to look for
the words “AND” and “OR” in the description of the sequence of choices
available. Here are a few simple examples.

Example 1.1. On a table before you are 7 apples, 8 oranges, and 5 ba-
nanas.
• Choose an apple and a banana.
There are 7 choices for an apple AND 5 choices for a banana: 7×5 =
35 choices in all.
• Choose an apple or an orange.
There are 7 choices for an apple OR 8 choices for an orange: 7 + 8 =
15 choices in all.
• Choose an apple and either an orange or a banana.
There are 7 × (8 + 5) = 91 possible choices.

13
14 Basic Principles. Section 1.1

• Choose either an apple and an orange, or a banana.


There are (7 × 8) + 5 = 61 possible choices.
Generally, “AND” corresponds to multiplication and “OR” corresponds
to addition. The last two of the above examples show that it is important
to determine exactly how the words “AND” and “OR” combine in the de-
scription of the problem.
From a mathematical point of view, “AND” corresponds to the Cartesian
product of sets. If you choose one element of the set A AND you choose one
element of the set B, then this is equivalent to choosing one element of the
Cartesian product of A and B:

A × B = {(a, b) : a ∈ A and b ∈ B},

which is the set of all ordered pairs of elements (a, b) with a ∈ A and b ∈ B.
In general, the cardinalities of these sets are related by the formula

|A × B| = |A| · |B|.

Similarly, from a mathematical point of view, “OR” corresponds to the


union of sets. If you choose one element of the set A OR you choose one
element of the set B, then this is equivalent to choosing one element of the
union of A and B:

A ∪ B = {c : c ∈ A or c ∈ B},

which is the set of all elements c which are either in A or in B.


It is not always true that |A ∪ B| = |A| + |B|, because any elements in both
A and B would be counted twice by |A| + |B|. The intersection of A and B
is the set
A ∩ B = {c : c ∈ A and c ∈ B},
which is the set of all elements c which are both in A and in B. What is
generally true is that

|A ∪ B| = |A| + |B| − |A ∩ B|.

(This is the first instance of the Principle of Inclusion/Exclusion, which will


be discussed in general in Subsection 1.1.6.) In particular, if A ∩ B = ∅
then |A ∪ B| = |A| + |B|. Thus, in order to interpret “OR” as addition, it
Section 1.1 Basic Principles. 15

is important to check that the sets of choices A and B have no elements in


common. Such a union of sets A and B for which A ∩ B = ∅ is called a
disjoint union of sets.
When solving enumeration problems it is usually very useful to describe
a choice sequence for constructing the set of objects of interest, paying close
attention to the words “AND” and “OR”.

1.1.2 Lists, permutations, and subsets.

A list of a set S is a list of the elements of S exactly once each, in some


order. For example, the lists of the set {1, a, X, g} are:
1aXg a1Xg X1ag g1aX
1agX a1gX X1ga g1Xa
1Xag aX1g Xa1g ga1X
1Xga aXg1 Xag1 gaX1
1gaX ag1X Xg1a gX1a
1gXa agX1 Xga1 gXa1
A permutation is a list of the set {1, 2, ..., n} for some n ∈ N. A per-
mutation σ : a1 a2 ...an can be interpreted as a function σ : {1, 2, ..., n} →
{1, 2, ..., n} by putting σ(i) = ai for all 1 ≤ i ≤ n.
To construct a list of S we can choose any element v of S to be the first
element in the list and follow this with any list of the set S r {v}. That is
how the table above is arranged – each of the four columns corresponds
to one choice of an element of {1, a, X, g} to be the first element of the list.
Within each column, all the lists of the remaining elements appear after the
first element.
Let pn denote the number of lists of an n-element set S. The first sentence
of the previous paragraph is translated into the equation

pn = n · pn−1 ,

provided that n is positive. (In this equation there are n choices for the first
element v of the list, AND pn−1 choices for the list of S r {v} which follows
it.) It is important to note here that each list of S will be produced exactly
once by this construction.
16 Basic Principles. Section 1.1

Since it is easy to see that p1 = 1 (and p2 = 2), a simple proof by induction


on n shows the following:

Theorem 1.2. For every n ≥ 1, the number of lists of an n-element set S is

n(n − 1)(n − 2) · · · 3 · 2 · 1.

In particular, taking S = {1, 2, ..., n}, this is the number of permutations of


size n. The term n factorial is used for the number n(n − 1) · · · 3 · 2 · 1, and it
is denoted by n! for convenience. We also define 0! to be the number of lists
of the 0-element (empty) set ∅. Since we want the equation pn = n · pn−1 to
hold when n = 1, and since p1 = 1! = 1, we conclude that 0! = p0 = 1 as
well.
A subset of a set S is a collection of some (perhaps none or all) of the
elements of S, at most once each and in no particular order.
To specify a particular subset A of S, one has to decide for each element v
of S whether v is in A or v is not in A. Thus we have two choices – v ∈ A OR
v 6∈ A – for each element v of S. If S = {v1 , v2 , ..., vn } has n elements then the
total number of choices is 2n since we have 2 choices for v1 AND 2 choices
for v2 AND . . . AND 2 choices for vn .

Theorem 1.3. For every n ≥ 0, the number of subsets of an n-element set


is 2n .

A partial list of a set S is a list of a subset of S. That is, it is a list of some


(perhaps none or all) of the elements of S, at most once each and listed in
some particular order. We are going to count partial lists of length k of an
n-element set.
First think about the particular case n = 6 and k = 3, and the set S =
{a, b, c, d, e, f }. A partial list of S of length 3 is a list xyz of elements of S,
which must all be different. There are:
6 choices for x (since x is in S), AND
5 choices for y (since y ∈ S but y 6= x), AND
4 choices for z (since z ∈ S but z 6= x and z 6= y).
Altogether there are 6 · 5 · 4 = 120 partial lists of {a, b, c, d, e, f } of length 3.
Section 1.1 Basic Principles. 17

This kind of reasoning works just as well in the general case. If S is an


n-element set and we want to construct a partial list v1 v2 ...vk of elements of
S of length k, then there are:
n choices for v1 , AND
n − 1 choices for v2 , AND
....
n − (k − 2) choices for vk−1 , AND
n − (k − 1) choices for vk .
This proves the following result.

Theorem 1.4. For n, k ≥ 0, the number of partial lists of length k of an


n-element set is n(n − 1) · · · (n − k + 2)(n − k + 1).

Notice that if k > n then the number 0 will appear as one of the factors in
the product n(n − 1) · · · (n − k + 2)(n − k + 1). This makes sense, because if
k > n then there are no partial lists of length k of an n-element set. On the
other hand, if 0 ≤ k ≤ n then we could also write this product as

n!
n(n − 1) · · · (n − k + 2)(n − k + 1) = .
(n − k)!

We next count subsets of an n-element set S which have a particular size


k. So for n, k ≥ 0 let nk denote the number of k-element subsets of an n-


element set S. Notice that if k < 0 or k > n then nk = 0 because in these




cases it is impossible for S to have a k-element subset. Thus we need only


consider k in the range 0 ≤ k ≤ n.
To count k-element subsets of S we consider another way of constructing
a partial list of length k of S. Specifically, we can choose a k-element subset
A of S AND a list of A. The result will be a list of a subset of S of length
k. Since every partial list of length k of S is constructed exactly once in this
way, this translates into the equation
 
n n!
· k! = .
k (n − k)!
18 Basic Principles. Section 1.1

In summary, we have proved the following result.

Theorem 1.5. For 0 ≤ k ≤ n, the number of k-element subsets of an n-


element set is  
n n!
= .
k k!(n − k)!

n

The numbers k
are read as “n choose k” and are called binomial coefficients .

1.1.3 Think of what the numbers mean.

Usually, when faced with a formula to prove, one’s first thought is to prove
it by algebraic calculations, or perhaps with an induction argument, or maybe
with a combination of the two. But often that is not the easiest way, nor is
it the most informative. A much better strategy is one which gives some in-
sight into the meaning of all of the parts of the formula. If we can interpret
all the numbers as counting things, addition as “OR”, and multiplication
as “AND”, then we can hope to find an explanation of the formula by con-
structing some objects in the correct way.

Example 1.6. Consider the equation, for any n ≥ 0:


       
n n n n
+ + + ··· + = 2n .
0 1 2 n

This could be proved by induction on n, but many more details would


have to be given and the proof would not address the true “meaning” of
the formula. Instead, let’s interpret everything combinatorially:
• the number of subsets of the n-element set {1, 2, ..., n} is 2n ;
• for each 0 ≤ k ≤ n, the number of k-element subsets of {1, 2, ..., n}
is nk ;


• addition corresponds to “OR” (that is, disjoint union of sets).


So, this formula is saying that choosing a subset of {1, 2, ..., n} (in one of
2n ways) is equivalent to choosing a k-element subset of {1, 2, ..., n} (in
one of nk ways) for exactly one value of k in the range 0 ≤ k ≤ n. Said


that way the formula becomes self–evident, and there is nothing more
to prove.
Section 1.1 Basic Principles. 19

Example 1.7. Consider the equation


     
n n−1 n−1
= +
k k−1 k

where we are using the fact that mj = 0 if j < 0 or j > m.




This equation can be proven algebraically from the formula of Theo-


rem 1.5, and that is a good exercise which I encourage you to try. But
a more informative proof interprets these numbers combinatorially as
follows:
• nk is the number of k-element subsets of {1, 2, ..., n};


• n−1

k−1 
is the number of (k − 1)-element subsets of {1, 2, ..., n − 1};
n−1
• k is the number of k-element subsets of {1, 2, ..., n − 1};
• addition corresponds to disjoint union of sets.
So, this equation is saying that choosing a k-element subset A of {1, 2, ..., n}
is equivalent to either choosing a (k −1)-element subset of {1, 2, ..., n−1}
or a k-element subset of {1, 2, ..., n − 1}. This is perhaps not as clear as
the previous example, but the two cases depend upon whether the cho-
sen k-element subset A of {1, 2, ..., n} is such that n ∈ A OR n 6∈ A. If
n ∈ A then A r {n} is a (k − 1)-element subset of {1, 2, ..., n − 1}, while if
n 6∈ A then A is a k-element subset of {1, 2, ..., n − 1}. This construction
explains the correspondence, proving the formula.

This principle – interpreting equations combinatorially and proving the


formulas by describing explicit correspondences between sets of objects –
is one of the most important and powerful ideas in enumeration. We will
apply this way of thinking throughout the first part of these notes.
Incidentally, the equation in Example 1.7 is a very useful recurrence rela-
tion for computing binomial coefficients quickly. Together with the facts

   
n n! n! n
= = =
k k!(n − k)! (n − k)!(n − (n − k))! n−k

n n
 
and 0
= n
= 1 it can be used to compute any number of binomial coeffi-
20 Basic Principles. Section 1.1

cients without difficulty. The resulting table is known as Pascal’s Triangle :

n\k 0 1 2 3 4 5 6 7 8
0 1
1 1 1
2 1 2 1
3 1 3 3 1
4 1 4 6 4 1
5 1 5 10 10 5 1
6 1 6 15 20 15 6 1
7 1 7 21 35 35 21 7 1
8 1 8 28 56 70 56 28 8 1

1.1.4 Multisets.

Imagine a bag which contains a large number of marbles of three colours


– red, green, and blue, say. The marbles are all indistinguishable from one
another except for their colours. There are N marbles of each colour, where
N is very, very large (more precisely we should be considering the limit
as N → ∞). If I reach into the bag and pull out a handful of 11 marbles,
I will have r red marbles, g green marbles, and b blue marbles, for some
nonnegative integers (r, g, b) such that r + g + b = 11. How many possibile
outcomes are there?
The word “multiset” is meant to suggest a set in which the objects can oc-
cur more than once. For example, the outcome (4, 5, 2) in the above situation
corresponds to the “set” {R, R, R, R, G, G, G, G, G, B, B} in which R is a red
marble, G is a green marble, and B is a blue marble. This is an 11-element
multiset with elements of three types. The number of these multisets is the
solution to the above problem.

Definition 1.8. Let n ≥ 0 and t ≥ 1 be integers. A multiset of size n with


elements of t types is a sequence of nonnegative integers (m1 , ..., mt )
such that
m1 + m2 + · · · + mt = n.

The interpretation is that mi is the number of elements of the multiset which


are of the i-th type, for each 1 ≤ i ≤ t.
Section 1.1 Basic Principles. 21

Theorem 1.9. For any n ≥ 0 and t ≥ 1, the number of n-element multisets


with elements of t types is
 
n+t−1
.
t−1

Proof. Think of what that number means! By Theorem 1.5, n+t−1



t−1
is the
number of (t − 1)-element subsets of an (n + t − 1)-element set. So, let’s
write down a row of (n + t − 1) circles from left to right:

O O O O O O O O O O O O O
and cross out some t − 1 of these circles to choose a (t − 1)-element subset:

O O O O X O O O O O X O O

Now the t − 1 crosses chop the remaining sequence of n circles into t seg-
ments of consecutive circles. (Some of these segments might be empty,
which is to say of length zero.) Let mi be the length of the i-th segment
of consecutive O-s in this construction. Then m1 + m2 + · · · + mt = n, so
that (m1 , m2 , ..., mt ) is an n-element multiset with t types. Conversely, if
(m1 , m2 , ..., mt ) is an n-element multiset with t types then write down a se-
quence of m1 O-s, then an X, then m2 O-s, then an X, and so on, finishing
with an X and then mt O-s. The positions of the X-s will indicate a (t − 1)-
element subset of the positions {1, 2, ..., n + t − 1}.
The construction of the above paragraph shows how to translate between
(t − 1)-element subsets of {1, 2, ..., n + t − 1} and n-element multisets with
t types of element. This one–to–one correspondence completes the proof of
the theorem.

To answer the original question of this section, the number of 11-element


multisets with elements of 3 types is 11+3−1 = 13
 
3−1 2
= 78.

1.1.5 Bijective proofs.

The arguments above, counting lists, permutations, subsets, multisets, and


so on, can be phrased more formally using the idea of bijections between
22 Basic Principles. Section 1.1

finite sets. In simple cases as we have seen so far this is not always neces-
sary, but it is good style. In more complicated situations, as we will see in
Chapters 2 to 4, it is a very useful way to organize one’s thoughts.

Definition 1.10. Let f : A → B be a function from a set A to a set B.


• The function f is surjective if for every b ∈ B there exists an a ∈ A
such that f (a) = b.
• The function f is injective if for every a, a0 ∈ A, if f (a) = f (a0 ),
then a = a0 .
• The function f is bijective if it is both surjective and injective.
• The notation A
B indicates that there is a bijection between
the sets A and B.

Functions with these properties are called surjections, injections, or bijec-


tions, respectively. An older terminology – now out of fashion – is that
surjections are “onto” functions, injections are “one-to-one” functions, and
bijections are “one-to-one and onto”. By Exercise 1.4(a), the relation
is
an equivalence relation.
The point of Definition 1.10 is the following. Consider a bijection f : A →
B. Then every b ∈ B is the image of at least one a ∈ A, since f is surjective.
On the other hand, every b ∈ B is the image of at most one a ∈ A, since f
is injective. Therefore, every b ∈ B is the image of exactly one a ∈ A. In
other words, the relation f (a) = b pairs off all the elements of A with all the
elements of B. It follows that A and B have the same number of elements.
That is, if A
B then |A| = |B|. The converse implication holds, and for
infinite sets the relation A
B is taken as the definition of two sets “having
the same size”.

Proposition 1.11. Let f : A → B and g : B → A be functions between


two sets A and B. Assume the following.
• For all a ∈ A, g(f (a)) = a.
• For all b ∈ B, f (g(b)) = b.
Then both f and g are bijections. Moreover, for a ∈ A and b ∈ B, we have
f (a) = b if and only if g(b) = a.

Proof. Exercise 1.4(b).


Section 1.1 Basic Principles. 23

A pair of functions as in Proposition 1.11 are called mutually inverse bijections .


The notation g = f −1 and f = g −1 is used to denote this relation. Notice that
for a bijection f , we have (f −1 )−1 = f .
Here are two examples of this way of thinking.

Example 1.12 (Subsets and indicator vectors.). Let P(n) be the set of all
subsets of {1, 2, ..., n}, and let {0, 1}n be the set of all indicator vectors
α = (a1 , a2 , ..., an ) in which each coordinate is either 0 or 1. There is a
bijection between these two sets. For a subset S ⊆ {1, 2, ..., n}, define the
vector α(S) = (a1 (S), a2 (S), ..., an (S)) by saying that for each 1 ≤ i ≤ n,

1 if i ∈ S,
ai (S) =
0 if i 6∈ S.

Conversely, for an indicator vector α = (a1 , ..., an ) define a subset S(α)


by saying that
S(α) = {i ∈ {1, 2, ..., n} : ai = 1}.
For example, when n = 8 the subset {2, 3, 5, 7} corresponds to the indica-
tor vector (0, 1, 1, 0, 1, 0, 1, 0). The constructions S 7→ α(S) and α 7→ S(α)
are mutually inverse bijections between the sets P(n) and {0, 1}n as in
Proposition 1.11. It follows that |P(n)| = |{0, 1}n | = 2n . This is a formal-
ization of the proof of Theorem 1.3.

Example 1.13 (Subsets and multisets.). The proof of Theorem 1.9 can be
phrased in terms of bijections, as follows.
Let M(n, t) be the set of all multisets of size n ∈ N with elements of t ≥
1 types. Let B(a, k) be the set of all k-element subsets of {1, 2, ..., a}. We
establish a bijection between M(n, t) and B(n+t−1, t−1) in what follows.
Theorem 1.5 implies that |B(n + t − 1, t − 1)| = n+t−1

t−1
, completing the
proof of Theorem 1.9. Here is a precise description of this bijection.
Let S be any (t − 1)-element subset of {1, 2, ..., n + t − 1}. We can sort
the elements of S in increasing order: S = {s1 , s2 , ..., st−1 } in which s1 <
s2 < · · · < st−1 . For notational convenience, let s0 = 0 and let st = n + t.
Now define a sequence µ = (m1 , m2 , ..., mt ) by letting mi = si − si−1 − 1
for all 1 ≤ i ≤ t.
24 Basic Principles. Section 1.1

For example, with n = 10 and t = 4, consider the 3-element subset


S = {2, 7, 11} of {1, 2, ..., 13}. Then s0 < s1 < · · · < st is 0 < 2 < 7 < 11 <
14, the sequence of differences is (2, 5, 4, 3), and subtracting 1 from each
of these yields µ = (1, 4, 3, 2). Notice that µ is a multiset of size 10 with 4
types of elements.
In general, since si−1 < si for all 1 ≤ i ≤ t, it follows that mi =
si − si−1 − 1 is a nonnegative integer. Also, since st = n + t, it follows
that m1 + m2 + · · · + mt = st − t = n. That is, µ is a multiset of size
n with elements of t types. This describes a function S 7→ µ from the
set B(n + t − 1, t − 1) to the set M(n, t). We claim that this function is a
bijection between these two sets.
To show that our construction S 7→ µ is a bijection, we will describe its
inverse function. Begin with a multiset µ = (m1 , m2 , ..., mt ) of size n with
t types of elements. For each 1 ≤ i ≤ t − 1, let si = m1 + m2 + · · · + mi + i.
Notice that
1 ≤ s1 < s2 < · · · < st−1 ≤ n + t − 1.
Therefore, S = {s1 , s2 , ..., st−1 } is a member of the set B(n + t − 1, t − 1).
To finish this example, one must check that these constructions, S 7→ µ
and µ 7→ S, are mutually inverse bijections as in Proposition 1.11. The
details are left as Exercise 1.6.

1.1.6 Inclusion/Exclusion.

In a vase is a bouquet of flowers. Each flower is (at least one of) fresh,
fragrant, or colourful:
(a) 11 flowers are fresh;
(b) 7 flowers are fragrant;
(c) 8 flowers are colourful;
(d) 6 flowers are fresh and fragrant;
(e) 5 flowers are fresh and colourful;
(f) 2 flowers are fragrant and colourful;
(g) 2 flowers are fresh, fragrant, and colourful.
How many flowers are in the bouquet?
The Principle of Inclusion/Exclusion is a systematic method for answer-
ing such questions, which involve overlapping conditions which can be sat-
Section 1.1 Basic Principles. 25

colourful

fresh fragrant

Figure 1.1: A Venn diagram for three sets.

isfied (or not) in various combinations.

Example 1.14. For a small problem as above we can reason backwards


as follows:
(g): there are 2 flowers with all three properties (fresh, fragrant, and
colourful);
(h): from (g) and (f) there are 0 flowers which are fragrant and colourful
but not fresh;
(i): from (g) and (e) there are 3 flowers which are fresh and colourful but
not fragrant;
(j): from (g) and (d) there are 4 flowers which are fresh and fragrant but
not colourful;
(k): from (c)(g)(h)(i) there are 3 flowers which are colourful but neither
fresh not fragrant;
(`): from (b)(g)(h)(j) there is 1 flower which is fragrant but neither fresh
nor colourful;
(m): from (a)(g)(i)(j) there are 2 flowers which are fresh but neither fra-
grant nor colourful.
The total number of flowers is counted by the disjoint union of the
cases (g) through (m); that is 2 + 0 + 3 + 4 + 3 + 1 + 2 = 15.

A Venn diagram is extremely useful for organizing this calculation. Figure


1.1 is a Venn diagram for the three sets involved in this question. Item (g) in
26 Basic Principles. Section 1.1

Figure 1.2: A Venn diagram for four sets.

the original data gives the number of flowers counted in the central trian-
gle. The subsequent steps (h) to (m) calculate the rest of the numbers in the
diagram, moving outwards from the center.
The above works very well for three properties (fresh, fragrant, colour-
ful) but becomes increasingly difficult to apply as the number of properties
increases. Figure 1.2 shows a Venn diagram for four sets, for instance. In-
stead, consider this alternative to the calculation in Example 1.14:

(a) + (b) + (c) − (d) − (e) − (f ) + (g) = 11 + 7 + 8 − 6 − 5 − 2 + 2 = 15.

This looks much easier to apply, and it gives the right answer. Why? That
is the Principle of Inclusion/Exclusion, which we now explain in general.
Let A1 , A2 , ..., Am be finite sets. We want a formula for the cardinality of
the union of these sets A1 ∪ A2 ∪ · · · ∪ Am . First a bit of notation: if S is a
nonempty subset of {1, 2, ..., m} then let AS denote the intersection of the
sets Ai for all i ∈ S. So, for example, with this notation we have A{2,3,5} =
A2 ∩ A3 ∩ A5 .

Theorem 1.15 (Inclusion/Exclusion). Let A1 , A2 ,..., Am be finite sets.


Then X
|A1 ∪ A2 ∪ · · · ∪ Am | = (−1)|S|−1 |AS |.
∅6=S⊆{1,...,m}
Section 1.1 Basic Principles. 27

We prove Theorem 1.15 in Section 2.5, but all that is required is the Binomial
Theorem 2.2.

1.1.7 Combinatorial probabilities.

We can interpret counting problems in terms of probabilities by making one


additional hypothesis. That hypothesis is that every possible outcome is
equally likely. The exact definition of what is an “outcome” depends on
the particular problem. If Ω denotes a finite set of all possible outcomes,
then any subset E of Ω is what a probabilist calls an “event”. The probabil-
ity that a randomly chosen outcome from Ω is in the set E is |E|/|Ω| exactly
because every outcome has probability 1/|Ω| of being chosen, and there are
|E| elements in E. Here are a few examples to illustrate these ideas.

Example 1.16. What is the probability that a random subset of {1, 2, ..., 8}
has at most 3 elements?
Here an outcome is a subset of {1, 2, ..., 8}, and there are 28 = 256 such
subsets. The number of subsets of {1, 2, ..., 8} with at most 3 elements is
       
8 8 8 8
+ + + = 1 + 8 + 28 + 56 = 93.
0 1 2 3

So the probability in question is

93
= 0.363281...
256
to six decimal places.

Example 1.17. What is the probability that a random list of {a, b, c, d, e, f }


contains the letters f ad as a consecutive subsequence?
Here an outcome is a list of {a, b, c, d, e, f }, and there are 6! = 720 such
lists. Those lists of this set which contain f ad as a consecutive subse-
quence can be constructed uniquely as the lists of the set {b, c, e, f ad}, so
28 Basic Principles. Section 1.2

there are 4! = 24 of these. Thus, the probability in question is

24 1
= = 0.03333...
720 30

Example 1.18. What is the probability that a randomly chosen 2-element


multiset with t types of element has both elements of the same type?
The outcomes are the 2-element multisets with t types, numbering
     
2+t−1 t+1 t+1 (t + 1)t
= = =
t−1 t−1 2 2

in total. Of these, exactly t of them have both elements of the same type
– choose one of the t types and take two elements of that type. Thus, the
probability in question is

2t 2
= .
(t + 1)t t+1

The values for the first few t are given in the following table to four
decimal places:

t 1 2 3 4 5 6 7
1.0000 0.6667 0.5000 0.4000 0.3333 0.2857 0.2500

1.2 Examples and Applications.

1.2.1 The Vandermonde convolution formula.

Example 1.19 (Vandermonde convolution formula). For m, n, k ∈ N,


  X k   
m+n m n
= .
k j=0
j k−j

For instance, with m = 4 and n = 2 and k = 3 this says that


             
6 4 2 4 2 4 2 4 2
= + + + .
3 0 3 1 2 2 1 3 0
Section 1.2 Basic Principles. 29

2

(Of course, 3
= 0, but that doesn’t matter.)
The Vandermonde convolution formula can be proven algebraically by
induction on m + n, but the proof is finicky and doesn’t give much insight
into what the formula “means”. (The formula can also be deduced easily
from the Binomial Theorem ??, as we will see in Example 2.3.)
Here is a direct combinatorial proof, illustrating the strategy of thinking
about what the numbers mean. On the LHS, m+n

k
is the number of k-
element subsets S of the set {1, 2, ..., m + n}. On the RHS, the number can
be produced as follows:
• choose a value of j in the range 0 ≤ j ≤ k, and
• choose a j-element subset A of {1, 2, ..., m}, and
• choose a (k − j)-element subset B of {m + 1, ..., m + n}.
n

(Notice that the set {m + 1, ..., m + n} has n elements, so it has k−j subsets
of size k − j.) Now the formula is proved by describing a bijection between
the k-element subsets S of {1, 2, ..., m+n} counted on the LHS, and the pairs
(A, B) of subsets counted on the RHS. To describe this correspondence, let
M = {1, 2, ..., m} and N = {m + 1, ..., m + n}. Notice that M ∩ N = ∅ and
M ∪ N = {1, 2, ..., m + n} and |M | = m and |N | = n. Now, given a k-element
subset S of {1, 2, ..., m + n} we let

A = S ∩ M and B = S ∩ N.

Conversely, given a pair of subsets (A, B) satisfying the conditions in the


points above, we let S = A ∪ B. After some thought, you will see that
these constructions S 7→ (S ∩ M, S ∩ N ) and (A, B) 7→ A ∪ B are mutually
inverse bijections between the sets in question. Therefore, there are the same
number of objects on each side, and the formula is proved.

1.2.2 Common birthdays.

Example 1.20. Let p(n) denote the probability that in a randomly chosen
group of n people, at least two of them are born on the same day of the
year. What does the function p(n) look like?

To simplify the analysis, we will ignore the existence of leap years and as-
sume that every year has exactly 365 days. Moreover, we will also assume
30 Basic Principles. Section 1.2

that people’s birthdays are independently and uniformly distributed over


the 365 days of the year, so that we can use the ideas of combinatorial prob-
ability theory. These are reasonable approximations – although they intro-
duce tiny errors they do not change the qualitative “shape” of the answer.
To begin with, p(1) = 0 since there is only n = 1 person in the group.
Also, if n > 365 then p(n) = 1 since there are more people in the group
than days in a year, so at least two people in the group must have the same
birthday.
For n in the range 2 ≤ n ≤ 365 it is quite complicated to analyze the
probability p(n) directly. However, the complementary probability 1 − p(n)
is relatively easy to compute. From the definition of p(n) we see that 1−p(n)
is the probability that in a randomly chosen group of n people, no two of
them are born on the same day of the year. This model is equivalent to
rolling “no pair” when throwing n independent dice each with 365 sides. If
we list the people in the group as P1 , P2 , ..., Pn in any order, then their birth-
days must form a partial list of the 365 days of the year, of length n. There
are 365!/(365 − n)! such partial lists. Since the total number of outcomes is
365n , we have derived the formula
365!
1 − p(n) = .
(365 − n)!365n
Therefore
365!
p(n) = 1 − .
(365 − n)!365n
To give some feeling for what this looks like, here is a table of p(n) (rounded
to six decimal places) for selected values of 2 ≤ n ≤ 365.

n p(n) n p(n) n p(n)


2 0.002740 25 0.568700 70 0.999160
3 0.008204 30 0.706316 80 0.999914
4 0.016356 35 0.814383 100 1.
5 0.027136 40 0.891232 150 1.
10 0.116948 45 0.940976 200 1.
15 0.252901 50 0.970374 250 1.
20 0.411438 60 0.994123 300 1.

Figure 1.3 gives a graph of this function. It is a rather surprising fact that
p(23) = 0.507297, so that if you randomly choose a set of 23 people on earth
Section 1.2 Basic Principles. 31

Figure 1.3: The probability of a common birthday among n people.

then there is a slightly better than 50% chance that at least two of them will
have the same birthday. (Approximately – we have ignored leap years and
twins.)

1.2.3 An example with multisets.

Example 1.21. A packet of Maynard’s Wine Gums consists of a roll or


packet of 10 candies, each of which has one of five “flavours” – Green,
Yellow, Orange, Red, or Purple. I especially like the purple ones. What is
the chance that when I buy some Wine Gums there are exactly k purple
candies (for each 0 ≤ k ≤ 10)?

This example is designed to illustrate the fact that the probabilities depend
on which model is used to analyze the situation. There are two reasonable
possibilities for this problem, which I will call the dice model and the mul-
tiset model.
In the “dice model” we keep track of the fact that the candies are stacked
up in the roll from bottom to top, so there is a natural sequence (c1 , c2 , ...., c10 )
of flavours one sees when the roll is opened. For example, the sequences

(G, P, R, Y, Y, G, O, R, Y, O)
32 Basic Principles. Section 1.2

and
(Y, G, O, P, R, R, Y, G, O, Y )

count as different outcomes in this model. We have a sequence of 10 candies,


and a choice of one of 5 flavours for each candy, giving a total of 510 =
9765625 outcomes. (This is equivalent to rolling a sequence of ten 5-sided
dice, hence the name for the model.)
In the “multiset model” we disregard the order in which the candies oc-
cur in the packet as being an inessential detail. The only important informa-
tion about the packet is the number of candies of each type that it contains.
For example, both of the outcomes in the previous paragraph reduce to the
same multiset
{G, G, Y, Y, Y, O, O, R, R, P }

or (2, 3, 2, 2, 1) in this model. Thus we are regarding the packet as a multiset


of size 10 with 5 types of element, giving a total of 10+5−1 14
 
5−1
= 4
= 1001
outcomes.
Notice that the number of outcomes in the dice model is vastly larger
than in the multiset model. It should come as no surprise, then, that the
probabilities we compute depend strongly on which of these two models
we consider. (The true values for the probabilities depend on the details of
the manufacturing process by which the rolls or packets are made. These
cannot be calculated, but must be measured instead.)
Consider the dice model first, and let d(k) denote the probability of get-
ting exactly k purple candies in a roll. There are 10

k
choices for the positions
10−k
of these k purple candies, and (5 − 1) choices for the sequence of (non–
purple) flavours of the other 10 − k candies. This gives a total of 10
 10−k
k
4
outcomes with exactly k purple candies in this model. Therefore,
  10−k
10 4
d(k) =
k 510

for each 0 ≤ k ≤ 10.


Next let’s consider the multiset model, and let m(k) denote the proba-
bility of getting exactly k purple candies in a packet. If we have k purple
candies then the rest of the candies form a multiset of size 10 − k with el-
ements of 4 types, so there are 10−k+4−1 13−k
 
4−1
= 3
such outcomes in this
Section 1.2 Basic Principles. 33

model. Therefore,
13−k

3
m(k) = 14

4

for each 0 ≤ k ≤ 10.


Here is a table of these probabilities (rounded to six decimal places).

k d(k) m(k)
0 0.107374 0.285714
1 0.268435 0.219780
2 0.301990 0.164835
3 0.201327 0.119880
4 0.088080 0.083916
5 0.026424 0.055944
6 0.005505 0.034965
7 0.000786 0.019980
8 0.000074 0.009990
9 0.000004 0.003996
10 0.000000 0.000999

The differences between the two models are clearly seen.


In closing, here are two more points about these models.
First, given a multiset (m1 , ..., mt ) of size n with elements of t types, the
number of outcomes in the dice model which “reduce” to this multiset is
 
n n!
= ,
m1 , ..., mt m1 ! · m2 ! · · · mt !

called a multinomial coefficient . This can be seen intuitively by arranging the


n elements of the multiset in a line in one of n! ways, and noticing that since
we can’t tell the mi elements of type i apart we can freely rearrange them
in mi ! ways without changing the arrangement. One could prove this more
carefully by induction on t, using the case t = 2 of binomial coefficients
as part of the induction step. Or, one could give a combinatorial proof by
constructing a bijection which makes the informal argument above more
precise.
34 Basic Principles. Section 1.2

For the second point, the above analysis of the multiset model can be
generalized to prove Exercise 1.11: for any integers n ≥ 0 and t ≥ 2,
  X n  
n+t−1 n−k+t−2
= .
t−1 k=0
t − 2

1.2.4 Poker hands.

Poker is played with a standard deck of 52 cards, divided into four suits:
spades ♠, hearts ♥, diamonds ♦, and clubs ♣.
Within each suit are 13 cards of different values:
A (Ace), 2, 3, 4, 5, 6, 7, 8, 9, 10, J (Jack), Q (Queen), K (King).
An Ace can be high (above K) or low (below 2) at the player’s choice.
Many variations on the game exist, but the common theme is to make
the best five-card hand according to the ranking of poker hands. This order
is determined by how unlikely it is to be dealt such a hand. From best to
worst, the types of poker hand are as follows:
• Straight Flush: five cards of the same suit with consecutive values.
For example, 8♥ 9♥ 10♥ J♥ Q♥.
• Four of a Kind (or Quads): four cards of the same value, with any fifth
card. For example, 7♠ 7♥ 7♦ 7♣ 4♦.
• Full House (or Tight, or Boat): three cards of the same value, and a
pair of cards of another value. For example, 9♠ 9♥ 9♦ A♦ A♣.
• Flush: five cards of the same suit, but not with consecutive values.
For example, 3♥ 7♥ 10♥ J♥ K♥.
• Straight: five cards with consecutive values, but not of the same suit.
For example, 8♥ 9♣ 10♠ J♥ Q♦.
• Three of a Kind (or Trips): three cards of the same value, and two
more cards not of the same value. For example, 8♠ 8♥ 8♦ K♦ 5♣.
• Two Pair: this is self-explanatory.
For example, J♥ J♣ 6♦ 6♣ A♠.
• One Pair: this is also self-explanatory.
For example, Q♠ Q♦ 8♦ 7♣ 2♠.
• Busted Hand: anything not covered above.
For example, K♠ Q♦ 8♦ 7♣ 2♠.
Section 1.2 Basic Principles. 35

There are 52

5
= 2598960 possible 5-element subsets of a standard deck
of 52 cards, so this is the total number of possible poker hands. How many
of these hands are of each of the above types? The answers can be found
easily on the WWWeb, so there’s no sense trying to keep them secret. Here
they are: N is the number of outcomes of each type, and p = N/ 52

5
is the
probability of each type of outcome (rounded to six decimal places).

Hand N p
Straight Flush 40 0.000015
Quads 624 0.000240
Full House 3744 0.001441
Flush 5108 0.001965
Straight 10200 0.003925
Trips 54912 0.021128
Two Pair 123552 0.047539
One Pair 1098240 0.422569
Busted 1302540 0.501177

The derivation of these numbers is excellent practice (see Exercise 1.14), so


we will do only two of the cases – Straight, and Busted – as illustrations.

Example 1.22.
• To construct a Straight hand there are 10 choices for the consecutive
values of the cards (A2345, 23456, ... up to 10JQKA), and 45 choices
for the suits on the cards. However, four of these choices for suits
give all five cards the same suit – these lead to straight flushes and
must be discounted. Hence the total number of straights is
10 · (45 − 4) = 10200.
• To construct a Busted hand there are 13

5
− 10 choices for 5 values
of cards which are not consecutive (no straight) and have no pairs.
Having chosen these values there are 45 − 4 choices for the suits on
the cards which do not give all five cards the same suit (no flush).
Hence the total number of busted hands is
13
 
5
− 10 · (45 − 4) = 1302540.
36 Basic Principles. Section 1.2

1.2.5 Derangements.

Here is a “classical” example. (In this context, the word “derangement”


makes more sense in French than in English.)

Example 1.23 (The Derangement Problem). A group of eight people


meet for dinner at a fancy restaurant and check their coats at the door.
After a delicious gourmet meal the group leaves, and on the way out the
eight coats are returned to the eight people completely at random by an
incompetent clerk. What is the probability that no-one gets the correct
coat?

Of course, we want to solve the derangement problem for any number


of people, not just for eight. To state the problem mathematically, list the
people P1 , P2 , ..., Pn in any order. We can record who gets whose coat by a
sequence of numbers (c1 , c2 , ..., cn ) in which ci = j means that Pi was given
the coat belonging to Pj . The sequence (c1 , c2 , ..., cn ) will thus contain each of
the numbers 1, 2, ..., n exactly once in some order. In other words, (c1 , ..., cn )
is a permutation of the set {1, 2, ..., n}, and we assume that this permutation
is chosen randomly by the incompetent clerk. Person i gets the correct coat
exactly when ci = i. Thus, in general the derangement problem is to de-
termine, for a random permutation (c1 , ..., cn ) of {1, 2, ..., n}, the probability
that ci 6= i for all 1 ≤ i ≤ n.
For small values of n the derangement problem can be analyzed directly,
but complications arise as n gets larger. In fact, this example is perfectly
designed to illustrate the principle of Inclusion/Exclusion. To see how this
applies, for each 1 ≤ i ≤ n let Ai be the set of permutations of {1, ..., n} such
that ci = i. That is, Ai is the set of ways in which the coats are returned and
person Pi gets the correct coat. From that interpretation, the union of sets
A1 ∪ A2 ∪ · · · ∪ An is the set of ways in which the coats are returned and
at least one person gets the correct coat. Therefore, the complementary set
of permutations gives those ways of returning the coats so that no-one gets
the correct coat. The number of these derangements of n objects is thus

n! − |A1 ∪ A2 ∪ · · · ∪ An |.

It remains to apply Inclusion/Exclusion to determine |A1 ∪ · · · ∪ An |. To


do this we need to determine |AS | for every nonempty subset ∅ 6= S ⊆
Section 1.2 Basic Principles. 37

{1, 2, ..., n}. Consider the example n = 8 and S = {2, 3, 6}. In this case
A{2,3,6} = A2 ∩ A3 ∩ A6 is the set of those permutations of {1, ..., 8} such that
c2 = 2 and c3 = 3 and c6 = 6. Such a permutation looks like  2 3   6  
in which the boxes are filled with the numbers {1, 4, 5, 7, 8} in some order.
Since there are 5! lists of the set{1, 4, 5, 7, 8} it follows that |A{2,3,6} | = 5! =
120 in this case. The general case is similar. If ∅ 6= S ⊆ {1, 2, ..., n} is a
k-element subset then the permutations of {1, 2, ..., n} in AS are obtained by
fixing ci = i for all i ∈ S, and then listing the remaining n − k elements of
{1, ..., n} r S in the remaining spaces. Since there are (n − k)! such lists we
see that |AS | = (n − k)!.
Since |AS | = (n − k)! for every k-element subset of {1, 2, ..., n}, and there
are nk such k-element subsets, Inclusion/Exclusion implies that


n   n
X n k−1
X (−1)k−1
|A1 ∪ · · · ∪ An | = (−1) (n − k)! = n! .
k=1
k k=1
k!

It follows that the number of derangements of n objects is

n n
X (−1)k−1 X (−1)k
n! − n! = n! .
k=1
k! k=0
k!

Since the total number of permutations of n objects is n!, the probability that
a randomly chosen permutation of {1, 2, ..., n} is a derangement is

n
X (−1)k
Dn = .
k=0
k!

The following table lists the first several values of the function Dn (with
the decimals rounded to six places). Notice that for n ≥ 7 the value of Dn
changes very little. If you recall the Taylor series expansion of the exponen-
tial function

x
X xk
e =
k=0
k!

then it is easy to see that as n tends to infinity the probability Dn approaches


38 Basic Principles. Section 1.3

the limiting value of e−1 = 0.3678794412....

n Dn Dn
0 1/1 1.
1 0/1 0.000000
2 1/2 0.500000
3 1/3 0.333333
4 3/8 0.375000
5 11/30 0.366667
6 53/144 0.368056
7 103/280 0.367857
8 2119/5760 0.367882
9 16687/45630 0.367879
10 16481/44800 0.367879

In summary, for the original Example 1.23, the probability that no-one gets
their own coat is very close to 36.79%.

1.3 Exercises.

Exercise 1.1. Fix integers n ≥ 0 and t ≥ 1. Consider a randomly


chosen multiset of size n with elements of t types. For each part below,
calculate the probability that the multiset has the stated property, and
give a brief explanation.
(a) Every type of element occurs at most once.
(b) Every type of element occurs at least once.
(c) Every type of element occurs an even number of times.
(d) Every type of element occurs an odd number of times.
(e) For k ∈ N, exactly k types of element occur with multiplicity at
least one.
(f) For k ∈ N, exactly k types of element occur with multiplicity at
least two.
Section 1.3 Basic Principles. 39

Exercise 1.2. Consider rolling six fair 6-sided dice, which are distin-
guishable, so that there are 66 = 46656 equally likely outcomes. Count
how many outcomes are of each of the following types. (The answers
add up to 46656.)
(a) Six-of-a-kind.
(b) Five-of-a-kind and a single.
(c) Four-of-a-kind and a pair.
(d) Four-of-a-kind and two singles.
(e) Two triples.
(f) A triple, a pair, and a single.
(g) A triple and three singles.
(h) Three pairs.
(i) Two pairs and two singles.
(j) One pair and four singles.
(k) Six singles.

Exercise 1.3. Let m ≥ 1, d ≥ 2, and k ≥ 0 be integers. When rolling m


fair dice, each of which has d sides, what is the probability of rolling
exactly k pairs and m − 2k singles?

Exercise 1.4.
(a) Prove that
is an equivalence relation.
(b) Prove Proposition 1.11.

Exercise 1.5. Define a function f : Z → N as follows: for a ∈ Z,



2a if a ≥ 0,
f (a) =
−1 − 2a if a < 0.

Show that f : Z → N is a bijection as follows.


(a) Define a function g : N → Z.
(b) Show that for all a ∈ Z, g(f (a)) = a.
(c) Show that for all b ∈ N, f (g(b)) = b.
40 Basic Principles. Section 1.3

Exercise 1.6. Complete the proof in Example 1.13.

Exercise 1.7. Give bijective proofs of the following identities.


(a) For all n ∈ N, nk=0 nk k = n2n−1 .
P 

(b) For all n ∈ N, nk=0 nk k(k − 1) = n(n − 1)2n−2 .


P 

Exercise 1.8. For an integer n ≥ 1, give a bijective proof that


X n X n
=
even k
k odd k
k

Exercise 1.9. Let n be a positive integer. Let Sn be the set of all ordered
pairs of sets (A, B) in which A ⊆ B ⊆ {1, 2, ..., n}. Let Tn be the set of
all functions f : {1, 2, ..., n} → {1, 2, 3}.
(a) What is |Tn |? (Explain.)
(b) Define a bijection g : Sn → Tn . Explain why g((A, B)) ∈ Tn
for any (A, B) ∈ Sn . (You do not need to explain why g is a
bijection.)
(c) Define the inverse function g −1 : Tn → Sn of your bijection g
from part (b). (You do not need to explain why g and g −1 are
mutually inverse bijections.)
(d) By counting Sn and Tn in two different ways, deduce that
n  
n
X n k
3 = 2 .
k=0
k

Exercise 1.10. Fix integers n ≥ 0 and k ≥ 1. Let A(n, k) be the set of


sequences (a1 , ..., ak ) ∈ Nk such that a1 + · · · + ak = n, and j divides
aj for all 1 ≤ j ≤ k. Let B(n, k) be the set of sequences (b1 , ..., bk ) ∈ Nk
such that b1 + · · · + bk = n, and b1 ≥ b2 ≥ · · · ≥ bk . For example, here
Section 1.3 Basic Principles. 41

are the sets for n = 7 and k = 3:

A(7, 3) B(7, 3)
(7, 0, 0) (7, 0, 0)
(5, 2, 0) (6, 1, 0)
(4, 0, 3) (5, 2, 0)
(3, 4, 0) (4, 3, 0)
(2, 2, 3) (5, 1, 1)
(1, 6, 0) (4, 2, 1)
(1, 0, 6) (3, 3, 1)
(0, 4, 3) (3, 2, 2)

Construct a pair of mutually inverse bijections between the sets A(n, k)


and B(n, k).

Exercise 1.11. For integers n ≥ 0 and t ≥ 2, give a bijective proof that


  X n  
n+t−1 n−k+t−2
= .
t−1 k=0
t − 2

Exercise 1.12. For integers n ≥ 1 and t ≥ 1, give a bijective proof that


  X t   
n+t−1 t n−1
= .
t−1 k=0
k k − 1

Exercise 1.13. Choose a permutation σ of {1, 2, ..., 7} at random, so


that each of the 7! = 5040 permutations are equally likely. What are
the probabilities of the following events?
1. Numbers 1 and 2 are consecutive (i.e. 3672154 or 3671254).
2. Number 1 is to the left of 2.
3. No two odd numbers are consecutive.
4. Any other condition you can think of.
5. Any similar questions for permutations of {1, 2, ..., n}.
42 Basic Principles. Section 1.3

Exercise 1.14. (The r = 13 and s = 4 case of this exercise completes the


table in Subsection 1.2.4.) Let r ≥ 2 and s ≥ 2 be integers. Consider a
(non-standard) deck of rs cards, divided into s suits each with cards
of r different values. The cards in each suit are numbered A, 2, 3, ..., r,
and A can be either below 2 or above r. Choose five cards from such a
deck in one of rs

5
ways. How many ways are there to produce each
kind of hand for this “poker in an alternate universe”?
(a) Count “quints” (five-of-a-kinds).
(b) Count straight flushes.
(c) Count quads.
(d) Count full houses.
(e) Count flushes.
(f) Count straights.
(g) Count trips.
(h) Count two-pairs.
(i) Count one-pairs.
(j) Count busted hands.
Exercise 1.15. The game called “Crowns and Anchors” or “Birdcage”
was popular on circus midways early in the 20th century. It is a game
between a Player and the House, played as follows. First, the Player
wagers w dollars on an integer p from one to six. Next, the House
rolls three six-sided dice. For every die that shows p dots on top, the
House pays the Player w dollars, but if no dice show p dots on top
then the Player’s wager is forfeited, and goes to the House. (Assume
that the dice are fair, so that every outcome is equally likely.)
For example, if I wager two dollars on the number five, and the
dice show five, five, and three dots, respectively, then the House pays
me four dollars for a total of six (a profit of four dollars). However, if
in this case the dice show four, three, and two dots, respectively, then
the House takes my wager for a total of zero (a loss of two dollars).
(a) For every dollar that the Player wagers, how much money should
the Player expect to win back in the long run? Would you play
this game?
(b) In a parallel universe there is a game of Crowns and Anchors
being played with m ≥ 1 dice, each of which has d ≥ 2 sides.
(Assume that the dice are fair, so that every outcome is equally
likely.) In which universes does the Player win in the long run?
In which universes does the House win in the long run? In
which universes is the game completely fair?
Chapter 2

The Idea of Generating Series.

We will be dealing algebraically with infinite power series G(x) = ∞ n


P
n=0 gn x
in which the coefficients g = (g0 , g1 , g2 , ...) form a sequence of integers.
These can, for the most part, be handled just like polynomials. Problems
of convergence can arise if one tries to substitute a particular real or com-
plex value for the indeterminate x. We usually don’t do this, and finiteness
of all the coefficients of G(x) is all that we require.

Example 2.1 (The Geometric Series). The simplest infinite case of power
series is if all the coefficients equal one. Then

G = 1 + x + x2 + x3 + x4 + · · · .

Multiply this by x:

xG = x + x2 + x3 + x4 + · · · .

It follows that G − xG = (1 − x)G = 1. In conclusion


1
= 1 + x + x2 + x3 + · · · .
1−x

Don’t worry about convergence – this is just algebra!

45
46 Generating Series. Section 2.1

2.1 The Binomial Theorem and Binomial Series.

We develop two of the most useful facts that we will need in what follows.
The proofs are also good illustrations of calculating with generating series.

Theorem 2.2 (The Binomial Theorem). For any natural number n ∈ N,


n  
n
X n k
(1 + x) = x .
k=0
k

This formula is an identity between two polynomials in the variable x. You


probably have seen a proof of it by induction on n, but we are going to prove
it here using the bijection between subsets and indicator vectors discussed
in Example 1.12.

Proof. Recall that P(n) is the set of all subsets of {1, 2, ..., n}, and that {0, 1}n
is the set of all indicator vectors α = (a1 , a2 , ..., an ) in which each coordi-
nate is either 0 or 1. Example 1.12 gives a bijection between these two sets,
which you should recall. For example, when n = 8 the subset {2, 3, 5, 7}
corresponds to the indicator vector (0, 1, 1, 0, 1, 0, 1, 0). The constructions
S 7→ α(S) and α 7→ S(α) are mutually inverse bijections between the sets
P(n) and {0, 1}n . From this, we concluded that |P(n)| = |{0, 1}n | = 2n , but
we can deduce more. Notice that if S is a subset with k elements then it
corresponds to an indicator vector α that sums to k. It is sometimes helpful
to record this information in a little table, like this:

P(n)
{0, 1}n
S ↔ α = (a1 , a2 , ..., an )
|S| = a1 + a2 + · · · + an .

Because of this bijection, if we introduce an “indeterminate” x, and if S


corresponds to α, then
x|S| = xa1 +a2 +···+an .
Moreover, also because of this bijection, summing over all subsets is equiv-
alent to summing over all indicator functions. That is,
X X
x|S| = xa1 +a2 +···+an .
S∈P(n) α∈{0,1}n
Section 2.1 Generating Series. 47

Now we can simplify both sides separately. On the LHS, we know from
Theorem 1.5 that there are nk k-element subsets of an n-element set, for


each 0 ≤ k ≤ n. Therefore,
n  
X
|S|
X n k
x = x .
k=0
k
S∈P(n)

On the RHS, summing over all the indicator vectors α ∈ {0, 1}n is equivalent
to summing over all a1 ∈ {0, 1} and all a2 ∈ {0, 1} and so on,... until all
an ∈ {0, 1}. This gives

X 1 X
X 1 1
X
a1 +a2 +···+an
x = ··· xa1 +a2 +···+an
α∈{0,1}n a1 =0 a2 =0 an =0
1 1 1 1
!n
X X X X
= xa1 xa2 · · · xan = xa = (1 + x)n .
a1 =0 a2 =0 an =0 a=0

This proves the Binomial Theorem. With practice and familiarity, it be-
comes a one-line proof:
n  
X n X X
xk = x|S| = xa1 +a2 +···+an = (1 + x)n .
k
k=0 S∈P(n) α∈{0,1}n

Example 2.3 (Vandermonde Convolution.). As mentioned in Subsection


1.2.1, the Binomial Theorem easily implies the Vandermonde Convolu-
tion formula. To see this, begin with the obvious identity of polynomials

(1 + x)m+n = (1 + x)m · (1 + x)n

and use the Binomial Theorem to expand each of the factors.


m+n m  
! n   !
X m + n X m j X n
k
x = x xi
k=0
k j=0
j i=0
i
m X n    m+n k   
X m n j+i X X m n
= x = xk .
j=0 i=0
j i k=0 j=0
j k − j
48 Generating Series. Section 2.1

(The last step is accomplished by re-indexing the double summation.)


Since the polynomials on the LHS and on the RHS are equal, they must
have the same coefficients. By comparing the coefficients of xk on both
sides we see that
  X k   
m+n m n
= ,
k j=0
j k−j

giving the result.

Consider the set M(t) of all multisets with t ≥ 1 types of elements, re-
gardless of the size of the multiset. That is, an element of M(t) is a sequence
µ = (m1 , m2 , ..., mt ) of t natural numbers, and the size of the multiset is
|µ| = m1 + m2 + · · · + mt . By Theorem 1.9, for each n ∈ N there are n+t−1

t−1
elements of M(t) of size n. By analogy with the Binomial Theorem 2.2, we
could collect these numbers as the coefficients of a power series:
∞  
X n+t−1 n
x .
n=0
t−1
The Binomial Series is an algebraic formula for this summation.

Theorem 2.4 (The Binomial Series). For any positive integer t ≥ 1,


∞  
1 X n+t−1 n
= x .
(1 − x)t n=0
t − 1

(Properly, this is the binomial series with negative integer exponent. The
general binomial series is discussed in Subsection 4.4.1).

Proof. The key observation is that the set of all multisets with t ≥ 1 types
of elements is M(t) = Nt , the Cartesian product of t copies of the natural
numbers N. This leads to a calculation similar to the proof of the Binomial
Theorem above, based on this structure:
M(t) = Nt
µ = (m1 , .., mt )
|µ| = m1 + · · · + mt
Section 2.2 Generating Series. 49

We use this to calculate as follows. The first equality is by Theorem 1.9.


∞   ∞
X n+t−1 n X X
x = |M(n, t)| xn = x|µ|
n=0
t − 1 n=0 µ∈M(t)
X ∞ X
X ∞ X∞
= xm1 +m2 +···mt = ··· xm1 +m2 +···+mt
(m1 ,m2 ,...,mt )∈Nt m1 =0 m2 =0 mt =0
∞ ∞ ∞ ∞
!t
X X X X 1
= xm 1 xm 2 · · · xmt = xm = .
m1 =0 m2 =0 mt =0 m=0
(1 − x)t

The last equality is by the geometric series 1 + x + x2 + · · · = 1/(1 − x).

2.2 The Theory in General.

In general terms we have a sequence of numbers g = (g0 , g1 , g2 , ...) which


we would like to determine. To do this we introduce an indeterminate x
and encode these numbers as the coefficients of a power series

X
2 3
G(x) = g0 + g1 x + g2 x + g3 x + · · · = gn xn ,
n=0

called the generating series for the sequence g.


By “indeterminate” we mean that x behaves algebraically as if it were a
number, but that it does not have any particular value. It should be thought
of as a punctuation mark that is there to keep the different coefficients gn
separated from each other. Sometimes, people call x a “variable” – but that
word is meant to convey the idea that x is a number, but that we don’t know
specifically what the value of that number is. The word “indeterminate”
is meant to convey the idea that x does not have any value at all – it is just a
punctuation mark. As will be seen, it is the coefficients of these power series
that carry information about our counting problems.
In this chapter and the next we will see how to use this strategy to encode
the answers to various counting problems as generating series. In Chapter 4
we will see how to get numbers out of these power series in order to answer
the counting problems explicitly.
50 Generating Series. Section 2.2

2.2.1 Generating series.

Let A be a set of “objects” which we want to count. For example, A might be


the set of subsets of the set {1, 2, ..., n}. Or, A might be the set of all multisets
with t types of elements. The set A can be quite arbitrary, but we assume
that each element of A has a “size” or “weight” attached to it. The weight
of α ∈ A is a nonnegative integer ω(α) ∈ N. We just require that there are
only finitely many elements of A of any given weight.

Definition 2.5 (Weight Function). Let A be a set. A function ω : A →


N from A to the set N of natural numbers is a weight function provided
that for all n ∈ N, the set

An = ω −1 (n) = {α ∈ A : ω(α) = n}

is finite. That is, for every n ∈ N there are only finitely many elements
α ∈ A of weight n.

Notice that if A is a set with a weight function ω : A → N, then



[
A= An
n=0

is a (disjoint) union of countably many finite sets, and so A is itself either


finite or countably infinite.

Definition 2.6 (Generating series). Let A be a set with a weight func-


tion ω : A → N as in Definition 2.5. The generating series of A with
respect to ω is X
A(x) = ΦωA (x) = xω(α) .
α∈A

(We usually suppress the superscript from the notation.) Remember – the
indeterminate x does not have a value. It is just used to keep track of the
weight of each object α ∈ A in the exponent.
Section 2.2 Generating Series. 51

Proposition 2.7. Let A be a set with a weight function ω : A → N, and let



X
2
ΦA (x) = a0 + a1 x + a2 x + · · · = an x n .
n=0

For every n ∈ N, the number of elements of A of weight n is an = |An |.

Proof.

X ∞
X X ∞
X X ∞
X
ω(α) ω(α) n
ΦA (x) = x = x = x 1= |An | xn .
α∈A n=0 α∈A: ω(α)=n n=0 α∈An n=0

Thus, for each n ∈ N, the coefficient of xn in ΦA (x) is the number of elements


in A that have weight n.

Since we will be doing a lot of long calculations with power series, and
because of Proposition 2.7, it is useful to have a handy notation for extract-
ing coefficients from them.

P∞
Definition 2.8. Let G(x) = g0 + g1 x + g2 x2 + · · · = n=0 gn xn be any
power series. Then for any k ∈ N,

[xk ] G(x) = gk

is the coefficient of xk in the power series G(x).

Example 2.9. For example, for any natural numbers a, b ∈ N,


∞    
a 1 a
X n+b n a+b
[x ] = [x ] x = .
(1 − x)1+b n=0
b b
52 Generating Series. Section 2.2

2.2.2 The Sum, Product, and String Lemmas.

Lemma 2.10 (The Sum Lemma.). Let A and B be disjoint sets, so that
A ∩ B = ∅. Assume that ω : (A ∪ B) → N is a weight function on the
union of A and B. We may regard ω as a weight function on each of A or B
separately (by restriction). Under these conditions,

ΦA∪B (x) = ΦA (x) + ΦB (x).

Proof. From the definition of generating series,


X X X
ΦA∪B (x) = xω(σ) = xω(σ) + xω(σ) = ΦA (x) + ΦB (x).
σ∈A∪B σ∈A σ∈B

(The condition that A ∩ B = ∅ is needed for the second equality.)

In fact, the above proof can be generalized slightly to give more.

Lemma 2.11 (The Infinite Sum Lemma.). Let A0 , A1 , A2 ,... be pairwise


disjoint sets (so that Ai ∩ Aj = ∅ if i 6= j), and let B = ∞ j=0 Aj . Assume
S

that ω : B → N is a weight function. We may regard ω as a weight function


on each of the sets Aj separately (by restriction). Under these conditions,

X
ΦB (x) = ΦAj (x).
j=0

Proof. Exercise 2.6.

Lemma 2.12 (The Product Lemma.). Let A and B be sets with weight
functions ω : A → N and ν : B → N, respectively. Define η : A × B → N
by putting η(α, β) = ω(α) + ν(β) for all (α, β) ∈ A × B. Then η is a weight
function on A × B, and

ΦηA×B (x) = ΦωA (x) · ΦνB (x).

(The superscripts ω, ν, and η indicate which weight function is being used


for each set.)
Section 2.2 Generating Series. 53

Proof. To see that η is a weight function, consider any n ∈ N. There are n + 1


choices for an integer 0 ≤ k ≤ n. For each such k, there are only finitely
many pairs (α, β) ∈ A × B with ω(α) = k and ω(β) = n − k. That is, the set
of elements of A × B of weight n is
n
[
(A × B)n = Ak × Bn−k ,
k=0

a finite (disjoint) union of finite sets. It follows that there are only finitely
many elements of A × B of weight n. Now,
X XX
ΦηA×B (x) = xη(α,β) = xω(α)+ν(β)
(α,β)∈A×B α∈A β∈B
X X
= xω(α) · xν(β) = ΦA (x) · ΦB (x).
α∈A β∈B

The Product Lemma 2.12 can be extended to the Cartesian product of any
finite number of sets, by induction on the number of factors. (Exercise 2.7.)
Finally, the String Lemma combines both disjoint union and Cartesian
product, as follows. Let A be a set with a weight function ω : A → N.
For any k ∈ N, the Cartesian product of k copies of A is denoted by Ak .
The entries of Ak are k-tuples (α1 , α2 , ..., αk ) with each αi ∈ A. Notice that
A0 = {ε} is the one-element set whose only element is the empty string
ε = () of length zero. We can define a weight function ωk on Ak by putting
ωk (α1 , ..., αk ) = ω(α1 ) + · · · + ω(αk ).
It is a good exercise to check that this is a weight function. Note that the
weight of the empty string is zero. Repeated application of the Product
Lemma 2.12 shows that for all k ∈ N,
ΦAk (x) = (ΦA (x))k .
We can take the union of the sets Ak for all k ∈ N:

[
A =

Ak .
k=0

Notice that the sets in this union are pairwise disjoint, since each Ak consists
of strings with exactly k coordinates. We define a function ω ∗ : A∗ → N by
saying that ω ∗ = ωk when restricted to Ak .
54 Generating Series. Section 2.2

Lemma 2.13. Let A be a set with weight function ω : A → N, and define


A∗ and ω ∗ : A∗ → N as above. Then ω ∗ is a weight function on A∗ if and
only if there are no elements in A of weight zero (that is, A0 = ∅).

Proof. If γ ∈ A has weight zero, ω(γ) = 0, then for any natural number
k ∈ N, a sequence of k γ-s in Ak also has weight zero: ωk (γ, γ, ..., γ) = 0. So,
by the way ω ∗ : A∗ → N is defined, there are infinitely many elements of
weight zero in A∗ , so that ω ∗ is not a weight function.
Conversely, assume that every element of A has weight at least 1. Then,
for each k ∈ N, every element of Ak has weight at least k. Now consider
any n ∈ N and all the strings (α1 , ..., αk ) ∈ A∗ of weight n. By the previous
sentence, if there are any such strings of length k then 0 ≤ k ≤ n. For each
0 ≤ k ≤ n, Ak has only finitely many elements of weight n. It follows that
A∗ has only finitely many elements of weight n. Therefore, ω ∗ is a weight
function on A∗ .

Lemma 2.14 (The String Lemma.). Let A be a set with a weight function
ω : A → N such that there are no elements of A of weight zero. Then

1
ΦA∗ (x) = .
1 − ΦA (x)

Proof. By the Infinite Sum and Product Lemmas 2.11 and 2.12,
∞ ∞
X X 1
ΦA∗ (x) = ΦAk (x) = (ΦA (x))k = .
k=0 k=0
1 − ΦA (x)
Section 2.3 Generating Series. 55

2.3 Compositions.

Definition 2.15. A composition is a finite sequence of positive integers:

γ = (c1 , c2 , ..., ck ),

in which k ∈ N is a natural number, and each ci ≥ 1 is a positive


integer. The entries ci are called the parts of the composition. The
length of the composition is `(γ) = k, the number of parts. The size of
the composition is
|γ| = c1 + c2 + · · · + ck ,
the sum of the parts.

Notice that there is exactly one composition of length zero: this is ε = (),
the empty string with no entries. Compositions are related to multisets,
but there are two important differences: the parts of a composition must
be positive integers, not just nonnegative, and the length of a composition
might not be specified, while the number of types of element in a multiset
must be fixed.

Example 2.16. Here are all the compositions of size five:

(5) (2,3) (2,2,1) (1,2,1,1)


(4,1) (3,1,1) (2,1,2) (1,1,2,1)
(1,4) (1,3,1) (1,2,2) (1,1,1,2)
(3,2) (1,1,3) (2,1,1,1) (1,1,1,1,1)

In this section we will apply the results of Subsection 2.2.2 to obtain for-
mulas for the generating series of various sets of compositions defined by
imposing some extra conditions. In Chapter 4 we will see how to use this
information to actually count such things.
56 Generating Series. Section 2.3

Theorem 2.17. Let P = {1, 2, 3, ...} be the set of positive integers.


(a) The set C of all compositions is C = P ∗ .
(b) The generating series for C with respect to size is
x
ΦC (x) = 1 + .
1 − 2x
(c) For each n ∈ N, the number of compositions of size n is

1 if n = 0,
|Cn | = n−1
2 if n ≥ 1.

Proof. A single part is a positive integer c ∈ P = {1, 2, 3, ...}. A composition


of length k is a sequence γ = (c1 , c2 , ..., ck ) of k positive integers, so is an
element of P k . Since the length k can be any natural number, the set C of all
compositions is

[
C= P k = P ∗.
k=0

This proves part (a).


The generating series for one-part compositions with respect to size is

X x
ΦP (x) = xc = x + x2 + x 3 + · · · = ,
c=1
1−x

by the geometric series. From the String Lemma 2.14 it follows that
1 1−x x
ΦC (x) = ΦP ∗ (x) = = = 1+ .
1 − x/(1 − x) 1 − 2x 1 − 2x
This proves part (b).
Expanding C(x) = ΦC (x) using the geometric series, we obtain

X ∞
X
C(x) = 1 + 2j xj+1 = 1 + 2n−1 xn .
j=0 n=1

Since |Cn | = [xn ]C(x) is the coefficient of xn in C(x), this proves part (c).

Proposition 2.23 is a bijection which gives a combinatorial proof of Theorem


2.17(c).
Section 2.3 Generating Series. 57

Many variations on the proof of Theorem 2.17 are possible. We will do a


few as examples, and present many more as exercises. The general approach
consists of three steps:
• Identify the allowed values for each part. This might depend on the
position of the part within the composition.
• Identify the allowed lengths for the compositions.
• Apply the Sum, Product, and String Lemmas to obtain a formula for
the generating series.

Example 2.18. Let F be the set of all compositions in which each part is
either one or two.
• The allowed sizes for a part are 1 or 2, so P = {1, 2} is the set of
allowed parts. The generating series for a single part is x + x2 .
• The length can be any natural number k ∈ N. By the Product
Lemma, the generating series for compositions in F of length k is
(x + x2 )k .
• Since F = {1, 2}∗ , the String Lemma implies that
∞ ∞
X X 1
F (x) = ΦF (x) = f n xn = (x + x2 )k = .
n=0 k=0
1 − x − x2

Here, fn = [xn ]F (x) = |Fn | is the number of compositions in F of


size n. In Section 4.1 we will see how to use this information to get
a formula for the numbers fn .

Example 2.19. Let H be the set of all compositions in which each part is
at least two.
• The allowed sizes for a part are P = {2, 3, 4, ...}. The generating
series for a single part is

X
c 2 3 x2
4
ΦP (x) = x = x + x + x + ··· = .
c=2
1−x

• The length can be any natural number k ∈ N. By the Product


Lemma, the generating series for compositions in H of length k
58 Generating Series. Section 2.3

is k
x2

.
1−x
• Since H = P ∗ , the String Lemma implies that
∞ ∞  k
X
n
X x2
H(x) = ΦH (x) = hn x =
n=0 k=0
1−x
1 1−x x2
= = = 1 + .
1 − x2 /(1 − x) 1 − x − x2 1 − x − x2

Here, hn = [xn ]H(x) is the number of compositions in H of size n.

Example 2.20. Let J be the set of all compositions in which each part is
odd.
• The allowed sizes for a part are P = {1, 3, 5, ...}. The generating
series for a single part is

X x
ΦP (x) = x2i+1 = x1 + x3 + x5 + · · · = .
i=0
1 − x2

• The length can be any natural number k ∈ N. By the Product


Lemma, the generating series for compositions in J of length k is
 k
x
.
1 − x2

• Since J = P ∗ , the String Lemma implies that



X 1
J(x) = ΦJ (x) = jn xn =
n=0
1 − x/(1 − x2 )
1 − x2 x
= = 1 + .
1 − x − x2 1 − x − x2
Here, jn = [xn ]J(x) is the number of compositions in J of size n.

Example 2.21. The sets F, H, and J in Examples 2.18 to 2.20 have very
similar generating series. In fact, after a little thought one sees that for
Section 2.3 Generating Series. 59

all n ≥ 2,
1
[xn ] H(x) = [xn−1 ] J(x) = [xn−2 ] F (x) = [xn−2 ] .
1 − x − x2
This means that for all n ≥ 2, we have hn = jn−1 = fn−2 , so for the sizes
of sets we have |Hn | = |Jn−1 | = |Fn−2 |. We have proven these equalities
even though we don’t yet know what those numbers actually are! This
seems slightly magical, but it works.
Since these sets have the same sizes there must be bijections between
them to explain this fact. Constructing such bijections is left to Exercise
2.17. As a starting point, here are the sets for n = 7:

H7 J6 F5
(7) (5, 1) (2, 2, 1)
(5, 2) (1, 5) (2, 1, 2)
(2, 5) (3, 3) (1, 2, 2)
(4, 3) (3, 1, 1, 1) (2, 1, 1, 1)
(3, 4) (1, 3, 1, 1) (1, 2, 1, 1)
(3, 2, 2) (1, 1, 3, 1) (1, 1, 2, 1)
(2, 3, 2) (1, 1, 1, 3) (1, 1, 1, 2)
(2, 2, 3) (1, 1, 1, 1, 1, 1) (1, 1, 1, 1, 1)

(It need not be the case that the bijections match up these sets of com-
positions line by line in this table.) In Section 4.1 we will determine the
coefficients of the power series 1/(1 − x − x2 ), answering the counting
problem for these sets F, H, and J.

Example 2.22. Let Q be the set of all compositions in which each part is
at least two, and the number of parts is even.
• The allowed sizes for a part are P = {2, 3, 4, ...}. The generating
series for a single part is

X x2
ΦP (x) = xc = x2 + x3 + x4 + · · · = .
c=2
1−x

• The length is an even natural number k = 2j for some j ∈ N. By


the Product Lemma, the generating series for a composition in Q
60 Generating Series. Section 2.4

of length 2j is
2j
x2

.
1−x
• Since Q = (P 2 )∗ , the String Lemma implies that
∞ ∞  2j
X
n
X x2
Q(x) = ΦQ (x) = qn x =
n=0 j=0
1−x
1 (1 − x)2
= =
1 − x4 /(1 − x)2 (1 − x)2 − x4
1 − 2x + x2 x4
= = 1 + .
1 − 2x + x2 − x4 1 − 2x + x2 − x4
Here qn = [xn ]Q(x) = |Qn | is the number of compositions in Q of
size n. In Example 4.11 we will see how to calculate the first several
values of |Qn |.

2.4 Subsets with Restrictions.

The theory above for compositions can be used to obtain generating series
for subsets of natural numbers subject to some restrictions on the “gaps”
between consecutive elements of the subset. This is because of the following
correspondence between such subsets and nonempty compositions.

Proposition 2.23. Let U be the set of pairs (n, A) in which n ∈ N is a


natural number and A ⊆ {1, 2, ..., n} is a subset. Let C r {ε} be the set of
nonempty compositions. There is a bijection U
C r {ε} between these
two sets.

Proof. We define mutually inverse bijections U


C r {ε} as follows.
First, given (n, A) in U, sort the elements of A = {a1 , a2 , ..., ak } into in-
creasing order:
1 ≤ a1 < a2 < · · · < ak ≤ n.

For convenience, put a0 = 0 and ak+1 = n + 1. Now define ci = ai − ai−1 for


all 1 ≤ i ≤ k + 1, and let γ = (c1 , c2 , ..., ck+1 ). Notice that each ci is a positive
integer, so that γ is a composition of length k + 1. Since k + 1 is at least one,
Section 2.4 Generating Series. 61

this composition γ is not empty, so that γ is in the set C r {ε}. The size of
this composition is
k+1
X k+1
X
|γ| = ci = (ai − ai−1 ) = ak+1 − a0 = n + 1,
i=1 i=1

and its length is `(γ) = |A| + 1.


Conversely, given a nonempty composition γ = (c1 , c2 , ..., c` ) in C r {ε},
notice that ` ≥ 1. We define aj = c1 + c2 + · · · + cj for each 1 ≤ j ≤ ` − 1, and
let A = {a1 , a2 , ..., a`−1 } and n = |γ| − 1. This defines a pair (n, A) in the set
U.
One can check that these constructions give a pair of mutually inverse
bijections U
C r {ε} by using Proposition 1.11. This is left as Exercise
2.18

The bijection of Proposition 2.23 can be neatly summarized in a little ta-


ble, as follows:

U
C r {ε}
(n, A) ↔ γ
n = |γ| − 1
|A| = `(γ) − 1.

Many variations on this bijection are possible, by putting some restrictions


on the allowed “gaps” between elements of the subset A and then analyzing
the corresponding set of (nonempty) compositions. When deriving these
generating series, we have to be careful that the n in the pair (n, A) corre-
sponds to |γ| − 1 for the corresponding composition γ.

Example 2.24. For each n ∈ N, let rn be the number of subsets of {1, ..., n}
that do not contain two consecutive numbers (like a and a+1). We obtain
a formula for the generating series R(x) = ∞ n
P
n=0 rn x using the ideas of
Proposition 2.23.
For n ∈ N, let Rn be the set of pairs (n, A) with A as in the statement
of the problem, and let R = ∞ n=0 Rn . Then |Rn | = rn for all n ∈ N, and
S

we want to determine the generating series for the set R with respect to
the weight function ω(n, A) = n.
62 Generating Series. Section 2.4

The first question to ask is: which nonempty compositions correspond


to pairs in the set R? Notice that (n, A) is in R if and only if the corre-
sponding composition γ = (c1 , c2 , ..., c` ) of size n + 1 has ci ≥ 2 for all
2 ≤ i ≤ ` − 1. It is possible that maybe c1 = 1 or c` = 1, though. Let M
be the set of compositions corresponding to pairs in R. Notice that
X X
M (x) = ΦM (x) = x|γ| = xn+1 = x R(x).
γ∈M (n,A)∈R

The compositions in M can be described as follows.


• The first and last parts are positive integers.
• Parts other than the first and last parts are integers greater than or
equal to 2.
• The length is at least one (since it is one more than the size of the
corresponding subset).
A part that is a positive integer has generating series x/(1 − x), and a
part that is at least 2 has generating series x2 /(1 − x), as we have seen.
Now we do a case analysis by the number of parts, using the Product
Lemma.
• For ` = 1 part the generating series is x/(1 − x).
• For ` ≥ 2 parts the generating series is
`−2
x2 x2`−2

x x
= .
1−x 1−x 1−x (1 − x)`

Combining the contributions for all lengths ` ≥ 1 using the Sum Lemma,
we have

x X x2`−2
xR(x) = M (x) = +
1−x `=2
(1 − x)`
∞  j
x x2 X x2
= +
1−x (1 − x)2 j=0 1 − x
Section 2.5 Generating Series. 63

x x2 1
= + 2
· 2
1−x (1 − x) 1 − x /(1 − x)
2 3
x−x −x x2
= +
(1 − x)(1 − x − x2 ) (1 − x)(1 − x − x2 )
x + x2
= .
1 − x − x2
It follows that
1+x
R(x) = .
1 − x − x2

2.5 Proof of Inclusion/Exclusion.

In this section we prove Theorem 1.15, the Principle of Inclusion/Exclusion.

Lemma 2.25. For any nonempty set T ,


X
(−1)|S|−1 = 1.
∅6=S⊆T

Proof. Consider the identity


X
x|S| = (1 + x)n
S⊆{1,2,...,n}

which was part of the proof of the Binomial Theorem. If T is any n-element
set then X
x|S| = (1 + x)n
S⊆T

as well (as can be seen by numbering the elements of T arbitrarily). Both


sides are polynomials in x, so we can substitute x = −1. The result is
X
(−1)|S| = (1 − 1)n = 0n = 0,
S⊆T

because n ≥ 1. (Note that 00 = 1, since it is an empty product.) On the LHS


we separate the term corresponding to S = ∅, and see that
X
1+ (−1)|S| = 0.
∅6=S⊆T
64 Generating Series. Section 2.5

Rearranging this gives the desired formula.

Recall the notation from Subsection 1.1.6: for any finite number of sets
A1 , A2 , . . . , Am and ∅ 6= S ⊆ {1, 2, ..., m}, let
\
AS = Ai .
i∈S

So, for example, A{2,3,5} = A2 ∩ A3 ∩ A5 .

Theorem 2.26 (Inclusion/Exclusion). Let A1 , A2 , . . . , Am be finite sets.


Then X
|A1 ∪ · · · ∪ Am | = (−1)|S|−1 |AS |.
∅6=S⊆{1,2,...,m}

Proof. Let V = A1 ∪ · · · ∪ Am , and let Nm = {1, 2, .., m}. For each v ∈ V let
T (v) = {i ∈ Nm : v ∈ Ai }. Notice that T (v) 6= ∅, for all v ∈ V . Also notice
that for ∅ 6= S ⊆ Nm we have v ∈ AS if and only if ∅ 6= S ⊆ T (v). Therefore,
using Lemma 2.25 above, we have
X X X
(−1)|S|−1 |AS | = (−1)|S|−1 1
∅6=S⊆Nm ∅6=S⊆Nm v∈AS
X X X
= (−1)|S|−1 = 1 = |V |,
v∈V ∅6=S⊆T (v) v∈V

as was to be shown.

Example 2.27 (The Euler totient function). For a positive integer n, the
Euler totient of n is the number ϕ(n) of integers b in the range 1 ≤ b ≤ n
such that b and n are relatively prime. That is,

ϕ(n) = |{b ∈ {1, 2, ..., n} : gcd(b, n) = 1}|.

We can use Inclusion/Exclusion to obtain a formula for ϕ(n), as follows.


Let the prime factorization of n be n = pc11 pc22 · · · pcmm , in which the pi
are pairwise distinct primes and the ci are positive integers. For each
1 ≤ i ≤ m, let
Ai := {b ∈ Nn : pi divides b}.
Section 2.6 Generating Series. 65

Then

ϕ(n) = |(Nn r (A1 ∪ · · · ∪ Am ))| = n − |A1 ∪ · · · ∪ Am |.

Since the factors pi are pairwise coprime, for any ∅ 6= S ⊆ Nm and


Q
b ∈ Nn we have b ∈ AS if and only if i∈S pi divides b. Therefore,
n
|AS | = Q .
i∈S pi

By Inclusion/Exclusion, it follows that


X Y 1
|A1 ∪ · · · ∪ Am | = n (−1)|S|−1 .
∅6=S⊆Nm i∈S
pi

Therefore
X Y 1
ϕ(n) = n − n (−1)|S|−1
∅6=S⊆Nm i∈S
pi
Y 1 m  
X
|S|
Y 1
= n (−1) = n 1− .
S⊆Nm i∈S
pi i=1
pi

2.6 Exercises.

Exercise 2.1. Calculate the following coefficients.


(a) [x8 ](1 − x)−7 .
(b) [x10 ]x6 (1 − 2x)−5 .
(c) [x8 ](x3 + 5x4 )(1 + 3x)6 .
(d) [x9 ]((1 − 4x)5 + (1 − 3x)−2 ).
(e) [xn ](1 − 2tx)−k .
(f) [xn+1 ]xk (1 − 4x)−2k .
(g) [xn ]xk (1 − x2 )−m .
(h) [xn ]((1 − x2 )−k + (1 − 7x3)−k ).
66 Generating Series. Section 2.6

Exercise 2.2. In each case, find an instance of a Binomial Series that


begins as shown.
(a) 1 − 2x + 3x2 − 4x3 + 5x4 − 6x5 + · · · .
(b) 1 + 3x + 6x2 + 10x3 + 15x4 + 21x5 + · · · .
(c) 1 − x3 + x6 − x9 + x12 − x15 + · · · .
(d) 1 + 2x2 + 4x4 + 8x6 + 16x8 + 32x10 + · · · .
(e) 1 − 4x2 + 12x4 − 32x6 + 80x8 − 192x10 + · · · .
(f) 1 + 6x + 24x2 + 80x3 + 240x4 + 672x5 + · · · .

Exercise 2.3. Give algebraic proofs of these identities from Exercise


1.7.
(a) For all n ∈ N, nk=0 nk k = n 2n−1 .
P 

(b) For all n ∈ N, nk=0 nk k(k − 1) = n(n − 1)2n−2 .


P 

Exercise 2.4. Calculate [xn ](1 + x)−2 (1 − 2x)−2 . Give the simplest ex-
pression you can find.

Exercise 2.5.
(a) Let a ≥ 1 be an integer. For each n ∈ N, extract the coefficient of
xn from both sides of this power series identity:

(1 + x)a 1
2 a
=
(1 − x ) (1 − x)a

to show that
  bn/2c
X  a k + a − 1
n+a−1
= .
a−1 k=0
n − 2k a − 1

(b) Can you think of a combinatorial proof?

Exercise 2.6. Prove the Infinite Sum Lemma 2.11.


Section 2.6 Generating Series. 67

Exercise 2.7. Extend the Product Lemma 2.12 to the product of finitely
many sets with weight functions.

Exercise 2.8. Show that for m, n, k ∈ N,


k     
j n+j −1 m m−n
X
(−1) = .
j=0
j k−j k

Exercise 2.9.
(a) Make a list of all the four-letter “words” that can be formed from
the “alphabet” {a, b}. Define the weight of a word to be the
number of occurrences of ab in it. Determine how many words
there are of weight 0, 1 and 2. Determine the generating series.
(b) Do the same for five-letter words over the same alphabet, but,
preferably, without listing all the words separately.
(c) Do the same for six-letter words.

Exercise 2.10.
(a) Consider throwing two six–sided dice, one red and one green.
The weight of a throw is the total number of pips showing on
the top faces of both dice (that is, the usual score). Make a table
showing the number of throws of each weight, and write down
the generating series.
(b) Do the same as for part (a), but throwing three dice: one red, one
green, and one white.

Exercise 2.11. Construct a table, as in Exercise 2.10(a), if the weight of


a throw is defined to be the absolute value of the difference between
the numberof pips showing on the two dice. Also, write down the
generating series.
68 Generating Series. Section 2.6

Exercise 2.12. Let S be the set of ordered pairs (a, b) of integers with
0 ≤ |b| ≤ a. Each part gives a function ω defined on the set S. De-
termine whether or not ω is a weight function on the set S. If it is
not, then explain why not. If it is a weight function, then determine
the generating series ΦS (x) of S with respect to ω, and write it as a
polynomial or a quotient of polynomials.
(a) For (a, b) in S, let ω((a, b)) = a.
(b) For (a, b) in S, let ω((a, b)) = a + b.
(c) For (a, b) in S, let ω((a, b)) = 2a + b.

Exercise 2.13. Let S = {1, 2, 3, 4, 5, 6}4 be the set of outcomes when


rolling four six-sided dice. For (a, b, c, d) ∈ S, define its weight to be
ω(a, b, c, d) = a + b + c + d. Consider the generating series ΦS (x) of S
with respect to ω.
4
x − x7

(a) Explain why ΦS (x) = .
1−x
(b) How many outcomes in S have weight 19?
(c) Let m, d, k be positive integers. When rolling m dice, each of
which has exactly d sides (numbered with 1, 2, ..., d pips, respec-
tively), how many different ways are there to roll a total of k
pips on the top faces of the dice? (Part (b) is the case m = 4,
d = 6, k = 19.)

Exercise 2.14. Let A be a set with weight function ω : A → N. Show


that for any n ∈ N, the number of α ∈ A with ω(α) ≤ n is

1
[xn ] ΦA (x).
1−x
Section 2.6 Generating Series. 69

Exercise 2.15. For each of the following sets of compositions, obtain


a rational function formula for the generating series of that set (with
respect to size).
(a) Let A be the set of compositions of length congruent to 1
(modulo 3).
(b) Let B be the set of compositions of length congruent to 2
(modulo 3).
(c) Let C be the set of compositions of even length, with each part
being at most 3.
(d) Let D be the set of compositions of odd length, with each part
being at least 2.
(e) Let E be the set of compositions γ = (c1 , c2 , ..., ck ) of any length,
in which each part ci is congruent to i (modulo 2). So c1 is odd, c2
is even, c3 is odd, and so on. (Note that the empty composition
ε = () is in the set E.)

Exercise 2.16.
(a) Let An be the set of all compositions of size n in which every
part is at most three. Obtain a formula for the generating series
P∞ n
n=0 |An | x .
(b) Let Bn be the set of all compositions of size n in which every
part is a positive integer that is not divisible by three. Obtain a
formula for the generating series ∞ n
P
n=0 |Bn | x .
(c) Deduce that for all n ≥ 3, |Bn | = |An | − |An−3 |.
(d)* Can you find a combinatorial proof of part (c)?

Exercise 2.17. Find bijections to explain the equalities in Example


2.21.
Exercise 2.18. Prove that the constructions in the proof of Proposition
2.23 define mutually inverse bijections U
C r {ε}.

Exercise 2.19. For each part, determine the generating series for the
number of subsets S of {1, 2, ..., n} subject to the stated restriction.
(a) Consecutive elements of S differ by at most 2.
(b) Consecutive elements of S differ by at least 3.
(c) Consecutive elements of S differ by at most 3.
(d) Consecutive elements of S differ by a number congruent to 1
(modulo 3).
(e) Consecutive elements of S differ by a number congruent to 2
(modulo 3).
(f) If S = {a1 < a2 < · · · < ak } then ai ≡ i (mod 2) for all 1 ≤ i ≤ k.
(g) Fix integers 1 ≤ g < h. If S = {a1 < a2 < · · · < ak } then
g ≤ ai − ai−1 ≤ h for 2 ≤ i ≤ k.

Exercise 2.20. Fix n, k ∈ N. Let R(n, k) be the number of k-element


subsets S = {a1 < a2 < · · · < ak } of {1, 2, ..., n} such that ai − ai−1 ≥ i
for all 2 ≤ i ≤ k. Show that
 
n − k(k − 1)/2
R(n, k) = .
k

Exercise 2.21. Let p(n) be a polynomial function of n.


(a) Prove, by induction on d = deg(p), that p(n) can be written as a
linear combination of n+j

j
for j = 0, 1, 2, ..., d.
(b) Briefly explain why there is a polynomial Ap (x) such that

X Ap (x)
p(n)xn = .
n=0
(1 − x)d+1

(c) What can you say about the degree of Ap (x)? What can you say
about the value of Ap (1)?
Chapter 3

Binary Strings.

This chapter presents a wide variety of examples to which the generating


series technique of Chapter 2 applies. In Chapter 4 we will see how to
use these generating series to answer the counting problems which arise.
Similar calculations which provide even more information are presented in
Chapter ??.

Definition 3.1. A binary string is a finite sequence σ = b1 b2 · · · bn in


which each bit bi is either 0 or 1. The number of bits is the length of
the string, denoted `(σ) = n. Thus, a binary string of length n is an
element of the Cartesian power {0, 1}n . A binary string of arbitrary
length is an element of the set {0, 1}∗ = ∞ n
S
n=0 {0, 1} . There is exactly
one binary string ε = () of length zero, the empty string with no bits.

Clearly, there are 2n binary strings of length n, so that the generating


series for binary strings with respect to length is

X X 1
Φ{0,1}∗ (x) = x`(σ) = 2n xn = .
1 − 2x
σ∈{0,1}∗ n=0

We will see how to describe various subsets of binary strings in a way which
allows us to determine their generating series (with respect to length).

71
72 Binary Strings. Section 3.1

3.1 Regular Expressions and Rational Languages.

Definition 3.2 (Regular Expressions.). A regular expression is defined


recursively, as follows.
• All of ε, 0, and 1 are regular expressions.
• If R and S are regular expressions, then so is R ` S.
• If R and S are regular expressions, then so is RS.
For any finite k ∈ N we also use Rk for the k-fold concatenation
of R: that is R2 = RR and R3 = RRR, and so on.
• If R is a regular expression, then so is R∗ .

For example, (ε ` 0∗ 00) (1∗ 0∗ 00)∗ 1∗ is a regular expression. These regular


expressions are just formal syntactic constructions with no intrinsic mean-
ing. However, we will interpret them in two different ways.
• A regular expression R will produce a subset R ⊆ {0, 1}∗ . Such a subset
is called a rational language. (See Definition 3.5.)
• A regular expression R will lead to a rational function R(x). (See Defi-
nition 3.11.)
In general, the rational function R(x) is quite meaningless. However, under
favourable conditions on the expression R, it turns out that R(x) = ΦR (x) is
the generating series of the set R with respect to length. Then the machinery
of Chapter 4 can be applied.

Definition 3.3 (Concatenation Product). Let α, β ∈ {0, 1}∗ be binary


strings – so α = a1 a2 · · · am and β = b1 b2 · · · bn . The concatenation of α
and β is the string

αβ = a1 a2 · · · am b1 b2 · · · bn .

Let A, B ⊆ {0, 1}∗ be sets of binary strings. The concatenation product


AB is the set
AB = {αβ : α ∈ A and β ∈ B}.
Section 3.1 Binary Strings. 73

Example 3.4. Consider the sets A = {011, 01} and B = {101, 1101}.
There are four ways to concatenate a string in A followed by a string
in B:
011.101, 011.1101, 01.101, 01.1101.
Here, the dot . indicates the point at which the concatenation takes place.
However, this information is not recorded when passing from α ∈ A
and β ∈ B to their concatenation αβ. Thus the concatenation product
AB consists of the strings

011101, 0111101, 01101, 011101.

The string 011101 is produced twice. The concatenation product AB has


only three elements:

AB = {011101, 0111101, 01101}.

Definition 3.5 (Rational Languages.). A rational language is a set R ⊆


{0, 1}∗ of binary strings that is produced by a regular expression; this
is defined recursively as follows.
• To begin with, ε produces {ε} and 0 produces {0} and
1 produces {1}.
• If R produces R and S produces S, then R ` S produces R ∪ S.
• If R produces R and S produces S, then RS produces RS.
• If R produces R then R∗ produces R∗ = ∞ k=0 R .
k
S

Here Rk is the concatenation product of k copies of R.

It is important to note that a rational language can be produced by many


different regular expressions, as we will see.
In Definition 3.5, when R produces R and S produces S, it might happen
that R ∪ S is not a disjoint union of sets. Also, the concatenation product RS
is not the same as the Cartesian product R × S, as Example 3.4 shows. These
facts lead to complications which are addressed in Section 3.2.
74 Binary Strings. Section 3.2

Example 3.6. Here are some easy examples.


• The regular expression 1∗ produces the rational language

{1}∗ = {ε, 1, 11, 111, 1111, ....}

of all finite strings of 1s (including the empty string ε).


• The regular expression (1 ` 11)∗ also produces the set {1}∗ .
• The regular expression 1(11)∗ produces the rational language of all
strings of 1s of odd (positive) length:

{1, 111, 11111, ...}.

• The regular expression (0 ` 1)∗ produces the rational language


{0, 1}∗ of all binary strings.
• The regular expression 1∗ (01∗ )∗ also produces the rational language
{0, 1}∗ of all binary strings.

Example 3.7. Not every set of binary strings is a rational language.


• The regular expression (01)∗ produces the rational language

{ε, 01, 0101, 010101, 01010101, ...}.

For every even natural number 2j there is exactly one string of


length 2j in this set.
• The set
{ε, 01, 0011, 000111, 00001111, ...}
is not a rational language, even though for every even natural
number 2j there is exactly one string of length 2j in this set.

The problem with Example 3.7 is that to describe the second set we would
need an expression like ∞ j j
S
j=0 0 1 . However, an infinite union like this is
not allowed according to Definition 3.2. The underlying difficulty is that a
regular expression has a “finite memory” and cannot remember arbitrarily
large numbers, like the j ∈ N needed in the above expression. There is a
close connection between rational languages and finite state machines, and
this is a central topic in the theory of computation.
Section 3.2 Binary Strings. 75

3.2 Unambiguous Expressions.

Definition 3.8 (Unambiguous Expression). Let R be a regular expres-


sion that produces a rational language R. Then R is unambiguous if
every string in R is produced exactly once by R. If an expression is
not unambiguous then it is ambiguous.

As is usual with regular expressions, whether or not it is unambiguous


can be decided recursively.

Lemma 3.9 (Unambiguous Expression). Let R and S be unambiguous


expressions producing the sets R and S, respectively.
• The expressions ε and 0 and 1 are unambiguous.
• The expression R ` S is unambiguous if and only if R ∩ S = ∅, so that
R ∪ S is a disjoint union of sets.
• The expression RS is unambiguous if and only if there is a bijection
RS
R×S between the concatenation product RS and the Cartesian
product R×S. In other words, for every string α ∈ RS there is exactly
one way to write α = ρσ with ρ ∈ R and σ ∈ S.
• The expression R∗ is unambiguous if and only if each of the concatena-
tion products Rk is unambiguous and the union ∞ k=0 R is a disjoint
k
S

union of sets.

Proof. Exercise 3.1.

Example 3.10. Here are some easy examples.


• The expression 1∗ is unambiguous.
• The expression (1 ` 11)∗ is ambiguous: 1.11 = 11.1 = 1.1.1.
• The expression (0 ` 1)∗ is unambiguous. This expression produces
each string in {0, 1}∗ one bit at a time, so each string is produced in
exactly one way.
• The expression 1∗ (01∗ )∗ is also unambiguous. First, the expression
01∗ is unambiguous, since it produces a 0 followed by a (possibly
empty) string of 1s – each such string is produced exactly once.
76 Binary Strings. Section 3.2

Now (01∗ )k is unambiguous for any k ∈ N, since any string it pro-


duces will begin with a 0, it will have k bits equal to 0, and the
strings of 1s following these 0s can only be constructed in one way.
Next, (01∗ )∗ is unambiguous since for each k ∈ N, the strings pro-
duced by (01∗ )k have exactly k bits equal to 0 (so the union of sets
corresponding to the outer ∗ is a disjoint union). Finally, 1∗ (01∗ )∗
is unambiguous since for any string it produces, the length of the
initial string of 1s is also determined uniquely.

3.2.1 Translation into generating series.

We translate regular expressions into rational functions as follows.

Definition 3.11. A regular expression leads to a rational function; this


is defined recursively, as follows. Assume that R and S are regular
expressions that lead to R(x) and S(x), respectively.
• To begin with, ε leads to 1 and 0 leads to x and 1 leads to x.
• The expression R ` S leads to R(x) + S(x).
• The expression RS leads to R(x) · S(x).
• The expression R∗ leads to 1/(1 − R(x)).

It is easy to see (again recursively!) that if R leads to R(x), then R(x) is a


rational function.

Example 3.12. Here are some easy examples.


• The unambiguous expression 1∗ leads to 1/(1 − x).
• The ambiguous expression (1 ` 11)∗ leads to 1/(1 − (x + x2 )).
But this expression produces the same rational language as 1∗ .
• The unambiguous expression (0 ` 1)∗ leads to

1 1
= .
1 − (x + x) 1 − 2x

• The unambiguous expression 1∗ (01∗ )∗ leads to

1 1 1
· = .
1 − x 1 − x · 1/(1 − x) 1 − 2x
Section 3.2 Binary Strings. 77

Theorem 3.13. Let R be a regular expression producing the rational lan-


guage R and leading to the rational function R(x). If R is an unambiguous
expression for R then R(x) = ΦR (x), the generating series for R with respect
to length.

Sketch of proof. The proof of this is, as usual, recursive. Or, one could say it
goes by induction on the complexity of the expression R, and uses the fact
that R is unambiguous. Certainly, each of ε, 0, and 1 are unambiguous and
lead to the correct generating series for the sets {ε}, {0}, and {1}, respec-
tively. The induction step follows from Lemma 3.9 and the Sum, Product,
and String Lemmas of Subsection 2.2.2, because each of the operations is
unambiguous.

Example 3.14. If the regular expression R producing R is ambiguous,


then the rational function R(x) is in general meaningless.
• For example, consider the regular expression (ε ` 1)∗ , which pro-
duces the rational language {1}∗ . It is an ambiguous expression.
In fact, it produces every string of 1s in infinitely many ways. The
generating series for the set {1}∗ is 1/(1−x). The expression (ε ` 1)∗
leads to 1/(1 − (1 + x)) = −x−1 . If this were a generating series it
would say that there are exactly −1 objects of size −1, and nothing
else. This makes no sense.
• Similarly, the ambiguous expression (1 ` 11)∗ also produces the set
{1}∗ . However, the expression (1 ` 11)∗ leads to 1/(1 − x − x2 ),
which is also incorrect.

3.2.2 Block decompositions.

Definition 3.15 (Blocks of a string). Let σ = b1 b2 b3 · · · bn be a binary


string of length n. A block of σ is a nonempty maximal subsequence
of consecutive equal bits. To be clearer, a block is a nonempty subse-
quence bi bi+1 · · · bj of consecutive bits all of which are the same (all are
0, or all are 1), and which cannot be made longer. So, either i = 1 or
bi−1 6= bi , and either j = n or bj+1 6= bj .
78 Binary Strings. Section 3.2

Example 3.16. The blocks of the string 11000101110010001111001011 are


separated by dots here:

11.000.1.0.111.00.1.000.1111.00.1.0.11

Proposition 3.17 (Block Decompositions.). The regular expressions

0∗ (1∗ 10∗ 0)∗ 1∗ and 1∗ (0∗ 01∗ 1)∗ 0∗

are unambiguous expressions for the set {0, 1}∗ of all binary strings.
They produce each binary string block by block.

Sketch of proof. By symmetry it is enough to consider the first expression.


The middle part 1∗ 10∗ 0 produces a block of 1s followed by a block of 0s.
This concatenation is unambiguous. The repetition of this (1∗ 10∗ 0)∗ is also
unambiguous, since each pass through the repetition starts with a 1 and
ends with a 0. (Try it out on Example 3.16.) But the string we want to build
might start with a block of 0s: the initial 0∗ allows this but does not require
it, since 0∗ = ε ` 0∗ 0. The final 1∗ similarly allows the string to end with a
block of 1s, but does not require it. All the operations are unambiguous, so
the whole expression is unambiguous.

Example 3.18. The block decomposition 0∗ (1∗ 10∗ 0)∗ 1∗ is unambiguous,


and produces {0, 1}∗ . It had better lead to the right generating series!
After a bit of calculation, we see that it leads to
1 1 1 1
· · = ,
1 − x 1 − x2 /(1 − x)2 1 − x 1 − 2x

which is good.

Example 3.19. Let G be the set of binary strings in which every block
of 1s has odd length. What is the generating series for G with respect
to length? We will modify the block decomposition 0∗ (1∗ 10∗ 0)∗ 1∗ for all
binary strings. The expression 1∗ 1 in the middle produces a block of 1s.
The expression 1∗ = ε ` 1∗ 1 produces either the empty string or a block
Section 3.2 Binary Strings. 79

of 1s. If we want a block of 1s of odd length, then that is produced by


(11)∗ 1. So the expression

G = 0∗ ((11)∗ 1 0∗ 0)∗ (ε ` (11)∗ 1)

is a block decomposition for the set G in question. It is therefore an un-


ambiguous expression that produces G. This expression leads to
 
1 1 x
G(x) = · · 1+
1 − x 1 − (x/(1 − x2 ))(x/(1 − x)) 1 − x2
1 + x − x2 1 + x − x2
= = .
(1 − x)(1 − x2 ) − x2 1 − x − 2x2 + x3

By Theorem 3.13, G(x) = ΦG (x) is the generating series of the set G. It


follows from Theorem 4.8 that the number gn of strings of length n in G
satisfies the linear recurrence relation with initial conditions given by


 1 if n = 0,

1 if n = 1,

gn − gn−1 − 2gn−2 + gn−3 =
 −1 if n = 2,


 0 if n ≥ 3,

(with the convention that gn = 0 for all n < 0). This gives the initial
conditions g0 = 1, g1 = 2, g2 = 3 (which can be checked directly), and the
recurrence gn = gn−1 + 2gn−2 − gn−3 for all n ≥ 3. It is easy to calculate
the first several of these numbers.

n 0 1 2 3 4 5 6 7 8
.
gn 1 2 3 6 10 19 33 61 108

To get an exact formula for gn we would need to factor the denominator


1 − x − 2x2 + x3 to find its inverse roots. They turn out to be slightly
horrible complex numbers, so we won’t do it.
80 Binary Strings. Section 3.2

Example 3.20. Let H be the set of binary strings in which each block of
0s has length one. It is not hard to see that (ε ` 0) (1∗ 1 0)∗ 1∗ is a block
decomposition for H, and is therefore unambiguous. This expression
leads to the formula

X 1 1 1+x
H(x) = hn xn = (1 + x) · · = .
n=0
1− x2 /(1 − x) 1 − x 1 − x − x2

This resembles Examples 2.21 and 2.24 yet again! These are the Fibonacci
numbers – see Example 4.1. With 1/(1 − x − x2 ) = ∞ n
P
n=0 fn x , we see
that for n ≥ 1,
hn = [xn ]H(x) = fn + fn−1 = fn+1 .
Let’s reality check this for n = 5. The strings in H5 are 11111, five strings
with one 0, six strings with two 0s, and 01010. And indeed, f6 = 13.
Neat!

3.2.3 Prefix decompositions.

Example 3.21. Consider the regular expression (0∗ 1)∗ 0∗ . We claim that
this is unambiguous. To see this, let σ = b1 b2 · · · bn be a binary string
produced by this expression. As an example, take

00111010110001011000.

How can this string be produced? The repetition (0∗ 1)∗ produces a bi-
nary string by chopping it into pieces after each occurrence of the bit 1.
But any string produced by this expression is either empty or ends with
a 1. The final “suffix” 0∗ in the expression allows the possibility that the
string might end with some 0s. The string above is produced as

001.1.1.01.01.1.0001.01.1.000

and this is the only way it is produced. This rule – “chop the string into
pieces after each occurrence of the bit 1” – gives a unique way to produce
each binary string from the expression (0∗ 1)∗ 0∗ . It follows that (0∗ 1)∗ 0∗ is
an unambiguous expression for the set {0, 1}∗ of all binary strings. And,
Section 3.3 Binary Strings. 81

indeed, (0∗ 1)∗ 0∗ leads to


1 1 1
· = .
1 − x/(1 − x) 1 − x 1 − 2x

In general, a prefix decomposition for a set of binary strings is a regular


expression of the form A∗ B. The idea is to chop each string that is produced
into initial segments produced by the expression A. There might be a ter-
minal segment produced by the expression B. (It is possible that B = ε.)
One does have to argue that such expressions are unambiguous, but – as in
Example 3.21 – this can usually be done by checking that:
• there is at most one way for a binary string to begin with an initial
segment produced by A, and
• if the string does not begin with an initial segment produced by A then
it is produced by B.
Both of the expressions A and B must be unambiguous, too, of course.
Similarly, a postfix decomposition has the form A(B∗ ).

3.3 Recursive Decompositions.

Recursive decompositions are more general than regular expressions, and


can produce sets of binary strings that are more general than rational lan-
guages. The added feature is that in addition to the elementary building
blocks “ε” and “0” and “1” in a regular expression, we are also allowed to
use letters that stand for sub-expressions on both sides of an equation.

Example 3.22. A simple example is the expression S = ε ` (0 ` 1)S. Since


S appears on both the LHS and the RHS, in some sense this “defines S
in terms of itself”. This is the key idea behind recursive expressions.
One reads this expression as saying that a string produced by S is either
empty, or it consists of a single bit (either 0 or 1) followed by another
(shorter) string produced by S. By induction on the length of the string,
one sees that every binary string is produced exactly once in this way.
Translating the above expression into rational functions by analogy
82 Binary Strings. Section 3.3

with Definition 3.11 leads to an equation for S(x):

S(x) = 1 + (x + x)S(x).

This is easily solved to yield S(x) = 1/(1 − 2x).

Example 3.23. As in Example 3.7, consider the set of strings

B = {ε, 01, 0011, 000111, ...}.

This is not a rational language, but it can be described by the unam-


biguous recursive expression B = ε ` 0 B 1. This leads to the equation
B(x) = 1 + x2 B(x), and thence to B(x) = 1/(1 − x2 ).

Subsection 4.4.2 presents a more substantial example of a recursive decom-


position which produces a set of binary strings that is not a rational lan-
guage. The generating series for that example is not even a rational func-
tion.

3.3.1 Excluded substrings.

Let κ ∈ {0, 1}∗ be a nonempty binary string. We say that σ ∈ {0, 1}∗ contains
κ if there are (possibly empty) binary strings α, β such that σ = α κ β. If
σ does not contain κ then σ avoids or excludes κ. Let Aκ ⊂ {0, 1}∗ be set of
strings that avoid κ. We will develop a general method for calculating the
generating series Aκ (x).

Example 3.24. As an easy first example, consider the case κ = 01011. Let
A be the set of strings avoiding 01011, and let B be the set of strings that
have exactly one occurrence of 01011, at the very end (that is, as a suffix).
Consider the strings in A ∪ B. Such a string is either empty, or it ends
with either a 0 or a 1. If this string is not empty, then removing the last
bit leaves a (possibly empty) string in A (because of the way the sets A
and B are defined). This translates into the relation

A ` B = ε ` A (0 ` 1)
Section 3.3 Binary Strings. 83

for expressions A and B producing A and B, respectively. This leads to


the equation
A(x) + B(x) = 1 + 2x A(x)
for the generating series.
We need another equation in order to determine A(x) and B(x). If
β = α 01011 is an arbitrary string in B, then α is in A, again from the
way the sets A and B are defined. We claim that the converse also holds:
if α ∈ A then β = α 01011 is in B. To see this we need to show that the
only occurrence of 01011 as a substring of β is the one at the very end.
We know that α ∈ A does not contain 01011 as a substring. So if there
is another occurrence of 01011 inside β then it must “overlap” the final
01011 in at least one position (but not in all positions). For this particular
excluded substring this is not possible, as the following table shows:

. . . . 0 1 0 1 1
0 1 0 1 1 . . . .
. 0 1 0 1 1 . . .
. . 0 1 0 1 1 . .
. . . 0 1 0 1 1 .

In each row after the first, there is at least one position at which the
shifted 01011 disagrees with the substring in the first row. So 01011 can-
not overlap itself in a nontrivial way. This gives the relation B = A 01011,
yielding the equation B(x) = x5 A(x). Substituting this into the first
equation gives 1 + 2x A(x) = (1 + x5 ) A(x), which is easily solved. We
conclude that A(x) = 1/(1 − 2x + x5 ).

Example 3.25. As a slightly trickier example, consider the case κ = 01101.


Again, let A be the set of strings avoiding 01101, and let B be the set of
strings that have exactly one occurrence of 01101, at the very end (that
is, as a suffix). As in the previous example, a string in A ∪ B is either
empty, or it ends with either a 0 or a 1. The reasoning of the previous
example also holds in this case, translating into the same relation

A ` B = ε ` A (0 ` 1)

and the same equation A(x) + B(x) = 1 + 2x A(x) for the generating
84 Binary Strings. Section 3.3

series.
The second equation is the slightly trickier part, because the string
01101 can overlap itself in a nontrivial way. As in the previous exam-
ple, we still have the set inclusion B ⊆ A 01101. But the reverse inclu-
sion does not hold in this case: for example 011.01101 = 01101.101 is in
A 01101 but not in B, because it contains a substring 01101 that is not at
the very end.
. . . . 0 1 1 0 1
0 1 1 0 1 . . . .
. 0 1 1 0 1 . . .
. . 0 1 1 0 1 . .
. . . 0 1 1 0 1 .
Looking at all the possible ways that 01101 can overlap itself, we see that
in this case A 01101 = B ∪ B 101. This gives A 01101 = B (ε ` 101) and
x5 A(x) = (1 + x3 )B(x). Substituting B(x) = x5 A(x)/(1 + x3 ) into the first
equation and solving for A(x) yields

1 + 3x + 2x2
A(x) = .
1 − 2x − 2x2 + x3 + x5
The proof of the general result follows exactly the same pattern.

Theorem 3.26. Let κ ∈ {0, 1}∗ be a nonempty string of length n, and let
A = Aκ be the set of binary strings that avoid κ. Let C be the set of all
nonempty suffixes γ of κ such that κ γ = η κ for some nonempty prefix η of
κ. Let C(x) = γ∈C x`(γ) . Then
P

1 + C(x)
A(x) = .
(1 − 2x)(1 + C(x)) + xn

Proof. Let B be the set of strings that contain exactly one occurrence of κ, at
the very end. Any string in A ∪ B is either empty or in the set A{0, 1}, so
that
A ∪ B = {ε} ∪ A {0, 1}.
This yields A(x) + B(x) = 1 + 2x A(x).
The key observation is that if β ∈ B and ρ is a proper prefix of β then
ρ ∈ A. Consequently, B ⊆ A κ. Conversely, consider any σ = α κ in A κ.
Section 3.4 Binary Strings. 85

Maybe σ ∈ B. If σ 6∈ B, then there is an “early” occurrence of κ in α κ that


is not the occurrence at the very end. All such early occurrences of κ must
overlap the final occurrence of κ nontrivially because α ∈ A. Consider the
first such early occurrence of κ in σ = α κ. Then there is a nonempty suffix
γ ∈ C of κ, and a nonempty prefix η of κ, and a (possibly empty) prefix ρ of
α such that
σ = α κ = ρ η κ = ρ κ γ.
Since we are looking at the first early occurrence of κ in σ, the substring ρ κ
is in B. Moreover, this argument shows that these substrings ρ, η, and γ are
determined uniquely from σ. This shows that every σ ∈ A κ is either in B,
or is in B γ for exactly one γ ∈ C, and this decomposition is unique. That is,
[
Aκ = B ∪ Bγ
γ∈C

is a disjoint union of sets. Translating this into generating series yields

xn A(x) = (1 + C(x)) B(x).

Solving this for B(x) and substituting this into the first equation gives

xn
 
1 + 2x A(x) = A(x) · 1 + .
1 + C(x)

Solving this for A(x) yields the result.

In Section ?? we use a completely different method to solve a vast gener-


alization of this excluded substring problem

3.4 Exercises.

Exercise 3.1. Prove Lemma 3.9.

Exercise 3.2. Let A = (10 ` 101) and B = (001 ` 100 ` 1001). For each
of AB and BA, is the expression unambiguous? What is the generating
series (by length) of the set it produces?
86 Binary Strings. Section 3.4

Exercise 3.3. Let A = (00 ` 101 ` 11) and B = (00 ` 001 ` 10 ` 110).
Prove that A∗ is unambiguous, and that B∗ is ambiguous. Find the
generating series (by length) for the set A∗ produced by A∗ .

Exercise 3.4. For each of the following sets of binary strings, write an
unambiguous expression which produces that set.
(a) Binary strings that have no block of 0s of size 3, and no block of
1s of size 2.
(b) Binary strings that have no substring of 0s of length 3, and no
substring of 1s of length 2.
(c) Binary strings in which the substring 011 does not occur.
(d) Binary strings in which the blocks of 0s have even length and
the blocks of 1s have odd length.

Exercise 3.5. Let G = 0∗ ((11)∗ 1(00)∗ 00 ` (11)∗ 11(00)∗ 0)∗ , and let G be
the set of binary strings produced by G.
(a) Give a verbal description of the strings in the set G.
(b) Find the generating series (by length) of G.
(c) For n ∈ N, let gn be the number of strings in G of length n. Give
a recurrence relation and enough initial conditions to uniquely
determine gn for all n ∈ N.

Exercise 3.6.
(a) Show that the generating series (by length) for binary strings in
which every block of 0s has length at least 2 and every block of
1s has length at least 3 is

(1 − x + x3 )(1 − x + x2 )
.
1 − 2x + x2 − x5
(b) Give a recurrence relation and enough initial conditions to
determine the coefficients of this power series.
Section 3.4 Binary Strings. 87

Exercise 3.7.
(a) For n ∈ N, let hn be the number of binary strings of length n
such that each even-length block of 0s is followed by a block of
exactly one 1 and each odd-length block of 0s is followed by a
block of exactly two 1s. Show that

1+x
hn = [xn ] .
1 − x2 − 2x3
(b) Give a recurrence relation and enough initial conditions to
determine hn for all n ∈ N.

Exercise 3.8. Let K be the set of binary strings in which any block of
1s which immediately follows a block of 0s must have length at least
as great as the length of that block of 0s. (Note: this is not a rational
language.)
(a) Derive a formula for K(x) = α∈K x`(α) .
P

(b) Give a recurrence relation and enough initial conditions to


determine the coefficients [xn ]K(x) for all n ∈ N.

Exercise 3.9.
(a) Fix an integer m ≥ 1. Find the generating series (by length) of
the set of binary strings in which no block has length greater
than m.
(b) Fix integers m, k ≥ 1. Find the generating series (by length)
of the set of binary strings in which no block of 0s has length
greater than m, and no block of 1s has length greater than k.

Exercise 3.10. Let L be the set of binary strings in which each block of
1s has odd length, and which do not contain the substring 0001. Let
Ln be the set of strings in L of length n, and let L(x) = ∞ n
P
n=0 |Ln |x .

(a) Give an expression that produces the set L unambiguously, and


explain briefly why it is unambiguous and produces L.
88 Binary Strings. Section 3.4

(b) Use your expression from part (a) to show that

1 + x − x2
L(x) = .
1 − x − 2x2 + x3 + x4

Exercise 3.11. Let M be the set of binary strings in which each block
of 0s has length at most two, and which do not contain 00111 as a
substring. Let Mn be the set of strings in M of length n, and let M (x) =
P∞ n
n=0 |Mn |x .

(a) Give an expression that produces the set M unambiguously, and


explain briefly why it is unambiguous and produces M.
(b) Use your expression from part (a) to show that

1 + x + x2
M (x) = .
1 − x − x2 − x3 + x 5

Exercise 3.12. Let N be the set of binary strings in which each block
of 0s has odd length, and each block of 1s has length one or two. Let
Nn be the set of strings in N of length n, and let N (x) = ∞ n
P
n=0 |Nn |x .

(a) Show that

1 + 2x + x2 − x4 3 + x − 3x2
N (x) = = −2 + x + .
1 − 2x2 − x3 1 − 2x2 − x3
(b) Derive an exact formula for |Nn | as a function of n.

Exercise 3.13. For n ∈ N, let pn be the number of binary strings of


length n in which every block of 0s is followed by a block of 1s with
the same parity of length.
(a) Determine the generating series P (x) = ∞ n
P
n=0 pn x .
(b) Show that if n ≥ 2, then pn = 2 · 3bn/2c−1 .
Exercise 3.14.
(a) Let Q be the set of binary strings that do not contain 11000 as a
substring. For n ∈ N, let Qn be the set of strings in Q of length n.
Obtain a formula for the generating series Q(x) = ∞ n
P
n=0 |Qn |x ,
with a brief explanation.
(b) Let R be the set of compositions, of any length, in which each
part is at most 4. For n ∈ N, let Rn be the set of compositions in
R of size n. Obtain a formula for the generating series R(x) =
P∞ n
n=0 |Rn |x , with a brief explanation.
(c) Deduce that for all integers n ≥ 1, |Rn | = |Qn | − |Qn−1 |.
(d)* Part (c) implies that for every integer n ≥ 1, there is a bijection
Qn
Rn ∪ Qn−1 . Can you determine such a bijection precisely?

Exercise 3.15. Let V be the set of binary strings that do not contain
0110 as a substring. Show that the generating series (by length) for V
is
1 + x3
V (x) = ΦV (x) = .
1 − 2x + x3 − x4

Exercise 3.16.
(a) Let W be the set of binary strings that do not contain 0101 as a
substring. Obtain a formula for the generating series (by length)
of W.
(b) Fix a positive integer r ≥ 1 and consider the binary string (01)r .
(Part (a) is the case r = 2.) Obtain a formula for the generating
series of the set of binary strings that do not contain (01)r .

Exercise 3.17. Let S = A∗ B be an unambiguous prefix decomposition


producing some set of strings S ⊆ {0, 1}∗ . Show that the recursion
R = B ` A R defines an expression R that produces the same set of
strings S ⊆ {0, 1}∗ . Also check that both S and R lead to the rational
function B(x)/(1 − A(x)).
Chapter 4

Recurrence Relations.

In Chapters 2 and 3 we saw how to encode a sequence of numbers as the


coefficients of a power series G(x) = ∞ n
P
n=0 gn x . We used the Sum, Product,
and String Lemmas to obtain algebraic formulas for these generating series.
In this section we will see two techniques for using these algebraic formulas
to compute the coefficients gn , which are the numbers we really want. First
we will do the example of Fibonacci numbers in detail, and then we will
develop the theory in general.

4.1 Fibonacci Numbers.

Example 4.1. The sequence of Fibonacci numbers f = (f0 , f1 , f2 , f3 , ...) is


defined by putting f0 = 1, f1 = 1, and fn = fn−1 + fn−2 for all n ≥ 2.
One can use this information to compute fn iteratively for as long as you
want:

n 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
fn 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610

Can we obtain a formula for fn as a function of n?

The answer is “yes”, of course – we obtain such a formula in this section.


Moreover, this is just the first example of a very general technique, which is
the main subject of this chapter.

91
92 Recurrence Relations. Section 4.1

Example 4.2. We start by finding a formula for the generating series


F (x) = ∞ n
P
n=0 fn x . From the information defining the Fibonacci num-
bers, we see that

X ∞
X
n
F (x) = f0 + f1 x + fn x = 1 + x + (fn−1 + fn−2 )xn .
n=2 n=2

The next step is to write the RHS in terms of F (x).



X ∞
X
n
F (x) = 1 + x + fn−1 x + fn−2 xn
n=2 n=2
X∞ ∞
X
=1+x+x fi x i + x 2
f j xj
i=1 j=0

= 1 + x + x(F (x) − f0 ) + x2 F (x)


= 1 + xF (x) + x2 F (x).

This equation can be solved for F (x), yielding

1
F (x) = .
1 − x − x2

We have seen this generating series before, relating to the sets of composi-
tions F, H, and J in Example 2.21. Obtaining a formula for Fibonacci num-
bers will thus solve the counting problem for each of these sets of composi-
tions.
The key is the denominator of the series, in this case 1−x−x2 .

Example 4.3. We factor the denominator in the form

1 − x − x2 = (1 − αx)(1 − βx)

for some complex numbers α and β, called the inverse roots of the poly-
nomial. To do this we can use the Quadratic Formula, but since we are
looking for the inverse roots of a polynomial we have to be careful. Sub-
stitute x = 1/t and multiply both sides by t2 to get

t2 − t − 1 = (t − α)(t − β).
Section 4.1 Recurrence Relations. 93

Now the inverse roots of the denominator 1 − x − x2 are the (ordinary)


roots of this auxiliary polynomial t2 − t − 1. By the Quadratic Formula,
they are √ √

α −b ± b2 − 4ac 1± 5
= = .
β 2a 2

Example 4.4. Having found the inverse roots of the denominator, the
next step is to apply the Partial Fractions Theorem 4.12, which will be
explained (and proved) in Section 4.3. In this case it implies that there
are complex numbers A and B such that

1 1 A B
2
= = + .
1−x−x (1 − αx)(1 − βx) 1 − αx 1 − βx

There are a few different ways to find the numbers A and B, as we will
see. Here we can multiply by 1 − x − x2 = (1 − αx)(1 − βx) and collect
like powers of x:

1 = A(1 − βx) + B(1 − αx) = (A + B) − (Aβ + Bα)x.

Comparing coefficients, we see that A + B = 1 and Aβ + Bα = 0.


From Aα + Bα = α and Aβ + Bα = 0, we see that

α 5+ 5
A= = .
α−β 10

Similarly, from Aβ + Bβ = β and Aβ + Bα = 0, we see that



β 5− 5
B= = .
β−α 10

Now all that remains is to put the pieces of this calculation together.

Example 4.5. We apply the geometric series expansion to the result of


the partial fractions decomposition. (More generally, we would use bi-
94 Recurrence Relations. Section 4.2

nomial series.)
∞ ∞ ∞
A B X
n n
X
n n
X
+ =A α x +B β x = (Aαn + Bβ n ) xn .
1 − αx 1 − βx n=0 n=0 n=0

It follows that for all n ∈ N, the Fibonacci numbers are given by the
formula
1
fn = [xn ]F (x) = [xn ] = Aαn + Bβ n
1!− x − x2
√ √ n √ √ !n
5+ 5 1+ 5 5− 5 1− 5
= + .
10 2 10 2

That seems kind of weird, since we know that the Fibonacci numbers are

integers. But notice that β = (1 − 5)/2 ≈ −0.618 so that as n → ∞, β n → 0.
√ √ !n
5+ 5 1+ 5
In fact, for all n ∈ N, fn is the integer closest to .
10 2

4.2 Homogeneous Linear Recurrence Relations.

Definition 4.6 (Homogeneous linear recurrence relation). Let g =


(g0 , g1 , g2 , ...) be an infinite sequence of complex numbers. Let a1 , a2 ,
..., ad be in C, and let N ≥ d be an integer. We say that g satisfies a
homogeneous linear recurrence relation provided that

gn + a1 gn−1 + a2 gn−2 + · · · + ad gn−d = 0

for all n ≥ N . The values g0 , g1 , ..., gN −1 are the initial conditions of the
recurrence. The relation is linear because the LHS is a linear combi-
nation of the entries of the sequence g; it is homogeneous because the
RHS of the equation is zero.

In Definition 4.6, if the RHS of the equation is instead a non-zero function


p : N → C, then this is an inhomogeneous linear recurrence relation.
The recurrence relation can be rewritten as
gn = −(a1 gn−1 + a2 gn−2 + · · · + ad gn−d )
for all n ≥ N , and this can be used to compute the numbers gn by induction
Section 4.2 Recurrence Relations. 95

on n, using the initial conditions as the basis of induction.


Consider the Fibonacci numbers from Example 4.1: f0 = f1 = 1 are the
initial conditions, and fn − fn−1 − fn−2 = 0 for all n ≥ 2 is a homogeneous
linear recurrence relation. We derived the formula

X 1
F (x) = f n xn =
n=0
1 − x − x2

for the generating series. This is an instance of a general fact about a se-
quence with a homogeneous linear recurrence relation. Here is another ex-
ample before we see the general theory.

Example 4.7. Define a sequence g = (g0 , g1 , ...) by the initial conditions


g0 = 2, g1 = 5, and g2 = 6, and the relation gn − 3gn−2 − 2gn−3 = 0 for all
n ≥ 3. Obtain a formula for the generating series G(x) = ∞ n
P
n=0 gn x .

The general method is to multiply the recurrence by xn and sum over


all n ≥ N . In this case

X
(gn − 3gn−2 − 2gn−3 ) xn = 0.
n=3

Now we split the LHS into separate summations, reindex them, and
write everything in terms of the power series G(x)

X ∞
X ∞
X
n n
gn x − 3 gn−2 x − 2 gn−3 xn = 0
n=3 n=3 n=3

X X∞
(G(x) − g0 − g1 x − g2 x2 ) − 3x2 gj xj − 2x
3
g k xk = 0
j=1 k=0

(G(x) − 2 − 5x − 6x ) − 3x (G(x) − 2) − 2x3 G(x) = 0


2 2

G(x) − 3x2 G(x) − 2x3 G(x) = 2 + 5x.

It follows that
2 + 5x
G(x) = .
1 − 3x2 − 2x3

Notice how the polynomial 1 − 3x2 − 2x3 in the denominator of this for-
mula is related to the linear recurrence relation gn − 3gn−2 − 2gn−3 = 0 for
n ≥ 3. We can explain the numerator, too, if we make the convention that
96 Recurrence Relations. Section 4.2

gn = 0 for all integers n < 0. Then, using the initial conditions, we have
g0 − 3g−2 − 2g−3 = 2 − 0 − 0 = 2 for n = 0,
g1 − 3g−1 − 2g−2 = 5 − 0 − 0 = 5 for n = 1,
g2 − 3g0 − 2g−1 = 6 − 3 · 2 − 0 = 0 for n = 2,
gn − 3gn−2 − 2gn−3 = 0 for n ≥ 3.

Theorem 4.8. Let g = (g0 , g1 , g2 , ...) be a sequence of complex numbers,


P∞ n
and let G(x) = n=0 gn x be the corresponding generating series. The
following are equivalent.
(a) The sequence g satisfies a homogeneous linear recurrence relation

gn + a1 gn−1 + · · · + ad gn−d = 0 for all n ≥ N,

with initial conditions g0 , g1 , ..., gN −1 .


(b) The series G(x) = P (x)/Q(x) is a quotient of two polynomials.
The denominator is

Q(x) = 1 + a1 x + a2 x2 + · · · + ad xd

and the numerator is P (x) = b0 + b1 x + b2 x2 + · · · + bN −1 xN −1 ,


in which
bk = gk + a1 gk−1 + · · · + ad gk−d
for all 0 ≤ k ≤ N − 1, with the convention that gn = 0 for all n < 0.

Proof. To prove this theorem, we just copy the calculation in Example 4.7,
but do it in the most general case. For convenience, let a0 = 1. Assume that
part (a) holds, and let
Q(x) = 1 + a1 x + a2 x2 + · · · + ad xd .
Consider the product Q(x)G(x):
d
! ∞
!
X X
Q(x)G(x) = aj x j gn xn
j=0 n=0
∞ ∞
d X d
!
X X X
n+j
= aj gn x = aj gk−j xk .
j=0 n=0 k=0 j=0
Section 4.2 Recurrence Relations. 97

In the last step we have re-indexed the double sum using k = n + j, and
used the convention that gn = 0 for all n < 0.
The coefficient of xk in this formula is gk + a1 gk−1 + · · · + ad gk−d . This
is the LHS of the recurrence relation for g applied when n = k. Thus, this
coefficient is zero for k ≥ N . On the other hand, for 0 ≤ k ≤ N − 1, we see
that it is dj=0 aj gk−j = bk by the way the numbers bk are defined. That is,
P

N
X −1
Q(x)G(x) = bk xk = P (x),
k=0

and it follows that G(x) = P (x)/Q(x). This shows that (a) implies (b).
Conversely, assume that (b) holds and that G(x) = P (x)/Q(x) is as given.
We essentially run the argument for the first part of the proof in reverse.
The equations bk = gk + a1 gk−1 + · · · + ad gk−d for 0 ≤ k ≤ N − 1 (with the
convention that gn = 0 for n < 0) determine the initial conditions g0 , g1 ,...
gN −1 inductively. For n ≥ N , the coefficient of xn in P (x) = Q(x)G(x) is
zero. This implies that gk + a1 gk−1 + · · · + ad gk−d = 0 for all k ≥ N , showing
that (b) implies (a).

Theorem 4.8 is useful in both directions, as the following two examples


show.

X 1 − 3x + 4x2
Example 4.9. Let D(x) = d n xn = 3
. Obtain a homoge-
n=0
1 − 2x + 3x
neous linear recurrence relation and initial conditions satisfied by the
sequence d = (d0 , d1 , d2 , ...).
From Theorem 4.8 we can read from the RHS that for all n ∈ N:


 1 if n = 0,

−3 if n = 1,

dn − 2dn−1 + 3dn−3 =

 4 if n = 2,

 0 if n ≥ 3,

with the convention that dn = 0 if n < 0. We can determine the initial


conditions inductively as follows: d0 = 1; d1 − 2d0 = −3, so d1 = −1;
d2 − 2d1 = 4, so d2 = 2. The recurrence dn − 2dn−1 + 3dn−3 = 0 holds for
all n ≥ 3. Using the initial conditions d0 = 1, d1 = −1, d2 = 2, and the
98 Recurrence Relations. Section 4.2

recurrence dn = 2dn−1 − 3dn−3 for all n ≥ 3, we can compute dn for as


long as we want:

n 0 1 2 3 4 5 6 7 8
dn 1 −1 1 1 5 4 5 −5 −22

Example 4.10. A sequence s = (s0 , s1 , s2 , ...) is defined by the initial con-


ditions s0 = 1, s1 = 2, s2 = 1, and the recurrence sn − sn−1 − 2sn−3 = 0 for
all n ≥ 3. Obtain a formula for the generating series S(x) = ∞ n
P
n=0 sn x .

Since we have the information at hand, we might as well compute a


few more values of sn :

n 0 1 2 3 4 5 6 7
sn 1 2 1 3 7 9 15 29

To get the generating series, Theorem 4.8 implies immediately that the
denominator is 1 − x − 2x3 . To obtain the numerator we apply the recur-
rence for small values of n, with the convention that sn = 0 if n < 0.

 1 if n = 0,
sn − sn−1 − 2sn−3 = 2 − 1 = 1 if n = 1,
1 − 2 = −1 if n = 2.

Thus, the numerator is 1 + x − x2 . The generating series is

1 + x − x2
S(x) = .
1 − x − 2x3

Example 4.11. Let’s revisit Example 2.22, concerning the set Q of all com-
positions in which each part is at least two, and the number of parts is
even. We derived the generating series

X 1 − 2x + x2
Q(x) = q n xn = .
n=0
1 − 2x + x2 − x4
Section 4.3 Recurrence Relations. 99

From Theorem 4.8 we see immediately that




 1 if n = 0,

−2 if n = 1,

qn − 2qn−1 + qn−2 − qn−4 =

 1 if n = 2,

 0 if n ≥ 3,

with the convention that qn = 0 if n < 0. We can inductively calculate


the first several values of qn :

n 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
qn 1 0 0 0 1 2 3 4 6 10 17 28 45 72 116

We have determined that |Q14 | = 116, but we have not listed all these
compositions individually. That is pretty cool, when you think about it.

4.3 Partial Fractions.

A rational function is a quotient of two polynomials P (x)/Q(x). This is anal-


ogous to a rational number being a quotient of two integers.

Theorem 4.12 (Partial Fractions). Let G(x) = P (x)/Q(x) be a rational


function in which deg P < deg Q and the constant term of Q(x) is 1. Factor
the denominator to obtain its inverse roots:

Q(x) = (1 − λ1 x)d1 (1 − λ2 x)d2 · · · (1 − λs x)ds

in which λ1 , ..., λs are distinct nonzero complex numbers and d1 +· · ·+ds =


d = deg Q. Then there are d complex numbers:
(1) (2) (d1 ) (1) (2) (d2 )
C1 , C1 , ..., C1 ; C2 , C2 , ..., C2 ; ... ; Cs(1) , Cs(2) , ..., Cs(ds )

(which are uniquely determined) such that


s X ds (j)
P (x) X Ci
G(x) = = .
Q(x) i=1 j=1
(1 − λi x)j
100 Recurrence Relations. Section 4.3

Proof. Consider the set VQ of all rational functions P (x)/Q(x) in which Q is


a fixed polynomial as in the statement of the theorem, and P is any poly-
nomial of degree strictly less than d = deg Q. It is easily seen that VQ is a
vector space over the complex numbers C, since if P (x) and R(x) both have
degree less than d and α ∈ C then P (x) + αR(x) has degree less than d. It is
also clear that the vectors

1 x x2 xd−1
, , , ...,
Q(x) Q(x) Q(x) Q(x)

span VQ as a vector space over C. Thus, the dimension of VQ is at most d.


Now we claim that for every 1 ≤ i ≤ s and 1 ≤ j ≤ di , the quotient
1/(1 − λi x)j is in VQ . This is because

(1 − λi x)di −j h6=i (1 − λh x)dh


Q
1
=
(1 − λi x)j Q(x)

and the numerator has degree d − j ≤ d − 1 < d.


The essential point in the proof is that the set of vectors
 
1
B = : 1 ≤ i ≤ s and 1 ≤ j ≤ di
(1 − λi x)j

in VQ is linearly independent. From this we can conclude that the dimension


of VQ is at least d1 + · · · + ds = d. It then follows that dim VQ = d and that B
is a basis for VQ . Therefore, every vector in VQ can be written uniquely as a
linear combination of vectors in B. That is exactly what the Partial Fractions
Theorem is claiming.
It remains only to show that B is a linearly independent set. Consider
any linear combination of vectors in B which gives the zero vector:

s X
ds (j)
X Ci
= 0. (4.1)
i=1 j=1
(1 − λi x)j

(j)
We must show that Ci = 0 for all 1 ≤ i ≤ s and 1 ≤ j ≤ di . Suppose not.
Then there is some index 1 ≤ p ≤ s for which at least one of the coefficients
(1) (2) (d ) (t)
Cp , Cp , ..., Cp p is not zero. Letting Cp 6= 0 be the one with the largest
(t+1) (d )
superscript, we also have Cp = · · · = Cp p = 0.
Section 4.3 Recurrence Relations. 101

Now multiply equation (4.1) by (1 − λp x)t . Separating out the terms with
(t+1) (d )
i = p and using the fact that Cp = · · · = Cp p = 0, we see that
t di
X XX (j) (1 − λp x)t
Cp(j) (1 − λp x) t−j
+ Ci = 0.
j=1 i6=p j=1
(1 − λi x)j

The LHS is a rational function of the variable x which does not have a pole
at the point x = 1/λp , so we can substitute this value for x. But every term
on the LHS has a factor of (1 − λp x) except for the term with i = p and j = t.
Thus, upon making the substitution x = 1/λp this equation becomes
Cp(t) = 0.
But this contradicts our choice of p and t. This contradiction shows that all
(j)
the coefficients Ci in equation (4.1) must be zero, and it follows that the set
B is linearly independent.
Since B is a set of d linearly independent vectors in a vector space VQ
of dimension at most d, it follows that B is a basis for VQ , and the proof is
complete.

Example 4.13. Let’s re-examine the generating series

2 + 5x
G(x) =
1 − 3x2 − 2x3
from Example 4.7. This satisfies the hypotheses of the Partial Fractions
Theorem 4.12. The denominator 1 − 3x2 − 2x3 vanishes when x = −1, so
that 1 + x is a factor. Some calculation shows that

1 − 3x2 − 2x3 = (1 + x)(1 − x − 2x2 ) = (1 + x)2 (1 − 2x).

Thus, there are complex numbers A, B, C such that

2 + 5x A B C
= + + .
1 − 3x2 − 2x3 1 + x (1 + x)2 1 − 2x

Now multiply by the denominator on the LHS.

2 + 5x = A(1 + x)(1 − 2x) + B(1 − 2x) + C(1 + x)2 .

This is an equality of polynomials, so it holds for any value of x.


102 Recurrence Relations. Section 4.3

• At x = −1 we find that 2 − 5 = B(1 + 2), so that B = −1.


• At x = 1/2 we find that 2 + 5/2 = C(3/2)2 , so that 9/2 = C(9/4), so
that C = 2.
• At x = 0 we find that 2 = A + B + C, so that A = 2 − B − C =
2 + 1 − 2 = 1.
Therefore
2 + 5x 1 1 2
= − + .
1 − 3x2 − 2x3 1 + x (1 + x)2 1 − 2x
Now we can expand each of these terms using Binomial Series, and col-
lect the results.
∞ ∞   ∞
X
n
X n+1 X
G(x) = (−x) − (−x)n + 2 (2x)n
n=0 n=0
1 n=0

X
= ((−1)n − (n + 1)(−1)n + 2 · 2n ) xn
n=0

X
2n+1 − n(−1)n xn .

=
n=0

It follows that gn = [xn ]G(x) = 2n+1 + n(−1)n+1 for all n ∈ N. This can
be “reality checked” by comparison with the initial conditions g0 = 2,
g1 = 5, and g2 = 6, and the recurrence relation gn − 3gn−2 − 2gn−3 = 0 for
all n ≥ 3 defining this sequence in Example 4.7. The first few values are

n 0 1 2 3 4 5 6
gn 2 5 6 19 28 69 122
Section 4.3 Recurrence Relations. 103

4.3.1 The Main Theorem.

Theorem 4.14. Let g = (g0 , g1 , g2 ) be a sequence of complex numbers, and


let G(x) = ∞ n
P
n=0 gn x be the corresponding generating series. Assume that
the equivalent conditions of Theorem 4.8 hold, and that

P (x)
G(x) = R(x) +
Q(x)

for some polynomials P (x), Q(x), and R(x) with deg P (x) < deg Q(x) and
Q(0) = 1. Factor Q(x) to obtain its inverse roots and their multiplicities:

Q(x) = (1 − λ1 x)d1 (1 − λ2 x)d2 · · · (1 − λs x)ds .

Then there are polynomials pi (n) for 1 ≤ i ≤ s, with deg pi (n) < di , such
that for all n > deg R(x),

gn = p1 (n)λn1 + p2 (n)λn2 + · · · + ps (n)λns .

Proof. The conclusion of the theorem only concerns terms with n > deg R(x),
so we can basically ignore the polynomial R(x). In truth, all it is doing is
getting in the way, and preventing the formula from holding for smaller
values of n. So we are going to concentrate on the quotient P (x)/Q(x), to
which the Partial Fractions Theorem 4.12 applies.
Consider the factor (1 − λi x)di of the denominator Q(x). In the partial
fractions expansion of P (x)/Q(x), this contributes
(1) (2) (d )
Ci Ci Ci i
+ + ··· + .
1 − λi x (1 − λi x)2 (1 − λi x)di

Each term is a binomial series, and can be expanded accordingly:

di (j) di ∞  
X Ci X (j)
X n+j−1 n n
= Ci λi x
j=1
(1 − λi x)j j=1 n=0
j−1
∞ di  !
(j) n + j − 1
X X
= Ci λni xn .
n=0 j=1
j−1

n+j−1

Notice that j−1
is a polynomial function of n of degree j − 1. It follows
104 Recurrence Relations. Section 4.3

that
di  
X (j) n+j−1
pi (n) = Ci
j=1
j−1
is a polynomial function of n of degree at most di − 1. The contribution of
the inverse root λi to the coefficient gn = [xn ]G(x) is thus pi (n)λni . By the
form of the partial fractions expansion we see that

gn = p1 (n)λn1 + p2 (n)λn2 + · · · + ps (n)λns ,

completing the proof.

The converse of Theorem 4.14 also holds – see Exercise 4.11.


One can use Theorem 4.14 to go straight from a recurrence relation to a
formula for its entries, without doing Partial Fractions explicitly. Here is an
example of this kind of calculation.

Example 4.15. A sequence h of integers is given by the initial conditions h0 =


1, h1 = 1, h2 = 0, h3 = 2, h4 = −4, h5 = 3, and the recurrence hn − 3hn−1 +
4hn−3 = 0 for all n ≥ 6. Obtain a formula for hn as a function of n.
From Theorem 4.8 we see that the denominator of the generating se-
ries H(x) = hn xn is 1 − 3x + 4x3 . This vanishes at x = −1, so 1 + x is a
factor. After some work, we obtain

1 − 3x + 4x3 = (1 + x)(1 − 4x + 4x2 ) = (1 − 2x)2 (1 + x).

Theorem 4.14 implies that there are constants A, B, C such that for suffi-
ciently large n, hn = (A + Bn)2n + C(−1)n . To determine these constants
we need to take data from the sequence h from a point later than the de-
gree of the polynomial R(x) appearing in Theorem 4.14. From Theorem
4.8, in this case the degree of the numerator of the generating series H(x)
is no more than five, since the general case of the recurrence holds for
n ≥ 6. Writing

P (x) (1 − 3x + 4x3 )R(x) + P (x)


H(x) = R(x) + = ,
1 − 3x + 4x3 1 − 3x + 4x3
it follows that the degree of R(x) is at most two. So we can fit the form
hn = (A + Bn)2n + C(−1)n to the data h3 = 2, h4 = −4, and h5 = 3.
Section 4.3 Recurrence Relations. 105

This gives three equations in three unknowns – a standard linear algebra


problem.

h3 = 2 = (A + 3B)8 − C = 8A + 24B − C
h4 = −4 = (A + 4B)16 + C = 16A + 64B + C
h5 = 3 = (A + 5B)32 − C = 32A + 160B − C

In this case, it is a rather unpleasant linear algebra problem. Sparing you


the details, the solution is A = −5/16, B = 1/16, C = −3, and so

hn = (n − 5)2n−4 − 3(−1)n

for all n ≥ 3. The values for hn with 0 ≤ n ≤ 2 are given in the initial
conditions.

4.3.2 Inhomogeneous Linear Recurrence Relations.

Example 4.16. Define a sequence of integers g = (g0 , g1 , g2 , ...) by the


initial conditions g0 = 1 and g1 = 2, and the recurrence relation

gn = gn−1 + 2 gn−2 − n + 1

for all n ≥ 2. This clearly determines the sequence g inductively:

n 0 1 2 3 4 5 6 7 8
gn 1 2 3 5 8 14 25 47 90

What is gn as a function of n ∈ N?

We solve Example 4.16 by generalizing the method above just a little bit.
First, write the recurrence in the form

gn − gn−1 − 2 gn−2 = −n + 1

for all n ≥ 2. This is an inhomogeneous linear recurrence relation according


to Definition 4.6. But we can proceed just as before. We begin by obtaining
a formula for the generating series G(x) = ∞ n
P
n=0 gn x . Multiply both sides
106 Recurrence Relations. Section 4.3

by xn and sum over all n ≥ 2. On the RHS we obtain



X ∞
X ∞
X
(−n + 1) xn = (−(j + 2) + 1) xj+2 = −x2 (j + 1) xj
n=2 j=0 j=0
2
−x
= .
(1 − x)2
On the LHS we obtain
X∞
(gn − gn−1 − 2 gn−2 ) xn
n=2
X∞ ∞
X ∞
X
n n
= gn x − gn−1 x − 2 gn−2 xn
n=2 n=2 n=2

X ∞
X
= (G(x) − g0 − g1 x) − x g j x j − 2 x2 gk xk
j=1 k=0
2
= (G(x) − 1 − 2x) − x (G(x) − 1) − 2x G(x)
= (1 − x − 2x2 )G(x) − 1 − x.
Equating the LHS and the RHS yields
x2 (1 + x)(1 − x)2 − x2
(1 − x − 2x2 )G(x) = 1 + x − =
(1 − x)2 (1 − x)2
Noting that 1 − x − 2x2 = (1 + x)(1 − 2x), we obtain the formula
1 − x − 2x2 + x3
G(x) = .
(1 + x)(1 − x)2 (1 − 2x)
This is a rational function, and so the Main Theorem 4.14 applies. There are
complex numbers A, B, C, D such that gn = A(−1)n + (B + Cn) + D2n for
all n ∈ N. For n ∈ {0, 1, 2, 3} this yields the system of linear equations
A +B +D =1
−A +B +C +2D =2
A +B +2C +4D =3
−A +B +3C +8D =5
Solving this system yields A = −1/12, B = 3/4, C = 1/2, D = 1/3, so that
1
2n+2 + (6n + 9) − (−1)n

gn =
12
for all n ∈ N.
Section 4.3 Recurrence Relations. 107

Example 4.17. The denominator of G(x) in the above example is 1 − 3x +


x2 + 3x3 − 2x4 . From Theorem 4.8 we see that the sequence g satisfies the
homogeneous linear recurrence relation and initial conditions given by


 1 if n = 0,

 −1 if n = 1,


gn − 3gn−1 + gn−2 + 3gn−3 − 2gn−4 = −2 if n = 2,



 1 if n = 3,

0 if n ≥ 4.

This agrees with the results above.

Examples 4.16 and 4.17 illustrate a general fact: if the generating series
of the RHS in an inhomogeneous linear recurrence relation is a rational
function, then the generating series for the entries of the sequence is also a
rational function. Thus, the sequence in fact satisfies a homogeneous linear
recurrence relation, so we are actually back in the case we have already
considered. Proving this in general is the main point of this subsection.
The following terminology is not standard but will be convenient. A
function q : N → C is polyexp if there are polynomial functions qi (n) and
complex numbers βi ∈ C for 1 ≤ i ≤ t such that

q(n) = q1 (n)β1n + q2 (n)β2n + · · · + qt (n)βtn (4.2)



for all n ∈ N. For example, cos(nθ) = (eiθn + e−iθn )/2 is polyexp, but n is
not. More generally, the function q : N → C is eventually polyexp if there is
an integer M ∈ N such that equation (4.2) holds for all n ≥ M . The Main
P∞ n
Theorem 4.14 thus states that if G(x) = n=0 gn x is a rational function
then gn is an eventually polyexp function of n. (Exercise 4.11 is the converse
implication.)

Theorem 4.18. Let g = (g0 , g1 , g2 , ...) be a sequence of complex numbers.


The following are equivalent.
(a) The sequence g satisfies a homogeneous linear recurrence relation (with
initial conditions).
(b) The sequence g satisfies a possibly inhomogeneous linear recurrence
relation (with initial conditions) in which the RHS is an eventually
108 Recurrence Relations. Section 4.4

polyexp function.
n
P
(c) The generating series G(x) = n=0 gn x is a rational function (a
quotient of polynomials in x).
(d) The sequence g = (g0 , g1 , g2 , ...) is an eventually polyexp function.

Proof. Theorem 4.8 shows that conditions (a) and (c) are equivalent. Theo-
rem 4.14 shows that (c) implies (d). That (d) implies (c) is left as Exercise
4.11. It is clear that (a) implies (b). All that remains is to show that (b) im-
plies (c).
Thus, assume that g satisfies the linear recurrence relation
gn + a1 gn−1 + · · · + ad gd = q(n)
for all n ≥ N , with initial conditions g0 , g1 , ..., gN −1 , in which q : N → C is an
eventually polyexp function as in equation (4.2) for all n ≥ M .
UNDER CONSTRUCTION

4.4 Quadratic Recurrence Relations.

Let g = (g0 , g1 , g2 , ...) be a sequence of numbers with generating series G(x) =


P∞ n
n=0 gn x . In Theorem 4.8 we saw that g satisfies a homogeneous linear re-
currence relation (with initial conditions) if and only if G(x) = P (x)/Q(x) is
a rational function. Rewriting this as Q(x)G(x) − P (x) = 0, we see that G(x)
is a solution to a linear equation: QG − P = 0.

Definition 4.19. The sequence g satisfies a quadratic recurrence if its


generating series G(x) satisfies a quadratic equation:

A(x)G(x)2 + B(x)G(x) + C(x) = 0.

Here, the coefficients A(x), B(x), and C(x) are power series in x.

There are two solutions to the equation in Definition 4.19, and they can
be found using the Quadratic Formula:
 p
G+ (x) −B(x) ± B(x)2 − 4 A(x) C(x)
= .
G− (x) 2 A(x)
Section 4.4 Recurrence Relations. 109

Rigorous justification for this kind of algebra with power series is discussed
in detail in CO 330. If G(x) is a generating series for some combinatorial ob-
jects then it has only nonnegative coefficients and nonnegative exponents.
This can be used to decide which case of the ± sign to take. In general, only
one of G+ (x) or G− (x) is the correct generating series.

4.4.1 The general binomial series.

In Section 2.1 we saw the Binomial Theorem and The Binomial Series with
negative integer exponents. That is, for a natural number n ∈ N,
n  
n
X n k
(1 + x) = x
k=0
k

and for a positive integer t ≥ 1,


∞  
1 X n+t−1 n
= x .
(1 − x)t n=0
t−1

These are two special cases of the general binomial series.

Definition 4.20. For any complex number α ∈ C and nonnegative


integer k ∈ N, the k-th binomial coefficient of α is
 
α 1
= (α)(α − 1) · · · (α − k + 1).
k k!

This binomial coefficient is a polynomial function of α of degree k.

Theorem 4.21 (The Binomial Series). For any complex number α ∈ C,


∞  
α
X α
(1 + x) = xk .
k=0
k

Sketch of proof. We can think of (1+x)α as a function of a complex variable x.


The only possible singularity is that 0α might not be well-defined – this can
happen only for x = −1. Therefore, (1 + x)α is analytic in the disc |x| < 1,
110 Recurrence Relations. Section 4.4

and so it has a Taylor series expansion. By Taylor’s Theorem, the coefficient


of xk in this Taylor series expansion is
1 dk
 

α 1
α−k α
k
(1 + x) = (α)(α − 1) · · · (α − k + 1)(1 + x) = .
k! dx x=0 k! x=0 k
This proves the stated formula.

We will use the following special case.



 
X 1 2k − 2 k
Proposition 4.22. 1 − 4x = 1 − 2 x .
k=1
k k − 1



 
X
k k 1/2 k
Proof. By Theorem 4.21, 1 − 4x = (−1) 4 x .
k=0
k
For k = 0, the coefficient of x0 is (−1)0 40 1/2

0
= 1.
For k ≥ 1, we can calculate as follows.
 
k k 1/2 1
(−1) 4 = (−1)k 4k (1/2)(−1/2)(−3/2) · · · (1/2 − k + 1)
k k!
1
= −4k (1/2)(1/2)(3/2) · · · (k − 3/2)
k!
k 1
= −2 (1)(1)(3)(5) · · · (2k − 3)
k!
2 (1)(3) · · · (2k − 3) (2)(4) · · · (2k − 2)
=− · ·
k (k − 1)! (k − 1)!
 
2 2k − 2
=− .
k k−1
(Where did we use the fact that k ≥ 1 in this calculation?)

4.4.2 Catalan numbers.


1 2n

The numbers Cn = n+1 n
are called Catalan numbers . The first few Cata-
lan numbers are shown here:
n 0 1 2 3 4 5 6 7 8 9 10
.
Cn 1 1 2 5 14 42 132 429 1430 4862 16796
Catalan numbers occur surprisingly often in answers to counting problems.
Section 4.4 Recurrence Relations. 111

Example 4.23 (Well-Formed Parenthesizations.).


A well-formed parenthesization (WFP) is a sequence of n opening paren-
theses and n closing parentheses which “match together” using the usual
rules for grouping parentheses. The size of a WFP is the number of open-
ing parentheses in it. Here are all the WFPs of size 3:

()()() ()(()) (())() (()()) ((()))

And here are all the WFPs of size 4:

()()()() (())()() (()())() ()()(())


(())(()) (()(())) ()(())()
((()))() ((())()) ()(()()) (()()())
((()())) ()((())) (((())))

We determine the number wn of WFPs of size n, for all n ∈ N. Let


X
W (x) = w n xn
n=0

be the generating series for WFPs with respect to size.


We can obtain a quadratic recurrence for W (x), as follows. The empty
sequence ε contributes x0 = 1 to the generating series W (x). Any other
WFP γ begins with an opening parenthesis. There is exactly one closing
parenthesis which matches to the beginning parenthesis. That is, γ = ( α ) β
for some other sequences α and β. Note that α or β might be empty. Because
of the way parentheses are matched to each other, both α and β are in fact
WFPs themselves. The total number of opening parentheses in γ is n(γ) =
1 + n(α) + n(β). Conversely, given any WFPs α and β we can always form
a new nonempty WFP: ( α ) β.
Writing a 0 instead of a (, and a 1 instead of a ), a WFP can be thought of
as a binary string in {0, 1}∗ . Let W be the set of all binary strings correspond-
ing to WFPs. The previous paragraph justifies the claim that the recursive
decomposition

W = ε ` 0W1W
112 Recurrence Relations. Section 4.4

is unambiguous. This allows us to calculate as follows:


X X
W (x) = xn(γ) = xn(ε) + xn(γ)
γ∈W γ∈Wr{ε}
X X
=1 + x1+n(α)+n(β)
α∈W β∈W
! !
X X
n(α) n(β)
=1 + x x x
α∈W β∈W

= 1 + xW (x)2 .

Now we can solve this equation xW (x)2 − W (x) + 1 = 0 using the Quadratic
Formula:  √
W+ (x) 1 ± 1 − 4x
= .
W− (x) 2x

Proposition 4.22 gives the power series for 1 − 4x, so that
√ ∞   !
1 ± 1 − 4x 1 1 X 1 2n n+1
= ± 1−2 x .
2x 2x 2x n=0
n+1 n

To get nonnegative coefficients, and to cancel the term 1/2x, we need to take
the minus sign from the ±. The result is
∞  
X 1 2n n
W (x) = x .
n=0
n+1 n

1 2n

Thus, the number of WFPs of size n is the n-th Catalan number Cn = n+1 n
,
for each n ∈ N.

Since the generating series for the set W is W (x) = (1 − 1 − 4x)/2x,
which is not a rational function, it follows from Theorem 3.13 that the set of
WFPs is not a rational language.
Section 4.5 Recurrence Relations. 113

4.5 Exercises.

Exercise 4.1. For each of the sets of compositions from Exercise 2.15,
do the following.
• Derive a recurrence relation and initial conditions for the coeffi-
cients of the corresponding generating series G(x) = ∞ n
P
n=0 gn x .
• Calculate the coefficients g0 , g1 , ... up to g9 .

Exercise 4.2. Let K be the set of compositions γ = (c1 , c2 , ..., ck ) with


at least one part, and such that the first part is odd. Let K(x) be the
generating series for K with respect to size.
(a) Show that
x
K(x) = .
(1 + x)(1 − 2x)
(b) Use part (a) to show that, among all 2n−1 compositions of size
n ≥ 1, the fraction of these compositions in the set K is
 n−1
2 1 −1
+ .
3 3 2

Exercise 4.3. Consider the power series



X 1 − 2x2
cn x n = 2 3
= 1 + 5x + 15x2 + 39x3 + · · ·
n=0
1 − 5x + 8x − 4x

(a) Give a linear recurrence relation that (together with the initial
conditions above) determines the sequence of coefficients (cn :
n ≥ 0) uniquely.
(b) Derive a formula for cn as a function of n ≥ 0.
[Hint: 1 − 5x + 8x2 − 4x3 = (1 − x)(1 − 4x + 4x2 ).]

Exercise 4.4. Consider the power series



X x + 7x2
A(x) = an x n = .
n=0
1 − 3x2 − 2x3
114 Recurrence Relations. Section 4.5

(a) Write down a linear recurrence relation and enough initial con-
ditions to determine the sequence (an : n ∈ N) uniquely.
(b) Given that 1 − 3x2 − 2x3 = (1 − 2x)(1 + x)2 , obtain a formula for
an as a function of n ∈ N.

Exercise 4.5. Consider the power series



X 3 − 11x + 11x2
cn x n = = 3 + x + 0x2 + x3 + 6x4 + 19x5 + · · ·
n=0
1 − 4x + 5x2 − 2x3

(a) Give a linear recurrence relation that (together with the initial
conditions above) determines the sequence of coefficients (cn :
n ≥ 0) uniquely.
(b) Derive a formula for cn as a function of n ≥ 0.

Exercise 4.6. A sequence of integers is determined by the initial con-


ditions g0 = 1, g1 = 2, g2 = 3, and the recurrence relation gn =
2gn−1 − gn−2 + 2gn−3 for all n ≥ 3.
(a) Obtain a rational function formula for the generating series

X
G(x) = gn xn = 1 + 2x + 3x2 + 6x3 + 13x4 + 26x5 + 51x6 + · · · .
n=0

(b) Obtain a formula for the coefficient gn as a function of n ∈ N.

Exercise 4.7. Define a sequence of numbers (cn : n ∈ N) by the initial


conditions c0 = 1, c1 = 2, and c2 = 3, and the recurrence relation
cn = −cn−1 + 2cn−2 + 2cn−3 for all n ≥ 3.
(a) Obtain an algebraic formula for the rational function

X
C(x) = cn xn = 1 + 2x + 3x3 + 3x3 + 7x4 + 5x5 + · · · .
n=0

(b) Obtain a formula for cn as a function of n ∈ N.


Section 4.5 Recurrence Relations. 115

Exercise 4.8.
(a) Obtain a formula for the coefficients of the rational function

X 1 + 3x − x2
B(x) = bn x n = .
n=0
1 − 3x2 − 2x3

(b) Derive a recurrence relation and use it to check your answer.

Exercise 4.9. Define a sequence (hn : n ∈ N) by the initial conditions


h0 = 1, h1 = 2, h2 = 0, h3 = 5, and the recurrence relation hn =
−2hn−1 + hn−2 + 4hn−3 + 2hn−4 for all n ≥ 4.
(a) Obtain an algebraic formula for the rational function

X
H(x) = hn xn = 1 + 2x + 0x2 + 5x3 + 0x4 + 9x5 + · · · .
n=0

(b) Obtain a formula for hn as a function of n ∈ N.

Exercise 4.10.
(a) Find rational numbers A, B, C such that for all n ∈ N,
 
2 n+2
n =A + B(n + 1) + C.
2

(b) Write ∞ n2 xn as a quotient of polynomials.


P
Pn=0
(c) Write ∞ 3 n
n=0 n x as a quotient of polynomials.
P∞ d n
(d) For each d ∈ N, let Fd (x) = n=0 n x .
Show that F0 (x) = 1/(1 − x) and for all d ≥ 1,

d
Fd (x) = x Fd−1 (x).
dx
(e) Let Fd (x) = Pd (x)/(1 − x)1+d . Derive a recurrence relation for
the polynomials Pd (x).
Exercise 4.11. Show that the converse of Theorem 4.14 holds. That is,
assume that

gn = p1 (n)λn1 + p2 (n)λn2 + · · · + ps (n)λns

for all n ≥ N , in which pi (n) is a polynomial of degree strictly less than


di and the λi are distinct nonzero complex numbers, for 1 ≤ i ≤ s. Let

Q(x) = (1 − λ1 x)d1 (1 − λ2 x)d2 · · · (1 − λs x)ds .

Then ∞
X P (x)
G(x) = gn xn = R(x) +
n=0
Q(x)
in which P (x) and R(x) are polynomials, and deg P (x) < deg Q(x)
and deg R(x) < N .

Exercise 4.12.
∞  
1 X 2k k
(a) Show that √ = x .
1 − 4x k=0 k
n   
X 2j 2n − 2j
(b) Deduce that for all n ≥ N, = 4n .
j=0
j n − j
(c)* Can you think of a combinatorial proof of part (b)?
Part II

Introduction to Graph Theory

117
Overview.

The idea of “six degrees of separation” is an enduring bit of popular culture.


The claim is that for any two people on Earth – a school teacher in Kiribati
and someone gardening in Punkeydoodles Corners, say – one can pass from
the teacher to someone they have met, from them to a next acquaintance,
and so on... arriving at the gardener in at most six steps. This is such an
attractive idea that it doesn’t really matter whether or not it is true. And
there is no need to stick to the present time – how many steps would it take
to get from you to Isaac Newton? Erdo ”s numbers and the Kevin Bacon game
are variations of the same idea.
Graph theory is the study of networks of this kind in the most abstract
and general setting. The common structure is some set of things that are
related to one another (or not) in pairs. Communication, transportation,
ecological, and social networks can all be modeled in this way, and there
are countless other applications.
In Chapter 5 we introduce graphs as mathematical structures and give
a wide assortment of examples. We discuss a few elementary concepts of
graph theory, the most important of which is that of isomorphism. This
formalizes the intuitive notion of when two graphs are “basically the same”.
In Chapter 6 we discuss walks in graphs, the concept of connectedness,
and related results about substructures inside a graph. We also give Euler’s
solution to the “seven bridges of Königsberg” problem – arguably the first
theorem of graph theory in history.
Chapter 7 builds upon Chapter 6, establishing some fundamental struc-
tural properties of graphs. These are important not only for the abstract
theory, but also as a framework on which various practical algorithms are
built.

119
In Chapter 8 we address the question of which graphs can be drawn in
the plane without crossing edges – the answer is surprisingly recent, due
to Kuratowski in 1930. The five Platonic solids – familiar from high-school
geometry – also make an appearance.
In Chapter 9 we discuss colourings of graphs. The famous Four Colour
Theorem takes center stage – ideas related to it have had a profound influ-
ence on the development of graph theory (and combinatorics, more gener-
ally) since the question was first posed in the 1850s.
Finally, Chapter 10 develops the theory of matchings, particularly in bi-
partite graphs. The main results are again surprisingly recent, due to König
and to Hall in the 1930s. And again, they have had a strong influence on
graph theory and optimization, right up to the present day.
In Chapters ?? and ?? we discuss a few other topics involving graphs,
algorithms, optimization, or linear algebra.
Chapter 5

Graphs and Isomorphism.

5.1 Graphs.

Definition 5.1 (Graphs). A graph G = (V, E) is an ordered pair of sets


in which the elements of E are 2-element subsets of V .

An element of the set V is called a vertex . The plural form of vertex is


vertices. An element of E is called an edge . For a graph G = (V, E) we also
write V (G) = V for the vertex-set and E(G) = E for the edge-set. Unless
mentioned otherwise, we only consider finite graphs.

Example 5.2. Here is a graph:

G = ({1, 2, 3, 4, 5}, {{1, 2}, {1, 3}, {1, 4}, {2, 3}, {3, 4}, {3, 5}}).

This graph has vertex-set

V (G) = {1, 2, 3, 4, 5}

and edge-set

E(G) = {{1, 2}, {1, 3}, {1, 4}, {2, 3}, {3, 4}, {3, 5}}.

That is mathematically precise, but difficult for a human being to grasp in-
tuitively.

121
122 Graphs and Isomorphism. Section 5.2

2 2
3

1 1 3 5

4
5 4

Figure 5.1: Two pictures of the graph in Example 5.2

We draw a picture of a graph G = (V, E) by representing the vertices as


dots, and joining two dots by a curve when the corresponding vertices are
both elements of the same edge. Then, labelling the dots in the picture with
the names of the vertices in V , we can see which pairs of vertices are joined
by edges, and so determine the set of edges E, too. Figure 5.1 shows two
different pictures of the graph in Example 5.2.
There is one empty graph (∅, ∅) with no vertices. For any finite set V
of vertices there is one edgeless graph (V, ∅) with no edges. (These are also
often called “empty graphs” when the vertex-set is known.) For any finite
set V of vertices there is one complete graph KV = (V, E) in which E is the
set of all 2-element subsets of V . If |V | = n then |E(KV )| = n2 .


5.2 The Handshake Lemma.

Definition 5.3 (Adjacency, Incidence, Degree).


Let G = (V, E) be a graph.
1. Two vertices v, w ∈ V are adjacent, or are neighbours, if {v, w} ∈ E
is an edge. We also use the notation vw for the edge {v, w}. The
neighbourhood of v ∈ V is the set

N (v) = {w ∈ V : vw ∈ E}
Section 5.2 Graphs and Isomorphism. 123

of vertices adjacent to V .
2. A vertex v ∈ V and edge e ∈ E are incident if v ∈ e. The two
vertices incident with an edge e ∈ E are the ends of e.
3. The degree of a vertex v ∈ V is the number of edges incident with
it. This number is denoted by deg(v). That is,

deg(v) = |{e ∈ E : v ∈ e}| = |N (v)|.

4. The degree sequence of G is the multiset of degrees of the vertices


of G. It is usually represented as a sequence of |V | natural num-
bers sorted into weakly decreasing order.
5. A graph is regular if all vertices have the same degree. If all
vertices have degree d then G is d-regular.

The degree sequence of the graph in Example 5.2 is (4 3 2 2 1). A 0-regular


graph is an edgeless graph. What does a 1-regular graph look like? What
does a 2-regular graph look like? A 3-regular graph can be very very com-
plicated.

Theorem 5.4 (The Handshake Lemma). Let G = (V, E) be a graph. Then


X
deg(v) = 2 · |E|.
v∈V

Proof. We count the size of the set of pairs

X = {(w, f ) : w ∈ V and f ∈ E and w ∈ f }

in two different ways. First, for every vertex v ∈ V there are deg(v) pairs
(w, f ) in X with vertex v as the first coordinate. Therefore,
X
|X| = deg(v).
v∈V

Second, for every edge e ∈ E there are 2 pairs (w, f ) in X with edge e as the
second coordinate. Therefore,

|X| = 2 · |E|.

This proves the result.


124 Graphs and Isomorphism. Section 5.3

Figure 5.2: Complete graphs K3 , K4 , K5 , K6 .

Corollary 5.5. Let G = (V, E) be a graph. Then G has an even number of


vertices of odd degree.

Proof. Let S0 be the set of vertices of even degree, and let S1 be the set of
vertices of odd degree. Consider the Handshake Lemma (modulo 2):
X X X
0 ≡ 2 · |E| ≡ deg(v) ≡ deg(v) + deg(v)
v∈V v∈S0 v∈S1
X X
≡ 0+ 1 ≡ |S1 | (mod 2).
v∈S0 v∈S1

That proves the claim.

5.3 Examples.

In this section we give some specific examples of graphs, as material to think


about. The serious investigation of graph properties begins in Section 5.4.

Example 5.6 (Complete Graphs). For n ∈ N, the complete graph Kn has

vertices V (Kn ) = {1, 2, ..., n}


edges E(Kn ) = {{v, w} : v, w ∈ V and v 6= w}.
Section 5.3 Graphs and Isomorphism. 125

Figure 5.3: Complete bipartite graphs K1,3 , K2,3 , K3,3 , K4,3 .

Figure 5.4: Cycles C3 , C4 , C5 , C6 .

Example 5.7 (Complete Bipartite Graphs). For r, s ∈ N, the complete


bipartite graph Kr,s has

vertices V (Kr,s ) = {a1 , a2 , ..., ar } ∪ {b1 , b2 , ..., bs }


edges E(Kr,s ) = {{ai , bj } : 1 ≤ i ≤ r and 1 ≤ j ≤ s}.

Example 5.8 (Paths and Cycles). For n ≥ 1, the path Pn has

vertices V (Pn ) = {1, 2, ..., n}


edges E(Pn ) = {{i, i + 1} : 1 ≤ i ≤ n − 1}.

For n ≥ 3, the cycle Cn has

vertices V (Cn ) = {1, 2, ..., n}


edges E(Cn ) = {{i, i + 1} : 1 ≤ i ≤ n − 1} ∪ {{1, n}}.
126 Graphs and Isomorphism. Section 5.3

Figure 5.5: Circulants C7 (1, 3) and C12 (1, 3, 5).

Example 5.9 (Circulants). Fix n ≥ 2 and let Zn = {[0], [1], ..., [n − 1]}
denote the integers (modulo n). Let S be any subset of Zn with [0] 6∈ S.
The circulant Cn (S) has

vertices V (Cn (S)) = Zn


edges E(Cn (S)) = {{[v], [v + s]} : [v] ∈ Zn and [s] ∈ S}.

To simplify the notation, we write C10 (1, 3, 4) instead of C10 ({[1], [3], [4]}),
and so on. From the definition of Cn (S), if [a] ∈ S then it makes no difference
whether or not [−a] ∈ S. In either case, the resulting graph will be the same.
Notice that the circulant Cn (1) “looks the same as” the cycle Cn . Also,
the circulant Cn (Zn r {[0]}) “looks the same as” the complete graph Kn .
Less obviously, the circulant C12 (1, 3, 5) in Figure 5.5 “looks the same as”
the complete bipartite graph K6,6 . This idea of two graphs looking the same
is made precise in Section 5.4.

Example 5.10 (Hypercubes). For d ≥ 0, the d-dimensional cube Qd has

vertices V (Qd ) = {0, 1}d


edges E(Qd ) = {{α, β} : |α − β| = 1}.

In this definition, |α − β| is the distance between α and β as vectors in


Euclidean space Rd .
Section 5.3 Graphs and Isomorphism. 127

Figure 5.6: The four-dimensional cube Q4 .

Example 5.11 (Word Graphs). For ` ≥ 1, the word graph Word(`) has
vertex-set consisting of all `-letter words in the English language. Two
words are adjacent in Word(`) if and only if they differ by the substitu-
tion of exactly one letter in one position.

For instance, in Word(4) we can hop along the edges from frog to toad as
follows.
frog − flog − flag − flat − feat
|
toad − goad − goat − boat − beat
When I found this path in Word(4) I didn’t know that “trog” (British slang
for a stupid oafish person) and “trad” (traditional jazz or folk music) are
actual English words. Here is a shorter path:

frog − trog − trod − trad − toad

Finding shortest paths between vertices in graphs is an important subject


which we consider in Section ??.

Example 5.12 (Unit Square Graphs). Fix a positive real number r > 0.
Choose n points in the unit square [0, 1] × [0, 1] independently and uni-
formly at random. Join two of these points by a line segment if they are
128 Graphs and Isomorphism. Section 5.3

Figure 5.7: A unit square graph with n = 30 and r ≈ 0.179.

Figure 5.8: A unit square graph with n = 30 and r ≈ 0.232.


Section 5.3 Graphs and Isomorphism. 129

Figure 5.9: A unit square graph with n = 30 and r ≈ 0.291.

Figure 5.10: A unit square graph with n = 30 and r ≈ 0.378.


130 Graphs and Isomorphism. Section 5.4

within distance r of each other. These points and lines can be thought of
as the vertices and edges of a graph.
Figures 5.7 to 5.10 give examples of unit square graphs. They all have the
same randomly chosen vertex-set of n = 30 points, for four different values
of r > 0.

5.4 Isomorphism.

Example 5.13. Consider the three graphs pictured in Figure 5.11. The
graphs G and H are the same graph, since they have the same set of
vertices V (G) = V (H) and the same set of edges E(G) = E(H). That is,
G = H; these graphs are equal even though the pictures “look different”.
The graph J is not equal to the graph G because these graphs do not have
the same set of vertices: V (G) 6= V (J). But from the picture it is clear that
J “looks the same as” G.

The concept of isomorphism makes this idea mathematically precise.

Definition 5.14 (Isomorphism). Let G and H be graphs. An isomor-


phism from G to H is
• a bijection f : V (G) → V (H) from the vertices of G to the ver-
tices of H, such that
• for all v, w ∈ V (G),

{f (v), f (w)} ∈ E(H) if and only if {v, w} ∈ E(G).

If there is an isomorphism from G to H then we say that G is isomorphic


to H and write G ' H.

When G ' H, we also say that G is isomorphic with H, or that G and H are
isomorphic. Informally, an isomorphism is a bijection between vertices that
sends edges to edges and non-edges to non-edges. In other words, it is a
bijection f such that both f and its inverse function f −1 preserve adjacency.
We sometimes write f : G → H for an isomorphism f : V (G) → V (H) to
simplify the notation.
The relation ' of isomorphism is an equivalence relation, for the follow-
Section 5.4 Graphs and Isomorphism. 131

5
3 2 f d
1
1 a

5 2 3 c
6 4
4 6 b e

G H J

Figure 5.11: G equals H and is isomorphic with J.

ing reasons.
• For any graph G, the identity function ι : G → G is an isomorphism, so
that G ' G. This is the reflexive property. (Here, the identity function
ι : V → V is such that ι(v) = v for all v ∈ V .)
• If f : G → H is an isomorphism then f −1 : H → G is an isomorphism.
Thus, if G ' H then H ' G. This is the symmetric property.
• If f : G → H and g : H → J are isomorphisms, then g ◦ f : G → J is
an isomorphism. This is the transitive property.

Example 5.15.
• For the graphs in Figure 5.11, the following function f : V (G) →
V (J) is an isomorphism.

v 1 2 3 4 5 6
f (v) a d f b c e

Here is another function g : V (G) → V (J) which is also an isomor-


phism.
v 1 2 3 4 5 6
g(v) b e c a f d
• For the isomorphisms f and g in the previous point, g −1 ◦f : G → G
132 Graphs and Isomorphism. Section 5.4

Figure 5.12: Two pictures of the Petersen graph.

is an isomorphism from G to G that is not the identity function.


An isomorphism from a graph to itself is called an automorphism .
• For any circulant graph Cn (S), the function f : Zn → Zn defined
by f ([a]) = [a + 1] for all [a] ∈ Zn is an automorphism of Cn (S).
• The two graphs pictured in Figure 5.12 are isomorphic. To see this,
find a way to label the vertices of each graph with the numbers
{1, 2, ..., 10} so that the edge-sets are the same. This is a famous
graph known as the Petersen graph .
• For any r ≥ 1, the circulant C2r (1, 3, 5, ..., 2r − 1) is isomorphic to
the complete bipartite graph Kr,r .
In order to show that two graphs G and H are isomorphic, it is enough to
exhibit an isomorphism between them. Finding such an isomorphism might
be a tricky problem, but given one particular bijection f : V (G) → V (H) it
is not difficult to check whether or not f is an isomorphism.
In order to show that two graphs G and H are not isomorphic, one must
show that none of the bijections between their vertex-sets can be an isomor-
phism. If G and H have n vertices, then there are n! such bijections, and so
checking them all individually is not a practical strategy. Instead, there are
many necessary conditions that follow from the fact that G ' H. If any of
these necessary conditions fails to hold, then we can conclude that G and H
are not isomorphic. More generally, we can use these necessary conditions
to narrow down our search for an isomorphism between two given graphs.
Section 5.5 Graphs and Isomorphism. 133

G H

Figure 5.13: G is not isomorphic to H.

Lemma 5.16. Let f : G → H be an isomorphism between graphs G and H.


(a) For all v ∈ V (G), degH (f (v)) = degG (v).
(b) The graphs G and H have the same degree sequence.
(c) For all v ∈ V (G), if f (v) = w then the multiset of degrees of the neigh-
bours of v in G is equal to the the multiset of degrees of the neighbours
of w in H.

Proof. For part (a), since f is an isomorphism it restricts to a bijection from


the set NG (v) of neighbours of v in G to the set NH (f (v)) of neighbours of
f (v) in H. Therefore, degG (v) = |NG (v)| = |NH (f (v))| = degH (f (v)). Part (b)
follows from part (a) since f : V (G) → V (H) is a bijection. Similarly, since f
restricts to a bijection from NG (v) to NH (w), part (a) also implies part (c).

Example 5.17. The two graphs pictured in Figure 5.13 have the same
degree sequence (4 3 3 3 3 3 3 2) but they are not isomorphic, for the fol-
lowing reason. They both have only one vertex of degree 4 (marked
with a circle), and only one vertex of degree 2 (marked with a square).
By Lemma 5.16(a), if f : G → H were an isomorphism then the circle
would map to the circle, and the square would map to the square. But
in G there is a vertex adjacent to both marked vertices, while in H there
is no such vertex. Therefore, there is no isomorphism from G to H.
134 Graphs and Isomorphism. Section 5.5

5.5 Some more Basic Concepts.

Definition 5.18 (Subgraphs). Let G = (V, E) be a graph.


1. A subgraph of G is a pair H = (W, F ) such that: W is a subset of
V ; F is a subset of E; and (W, F ) is a graph.
2. A subgraph H = (W, F ) of G is proper if H 6= (∅, ∅) and H 6=
(V, E).
3. A subgraph H = (W, F ) of G is spanning if W = V . That is, H
contains all the vertices of G.
4. A subgraph H = (W, F ) of G is induced if F = {e ∈ E : e ⊆ W }.
That is, H contains all the edges of G that have both ends in
W . We say that this is the subgraph of G induced by W ⊆ V , and
denote it by G[W ] or G|W .
5. If S ⊆ E is a set of edges of G then the deletion of S from G is the
spanning subgraph G r S = (V, E r S).
6. If S ⊆ V is a set of vertices of G then the deletion of S from G is
the subgraph G[V r S] of G induced by V r S.

The point of the last condition in Definition 5.18.1 (that (W, F ) is a graph) is
that if one chooses an edge e of G to be in the subgraph H, then one must
also choose both of the vertices at the ends of e to be in H as well. For edge-
deletion, we also write G r e instead of G r {e} to simplify notation. For
vertex-deletion, we also use the notation G r S for G[V r S], and G r v for
G r {v}.
The empty graph (∅, ∅) is a subgraph of every graph. Every graph G
is a spanning subgraph of the complete graph KV (G) with the same vertex-
set. To get a feel for these concepts, consider the following questions. What
does a proper spanning subgraph look like? What does a proper induced
subgraph look like? What does an induced spanning subgraph look like?
Informally, we often say that “G has H as a subgraph” or “G contains H”
to mean that there is a subgraph of G that is isomorphic with H. This can
also be qualified with the adjectives “proper”, “spanning”, or “induced”.
For instance, the 4-cube Q4 in Figure 5.6 has C16 as a proper spanning sub-
graph. (It is not too hard to find one.) A spanning cycle in a graph is called
a Hamilton cycle .
Section 5.5 Graphs and Isomorphism. 135

Lemma 5.19. Let f : G → H be an isomorphism between graphs G and H.


(a) For any v ∈ V , if f (v) = w then the subgraph of G induced by the
neighbours of v is isomorphic to the subgraph of H induced by the
neighbours of w. That is, G[NG (v)] ' H[NH (w)].
(b) For any d ∈ N, the subgraph of G induced by vertices of degree d is
isomorphic to the subgraph of H induced by vertices of degree d.
(c) For any graph J, the number of induced subgraphs of G that are iso-
morphic to J is equal to the number of induced subgraphs of H that
are isomorphic to J.

Proof. Exercise 5.10.

Example 5.20. Revisiting the graphs pictured in Figure 5.13, let G0 be


the subgraph of G induced by its vertices of degree 3, and let H 0 be the
subgraph of H induced by its vertices of degree 3. One sees that G0 and
H 0 do not have the same degree sequence. Lemma 5.16(b) implies that
G0 6' H 0 . Finally, Lemma 5.19(b) implies that G 6' H.

Definition 5.21 (Graph Complement). Let G = (V, E) be a graph. Let


B(V, 2) be the set of all 2-element subsets of V . The complement of G is
the graph Gc = (V, E c ) in which E c = B(V, 2) r E.

vertices V (Gc ) = V (G)


edges E(Gc ) = {vw : vw 6∈ E(G)}.

The graph Gc has the same set of vertices as G, and vertices v and w are
adjacent in Gc if and only if v and w are not adjacent in G. This could also
be described as Gc = KV (G) r E(G).

Definition 5.22 (Cartesian Product). Let G and H be graphs. The


Cartesian product G  H has vertices V (G  H) = V (G) × V (H). Two
vertices (v1 , v2 ) and (w1 , w2 ) are adjacent in G  H if and only if: ei-
ther v1 = w1 in V (G) and v2 w2 ∈ E(H), or v1 w1 ∈ E(G) and v2 = w2 in
V (H).
136 Graphs and Isomorphism. Section 5.5

Figure 5.14: The grid P5  P8 .

Example 5.23.
• For r, s ≥ 1, the r-by-s grid is Pr  Ps . The points and lines on a go
board form the grid P19  P19 .
• The game board for nine-man morris (Figure 5.15) is a spanning
subgraph of C8  P3 .
• The d-dimensional cube Qd of Example 5.10 is isomorphic to the
Cartesian power (K2 )d = K2  K2  · · ·  K2 of K2 with d factors.
• For r, d ∈ N, the Hamming graph is H(r, d) = (Kr )d . Considering
the 64 squares of a chessboard as vertices, with two vertices joined
by an edge when they are one rook’s move apart – that is, either in
the same rank (row) or same file (column) – we have the Hamming
graph H(8, 2) = K8  K8 .
• For ` ≥ 1, the word graph Word(`) is an induced subgraph of the
Hamming graph H(26, `).

Definition 5.24 (Bipartite Graph). A bipartition of a graph G = (V, E)


is an ordered pair (A, B) of subsets of V with the following two prop-
erties:
• both A ∪ B = V and A ∩ B = ∅; and
• for every edge e ∈ E, both e ∩ A 6= ∅ and e ∩ B 6= ∅.
If a graph has a bipartition then it is a bipartite graph.

That is, for a bipartition (A, B) of a graph, every vertex is in exactly one of
A or B, and every edge has one end in A and one end in B.
Section 5.5 Graphs and Isomorphism. 137

Figure 5.15: The game board for nine-man morris.

Exercise 5.5(a) gives a “bipartite version” of the Handshake Lemma.

Proposition 5.25. Let G and H be graphs.


(a) If G ' H then G is bipartite if and only if H is bipartite.
(b) If G is bipartite then every subgraph of G is bipartite.
(c) For n ≥ 3, the cycle Cn is bipartite if and only if n is even.
(d) If G contains an odd cycle then G is not bipartite.

Proof. For part (a), if f : G → H is an isomorphism and (A, B) is a biparti-


tion of G, then ({f (v) : v ∈ A}, {f (w) : w ∈ B}) is a bipartition of H. This
reasoning applies to f −1 as well, implying the result.
For part (b), let (A, B) be a bipartition of G. Let H = (W, F ) be a subgraph
of G. Then (W ∩ A, W ∩ B) is a bipartition of H, so that H is bipartite.
For part (c), regard Cn with the vertices and edges labelled as in Example
5.8. Assume that (A, B) is a bipartition of Cn . Switching the sets A and B if
necessary, we may assume that 1 ∈ A. Since {1, 2} is an edge, it follows that
2 ∈ B. Since {2, 3} is an edge, it follows that 3 ∈ A. By induction on j, it
follows that for all 1 ≤ j ≤ n, j ∈ A if j is odd, and j ∈ B if j is even. Thus,
there is at most one possibility for a bipartition of Cn (with 1 ∈ A). Only
the edge {1, n} has not been considered. If n is odd then this edge has both
ends in A, and so Cn does not have a bipartition. If n is even, then the sets
A = {1, 3, 5, ..., n − 1} and B = {2, 4, 6, ..., n} do form a bipartition of Cn .
Part (d) follows immediately from parts (b) and (c).
138 Graphs and Isomorphism. Section 5.6

Figure 5.16: A general (mixed) graph.

The converse to Proposition 5.25(d) is also true. We could prove it now, but
it will be much easier once we have developed the ideas in Chapter 7 (see
Theorem 7.10).

5.6 Multigraphs and Directed Graphs.

For some purposes we would like to allow a graph to have more than one
edge between a given pair of vertices, or to have an edge with both ends at
the same vertex, or to have a direction on an edge from one end to the other.
(Chapters 8 and ?? are two such situations.) See Figure 5.16 for a picture
of such a general graph. We will not give a formal definition that covers all
possibilities – in practice, different people use different definitions which
are chosen for their convenience in a given context.
We will say that an (undirected) multigraph is a triple G = (V, E, B) in
which V is a set of vertices, E is a set of edges, and B : V × E → {0, 1, 2} is an
incidence function. The interpretation is that B(v, e) is the number of ends of
the edge e that are incident at the vertex v. We require that every edge e ∈ E
P
has exactly two ends (which may be equal) – that is, v∈V B(v, e) = 2. A
Section 5.7 Graphs and Isomorphism. 139

loop at v ∈ V is an edge e ∈ E such that B(v, e) = 2. We use the notation


vew ∈ E(G) to indicate that the edge e is incident with vertices v and w.
Thus, vew is a loop if and only if v = w. The degree of a vertex v ∈ V is
P
deg(v) = e∈E B(v, e). It is easy to see that the Handshake Lemma holds
for multigraphs.
The simplification of a multigraph G = (V, E, B) is a simple graph si(G)
defined as follows. The vertex set is V (G), and the edges are all pairs {v, w}
of vertices such that B(v, e) = B(w, e) = 1 for some e ∈ E. Informally,
the simplification is obtained by removing all loops and replacing multiple
edges between a pair of vertices by a single edge. The simplification of G
can naturally be regarded as a spanning subgraph of G.
We will also say that a directed multigraph is a quadruple G = (V, A, o, t)
in which V is a set of vertices, A is a set of arcs (directed edges), o : A → V
is an origin function, and t : A → V is a terminus function. The interpretation
is that an arc a ∈ A is directed out of o(a) and into t(a). The indegree of
a vertex v ∈ V is deg+ (v) = |t−1 (v)|, the number of arcs pointing into v;
its outdegree is deg− (v) = |o−1 (v)|, the number of arcs pointing out. The
analogue of the Handshake Lemma for directed multigraphs is that
X X
deg+ (v) = |A| = deg− (v).
v∈V v∈V

These definitions will suffice for our purposes. They could be combined
to represent a mixed multigraph which contains both undirected edges and
directed arcs. However, the vast majority of these notes involve only the
simple graphs of Definition 5.1.

5.7 Exercises.

Exercise 5.1.
(a) Find a path from hard to easy in Word(4).
(b) Find a path from wrong to right in Word(5).
140 Graphs and Isomorphism. Section 5.7

3 C c
2 d
D B b
4 e
8
1 E J A a
9 f
5
F H j
7 g
6 G h

G H J

Figure 5.17: Three graphs for Exercise 5.6.

Exercise 5.2. Let G be a graph with at least two vertices. Show that G
has two different vertices of the same degree.

Exercise 5.3. Assume that all vertices of G = (V, E) have degree either
1 or 3. Show that if |V | = |E| then the number of vertices of degree 1
is equal to the number of vertices of degree 3.

Exercise 5.4. Let G = (V, E) be a graph, S ⊆ V a subset of vertices,


and ∂S ⊆ E the set of edges that have exactly one end in S. Show that
if every vertex in S has even degree, then |∂S| is even.

Exercise 5.5 (Bipartite Handshake Lemma). Let G = (V, E) be a graph


with a bipartition (A, B).
X X
(a) Show that deg(a) = |E| = deg(b).
a∈A b∈B

(b) Show that if G is regular with at least one edge, then |A| = |B|.
(c) Use part (b) to give another proof of Proposition 5.25(c).

Exercise 5.6. For each pair of the graphs pictured in Figure 5.17, give
either an isomorphism between them or a reason why they are not
isomorphic to each other.
Section 5.7 Graphs and Isomorphism. 141

3 C c
2 d
D B b
4 e
8
1 E J A a
9 f
5
F H j
7 g
6 G h

G H J

Figure 5.18: Three graphs for Exercise 5.7.

3 D C d c
4 2 E B e b
9
5 1 F A f a

10 G K g k
6 8
7 H J h j

G H J

Figure 5.19: Three graphs for Exercise 5.9.

Exercise 5.7. For each pair of the graphs pictured in Figure 5.18, give
either an isomorphism between them or a reason why they are not
isomorphic to each other.

Exercise 5.8. Are any of the graphs in Figure 5.17 isomorphic to any
of the graphs in Figure 5.18?

Exercise 5.9. For each pair of the graphs pictured in Figure 5.19, give
either an isomorphism between them or a reason why they are not
isomorphic to each other.
142 Graphs and Isomorphism. Section 5.7

Exercise 5.10. Prove Lemma 5.19.

Exercise 5.11.
(a) There are two 3-regular graphs with 6 vertices (up to isomor-
phism). Draw pictures of them and explain why they are not
isomorphic, and why any 6-vertex 3-regular graph is isomor-
phic to one or the other.
(b) There are several 3-regular graphs with 8 vertices (up to isomor-
phism). Draw pictures of them and explain why they are not
isomorphic, and why any 8-vertex 3-regular graph is isomor-
phic to one of the graphs on your list.

Exercise 5.12. Recall the circulant graphs from Example 5.9.


(a) Draw pictures of C8 (1, 3), C8 (1, 5), and C9 (1, 3).
(b) Show that C10 (2, 3) and C10 (1, 4) and C10 (1, 6) are isomorphic to
each other.
(c) Show that C14 (1, 3) is isomorphic to C14 (1, 5).
(d) Show that if ab ≡ 1 (mod n), then Cn (1, a) is isomorphic to
Cn (1, b).

Exercise 5.13. A graph G is self-complementary if it is isomorphic to


its complement: G ' Gc .
(a) If G is self-complementary then |V (G)| ≡ 0 or 1 (mod 4).
(b) For each k ∈ N, give an example of a self-complementary graph
with 4k vertices.
(c) For each k ∈ N, give an example of a self-complementary graph
with 4k + 1 vertices.
(d) If G is a self-complementary graph with 4k + 1 vertices, then
there is a v ∈ V (G) such that G r v is self-complementary.
[Hint: Let f : G → Gc be an isomorphism, regarded as a permu-
tation of V (G). One of the cycles of this permutation must have
odd length.]
Section 5.7 Graphs and Isomorphism. 143

Exercise 5.14. Let G = (V, E) be a self-complementary graph with 4k


vertices, and let f : G → Gc be an isomorphism. Prove the following.
(a) For each v ∈ V , exactly one of v or f (v) has degree (in G) strictly
less than 2k.
(b) Exactly 2k vertices of G have degree strictly less than 2k (in G).
(c) Define a new graph G+ = (W, F ) by adding a new vertex W =
V ∪ {z} and new edges zv for all vertices v ∈ V that have degree
strictly less than 2k in G. Show that G+ is self-complementary.

Exercise 5.15. Let G = (V, E) be a bipartite graph with |V | = n ver-


tices. Show that G has at most |E| ≤ bn2 /4c edges.

Exercise 5.16. For each k ≥ 2 and n ≥ 2k, determine whether or not


the circulant Cn (1, k) is bipartite. Give a proof. [Hint: look at some
small examples, then make a conjecture, then prove your conjecture.]

Exercise 5.17. Show that for any graphs G and H, the Cartesian prod-
uct G  H is bipartite if and only if both G and H are bipartite.

Exercise 5.18. Let’s say that a graph with a Hamilton (spanning) cycle
is Hamiltonian . (A graph with a spanning path is weakly Hamiltonian.)
(a) Show that if G is bipartite and Hamiltonian then |V (G)| is even.
(b) For which r, s ≥ 2 is the grid Pr  Ps Hamiltonian? Explain.
(c) Show that for n ≥ 3, the product Cn  K2 is Hamiltonian.
(d) Deduce that for d ≥ 2, the d-cube Qd is Hamiltonian. (Hamilton
cycles in hypercubes are called “binary Gray codes”.)

Exercise 5.19. For each r ≥ 1 and s ≥ 3, determine whether or not


K1,r  Cs is Hamiltonian. Give a proof. (Hint: look at some small
examples, then make a conjecture, then prove your conjecture.)

Exercise 5.20. Is the Petersen graph Hamiltonian? Explain.


Exercise 5.21. Let G = (V, E) be a graph. The line-graph L(G) of G
has the edges of G as its vertices, and two vertices of L(G) are ad-
jacent if and only if the corresponding edges of G have a common
end-vertex. That is,

vertices V (L(G)) = E(G)


edges E(L(G)) = {ef : e ∩ f 6= ∅}.

(a) Find a graph G that is isomorphic to its own line-graph.


(b) Find two graphs G and H such that G 6' H, but L(G) ' L(H).
(c) Show that for r, s ∈ N, the product Kr  Ks is isomorphic to the
line-graph L(Kr,s ).

Exercise 5.22. For d ≥ 3, the d-th Odd graph Od is defined as fol-


lows. The vertices of Od are the (d − 1)-element subsets of the set
{1, 2, ..., 2d − 1}. Two vertices S and S 0 of Od are adjacent if and only
if S ∩ S 0 = ∅. Prove the following claims.
(a) The Odd graph Od is d-regular. How many vertices and edges
does it have?
(b) The Petersen graph is isomorphic to O3 = L(K5 )c ,
the complement of the line-graph of K5 .
(c) The Odd graph Od does not contain C3 as a subgraph.
(d) The Odd graph Od does have C6 as an induced subgraph.
(e) The Odd graph Od does not contain C4 as a subgraph.
(f) The Odd graph Od does have C2d−1 as an induced subgraph.

Exercise 5.23. Find an example of a graph G = (V, E) and two vertices


v, w ∈ V with the following properties:
• the subgraphs G r v and G r w are isomorphic; but
• there is no automorphism f : G → G such that f (v) = w.
Chapter 6

Walks, Paths, and Connectedness.

6.1 Walks, Trails, Paths, and Cycles.

Definition 6.1 (Walks,Trails,Paths,Cycles). Let G = (V, E) be a graph.


1. A walk in G is a sequence of vertices W = (v0 v1 ... vk ) such that
vi−1 vi ∈ E is an edge for all 1 ≤ i ≤ k. Each consecutive pair
vi−1 vi is a step of the walk. The length of the walk is `(W ) = k,
the number of steps.
2. The vertices v0 and vk are the ends of W , and W is a walk from v0
to vk , or a (v0 , vk )-walk. The walk is closed if v0 = vk .
3. Two walks W = (v0 v1 ... vk ) and Z = (z0 z1 ... z` ) are equal if and
only if k = ` and vi = zi for all 0 ≤ i ≤ k.
4. A walk W in G is a trail if the edges vi−1 vi are all different: if
1 ≤ i < j ≤ k then {vi−1 , vi } = 6 {vj−1 , vj }.
5. A walk W in G is a path if the vertices vi are all different: if 0 ≤
i < j ≤ k then vi 6= vj .
6. A walk W in G is a cycle if it is closed, the length is at least three,
and the vertices vi are all different except that v0 = vk . That is:
v0 = vk , and `(W ) ≥ 3, and if 0 ≤ i < j ≤ k are such that vi = vj ,
then i = 0 and j = k.

145
146 Walks and Connectedness. Section 6.1

A walk W = (v0 v1 ... vk ) in G is supported on a particular subgraph of G:


the one with

vertex-set V (W ) = {v0 , v1 , ..., vk }


and edge-set E(W ) = {v0 v1 , v1 v2 , ..., vk−1 vk }.

The words “path” and “cycle” have been used before, for the graphs in Ex-
ample 5.8. In Sections 5.4 and 5.5, we broadened the use of these words
to mean any graph isomorphic to some Pn or Cn . A walk that is a path as
in Definition 6.1 is supported on a path, and a walk that is a cycle as in
Definition 6.1 is supported on a cycle.
In a multigraph, to specify a walk one must also specify the choice of
edge between successive vertices at each step: W = (v0 e1 v1 e2 v2 ... ek vk ). If
e 6= f then (v e w f v) is a cycle of length two, and a loop (v e v) is a cycle of
length one.

Definition 6.2 (Concatenation of walks). Let W = (v0 v1 ... vk ) and Z =


(z0 z1 ... z` ) be walks in a graph G = (V, E). The concatenation of W
followed by Z is defined only when vk = z0 , in which case it is the walk

W Z = (v0 v1 ... vk−1 vk z1 ... z` )

obtained by superimposing the vertices vk = z0 and concatenating the


sequences of steps.

Notice that for concatenation of walks, the length (number of steps) is addi-
tive: `(W Z) = `(W ) + `(Z).

Example 6.3. Consider the graph pictured in Figure 6.1.


• The sequence (x a p r b c b q) is not a walk, because rb is not an
edge.
• The walk (s q r d s z y r p) is a trail, but not a closed trail.
• The closed walk (r c d s q b c r) is not a trail.
• The trail (x q p r q s r c d s z) is not a path.
• The closed walk (y z y) is not a cycle, and not a trail.
• The walk (a b c b c d) is not a path, although it is supported on a
path.
Section 6.1 Walks and Connectedness. 147

a b c d

p q r s

w x y z

Figure 6.1: Graph for Example 6.3.

• The concatenation of the walks W = (c r s q r) and Z = (r s z d) is


W Z = (c r s q r s z d).
• The concatenation of the paths P = (p q x a) and Q = (p r q b) is not
defined. However, P (a p) Q = (p q x a p r q b).

Proposition 6.4. Let W be a walk in a graph G = (V, E). If W is either a


path or a cycle then W is a trail.

Proof. We prove the contrapositive form of this: if W is not a trail then it is


not a path or a cycle. Let W = (v0 v1 ... vk ) be a walk in G, and assume that W
is not a trail. Then W has a repeated edge: there exist indices 1 ≤ i < j ≤ k
such that {vi−1 , vi } = {vj−1 , vj }. Now either vi = vj−1 or vi = vj . Since
1 ≤ i < j ≤ k, if vi = vj then this is a repeated vertex other than v0 = vk .
This implies that W is neither a path nor a cycle. In the remaining case,
vi = vj−1 . If i < j − 1 then this is a repeated vertex other than v0 = vk , so
that again W is neither a path nor a cycle. Finally, we have the case that
i = j − 1 so that vi = vj−1 is not a repeated vertex. But in this case vi−1 = vj
is a repeated vertex (since {vi−1 , vi } = {vj−1 , vj }). It follows that W is not
a path. If W is a cycle then i − 1 = 0 and j = k since v0 = vk are the only
repeated vertices allowed. But since i = j − 1 this implies that k = 2, and so
W can not be a cycle since it has length two.
148 Walks and Connectedness. Section 6.1

Theorem 6.5. Let G = (V, E) be a graph and let v, w ∈ V be any two


vertices. Any walk from v to w of minimum length is a path.

Proof. If v = w then (v) is a walk from v to w of length zero. Clearly this is


the minimum possible, (v) is the only walk of length zero from v to w, and
it is a path. So we can assume that v 6= w.
Let W = (v0 v1 ... vk ) be a walk in G from v0 = v to vk = w, and assume
that `(W ) = k is as small as possible among all (v, w)-walks in G. Arguing
for a contradiction, suppose that W is not a path. Then W has a repeated
vertex: there are indices 0 ≤ i < j ≤ k such that vi = vj . Now the con-
catenation of walks (v0 v1 ... vi ) and (vj vj+1 ... vk ) is a (v, w)-walk of length
i + (k − j) < `(W ). This contradicts the hypothesis that W is as short as
possible among all (v, w)-walks. This contradiction shows that W has no
repeated vertices. Therefore, W is a path.

Corollary 6.6. For vertices v, w of a graph G, if there is a (v, w)-walk in G


then there is a (v, w)-path in G.

Proof. This follows immediately from Theorem 6.5.

Proposition 6.7. Let G = (V, E) be a graph and let v, w ∈ V be distinct


vertices. If G contains two distinct paths from v to w then G contains a
cycle.

Proof. Let P = (v0 v1 ... vk ) and Q = (z0 z1 ... z` ) be distinct paths in G from
v = v0 = z0 to w = vk = z` . Since P 6= Q there is an index a with 0 ≤ a <
min{k, `} such that v0 = z0 , v1 = z1 , ..., va = za , but va+1 6= za+1 . Since vk = w
is on the path Q, there is a smallest index b such that a + 1 ≤ b ≤ k and vb is
on the path Q. Let 0 ≤ c ≤ ` be the index such that zc = vb . This index c is
determined uniquely because Q has no repeated vertices. If 0 ≤ c ≤ a then
vc = zc = vb would be a repeated vertex of P . But P is a path, so that this
does not happen. Therefore, a + 1 ≤ c ≤ `. Also, if b = a + 1 then c ≥ a + 2,
because otherwise va+1 = vb = zc = za+1 would contradict the way the index
a was determined.
Section 6.2 Walks and Connectedness. 149

The vertices va , va+1 , ..., vb are pairwise distinct since P has no repeated
vertices, and the only ones of these vertices that are also on Q are va = za
and vb = zc . The vertices za , za+1 , ..., zc−1 , zc are pairwise distinct since Q has
no repeated vertices. It follows that the closed walk

C = (va va+1 ... vb zc−1 zc−2 ... za+1 za )

has no repeated vertices except that va = za . Since the length of C is `(C) =


(b − a) + (c − a) ≥ 3, it follows that C is a cycle in G.

Proposition 6.8. Let G = (V, E) be a nonempty graph in which every


vertex has degree at least 2. Then G contains a cycle.

Proof. Let P = (v0 v1 ... vk ) be a path in G of maximum length. Since G has


a vertex and this vertex has degree at least 2, the path P has length at least
2. Since the degree of v0 is at least 2, it has a neighbour w 6= v1 different
from v1 . If w is not a vertex on P then (w v0 v1 ... vk ) is a path in G that is
longer than P . We assumed that P is a path of maximum length in G, so
this does not happen. Therefore, the vertex w is on P , and so w = vj for
some 2 ≤ j ≤ k. Now C = (v0 v1 ... vj v0 ) is a cycle in G.

6.2 Connectedness.

Definition 6.9 (Reachability). Let G = (V, E) be a graph. For vertices


v, w ∈ V we say that v reaches w in G if there exists a walk in G from v
to w.

Lemma 6.10. For a graph G = (V, E), reachability is an equivalence rela-


tion on the set V of vertices.

Proof. The relation of reachability has the following three properties. Let
u, v, w ∈ V be vertices.
• It is reflexive: (v) is a walk, so that v reaches v.
• It is symmetric: if (z0 z1 ... zk ) is a (v, w)-walk then (zk zk−1 ... z0 ) is a
(w, v)-walk. Thus, if v reaches w then w reaches v.
150 Walks and Connectedness. Section 6.2

• It is transitive: if (z0 z1 ... zk ) is a (u, v)-walk and (t0 t1 ... t` ) is a (v, w)-
walk, then (z0 z1 ... zk t1 ... t` ) is a (u, w)-walk. Thus, if u reaches v and
v reaches w, then u reaches w.

Definition 6.11 (Connected components, and connectedness). Let G =


(V, E) be a graph. Let U1 , U2 , ..., Uc be the equivalence classes of
the reachability relation on V . (Recall that equivalence classes are
nonempty, by definition.)
1. The connected components of G are the subgraphs Gi = G[Ui ] of G
induced by these equivalence classes.
2. The number of connected components of G is denoted by c(G).
3. The graph G is connected when c(G) = 1.

Note that the empty graph (∅, ∅) is not connected according to Defini-
tion 6.11, because it has no connected components at all. A graph is con-
nected if and only if it has exactly one connected component.
At this point we can now describe paths and cycles structurally, or intrin-
sically, using the concept of connectedness. A cycle is a connected 2-regular
graph. A path is a connected graph in which all vertices have degree at
most 2, and which is not a cycle.

Lemma 6.12. Let G = (V, E) be a graph with connected components G1 ,


..., Gc , and let v, w ∈ V be vertices. If v reaches w in G then v reaches w in
Gi for exactly one 1 ≤ i ≤ c.

Proof. If v reaches w in G then v and w are in the same equivalence class Ui


of reachability in G, by definition. Since equivalence classes are pairwise
disjoint, there is exactly one equivalence class Ui containing both v and w.
If W is a (v, w)-walk in G, then any two vertices in W are equivalent by
reachability in G, so that the vertices of W are all in the same equivalence
class Ui . Since Gi = G[Ui ] is the subgraph of G induced by Ui , it follows that
W is a walk in Gi , so that v reaches w in Gi .
Section 6.2 Walks and Connectedness. 151

Corollary 6.13. The connected components of a graph are connected graphs.

Proof. Let Gi = G[Ui ] be a connected component of a graph G. Since Ui


is nonempty (by definition of equivalence classes), Gi has at least one con-
nected component. Let v, w ∈ Ui be vertices of Gi . By definition of Ui , v
reaches w in G. By Lemma 6.12, it follows that v reaches w in Gi . This shows
that any two vertices of Gi are equivalent by reachability in Gi . Thus Gi is
connected.

Proposition 6.14. Let G = (V, E) be a graph. The following are equivalent.


(a) G is connected.
(b) G is nonempty and every vertex v ∈ V is such that for all w ∈ V ,
there is a (v, w)-path in G.
(c) There is a vertex v ∈ V such that for all w ∈ V , there is a (v, w)-path
in G.

Proof. First, assume that G is connected. Then G is not the empty graph. Let
v ∈ V be any vertex. For any vertex w ∈ V , v reaches w. By Theorem 6.5
there is a (v, w)-path in G. This shows that (a) implies (b). That (b) implies
(c) is clear. If (c) holds then let v ∈ V be such a vertex of G. Since V 6= ∅,
G is nonempty. Since v reaches every vertex of G, and reachability is an
equivalence relation, G has exactly one connected component – that is, G is
connected.

Let G = (V, E) be a graph. For a set S ⊆ V of vertices, the boundary of S


is the set
∂S = {e ∈ E : |e ∩ S| = 1}
of edges of G that have exactly one end in S.

Theorem 6.15. Let G = (V, E) be a nonempty graph. The following are


equivalent:
(a) The graph G is connected.
(b) For every proper subset ∅ 6= S ⊂ V , the boundary ∂S 6= ∅ is not
empty.
152 Walks and Connectedness. Section 6.3

Figure 6.2: The seven bridges of Königsberg.

Proof. First, assume that G is connected and let S be a proper subset of V .


Thus, there is a vertex v ∈ S and a vertex w ∈ V r S. Since G is connected,
there is a (v, w)-walk W = (z0 z1 ... zk ) in G. Since z0 ∈ S and zk 6∈ S, there is
an index 1 ≤ i ≤ k such that zi−1 ∈ S and zi 6∈ S. Now zi−1 zi is an edge in
∂S, so that ∂S 6= ∅.
Second, assume that G is not connected. Since G is not empty, it has
at least two connected components. Let S be the set of vertices of any con-
nected component of G. This S is a proper subset of V . Suppose that vw ∈ E
has v ∈ S and w 6∈ S. But v reaches w in G, so that w ∈ S. This contradiction
shows that ∂S = ∅.

6.3 Euler Tours.

In the 18th century, Königsberg was the easternmost major city of Prus-
sia. (It is now Kaliningrad, on the Baltic coast in an exclave of Russia be-
tween Poland and Lithuania.) On Sunday afternoons, the good people of
Königsberg would promenade about town, trying to walk across each of
the seven bridges exactly once each. (See Figure 6.2.) No-one was ever able
Section 6.3 Walks and Connectedness. 153

W E

Figure 6.3: The graph of Königsberg.

to do it – eventually the mayor asked Leonard Euler why this seemed to be


impossible. And so, in 1736, Euler explained why this was in fact impossi-
ble.
Let’s form a bipartite graph as follows. On one side of the bipartition
are the two banks of the river and the two islands. On the other side of the
bipartition are the seven bridges. A bridge is joined to the two locations
at either end of it. This gives the graph in Figure 6.3. The good people of
Königsberg were trying to find a walk in this graph that traverses each edge
exactly once.

Definition 6.16 (Euler Tour, Eulerian Graph). An Euler tour in a graph


is a walk which traverses each edge exactly once. A graph which has
an Euler tour is an Eulerian graph.

The term “Euler tour” is conventional, but “Eulerian trail” would have been
better. Our goal is to give a structural characterization of Eulerian graphs.
Vertices of degree zero are irrelevant in the context of Euler tours, so we can
safely assume that every vertex has degree at least one.

Theorem 6.17 (Euler Tours). Let G be a graph with no vertices of degree


zero.
(a) Then G is Eulerian if and only if it is connected and has at most two
vertices of odd degree.
154 Walks and Connectedness. Section 6.3

(b) If an Eulerian graph has no vertices of odd degree then every Euler
tour is a closed trail.
(c) If an Eulerian graph has two vertices v, w of odd degree then every
Euler tour is a trail with ends v and w.

Proof. To begin with, let W = (v0 v1 ... vk ) be an Euler tour of G. Since G


has no vertices of degree zero, every vertex is incident with at least one
edge. Since every edge occurs in W , the vertex v0 reaches every vertex of G.
Therefore, G is connected. Now consider any vertex w ∈ V . Let X = {i :
1 ≤ i ≤ k − 1 and w = vi } and Y = {i : i ∈ {0, k} and w = vi }. Since every
edge of G occurs exactly once in W , it follows that deg(w) = 2 |X| + |Y |.
Therefore, the only vertices of G that could have odd degree are v0 and vk .
If v0 6= vk then these two vertices both have odd degree, while if v0 = vk
then this vertex has even degree. This proves one direction of part (a): if G
is Eulerian then G is connected and has at most two vertices of odd degree.
This also implies parts (b) and (c).
For the converse direction of part (a), first consider the case that G =
(V, E) is connected and every vertex has even degree. We prove by induc-
tion on |E| that G has a closed Euler tour. The basis of induction is the case
|E| = 0, in which case G = ({v}, ∅) is a vertex of degree zero, and (v) is
a closed Euler tour of G. The induction step uses the case that G is a cycle
– a 2-regular connected graph. In this case, starting at any vertex of G we
can walk around the cycle in either direction to get a closed Euler tour of
G. For the induction step, let G be a connected graph in which every vertex
has even degree, which is not just a vertex of degree zero, and assume the
result for such graphs with fewer edges than G.
Since G has no vertices of degree zero, every vertex has degree at least
two. By Proposition 6.8, G contains a cycle C. Let Z = (z0 z1 ... z` ) be an
Euler tour of the cycle C. Let H = G r E(C). Then every vertex of H has
even degree. But H might not be connected, and might even have some
vertices of degree zero. Let H1 , H2 , ..., Hc be the connected components of
H.
Every component Hi has at least one vertex in common with C. This is
clear if H is connected, because H is a spanning subgraph of G. Otherwise,
V (Hi ) is a proper subset of V (G). Since G is connected, Theorem 6.15 im-
plies that in G, ∂V (Hi ) 6= ∅. Now, since Hi is a connected component of
H = G r E(C), this implies that E(C) ∩ ∂V (Hi ) 6= ∅. Thus, Hi has at least
Section 6.3 Walks and Connectedness. 155

Figure 6.4: Proof of Theorem 6.17.

one vertex in common with C.


For each 1 ≤ i ≤ c, let wi be a vertex in V (Hi ) ∩ V (C). By the induction
hypothesis, each Hi has a closed Euler tour, which we may take to begin and
end at wi : denote this closed walk by Wi . Now construct a walk Q in G as
follows. For each 1 ≤ i ≤ c, the vertex wi occurs exactly once on the closed
walk Z (with the understanding that z0 = z` is a single occurrence in cyclic
order). Replace the occurrence of each vertex wi in Z by the closed walk Wi
to produce the closed walk Q. (See Figure 6.4 – the cycle C is in black and
the various Hi and wi are in different colours.) It is not hard to check that Q
is a closed Euler tour of G, completing this part of the proof.
To finish the proof, what remains is the case that G = (V, E) is connected
and has exactly two vertices v, w ∈ V of odd degree. Let z be a new vertex
(not in V ) and let G0 = (V ∪ {z}, E ∪ {vz, wz}). Now G0 is connected and
every vertex has even degree. By the previous part of the proof, G0 has a
closed Euler tour which we may take to be of the form (z v u2 u3 ... uk−2 w z).
Deleting the vertex z we obtain the (v, w)-trail (v u2 u3 ... uk−2 w), which is an
Euler tour of G. This completes the proof.
156 Walks and Connectedness. Section 6.4

Example 6.18. The graph of Königsberg has four vertices of odd degree,
so it does not have an Euler tour.

6.4 Bridges / Cut-edges.

With the idea of connectedness in mind, certain edges of a graph play a


special role. These are the edges which are essential to maintaining con-
nectedness in the graph.

Definition 6.19 (Bridges). An edge e of a graph G is a bridge if G r e


has strictly more components than G has: that is, c(G r e) > c(G).

The words “cut-edge” or “coloop” or “isthmus” are synonyms for “bridge”.


The graphs pictured in Figures 5.7 to 5.10 give good illustrations of The-
orem 6.20.

Theorem 6.20. Let G = (V, E) be a graph. An edge e ∈ E is a bridge in G


if and only if e is not contained in any cycles of G.

Proof. Consider any edge e ∈ E, and let G1 be the connected component of


G that contains e. Then e is a bridge in G if and only if e is a bridge in G1 .
Similarly, e is contained in a cycle of G if and only if e is contained in a cycle
of G1 . Replacing G by G1 , if necessary, we can assume that G is connected.
First, assume that e = xy is contained in a cycle C. Then C r e supports a
path (x P y) in G r e from x to y. To show that e is not a bridge we show that
G r e is connected. Let v, w ∈ V . Since G is connected, there is a (v, w)-walk
in G. By Corollary 6.6, there is a (v, w)-path Q = (v ... w) in G. If Q does not
use the edge e then Q shows that v reaches w in Gre. If Q does use the edge e
then this edge occurs exactly once (since paths are trails by Proposition 6.4).
Exchanging the names of x and y if necessary, we may assume that Q has
the form Q = (v ... x y ... w). Replacing the step (x y) with the path (x P y)
produces (v ... x P y ... w), which is a (v, w)-walk in G r e. This shows that v
reaches w in G r e in this case as well. Hence, G is connected and e is not a
bridge.
Section 6.4 Walks and Connectedness. 157

x e y
X Y

Figure 6.5: Schematic picture of a bridge.

Conversely, assume that e = xy is not a bridge of G. Then G r e is con-


nected, so that G r e contains an (x, y)-walk, and hence an (x, y)-path P (by
Corollary 6.6). Now C = (V (P ), E(P ) ∪ {e}) is a cycle in G that contains e,
completing the proof.

Figure 6.5 illustrates Proposition 6.21 and motivates the terminology.

Proposition 6.21. Let G = (V, E) be a connected graph, and let e = xy ∈


E be a bridge. Then G r e has exactly two connected components X and Y ,
with x ∈ V (X) and y ∈ V (Y ).

Proof. Let X be the connected component of G r e that contains x, and let Y


be the connected component of G r e that contains y. We claim that X 6= Y
and that these are the only components of G r e.
Suppose that X = Y . Then there is an (x, y)-walk in G r e, and hence an
(x, y)-path P in G r e (by Corollary 6.6). As above, then C = (V (P ), E(P ) ∪
{e}) is a cycle in G that contains e. By Theorem 6.20, this contradicts the
hypothesis that e is a bridge in G. Therefore, X 6= Y .
To see that X and Y are the only components of Gre, consider any vertex
z ∈ V . Since G is connected, there is a path P from x to z in G. If P does not
use the edge e then z is in the component X of G r e. If P does use the edge
e = xy then this must be the first edge of P – for otherwise P would have
to have x as a repeated vertex. That is, P has the form P = (x y R z) and the
path (y R z) shows that z is in the component Y of G r e.
158 Walks and Connectedness. Section 6.5

Corollary 6.22. If e is a bridge of a graph G then c(G r e) = c(G) + 1.

Proof. Exercise 6.9.

6.5 Exercises.

Exercise 6.1. Let H be a subgraph of G. Prove that every connected


component of H is a subgraph of some connected component of G.

Exercise 6.2. Fix an integer k ≥ 2. Let G be a graph in which every


vertex has degree at least k. Show that G contains (as a subgraph) a
cycle with at least k + 1 edges. (Hint: generalize Proposition 6.8.)

Exercise 6.3. Let G be a graph in which every vertex has degree at


least 3. Show that G contains a cycle of even length.

Exercise 6.4. Let G be a graph that contains a closed walk of odd


length. Show that G contains an odd cycle. (Hint: consider a closed
walk of odd length that is as short as possible.)

Exercise 6.5. Let P and Q be two paths of maximum length in a con-


nected graph G. Show that P and Q have a vertex in common. (Hint:
use proof by contradiction.)

Exercise 6.6. Let G = (V, E) be a graph. Let C = (W, F ) be a subgraph


of G that is a cycle with an odd number of edges. Assume that C has
the smallest number of edges among all odd cycles in G. Show that if
v and w are vertices of C and vw is an edge of G, then vw is an edge
of C. (That is, “a shortest odd cycle is an induced subgraph”.)
Section 6.5 Walks and Connectedness. 159

Exercise 6.7. Let C 6= C 0 be distinct cycles in a graph G, such that


E(C) ∩ E(C 0 ) 6= ∅. Show that there is a cycle of G with edge-set
contained in the symmetric difference E(C) 4 E(C 0 ).

Exercise 6.8. Fix an integer t ≥ 1.


(a) Show that if G is a graph with 2t + 1 vertices, in which every
vertex has degree at least t, then G is connected.
(b) Give an example of a graph G with 2t+1 vertices, in which every
vertex has degree at least t − 1, but such that G is not connected.

Exercise 6.9. Prove Corollary 6.22.

Exercise 6.10. Let G = (V, E) be a graph, let v ∈ V be a vertex in G


of degree one, and let e = vz ∈ E be the edge of G incident with v.
Denote by G r v the subgraph (V r {v}, E r {e}) of G.
(a) Show that G is connected if and only if G r v is connected.
(b) Show that G contains a cycle if and only if Grv contains a cycle.

Exercise 6.11. Prove the following about a graph G.


(a) If exactly two vertices u and v of G have odd degree, then G
contains a path from u to v.
(b) If every vertex of G has even degree, then G does not contain a
bridge.
(c) If every vertex of G has even degree, then the edges of G can be
partitioned into edge-disjoint cycles.

Exercise 6.12. Let G = (V, E) be a graph with no bridges. Consider


the following relation ≈ defined on the set E: for e, f ∈ E, e ≈ f
means that every cycle in G that contains e also contains f . Clearly the
relation ≈ is reflexive (for all e ∈ E: e ≈ e). This exercise completes the
verification that ≈ is an equivalence relation on E. (The equivalence
classes of this relation are called the series classes of E.)
160 Walks and Connectedness. Section 6.5

(a) Show that ≈ is transitive: for all e, f, g ∈ E, if e ≈ f and f ≈ g


then e ≈ g.
(b) Show that ≈ is symmetric: for all e, f ∈ E, if e ≈ f then f ≈ e.

Exercise 6.13. The girth of a graph G is the shortest length of a cycle


in G. (If G has no cycles then the girth is infinite, by convention.) Fix
integers d ≥ 2 and g ≥ 3. Let G = (V, E) be a d-regular graph of girth
g.
(a) Show that if g = 4 then |V | ≥ 2d.
(b) For each d ≥ 2, give an example of a d-regular graph of girth 4
with 2d vertices.
(c) Show that if g = 5 then |V | ≥ d2 + 1.
(d) Give examples of d-regular graphs of girth 5 and d2 + 1 vertices
for d = 2 and d = 3. (Another example is known to exist for
d = 7, with 50 vertices. It is known that the only other value of
d for which such a graph could exist is for d = 57, with n = 3250
vertices. But it is not known whether there is such a graph or
not. These are called “Moore graphs”.)
(e) Show that if d ≥ 3 and g = 2k + 1 ≥ 3 is odd, then

d(d − 1)k − 2
|V | ≥ .
d−2
(f) When d ≥ 3 and g = 2k ≥ 4 is even, give a lower bound on |V |
similar to the bound in part (e).
(g) Give an example meeting the bound in part (f) when d = 3 and
g = 6.

Exercise 6.14. Recall the Odd graphs from Exercise 5.22. Fix d ≥ 3,
and let X = {1, 2, ..., 2d − 1}, so the vertices of Od are the (d − 1)-
element subsets of X.
(a) Let β : X → X be any bijection. Define a function f : V (Od ) →
V (Od ) by putting f (S) = {β(s) : s ∈ S} for each vertex S of Od .
Show that f is an automorphism of Od .
(b) For any two vertices v, w of Od , there is an automorphism f :
Od → Od such that f (v) = w.
(c) For any two edges v0 v1 and w0 w1 of Od , there is an automor-
phism f : Od → Od such that f (v0 ) = w0 and f (v1 ) = w1 .
(d) For any two paths v0 v1 v2 and w0 w1 w2 of length two in Od , there
is an automorphism f : Od → Od such that f (i) = wi for i ∈
{0, 1, 2}.
(e) For any two paths v0 v1 v2 v3 and w0 w1 w2 w3 of length three in Od ,
there is an automorphism f : Od → Od such that f (i) = wi for
i ∈ {0, 1, 2, 3}.
Chapter 7

Trees.

7.1 Trees and Minimally Connected Graphs.

When thinking about graphs as models of communication or transportation


networks, it is natural to consider networks that are connected as efficiently
as possible – that is, with no redundancy. This corresponds to a graph G =
(V, E) that is minimally connected : G is connected, but for every edge e ∈ E,
G r e is not connected. In other words, G is connected and every edge is a
bridge.

Definition 7.1 (Trees, Forests, Leaves).


1. A tree is a graph that is connected and contains no cycles.
2. A forest is a graph that contains no cycles. Every connected com-
ponent of a forest is a tree.
3. A leaf is a vertex of degree one.

Proposition 7.2. A graph is minimally connected if and only if it is a tree.

Proof. If G is minimally connected then it is connected and since every edge


of G is a bridge, Theorem 6.20 implies that G contains no cycles. Conversely,
if G is a tree then G is connected. Since G contains no cycles, none of the
edges of G are contained in cycles, so by Theorem 6.20 again, every edge of
G is a bridge.

163
164 Trees. Section 7.1

Proposition 7.3. A tree T = (V, E) with at least two vertices has at least
two leaves.

Proof. Let P = (v0 v1 ... vk ) be a path in T of maximum length. Then P has at


least one edge, since T is connected and has at least two vertices. Therefore,
v0 6= vk . If the degree of v0 were bigger than one then v0 would have a
neighbour w 6= v1 . If w is not on the path P then (w v0 v1 ... vk ) is a path in T
that is strictly longer than P , a contradiction. If w = vj is on the path P then
(v0 v1 ... vj v0 ) is a cycle in T , contradicting the fact that T is a tree. Therefore,
the degree of v0 is equal to one. Similarly, the degree of vk is also equal to
one.

Proposition 7.4. A nonempty graph G = (V, E) is a tree if and only if for


any two vertices v, w ∈ V , there is exactly one path from v to w in G.

Proof. First assume that G is a tree, and let v, w ∈ V . Since G is connected,


there is a walk from v to w in G, so there is at least one path from v to w in
G (by Corollary 6.6). If there are two distinct paths from v to w in G then G
contains a cycle (by Proposition 6.7). Since G has no cycles, there is at most
one path from v to w.
Conversely, if G is nonempty but not a tree then either G has more than
one component or G contains a cycle. If G is not connected then let v, w ∈ V
be in different connected components of G. Then there is no path in G from
v to w. If G contains a cycle C = (v0 v1 v2 ... vk v0 ) then (v0 v1 v2 ... vk ) and
(v0 vk ) are two different paths from v0 to vk in G.

Theorem 7.5. Let G = (V, E) be a graph with |V | = n vertices, |E| = m


edges, and c(G) = c components. Then m ≥ n − c, and equality holds if and
only if G is a forest.

Proof. We prove the result by induction on m = |E|. For the basis m = 0


of induction, G = (V, ∅) is an edgeless graph with |V | = n vertices and
c(G) = |V | = n components, and it is a forest since it contains no cycles.
Section 7.1 Trees. 165

For the induction step, assume that G has at least one edge, and that the
result holds for all graphs with fewer edges than G. Let e ∈ E be any edge
of G, and consider the spanning subgraph G0 = G r e with n0 = n vertices,
m0 = m−1 edges, and c0 = c(Gre) connected components. By the induction
hypothesis, m0 ≥ n0 − c0 and equality holds if and only if G0 is a forest.
First, assume that e is a bridge in G, so that c0 = c + 1 by Corollary 6.22. It
follows that m = m0 + 1 ≥ (n0 − c0 ) + 1 = n − (c0 − 1) = n − c, proving part of
the induction step. Also, m = n − c if and only if m0 = n0 − c0 . By induction,
this occurs if and only if G0 is a forest. We claim that since e is a bridge, G is
a forest if and only if G r e is a forest. Proof of this claim is left as Exercise
7.2, and completes this part of the induction step.
Second, assume that e is not a bridge in G, so that c0 = c. It follows that
m = m0 + 1 ≥ (n0 − c0 ) + 1 = n − c + 1 > n − c. The claimed inequality holds,
but not with equality. Since e is not a bridge it is contained in a cycle (by
Theorem 6.20), and so G is not a forest. This completes the induction step
and the proof.

The special case of Theorem 7.5 for connected graphs (c = 1) is particu-


larly important.

Corollary 7.6. Let G = (V, E) be a connected graph with |V | = n vertices


and |E| = m edges. Then m ≥ n − 1, and equality holds if and only if G is
a tree.

Example 7.7 (Numerology of Trees). Let T = (V, E) be a tree with nd


vertices of degree d, for all d ∈ N. Then

n = |V | = n0 + n1 + n2 + n3 + · · ·

and, by the Handshake Lemma,

2m = 2 |E| = n1 + 2n2 + 3n3 + · · · .

Since |E| = |V | − 1 by Corollary 7.6 we have

2(n0 + n1 + n2 + n3 + · · · ) = 2 |V | = 2 + 2 |E| = 2 + n1 + 2n2 + 3n3 + · · · .


166 Trees. Section 7.2

This yields
2n0 + n1 = 2 + n3 + 2n4 + 3n5 + · · ·
If n = 1 then n0 = 1 and nd = 0 for all d ≥ 1. If n ≥ 2 then n0 = 0, and
we deduce that n1 ≥ 2. This gives a second (more quantitative) proof of
Proposition 7.3.

Theorem 7.8 (Two-out-of-Three Theorem). Let G = (V, E) be a graph


with |V | = n vertices and |E| = m edges. Consider the following three
conditions:
(i) G is connected;
(ii) G has no cycles;
(iii) m = n − 1.
Any two of these conditions together imply that all three hold.

Proof. If (i) and (ii) hold then G is a tree. Corollary 7.6 implies that (iii) holds.
If (i) and (iii) hold then the inequality of Corollary 7.6 holds with equality,
so that G is a tree and hence has no cycles.
If (ii) and (iii) hold then let G1 , G2 , ..., Gc be the connected components of
G. Let Gi have ni vertices and mi edges. Each Gi is connected and by (ii) has
no cycles, so is a tree, so that mi = ni − 1 by Corollary 7.6. Now (iii) implies
that

1 = n − m = (n1 + n2 + · · · + nc ) − (m1 + m2 + · · · + mc )
= (n1 − m1 ) + (n2 − m2 ) + · · · + (nc − mc ) = c.

Since c = 1, G is connected, and so (i) holds. This completes the proof.

7.2 Spanning Trees and Connectedness.

A spanning tree of a graph is just what it sounds like: it is a spanning sub-


graph that is a tree.
Section 7.2 Trees. 167

Theorem 7.9. A graph is connected if and only if it has a spanning tree.

Proof. First, assume that T is a spanning tree of G. Since T is connected, it


is nonempty, so G is nonempty. Let v, w ∈ V (G). Since T is spanning and
connected, v reaches w in T . Since T is a subgraph of G, this implies that v
reaches w in G. Therefore, G is connected.
Conversely, assume that G = (V, E) is connected, with |V | = n vertices
and |E| = m edges. By Corollary 7.6, m ≥ n − 1, with equality if and only
if G is a tree. We proceed by induction on m. The basis of induction is
m = n − 1. In this case, G is a tree, and hence is a spanning tree of itself.
Assume that the result holds for all connected graphs G0 with V (G0 ) = V (G)
and |E(G0 )| < |E(G)|. For the induction step, G is connected and m ≥ n >
n − 1. By Corollary 7.6 again, G is not a tree. Thus, G contains a cycle C. Let
e ∈ E be an edge of C and let G0 = G r e. By Theorem 6.20, the edge e is
not a bridge of G, so that G0 is connected. By the induction hypothesis, G0
contains a spanning tree T . Since G0 is a spanning subgraph of G, it follows
that T is also a spanning tree of G.

In Proposition 5.25(d) we saw that if G contains an odd cycle then G is


not bipartite. Using spanning trees we can give an efficient proof of the
converse implication.

Theorem 7.10. A graph is bipartite if and only if it does not contain any
odd cycles.

Proof. First, notice that a graph is bipartite if and only if every one of its
connected components is bipartite. Also, a graph contains an odd cycle if
and only if at least one of its connected components contains an odd cycle.
These observations allow us to reduce the proof of this theorem to the con-
nected case. That is, if the statement holds for all connected graphs then it
holds for all graphs. Thus, we may assume that G = (V, E) is a connected
graph.
If G contains an odd cycle then G is not bipartite, by Proposition 5.25(d).
Conversely, assume that G is not bipartite. Since G is connected, Theorem
7.9 implies that G has a spanning tree T . An easy induction shows that
168 Trees. Section 7.2

trees are bipartite (this is left as Exercise 7.3). Let (A, B) be a bipartition of
T . Since G is not bipartite, this is not a bipartition of G. Thus, there is an
edge vw ∈ E with both ends in A or both ends in B. By symmetry, we may
assume that v, w ∈ A. By Proposition 7.4 there is exactly one (v, w)-path P
in T . Since both ends of P are in the set A of the bipartition (A, B) of T , the
path P has an even number of steps. Now C = (V (P ), E(P ) ∪ {vw}) is a
cycle in G with an odd number of edges, completing the proof.

The proof of Theorem 7.9 suggests the following strategy for finding a
spanning tree of a connected graph. Given a connected graph G, if G con-
tains a cycle then delete an edge of that cycle. Repeat this until what is left
has no cycles. Then what is left is a spanning tree of G. This is difficult to
turn into an algorithm because of the phrase “if G contains a cycle”. We
would need a subroutine that takes a connected graph G as input, and pro-
duces as output either a cycle in G or a certificate that G contains no cycles.
To do this, it seems to be easier just to find a spanning tree first.

Algorithm 7.11 (Constructing a spanning forest).


Input: a graph G = (V, E);
let F := ∅; let n := 0;
for v ∈ V do { let n := n + 1; let g(v) := n; };
for e = vw ∈ E do
{ if g(v) 6= g(w) then
{ let F := F ∪ {e};
let a := g(v); let b := g(w);
for z ∈ V do { if g(z) = b then let g(z) := a; };
};
};
Output: (V, F ) and g : V → {1, 2, ..., n}.

Informally, Algorithm 7.11 does the following. The loop over vertices v ∈ V
defines an arbitrary bijection g : V → {1, 2, ..., n}. The values of g will be
used to label the components of the output spanning forest. The loop over
edges vw ∈ E tests if an edge has the same label at both ends: g(v) = g(w).
If so, then that edge is skipped. But if g(v) 6= g(w) then the edge is included
in the output, and all of the vertices labelled g(w) are re-labelled to have the
same label as v ∈ V . After all edges have been examined, the algorithm
Section 7.2 Trees. 169

stops and produces its output.

Theorem 7.12. Let G = (V, E) be a graph. Apply Algorithm 7.11 to the


input G = (V, E), and let (V, F ) and g : V → {1, 2, ..., n} be the corre-
sponding output.
(a) Then (V, F ) is a spanning forest of G.
(b) Vertices v, w ∈ V are in the same component of (V, F ) if and only if
g(v) = g(w).
(c) Each component of (V, F ) is a spanning tree of a component of G.

Proof. To prove part (a) we only need to show that (V, F ) does not contain a
cycle. We prove this together with part (b) by showing that these statements
hold after every passage through the loop over e = vw ∈ E. Before this loop
starts we have F = ∅, and both statements (a) and (b) hold.
Now consider one iteration of the loop, and the edge e = vw ∈ E which
is being examined. At this stage the subgraph (V, F ) and function g satisfy
statements (a) and (b), by induction on the number of passages through the
loop. There are two cases. If g(v) = g(w) then the set F and function g do
not change, and so statements (a) and (b) continue to hold. If g(v) 6= g(w)
then let F 0 = F ∪ {vw} be the updated set F , and let g 0 : V → {1, 2, ..., n}
be the updated function. Since (b) holds for (V, F ), the vertices v and w are
in different components of (V, F ). But v and w are in the same component
of (V, F 0 ). Therefore, e = vw is a bridge of (V, F 0 ). By Exercise 7.2, since
(V, F ) is a forest it follows that (V, F 0 ) is a forest. Because of the way g 0 is
updated, and becuase (b) holds for (V, F ) and g, it follows that for all z ∈ V ,
g 0 (z) = g 0 (v) if and only if z is in the component of (V, F 0 ) containing v. From
this the statement (b) follows for the subgraph (V, F 0 ) and function g 0 . This
completes the induction step, and the proof of parts (a) and (b).
For part (c), since (V, F ) is a subgraph of G, every component of (V, F )
is contained in a component of G. To prove (c), it suffices to show that if x
reaches y in G then x reaches y in (V, F ). To do this the following observation
is useful: if at any stage of the algorithm we have g(x) = g(y), then this
continues to hold at all later stages. (This can be proved by induction on the
number of iterations of the loop over the edges.) The contrapositive form is
even more useful: if at any stage of the algorithm we have g(x) 6= g(y), then
g(x) 6= g(y) also held at all earlier stages.
170 Trees. Section 7.2

a b c d e

p q r s t

v w x y z

Figure 7.1: Graph for Examples 7.13 and 7.16.

Now suppose that x, y ∈ V are such that x reaches y in G, but that x and y
are in different components of the output (V, F ). Since we have proved (b),
we know that g(x) 6= g(y). Let W be an (x, y)-walk in G. Then there is an
edge e = vw on W for which g(v) 6= g(w). Since (a) and (b) hold, it follows
that e is not an edge in F . Now consider the iteration of the loop at which the
edge e = vw is considered. By the observation in the previous paragraph,
at this stage we also have g(v) 6= g(w). But then the algorithm would have
included e in the set F . This contradiction shows that if x reaches y in G,
then x reaches y in (V, F ), completing the proof.

Example 7.13. Table 7.1 shows Algorithm 7.11 applied to the graph pic-
tured in Figure 7.1. The columns are indexed by the vertices of the graph.
The first row indicates the initial (arbitrary) values of the function g. In
the first column, the remaining rows are indexed by the edges, in the
order they are considered by the algorithm. In the row corresponding
to an edge, the first-named vertex is marked with an asterisk (*). If the
labels of the two ends are equal, this is marked with an equal sign (=) at
Section 7.2 Trees. 171

E a b c d e p q r s t v w x y z F
g(·) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
ac ∗ . 1 . . . . . . . . . . . . ac
ws . . . . . . . . 12 . . ∗ . . . ws
dt . . . ∗ . . . . . 4 . . . . . dt
cr . . ∗ . . . . 1 . . . . . . . cr
vw . . . . . . . . 11 . ∗ 11 . . . vw
pb . 6 . . . ∗ . . . . . . . . . pb
ye . . . . 14 . . . . . . . . ∗ . ye
bx . ∗ . . . . . . . . . . 6 . . bx
xz . . . . . . . . . . . . ∗ . 6 xz
qw . . . . . . ∗ . 7 . 7 7 . . . qw
ar ∗ . . . . . . = . . . . . . .
er 14 . 14 . ∗ . . 14 . . . . . . . er
vq . . . . . . = . . . ∗ . . . .
bd . ∗ . 6 . . . . . 6 . . . . . bd
qs . . . . . . ∗ . = . . . . . .
ry . . . . . . . ∗ . . . . . = .
tz . . . . . . . . . ∗ . . . . =
px . . . . . ∗ . . . . . . = . .
g(·) 14 6 14 6 14 6 7 14 7 6 7 7 6 14 6

Table 7.1: Algorithm 7.11 in action.

the other end. Otherwise, the numbers in that row indicate the process
of re-labelling the vertices, and the last column contains the name of the
edge, which is included in the output. The subgraph (V, F ) output from
this example is shown in Figure 7.2.
172 Trees. Section 7.3

a b c d e

p q r s t

v w x y z

Figure 7.2: The subgraph output for Example 7.13.

7.3 Search Trees.

In this section we give an algorithm that produces a spanning tree T of a


connected graph G, along with some extra information that helps us navi-
gate within the graph. This extra information is a “root vertex” v∗ , a “parent
function” pr, and a “level function” `. These are explained below.
Recall the concept of the boundary of a subset S ⊆ V in a graph G =
(V, E): this is the set ∂S = {e ∈ E : |e ∩ S| = 1} of edges with exactly one
end in S. We will need to calculate ∂S from S in our algorithm. Clearly this
can be done using a loop over the set of all edges of G, and we will use this
as a subroutine without going into details. (This whole algorithm can be
implemented more efficiently than we do here, using clever data structures,
but we are not concerned with issues of computational complexity.)

Algorithm 7.14 (Constructing a search tree).


Input: a graph G = (V, E) and a vertex v∗ ∈ V ;
let W := {v∗ }; let F := ∅;
Section 7.3 Trees. 173

let pr(v∗ ) := null; let `(v∗ ) := 0;


let ∆ := ∂W ;
while (∆ 6= ∅) do
{ pick any e = xy ∈ ∆ with x ∈ W and y 6∈ W ;
let W := W ∪ {y}; let F := F ∪ {e};
let pr(y) := x; let `(y) := 1 + `(x);
let ∆ := ∂W ;
};
Output: T = (W, F ) and pr : W → W ∪ {null} and ` : W → N.

This is a non-deterministic algorithm because of the phrase “pick any


e = xy ∈ ∆”. By restricting the choice of edge from ∆ in various ways one
can specialize to particular kinds of search trees which have extra useful
properties. This is discussed in Chapter ??.

Theorem 7.15 (Search Trees). Let G = (V, E) be a graph, and let v∗ ∈ V .


Apply Algorithm 7.14 to the input G and v∗ , and let T = (W, F ), pr : W →
W ∪ {null}, and ` : W → N be the corresponding output.
(a) Then T = (W, F ) is a spanning tree of the connected component of G
that contains v∗ .
(b) For any w ∈ W , the unique path P in T from w to v∗ is obtained by
following the steps v → pr(v) until pr(v) = null.
(c) For any w ∈ W , the length of the path P from w to v∗ in T is `(w).

Proof. We prove that T is a tree and that parts (b) and (c) hold by induction
on the number of iterations through the “while (∆ 6= ∅)” loop. At the end
we finish the proof that (a) holds.
Before the loop begins, T = ({v∗ }, ∅) is a tree, the functions pr and ` are
defined on the set W , and parts (b) and (c) hold. Now consider an iteration
of the loop in which the edge e = xy ∈ ∆ is considered. Let T = (W, F ) and
pr and ` be the data before the edge e is added, and let T 0 = (W 0 , F 0 ) and pr0
and `0 be the data after the edge e is added. By induction, T = T 0 r y is a
tree. By construction, y is a vertex of degree one in T 0 . Exercise 6.10 (or the
Two-out-of-Three Theorem 7.8) now implies that T 0 is a tree. Parts (b) and
(c) only need to be checked for the new vertex y. By induction, the unique
path in T from x to v∗ is obtained by following the steps v → pr(v) until
pr(v) = null, and the length of this path is `(x). It follows that the unique
174 Trees. Section 7.4

F W `(·) ∂W
∅ x 0 xp, xb, xd, xz
xb b 1 xp, xd, xz, bp, bd
xz z 1 xp, xd, bp, bd, zt
bp p 2 xd, bd, zt
bd d 2 zt, dt
zt t 2 ∅

Table 7.2: Algorithm 7.14 in action.

path in T 0 from y to v∗ is obtained by following the steps v → pr0 (v) until


pr0 (v) = null, and the length of this path is `0 (y) = 1 + `(x).
To see that T is a spanning tree of the component of G containing v∗ ,
suppose that v∗ reaches z ∈ V in G but that z 6∈ W when the algorithm
terminates. Let Z be a (v∗ , z)-walk in G. Since v∗ ∈ W and z 6∈ W , there
is a step xy of Z with x ∈ W and y 6∈ W . But this edge e = xy is in the
boundary of W . Now, since ∂W 6= ∅, the algorithm has not terminated yet.
This contradiction shows that if v∗ reaches z ∈ V in G, then z ∈ W . Thus, T
is a spanning tree of the component of G containing v∗ .

Example 7.16. Table 7.2 shows Algorithm 7.14 applied to the graph pic-
tured in Figure 7.1 with root vertex x. The first row indicates the data
initialization stage. The first column indicates the edges included in the
output set F , in the order they are chosen by the algorithm. The second
column indicates the new vertex that is adjoined to the set W at each
step, and the third column is the level of the new vertex. The fourth col-
umn is the boundary ∂W of the updated set W . The output from this
example is shown in Figure 7.3.

7.4 Exercises.

Exercise 7.1. Draw pictures of all trees with six or fewer vertices (up
to isomorphism). (Be brave and do seven!)
Section 7.4 Trees. 175

1
b d 2

2 p t 2

0 x z 1

Figure 7.3: The output for Example 7.16.

Exercise 7.2. Let e ∈ E be a bridge in a graph H = (V, E). Show that


H is a forest if and only if H r e is a forest.

Exercise 7.3. Prove that trees are bipartite. (Hint: go by induction on


the number of vertices, by deleting a leaf.)

Exercise 7.4. Let G = (V, E) be a graph.


(a) Show that if |E| = |V | − 1 then G has a vertex of degree at most
one.
(b) Use part (a) and Exercise 6.10 to give a proof of the Two-out-of-
Three Theorem 7.8 that does not use Theorem 7.5 or its conse-
quences. (You can use Proposition 7.3.)

Exercise 7.5. Fix an integer d ≥ 3, and let T be a tree with n1 vertices of


degree one, nd vertices of degree d, and no other vertices. Determine
|V (T )| = n1 + nd as a function of n1 . For which values of n1 does such
a tree exist?
Exercise 7.6. Let T be a tree with n ≥ 2 vertices and no vertices of
degree 2. What is the minimum possible number of leaves that such
a tree can have, as a function of n? Which trees attain this minimum
bound?

Exercise 7.7. Let d = (d1 d2 ... dn ) be a weakly decreasing sequence of


n ≥ 2 positive integers. Show that there is a tree with degree sequence
d if and only if d1 + d2 + · · · + dn = 2n − 2.

Exercise 7.8. Let G = (V, E) be a connected graph for which |V | = |E|.


Prove that G contains exactly one cycle.

Exercise 7.9. Let e be an edge in a connected graph G. Prove that e is


a bridge in G if and only if e is in every spanning tree of G.

Exercise 7.10. Let G = (V, E) be a connected graph, and let T1 and T2


be two spanning trees of G.
(a) Let e ∈ E(T1 ) r E(T2 ). Prove that there is an edge f ∈ E(T2 ) r
E(T1 ) such that (T1 r {e}) ∪ {f } is also a spanning tree of G.
(b) Let e ∈ E(T1 ) r E(T2 ). Prove that there is an edge f ∈ E(T2 ) r
E(T1 ) such that (T2 ∪ {e}) r {f } is also a spanning tree of G.

Exercise 7.11. Describe an algorithm that takes as input a graph G =


(V, E) and produces as output a subset R ⊆ V and a collection of
subsets {Ur : r ∈ R} with the following properties.
• The set R contains exactly one vertex from each component of G.
• For each r ∈ R, Ur is the set of vertices in the same component as r.

Exercise 7.12. In Algorithm 7.14, the line “let ∆ := ∂W ;” can be re-


placed by “let ∆ := ∆ ⊕ ∂{y};”. (Here, ⊕ denotes the symmetric
difference of sets.) Explain why.
Chapter 8

Planar Graphs.

We consider the question: which graphs can be drawn in the plane with-
out crossing edges? This is not only interesting in its own right, but also
has practical implications. For instance, in the manufacture of very large-
scale integrated circuits, electrical conductors are printed onto a polymer
substrate. These conductors are the edges of a graph, and to avoid short
circuits these edges must not cross one another. Another example is a map
in which cities, towns, and crossroads are represented by vertices, and high-
ways are represented by edges
Several results of this chapter are stated most naturally in terms of (undi-
rected) multigraphs, and so we adopt this point of view from the beginning.
For this chapter, the word “graph” will tacitly mean an undirected multi-
graph. Where necessary, we will be clear about restricting to simple graphs.

8.1 Plane Embeddings of Graphs.

What do we mean by a drawing of a graph? A simple (parameterized plane)


curve is an injective continuous function γ : [0, 1] → R2 . We will conflate a
simple curve with its image in R2 , since any particular parameterization will
turn out to be irrelevant. The endpoints of γ are γ(0) and γ(1), and γ(1/2)
is one of infinitely many midpoints. A simple closed curve is a continuous
function γ : [0, 1] → R2 that is almost injective, the only exception being that
γ(0) = γ(1).

177
178 Planar Graphs. Section 8.1

Definition 8.1 (Plane Embedding, Planar Graph). Let G = (V, E, B)


be an undirected multigraph. A plane embedding of G is a pair of sets
(P, Γ) such that:
1. P = {pv : v ∈ V } is a set of distinct points in R2 indexed by V .
2. Γ = {γe : e ∈ E} is a set of distinct simple curves in R2 indexed
by E.
3. For e ∈ E, the endpoints γe (0) and γe (1) of γe are the points pv
for which B(v, e) > 0. Moreover, γe (0) = γe (1) if and only if e is
a loop at v.
4. For v ∈ V and e ∈ E, if pv ∈ γe then B(v, e) > 0 and pv ∈
{γe (0), γe (1)}.
5. For e, f ∈ E with e 6= f , if 0 ≤ s, t ≤ 1 and γe (s) = γf (t) then
s, t ∈ {0, 1}.
A graph is planar if it has a plane embedding, and otherwise it is non-
planar.

Condition 3. says that the curves representing edges have the right end-
points. Condition 4. says that edges don’t go through vertices except at
their ends. Condition 5. says that distinct edges cannot intersect except at
their endpoints.
Here is a link to an amusing puzzle based on plane embeddings of graphs.

Example 8.2.
• The complete graphs K1 , K2 , K3 , K4 are planar, but K5 seems to be
non-planar. (This is proved in Example 8.20.)
• The complete bipartite graphs K1,r and K2,r are planar, but K3,3
seems to be non-planar. (This is proved in Example 8.22.)

To avoid topological complications, we usually restrict the simple curves


in a plane embedding of a graph. For instance, there are injective functions
γ : [0, 1] → R2 which are continuous but nowhere differentiable. The limit
of the process shown in Figure 8.2 is such an example, known as the Koch
snowflake curve. To eliminate such pathologies, we require that an edge of a
plane embedding is represented by a tame curve . Various conventions are
used: if γ is continuously differentiable to all orders, or if γ is a concatenation
Section 8.1 Planar Graphs. 179

Figure 8.1: K5 and K3,3 seem to be non-planar.

of finitely many straight line segments, then γ is a tame curve. This will
suffice for our purposes.

Theorem 8.3 (Jordan Curve Theorem). Let γ be a simple closed curve


in R2 . Then the complementary subset R2 r γ has exactly two connected
components, the interior of γ and the exterior of γ.

For tame curves Theorem 8.3 is evident, and it was not until the early 1800s
that people realized that this statement requires proof. For non-tame (“wild”)

Figure 8.2: The Koch snowflake curve.


180 Planar Graphs. Section 8.1

Figure 8.3: Stereographic projection.

curves, the proof is surprisingly tricky. Details can be found in any introduc-
tory book on point-set topology. We say that a simple closed curve separates
the points in its interior from the points in its exterior.

8.1.1 Stereographic projection.

A plane embedding of a graph can be transferred to an embedding of the


graph on the surface of a sphere, as follows. Informally, draw the graph on
a piece of paper and then put the piece of paper on the floor. The graph
is now drawn on the surface of the Earth, which is a sphere. The formal
description of this process is known as stereographic projection .
Identify R2 with the plane P = {(x, y, 0) : (x, y) ∈ R2 } in three-space in
the obvious way. Let S = {(x, y, z) ∈ R3 : x2 + y 2 + z 2 = 1} be the unit
sphere in R3 , and let N = (0, 0, 1) be the “north pole” of S. For any point P
in the plane P, there is a unique line PN in R3 containing the points N and
P. This line intersects the sphere S in two distinct points N and P0 . This
construction P 7→ P0 defines a continuous bijection from the plane P ' R2 to
the punctured sphere S r N. (See Figure 8.3.) The exterior of the “equator”
S ∩ P in P is mapped to the “northern hemisphere” of S, and the interior of
S∩P is mapped to the “southern hemisphere”. In this way, any simple curve
can be transferred between R2 and S r N, and so any plane embedding of a
graph can be transferred similarly.
Section 8.2 Planar Graphs. 181

Stereographic projection is useful because one can take a plane embed-


ding of a graph, project it onto the sphere, then rotate the sphere in three-
space so that any point in the complement of the embedding is at the north
pole, and then project the embedding from the sphere back onto the plane.
This is an extra symmetry of plane embeddings that is not apparent at first
glance.

8.2 Kuratowski’s Theorem.

Which graphs can be drawn in the plane? In Example 8.2 we saw that K5
and K3,3 seem to be non-planar. This is the starting point for a complete
characterization of planar graphs.

Lemma 8.4. If G is planar then every subgraph of G is planar.

Proof. If (P, Γ) is a plane embedding of G then


({pw : w ∈ V (H)}, {γe : e ∈ E(H)})
is a plane embedding of the subgraph H.

Lemma 8.5. A multigraph G is planar if and only if its simplification si(G)


is planar.

Proof. Since si(G) can be regarded as a subgraph of G, Lemma 8.4 implies


one direction. The converse implication is Exercise 8.1(a).

Definition 8.6 (Subdivision). Let G = (V, E, B) be a multigraph, and


let vew ∈ E. Let z be a new vertex not in V , and let e0 and e00 be new
edges not in G. The subdivision of e in G is the multigraph G • e with
vertices V (G•e) = V (G) ∪ {z}, edges E(G•e) = (E(G)r{e}) ∪ {e0 , e00 },
and incidences ve0 z and we00 z for the new edges.

Informally, subdivision inserts a new vertex in the middle of the edge e. For
example, the graph of Figure 5.15 can be obtained by repeated subdivision
of edges starting from the graph C4  P3 .
182 Planar Graphs. Section 8.3

Lemma 8.7. Let G be a multigraph and e ∈ E(G). Then G is planar if and


only if G • e is planar.

Proof. First, assume that (P, Γ) is a plane embedding of G, and let vew ∈ E
with pv = γe (0) and pw = γe (1). Let pz = γe (1/2), and define two simple
curves by γe0 (t) = γe (t/2) and γe00 (t) = γe (1 − t/2) for t ∈ [0, 1]. Together
with the points and curves from the embedding of G r e, this gives a plane
embedding of G • e. The converse implication is Exercise 8.1(b).

Theorem 8.8 (Kuratowksi, 1930). A multigraph is planar if and only if it


does not contain a (repeated) subdivision of K5 or K3,3 as a subgraph.

Proof of the easy implication. By Examples 8.20 and 8.22 (below), the graphs
K5 and K3,3 are non-planar. By Lemmas 8.4 and 8.7, if G contains a (re-
peated) subdivision of K5 or K3,3 then G is non-planar.

The other direction of the proof – that every non-planar graph contains a (re-
peated) subdivision of K5 or K3,3 – is done in CO 342. In fact, one can adapt
the proof of Kuratowski’s Theorem to obtain an algorithm which takes as
input a graph G, and produces as output either a plane embedding of G or
a Kuratowski subgraph – a subgraph of G which is a (repeated) subdivision
of K5 or K3,3 . Moreover, the running time of this algorithm is a polyno-
mial function of the size of the input graph, and it is both practically and
theoretically tractable.

Example 8.9. While we can’t present planarity testing algorithms here,


there is a simple heuristic which works very well for smallish graphs.
Just drop the vertices one-by-one onto the plane, and at each step either
adjust the partial embedding (if necessary) to accommodate the new ver-
tex, or find a Kuratowski subgraph obstruction. Figure 8.4 shows this for
the coprimality graph: the vertices are the integers that are at least 2, and
the edges are the coprime pairs of integers. The coloured vertices indi-
cate the two sides of a K3,3 subgraph, so this graph is not planar.
Section 8.3 Planar Graphs. 183

Figure 8.4: Part of the coprimality graph.

8.3 Numerology of Planar Graphs.

8.3.1 The “Faceshaking” Lemma.

Definition 8.10 (Faces of a plane embedding). Let G = (V, E, B) be a


multigraph with a plane embedding (P, Γ).
1. The footprint of a subgraph H of G is the union of the points
and curves representing vertices and edges in H, considered as
a subset of R2 . It is denoted by fp(H).
2. A face of (P, Γ) is a connected component of the complementary
subset R2 r fp(G) with the usual topology.
3. The boundary ∂F of a face F ∈ F is a subgraph of G. It has for
vertices those v ∈ V for which pv is in the closure of F , and for
edges those e ∈ E for which γe is contained in the closure of F .
4. The degree of a face F is the number of edges plus the number of
bridges of its boundary ∂F .
184 Planar Graphs. Section 8.3

Figure 8.5: A face of an embedding, and its boundary.

(Note that the boundary of a face F is different from the boundary of a


subset S ⊆ V of vertices.) The footprint fp(P ) of a path P is a simple curve,
and the footprint fp(C) of a cycle C is a simple closed curve. The definition
of the degree of a face might seem strange at first, but it is designed so that
an analogue of the Handshake Lemma holds.

Example 8.11. Figure 8.5 shows a typical face in a plane embedding, and
its boundary.

Lemma 8.12. Let e be an edge of a multigraph G = (V, E, B) with a plane


embedding (P, Γ). Let F1 and F2 be the two faces on either side of the curve
γe . Then e is a bridge if and only if F1 = F2 .

Sketch of proof. If e is not a bridge then it is contained in a cycle C in G, by


Theorem 6.20. The footprint of C is a simple closed curve in R2 , with one of
the faces F1 or F2 in the interior and the other in the exterior. It follows from
the Jordan Curve Theorem 8.3 that F1 6= F2 .
Conversely, assume that xey is a bridge in G. Let H be the connected
component of G containing e, and let X and Y be the connected components
of H r e as in Proposition 6.21, with x in X and y in Y . For q ∈ R2 and (a
Section 8.3 Planar Graphs. 185

small)  > 0, let B (q) be the closed disc of radius  centered at the point
q. Let B (X) be the union of the sets B (q) for all points q ∈ fp(X) in the
footprint of X. Since all the curves in the embedding are tame, we can take
 > 0 small enough that Bε (X) is disjoint from the footprint of everything
in G except the component X and the edge e. Let C be the boundary of
the component of the set R2 r B (X) which contains the point py . Again
by tameness, we can take  > 0 sufficiently small that C is a simple closed
curve which intersects γe at a single point and is otherwise disjoint from the
footprint of G. This shows that the two faces of (P, Γ) on either side of the
curve γe are the same face: that is, F1 = F2 .

Theorem 8.13 (The “Faceshaking” Lemma). Let G = (V, E, B) be a


multigraph with a plane embedding (P, Γ) and set of faces F. Then
X
deg(F ) = 2 |E|.
F ∈F

Proof. Define an auxiliary undirected multigraph H as follows. The vertices


of H are the edges E and the faces F, and (E, F) will be a bipartition of H.
Join edge e ∈ E to face F ∈ F by an edge of H when e is in the boundary of
the face F ; if e is a bridge then join e to F by two edges of H. In the graph
H, every “edge-vertex” has degree 2, and the degree of a “face-vertex” F is
deg(F ) as in Definition 8.10. The Bipartite Handshake Lemma (Exercise 5.5)
holds for multigraphs and implies that
X
2 |E(G)| = |E(H)| = deg(F ).
F ∈F

8.3.2 Euler’s Formula.

Theorem 8.14 (Euler’s Formula). Let G = (V, E, B) be a multigraph


embedded in the plane, with |V | = n vertices, |E| = m edges, |F| = f faces,
and c(G) = c connected components. Then

n − m + f = c + 1.
186 Planar Graphs. Section 8.3

Proof. We proceed by induction on m = |E|. For the basis of induction we


have m = 0, in which case n = c and f = 1, and the result is seen to hold.
For the induction step, let G have at least one edge e ∈ E, and consider
the embedding of G0 = G r e inherited from the embedding of G. Let this
embedding of G0 have m0 = m − 1 edges, n0 = n vertices, f 0 faces, and c0
components. By induction, we may assume that n0 − m0 + f 0 = c0 + 1.
There are two cases: the edge e is either a bridge in G or it is not. If e is
a bridge in G then c0 = c + 1 by Corollary 6.22, and f 0 = f by Lemma 8.12.
Now
n − m + f = n0 − (m0 + 1) + f 0 = (n0 − m0 + f 0 ) − 1 = (c0 + 1) − 1 = c + 1,
as desired. Similarly, if e is not a bridge then c0 = c (by definition) and
f 0 = f − 1 by Lemma 8.12, and
n − m + f = n0 − (m0 + 1) + (f 0 + 1) = n0 − m0 + f 0 = c0 + 1 = c + 1.
This completes the induction step, and the proof.

Lemma 8.15 is the key point at which restriction to the case of simple
graphs is important. For multigraphs with loops or multiple edges, its con-
clusion need not hold.

Lemma 8.15. If G is a simple graph with at least two edges, then every face
of every plane embedding of G has degree at least three.

Proof. Exercise 8.10

Proposition 8.16. Let G = (V, E) be a connected planar simple graph with


|V | ≥ 3 vertices. Let nd be the number of vertices of G degree d, for each
d ∈ N. (Notice that n0 = 0.)
(a) Then 5n1 + 4n2 + 3n3 + 2n4 + n5 ≥ 12 + n7 + 2n8 + 3n9 + · · · .
(b) Equality holds in (a) if and only if, for every plane embedding of G, all
faces have degree 3.

P∞
Proof. It is clear that |V | = d=1 nd . The Handshake Lemma implies that

X X
d nd = deg(v) = 2 |E|.
d=1 v∈V
Section 8.3 Planar Graphs. 187

(In the summations over d, only finitely many terms are non-zero.) Since G
is connected with at least three vertices, Corollary 7.6 implies that G has at
least two edges. Let (P, Γ) be any plane embedding of G. By Lemma 8.15,
every face of this embedding has degree at least three. By the Faceshaking
Lemma 8.13,
X
2 |E| = deg(F ) ≥ 3 |F|, (8.1)
F ∈F

with equality if and only if every face has degree three.


Since G is connected, Euler’s Formula implies that |V | − |E| + |F| = 2.
Now multiply by 6 and calculate:

12 = 6 |V | − 6 |E| + 6 |F|
≤ 6 |V | − 6 |E| + 4 |E| = 6 |V | − 2 |E|

X X∞ ∞
X
= 6 nd − d nd = (6 − d) nd .
d=1 d=1 d=1

Rearranging this yields part (a), and part (b) follows from the characteriza-
tion of equality in (8.1).

Corollary 8.17. Every nonempty planar simple graph has a vertex of degree
at most five.

Proof. Consider any connected component of the graph. If it has at most two
vertices then it has a vertex of degree at most one. Otherwise, Proposition
8.16 applies. Since the LHS of the inequality of part (a) is positive, the result
follows.

Example 8.18. Corollary 8.17 does not hold more generally for all planar
multigraphs. Think of two vertices joined by seven edges – it has seven
faces of degree two and two vertices of degree seven.

Corollary 8.19. Let G = (V, E) be a connected planar simple graph with


|V | ≥ 3 vertices. Then |E| ≤ 3 |V | − 6. Equality holds if and only if, for
every plane embedding of G, all faces have degree 3.
188 Planar Graphs. Section 8.3

Proof. Let (P, Γ) be any plane embedding of G. Euler’s Formula implies that
|V | − |E| + |F| = 2. The inequality (8.1) also holds, and we use it to eliminate
|F| as follows:

6 = 3|V | − 3|E| + 3|F| ≤ 3|V | − 3|E| + 2|E| = 3|V | − |E|.

Rearranging this yields the result, with equality characterized as in (8.1).

Example 8.20. K5 is not planar, since it is connected with |V | = 5 vertices


and |E| = 10 edges, and 3|V | − 6 = 9 < 10 = |E|.

We have to be just a little bit more careful to show that K3,3 is not planar,
since it does satisfy the inequality |E| = 9 ≤ 12 = 3|V | − 6.

Corollary 8.21. Let G = (V, E) be a connected planar simple graph with


|V | ≥ 3 vertices and girth g(G) ≥ 4. Then |E| ≤ 2 |V | − 4. Equality holds
if and only if, for every plane embedding of G, all faces have degree 4.

Proof. Let (P, Γ) be any plane embedding of G. Euler’s Formula yields |V | −


|E| + |F| = 2. Since G has no 3-cycles, every face has degree at least four.
The Faceshaking Lemma then implies that 2|E| ≥ 4|F|, with equality if and
only if every face has degree four. Eliminating |F| from Euler’s Formula as
in the proof of Corollary 8.19 yields the result.

Example 8.22. K3,3 is not planar, since it is connected and has girth 4 and
2|V | − 4 = 8 < 9 = |E|.

8.3.3 The Platonic solids.

The Platonic solids are familiar from high school geometry and have been
known since antiquity. We can use graph theory to show that there are only
five possible examples. (Actually constructing them as regular polyhedra
in three-dimensional space is a bit of geometry beyond graph theory.)
Section 8.4 Planar Graphs. 189

Figure 8.6: The tetrahedron.

Theorem 8.23 (The Platonic Solids). Let d, k ≥ 3 be integers. There is a


connected d-regular plane embedding that is face-k-regular in the following
five cases, and in no others.
• (d, k) = (3, 3): the tetrahedron.
• (d, k) = (4, 3): the octahedron.
• (d, k) = (3, 4): the cube.
• (d, k) = (5, 3): the icosahedron.
• (d, k) = (3, 5): the dodecahedron.
In each case, the embedding is unique up to isomorphism.

Proof. Let such an embedding have n vertices, m edges, f faces, and c = 1


component. By the Handshake and Faceshaking Lemmas, we have dn =
2m = kf . Now substitute n = 2m/d and f = 2m/k into Euler’s Formula:
n−m+f = 2. The condition is equivalent to 1/d+1/k = 1/2+1/m. The five
pairs listed are the only ones for which 1/d + 1/k > 1/2, as one can easily
check. Figures 8.6 to 8.10 show the five Platonic solids as plane embeddings
of graphs. Uniqueness up to isomorphism is left as Exercise 8.14.

The case d = 2 and k ≥ 3 is satisfied by a plane embedding of a k-cycle


Ck . The case d ≥ 3 and k = 2 can be realized if one allows multigraphs in
place of graphs. If one allows infinite graphs then examples for all d ≥ 3 and
k ≥ 3 can be constructed. Only three of these cases have nice embeddings
in Euclidean space, though. These “regular tesselations of the plane” are
considered in Section ??.
190 Planar Graphs. Section 8.4

Figure 8.7: The octahedron.

Figure 8.8: The cube.


Section 8.4 Planar Graphs. 191

Figure 8.9: The icosahedron.

Figure 8.10: The dodecahedron.


192 Planar Graphs. Section 8.4

8.4 Planar Duality.

Definition 8.24 (Dual Graph). Let (P, Γ) be a plane embedding of a


multigraph G = (V, E, B), with set of faces F. The dual graph of this
embedding is a multigraph G∗ = (V ∗ , E ∗ , B ∗ ). The vertices of G∗ are
the faces of G: that is, V ∗ = F. The edges of G∗ correspond bijectively
to the edges of G: that is, E ∗ = {e∗ : e ∈ E}. For every bridge e of G,
e∗ is a loop in G∗ at the vertex corresponding to the face in F that has
e in its boundary. For every non-bridge e of G, e∗ is an edge incident
with the two faces in F that have e in their boundary.

Lemma 8.25. Let (P, Γ) be a plane embedding of a multigraph G = (V, E, B),


with set of faces F. Let G∗ = (V ∗ , E ∗ , B ∗ ) be the dual graph of this embed-
ding. For every face F ∈ F, the degree of F as a face of (P, Γ) equals the
degree of F as a vertex of G∗ .

Proof. Exercise 8.17.

Lemma 8.25 shows that the Faceshaking Lemma for a plane embedding is
equivalent to the Handshake Lemma for its dual graph.

Example 8.26. Figure 8.11 shows two plane embeddings of isomorphic


graphs. The dual graphs of these embeddings have different degree se-
quences – one is (6 4 3 3) and the other is (5 5 3 3) . While the graphs are
isomorphic, the dual graphs of the plane embeddings are not isomor-
phic.

To define the dual embedding of a plane embedding of a graph, we need


the following lemma.

Lemma 8.27. Let F be a face of a plane embedding (P, Γ) of a multigraph


G = (V, E, B). Let p∗ be any point in F . For each edge e ∈ E(∂F ) in the
boundary of F , let qe = γe (1/2) be a midpoint of the curve representing e.
Let Q = {qe : e ∈ E(∂F )}. Then there is a set C of simple curves in R2
with the following properties.
Section 8.4 Planar Graphs. 193

Figure 8.11: Two different plane embeddings of the same graph.

1. Each simple curve in C has endpoints p∗ and qe for some qe ∈ Q, and


is contained in the set F ∪ {qe }.
2. If e ∈ E(∂F ) is not a bridge then there is exactly one such curve in C.
3. If e is a bridge then there are exactly two such curves in C, the union
of which is a simple closed curve that separates the endpoints of γe .
4. The curves in C are pairwise disjoint except at their endpoints.

Proof of Lemma 8.27 is a rather tedious exercise in point-set topology – not


graph theory – and is omitted. (It is intuitively clear in the case that ∂F is
a single cycle. By induction on the number of components of ∂F , it then
follows in the case that ∂F has no bridges. Finally, the general case follows
by induction on the number of bridges. Proving Exercise 8.12 first helps to
clarify the picture.)

Definition 8.28 (Dual Embedding). Let (P, Γ) be a plane embedding


of a multigraph G = (V, E, B), with set of faces F. Let G∗ = (V ∗ , E ∗ , B ∗ )
be the dual graph of this embedding. We define a plane embedding
(P∗ , Γ∗ ) of G∗ as follows.
UNDER CONSTRUCTION

UNDER CONSTRUCTION

Example 8.29. Ponder Figure 8.12.

Proposition 8.30. If G is a connected multigraph embedded in the plane,


then G∗∗ is isomorphic with G.
194 Planar Graphs. Section 8.5

Figure 8.12: A plane embedding (black) and its dual embedding (red).

Proof. UNDER CONSTRUCTION

8.5 Exercises.

Exercise 8.1.
(a) Finish the proof of Lemma 8.5.
(b) Finish the proof of Lemma 8.7.

Exercise 8.2. For each of the graphs in Figure 8.13, give either a plane
embedding or a Kuratowski subgraph.

Exercise 8.3. For each of the graphs in Figure 8.14, give either a plane
embedding or a Kuratowski subgraph.
Section 8.5 Planar Graphs. 195

Figure 8.13: Examples for Exercise 8.2.

Figure 8.14: Examples for Exercise 8.3.


196 Planar Graphs. Section 8.5

Figure 8.15: The Knight’s move graph KM(4, 4).

Exercise 8.4. For k ≥ 2 and n ≥ 2k, determine whether or not the


circulant Cn (1, k) is planar.

Exercise 8.5. For k ≥ 3 and n ≥ 2k, determine whether or not the


circulant Cn (2, k) is planar.

Exercise 8.6. For k ≥ 4 and n ≥ 2k, determine whether or not the


circulant Cn (3, k) is planar.

Exercise 8.7. For a, b ∈ N, the a-by-b knight’s move graph KM(a, b) is


defined as follows. The vertex-set is V (KM(a, b)) = {1, 2, ..., a} ×
{1, 2, ..., b}. Two vertices (v1 , v2 ) and (w1 , w2 ) are adjacent if and only
if
(v1 − w1 )2 + (v2 − w2 )2 = 5.
Figure 8.15 is a picture of KM(4, 4).
(a) Show that KM(4, 4) is not a planar graph.
(b) There is a positive integer k such that KM(k, 3) is planar, but
KM(k + 1, 3) is not planar. Determine the value of k and give a
complete explanation.

Exercise 8.8. Give an example of a planar bipartite 3-regular simple


graph with |V | = 14 vertices.
Section 8.5 Planar Graphs. 197

Exercise 8.9. Show that if G is planar and 3-regular then the line-
graph L(G) of G is planar.

Exercise 8.10. Prove that if G is simple and has at least two edges
then every face of every plane embedding of G has degree at least
three (Lemma 8.15).

Exercise 8.11. Give an example of a plane embedding of a simple


graph G such that: every vertex has degree at least three; every face
has degree at least four; G contains a 3-cycle.

Exercise 8.12. Let F be a face of a plane embedding of a multigraph


G = (V, E, B).
(a) Every edge e ∈ E(∂F ) in the boundary of F is contained in at
most one cycle in ∂F .
(b) The boundary of F is an edge-disjoint union of cycles, bridges,
and vertices of degree zero.
(c) If G contains a cycle then ∂F contains a cycle.

Exercise 8.13. Let G = (V, E, B) be a multigraph with a plane embed-


ding (P, Γ).
(a) Show that all faces in F have even degree if and only if G is
bipartite.
(b) Show that all vertices in V have even degree if and only if the
dual graph G∗ is bipartite.

Exercise 8.14. Show that each of the five Platonic solids are unique up
to isomorphism.

Exercise 8.15. Let G = (V, E) be a 3-regular connected simple graph


embedded in the plane, with f4 faces of degree 4 and f7 faces of degree
7, and no faces of any other degree. The cube is an example with
198 Planar Graphs. Section 8.5

f4 = 6 and f7 = 0.
(a) Show that for any such graph there is an a ∈ N such that
f4 = 6 + a and f7 = 2a.
(b) Give an example of such a graph with f7 = 2.
(c) Give an example of such a graph with f7 = 4.
(d)* (Not required.) Give examples of such graphs for all a ∈ N.

Exercise 8.16. Let G = (V, E) be a 4-regular connected graph embed-


ded in the plane, with fd faces of degree d ∈ {3, 4, 6} and no faces
of any other degree. The octahedron is an example with f3 = 8 and
f4 = f6 = 0.
(a) Show that for any such graph, f3 = 8 + 2f6 .
(b) Give an example of such a graph with f3 = 8 and f4 = 6.
(c) Give an example of such a graph with f4 = 0 and f6 = 2.
(d) Show that there is no such graph with f4 = 0 and f6 = 1.
(e) Give an example of such a graph with f6 ≥ 3.
(f)* (Not required.) Give examples of such graphs for as many val-
ues of f6 ∈ N as you can.

Exercise 8.17. Prove Lemma 8.25.

Exercise 8.18. Let G = (V, E, B) be a connected multigraph with a


plane embedding (P, Γ) and dual graph G∗ = (V ∗ , E ∗ , B ∗ ). Let (V, T )
be a spanning tree of G. Show that (V ∗ , {e∗ ∈ E ∗ : e 6∈ T }) is a
spanning tree of G∗ .
Chapter 9

Graph Colouring.

Example 9.1 (The Channel Assignment Problem). A commercial radio


station broadcasts with a power of several tens of kilowatts, and its sig-
nal can be received from a distance of up to several tens of kilometers.
To avoid interference between the signals, if two transmitters are close
enough and powerful enough that they could both be received from the
same location, then they must broadcast at different frequencies. The
range of available frequencies is split into several channels. Radio band-
width is a valuable commodity, so one would like to minimize the total
number of channels that are assigned to the radio stations in a given
region.

The channel assignment problem is a prototypical example of a graph colour-


ing problem. Let the vertices be the radio transmitters. Join two vertices
by an edge if the corresponding transmitters would interfere with one an-
other (if they broadcast at the same frequency). We are motivated to find a
function from vertices to channels such that vertices joined by an edge get
different channels, and the total number of channels is minimized.

9.1 Chromatic Number.

Definition 9.2 (Proper colouring, chromatic number). Let G = (V, E)


be a graph. Let X be a finite set of colours. (Often, X = {1, 2, ..., k} for

199
200 Graph Colouring. Section 9.1

some k ∈ N.)
1. A (proper) X-colouring of G is a function f : V → X such that if
vw ∈ E then f (v) 6= f (w).
2. If |X| = k then such a function f is a (proper) k-colouring of G.
3. The chromatic number χ(G) of G is the smallest natural number
k ∈ N for which G has a (proper) k-colouring.

Example 9.3. In Definition 9.2, we can take X = V for the set of colours,
and then the identity function ι : V → V is a proper |V |-colouring of G.
This shows that the chromatic number exists and that χ(G) ≤ |V |. It is
easy to see that for complete graphs, χ(Kn ) = n. The converse is also
true: if χ(G) = |V (G)|, then G is a complete graph.

Example 9.4. Graphs with small chromatic number are easy to under-
stand.
• The only graph with chromatic number zero is the empty graph.
• A graph has chromatic number one if and only if it has no edges
and at least one vertex.
• A graph has chromatic number two if and only if it is bipartite and
has at least one edge.

Graphs with chromatic number three or more are hard to understand.


Consider the following problem: given a graph G, determine whether or
not χ(G) = 3. Nobody has a good (“polynomial time”) algorithm to solve
this problem. It is known to be what is called an “NP-complete” problem.
Roughly speaking, this means that if there is a good algorithm to solve this
problem then there are good algorithms to solve a huge variety of problems,
all of which are considered to be hard. In short, this is considered to be a
hard problem.
The inequality of Example 9.3 is terrible, and can easily be improved.

Proposition 9.5. Let G be a graph and let dmax (G) be the maximum degree
of a vertex in G. Then χ(G) ≤ 1 + dmax (G).

Proof. Let k = 1 + dmax (G) and X = {1, 2, ..., k}. We construct a proper k-
Section 9.2 Graph Colouring. 201

colouring f : V → X of G as follows. List the vertices of G as v1 , v2 , ..., vn in


any order. Define f (vi ) = i for all 1 ≤ i ≤ k. There are no edges violating
the condition of being a proper colouring at this stage. Now, inductively,
assume that we have properly coloured vertices v1 , ..., vj−1 for some 2 ≤ j ≤
n. The degree of vj is at most k − 1, so vj has at most k − 1 neighbours among
the previously coloured vertices v1 , ..., vj−1 . Thus, at most k − 1 colours
are used on these previously coloured neighbours of vj . Since there are k
colours available, there is a colour we can choose for f (vj ) so that no edge
gets the same colour at both ends. Now we have properly coloured the
vertices v1 , ..., vj . By induction, we arrive at a proper k-colouring of G.

Example 9.6. Consider the infinite graph with vertex-set R2 , with an


edge between two vertices if and only if the distance between the two
points is exactly one. Figure 9.1 shows a 7-colouring of this graph. (The
colours on the boundaries of the hexagons can be defined in a way to
make this work.) If the distance between the centers of adjacent hexagons

is λ, then the lengths of the edges is λ/ 3, and the diameter of the

hexagons is 2λ/ 3. Look at the hexagons of any one of the seven colours.
The distance between corners ofp different hexagons of the same colour
√ iπ/3
is at least (λ/ 3)|2 + e | = λp 7/3. So there will be no monochro-

matic edges if 2λ/ 3p< 1 and λ p 7/3 > 1. So if Figure 9.1 is scaled by
any factor 0.6546 ≈ 3/7 < λ < 3/4 ≈ 0.8660 then it gives a proper
7-colouring of R2 .
Also shown: the graph of Figure 9.2 to appropriate scale, a random
walk in the unit distance graph of R2 , and an embedding of the complete
graph K7 on the torus.

Example 9.7 (The Hadwiger-Nelson Problem).


What is the chromatic number of the unit distance graph of R2 ?
Example 9.6 shows that it is at most seven, and the graph of Figure 9.2
shows that it is at least four – this has been known since 1950. In 2018,
de Grey – an amateur mathematician – constructed an example with
chromatic number five. His first example had more than 20,000 vertices
– this has since been reduced to around 850. Quanta magazine published
a nice non-technical article about this.
202 Graph Colouring. Section 9.2

2 1
3 0 6
4 5

Figure 9.1: A 7-colouring of the unit-distance graph of R2 .

Figure 9.2: A 4-chromatic unit distance graph.


Section 9.2 Graph Colouring. 203

9.2 Colouring Planar Graphs.

9.2.1 The Four Colour Theorem.

In 1852, an engineer named Guthrie was looking at a map of England, and


noticed that he could colour the counties in such a way that those which
shared a border had different colours, and that he could do this using only
four colours. He wondered whether this was possible for any map drawn
on the plane (or sphere). This became the Four Colour Conjecture or Four
Colour Problem, and has motivated a huge amount of graph theory and
combinatorics since then. It was finally solved in 1976 by Appel and Haken,
with a then-controversial computer-aided proof.

Theorem 9.8 (The Four Colour Theorem). Every planar graph can be
properly coloured with at most four colours.

Notice that Guthrie was thinking of colouring the faces of an embedded


plane graph in such a way as to give a proper colouring of the dual graph
of the embedding. Since every connected planar graph is the dual of some
embedded plane graph, the problems of colouring vertices or of colouring
faces are equivalent.
Here is a link to an amusing puzzle based on the Four Colour Theorem.
Even the shortest proofs of the Four Colour Theorem still involve a long
computer-aided case analysis. But we can do fairly well with a little bit of
effort.

9.2.2 The Five Colour Theorem.

As an easy warm-up exercise, we can colour planar graphs with at most six
colours.

Proposition 9.9 (The Six Colour Theorem). Every planar graph can be
properly coloured with at most six colours.
204 Graph Colouring. Section 9.2

Proof. Let G = (V, E) be a planar graph. We prove the result by induction


on |V | = n, the basis n ≤ 6 being evident. Assume that n ≥ 7. By Corollary
8.17, G has a vertex v of degree at most five. Since G r v is planar, by
induction we have a proper 6-colouring f : V (G r v) → {1, 2, ..., 6} of G r
v. At most five colours are used by f on the neighbours of v, so at least
one colour is available to use for f (v) without producing edges with the
same colour at both ends. So G has a proper 6-colouring, completing the
induction step, and the proof.

The idea behind the proof of the Six Colour Theorem is good – perhaps
with a little more care in the induction step we can reduce the number of
colours required. In 1879, Kempe thought he had solved the Four Colour
Problem along these lines. In 1890, Heawood found a flaw in Kempe’s ar-
gument – but he also saw that it worked for five colours.

Theorem 9.10 (The Five Colour Theorem). Every planar graph can be
properly coloured with at most five colours.

Proof. Let G = (V, E) be a planar graph. We prove the result by induction


on |V | = n, the basis n ≤ 5 being evident. Assume that n ≥ 6. By Corollary
8.17, G has a vertex v of degree at most five. Since G r v is planar, by
induction we have a proper 5-colouring f : V (G r v) → {1, 2, ..., 5} of G r v.
If at most four colours are used by f on the neighbours of v, then at least
one colour is available to use for f (v) without producing edges with the
same colour at both ends. In this case G has a proper 5-colouring, as desired.
In the remaining case, f uses all five colours on the neighbours of v. In
particular, v has degree five.
Now embed G in the plane, with the neighbours of v labelled w1 , w2 , ..., w5
in cyclic order around v. We may permute the colours to assume that f :
V r {v} → {1, 2, ..., 5} is such that f (wi ) = i for all 1 ≤ i ≤ 5. The idea is
to adjust the 5-colouring f so as to produce another 5-colouring which uses
only four colours on the neighbours of v. Then the previous argument can
be applied to finish the induction step.
For i ∈ {1, 2, ..., 5}, let Vi be the set of vertices z ∈ V such that f (z) = i.
For 1 ≤ i < j ≤ 5, let Gij be the subgraph of G r v induced by Vi ∪ Vj . Let
H be a connected component of Gij . Define a new 5-colouring g of G r v
Section 9.2 Graph Colouring. 205

Figure 9.3: Proof of the Five Colour Theorem.

as follows. Consider any z ∈ V (G r v): if z 6∈ V (H) then let g(z) = f (z);


if z ∈ V (H) then let g(z) = i if z ∈ Vj , and let g(z) = j if z ∈ Vi . Notice
that this g is also a proper 5-colouring of G r v. We refer to this operation as
“flipping f along H”.
Now consider the subgraph G13 of G r v, and the component H of G13
that contains w1 . If w3 is not in H then consider the result g of flipping f
along H. This is a proper 5-colouring of G r v such that g(w1 ) = g(w3 ) = 3.
Thus, g uses only four colours on the neighbours of v, and we have reduced
the problem to a previously solved case. In the remaining case, there is a
path P in G13 from w1 to w3 .
Next, consider the subgraph G24 of G r v, and the component H of G24
that contains w2 . If w4 is not in H then consider the result g of flipping f
along H. This is a proper 5-colouring of G r v such that g(w2 ) = g(w4 ) = 4.
Thus, g uses only four colours on the neighbours of v, and we have reduced
the problem to a previously solved case. In the remaining case, there is a
path Q in G24 from w2 to w4 .
Now, in the embedding of G, the footprint of the cycle (v w1 P w3 v) is
206 Graph Colouring. Section 9.3

a simple closed curve in R2 that separates the points representing w2 and


w4 . Therefore, the footprints of the paths P and Q have a point in common.
(See Figure 9.3.) Since G is embedded properly, this common point must
represent a common vertex z ∈ V (P ) ∩ V (Q). But V (G13 ) ∩ V (G24 ) = ∅,
by the way these subgraphs are defined. This contradiction shows that the
paths P and Q cannot both exist. This completes the induction step, and the
proof.

9.3 Chromatic Number versus Girth.

A large chromatic number seems to require a graph to have highly com-


plicated connections among its vertices. Large girth seems to require very
sparse connections. One might expect some tension between these prop-
erties – that is the case, but somewhat surprisingly there are graphs with
arbitrarily large girth and chromatic number at the same time.

Theorem 9.11 (Erdo ”s, 1959). For all k ≥ 2 and g ≥ 3, there is a graph
with girth at least g and chromatic number at least k.

You might see a proof of Theorem 9.11 in a fourth-year course on graph


theory. We will find graphs of girth four and any chromatic number.

Definition 9.12. . Let G = (V, E) be a graph. Let V 0 = {v 0 : v ∈ V }


be a set disjoint from V , let z be another vertex not in V ∪ V 0 , and let
M(G) be the graph with vertices V (M(G)) = V ∪ V 0 ∪ {z}and edges
E(M(G)) = E(G) ∪ {zv 0 : v ∈ V } ∪ {v 0 w : v ∈ V and vw ∈ E}.
This is called the Mycielski construction.

Lemma 9.13. If G has girth at least four then M(G) has girth at least four.

Proof. Exercise 9.7.

Proposition 9.14. For any graph G, χ(M(G)) = 1 + χ(G).


Section 9.4 Graph Colouring. 207

Figure 9.4: The Mycielski construction M(C11 ).

Proof. Exercise 9.8.

Corollary 9.15. For every k ≥ 2 there exists a k-chromatic graph of girth


four.

Proof. Examples for k = 2 and k = 3 are easily found. By Lemma 9.13 and
Proposition 9.14, the sequence

M(C5 ), M(M(C5 )), M(M(M(C5 ))), ...

settles the remaining cases.

9.4 Exercises.

Exercise 9.1. Let G be a graph for which χ(G) = |V (G)|. Prove that G
is a complete graph.

Exercise 9.2. Prove that if G is a self-complementary graph then


χ(G) ≥ |V (G)|1/2 .
Exercise 9.3. Fix a natural number k ∈ N. A graph G = (V, E)
is k-degenerate if its vertices can be listed v1 , ..., vn with the follow-
ing property: for all 1 ≤ j ≤ n, the vertex vj has at most k neighbours
among v1 , ..., vj−1 .
(a) If G is k-degenerate then χ(G) ≤ 1 + k.
(b) If G is planar then G is 5-degenerate.
(c) If G is planar and has no 3-cycles then G is 3-degenerate.

Exercise 9.4. Show that a graph with 2k ≥ 2 vertices and k 2 + 1 edges


is not 2-colourable.

Exercise 9.5. Show that a planar graph with n ≥ 3 vertices and m =


2n − 3 edges is not 2-colourable.

Exercise 9.6. Let G be a 3-regular planar graph with its edges parti-
tioned into three perfect matchings (see Example 10.3). Show that the
dual of any plane embedding of G is 4-colourable.

Exercise 9.7. Prove Lemma 9.13

Exercise 9.8.
(a) Show that the chromatic number of M(C5 ) is 4.
(b) Show that if G is k-colourable then M(G) is (k + 1)-colourable.
(c) Show that if M(G) is k-colourable then M(G) has a k-colouring
f : V (M(G)) → {1, 2, ..., k} such that f −1 (k) = {z}. (That is, z is
the only vertex of M(G) at which f takes the value k.)
(d) Prove Proposition 9.14.
Chapter 10

Bipartite Matching.

Example 10.1 (The Job Assignment Problem). Shawn has contracts to


renovate some residential properties in Kitchener. Each property needs
at least one of several types of jobs done: carpentry, plumbing, electri-
cal, drywall, painting, et cetera. Shawn is on good terms with several
work teams in the region. Not every team is proficient at each kind of
job. Shawn would like to assign jobs to teams so that as many teams
as possible are working, and all are working on jobs they are good at.
Each team can only work on one job. Each job can only be assigned to
one team. Is there a method to solve this kind of problem? In particular,
is the assignment of jobs to teams in the graph of Figure 10.1 as good
as possible? (Work teams are denoted by letters, jobs are denoted by
numbers, and the edge A1 means that team A is qualified to do job 1.)

A B C D E F G H J

1 2 3 4 5 6 7 8 9 10

Figure 10.1: An instance of the job assignment problem

209
210 Bipartite Matching. Section 10.1

10.1 Matchings and Covers.

Definition 10.2 (Matchings). Let G = (V, E) be a graph.


1. A matching in G is a subset M ⊆ E of edges such that in the
spanning subgraph (V, M ), every vertex has degree at most one.
2. A vertex is M -saturated if it has degree one in (V, M ), and is M -
unsaturated if it has degree zero in (V, M ).
3. A matching M is maximum if |M | is as big as possible among all
matchings of G.

Example 10.3 (The Game of Slither). The game of Slither can be played
on any graph; for concreteness, imagine a grid like P5  P5 . There are
two players who take alternate turns – the last player to be able to move
wins. The first player chooses any edge of G to form a path with two
vertices. Next, the second player chooses an edge to extend this path (at
either end) if possible, or else loses. The chosen subgraph must remain a
path. Next, play returns to the first player, who must also either extend
the path or lose, and so it continues.
A matching M is perfect if every vertex of G is saturated. In Exercise
10.4, you are asked to show that if G has a perfect matching then the first
player has a winning strategy for Slither.

Definition 10.4 (Alternating Paths, Augmenting Paths). Let G = (V, E)


be a graph, and let M be a matching in G.
1. A path P = (v0 v1 ... vk ) in G is M -alternating when:
for all 1 ≤ i ≤ k − 1, vi−1 vi ∈ M if and only if vi vi+1 6∈ M .
2. A path in G is M -augmenting if it is M -alternating, has at least
one edge, and both its ends are M -unsaturated.

Informally, a path is M -alternating when “every second edge is in M ”.

Example 10.5. If G has an M -alternating path P then we can find another


matching, as follows. We “flip” the edges on the path P : those that were
in M come out, and those that were not in M go in. This is the symmetric
Section 10.1 Bipartite Matching. 211

difference of sets M 0 = M 4E(P ). Since M is a matching and P is an M -


alternating path, it follows that M 0 is also a matching. Notice that if P is
an M -augmenting path then |M 0 | = 1 + |M |.
For example, (B 2 A 6 J 9) is an augmenting path for the matching in
Figure 10.1, so that matching can be improved.

Proposition 10.6. Let G = (V, E) be a graph and M ⊆ E a matching in G.


Then M is a maximum matching if and only if there are no M -augmenting
paths.

Proof. One direction follows directly from Example 10.5: if M has an aug-
menting path P then M 0 = M 4E(P ) is a matching in G that is strictly
bigger than M . Thus, if M is a maximum matching then there are no M -
augmenting paths.
Conversely, assume that M is not a maximum matching. There is a max-
imum matching M f of G, and |M | < |M
f|. Now consider the spanning sub-
graph H = (V, M ∪ M f) of G. Since H is the union of two matchings, every
vertex has degree at most two. So every connected component of H is either
a path or a cycle. Moreover, each path component is both M -alternating and
f-alternating, and each cycle component has edges alternating between M
M
and Mf as well. In particular, each cycle component has the same number
of edges in M as in M f. Now, since |M f| > |M |, there must be some com-
ponent of H with more edges in M f than in M . By the above, this is an
M -augmenting path.

We next come to a concept which is dual to the idea of a matching. It will


be useful for characterizing maximum matchings in bipartite graphs.

Definition 10.7 (Covers). Let G = (V, E) be a graph.


1. A cover in G is a subset C ⊆ V of vertices such that every edge
has at least one end in C: for all e ∈ E, e ∩ C 6= ∅.
2. A cover C in G is minimum if |C| is as small as possible among
all covers of G.
212 Bipartite Matching. Section 10.2

Proposition 10.8. Let G = (V, E) be a graph, let M ⊆ E be a matching in


G, and let C ⊆ V be a cover in G.
(a) Then |M | ≤ |C|.
(b) If |M | = |C| then M is maximum and C is minimum.

Proof. Let X be the set of pairs (v, e) in C × M for which v ∈ e. Since M is a


matching it follows that
X X X
|X| = 1= degM (v) ≤ 1 = |C|.
(v,e)∈X v∈C v∈C

Since C is a cover it follows that


X X X
|X| = 1= |e ∩ C| ≥ 1 = |M |.
(v,e)∈X e∈M e∈M

This proves (a). For part (b), let matching M and cover C satisfy |M | = |C|.
If M 0 is any other matching then, by part (a), |M 0 | ≤ |C| = |M |. Thus, M is
a maximum matching. The proof that C is a minimum cover is similar.

Example 10.9. Notice that for an odd cycle C2k+1 , a maximum matching
has k edges and a minimum cover has k + 1 vertices. So there can be
a gap between the two sides in the inequality of Proposition 10.8. Tak-
ing a disjoint union of many odd cycles, one sees that this gap can be
arbitrarily large. It is interesting to try to find connected examples with
arbitrarily large “gap” min |C| − max |M |. (See Exercise 10.6.)

10.2 König’s Theorem.

In Shawn’s job assignment problem (Example 10.1) the underlying graph


was bipartite – does that help? It turns out that – yes – it does help. König’s
Theorem states that for bipartite graphs there is no “gap” as in Example
10.9.
Section 10.2 Bipartite Matching. 213

Theorem 10.10 (König’s Theorem, 1931). Let G = (V, E) be a graph with


a bipartition (A, B). Let M ⊆ E be a maximum matching and let C ⊆ V
be a minimum cover in G. Then |M | = |C|.

We prove this after a close look at a matching in a bipartite graph.

10.2.1 Anatomy of a bipartite matching.

The key step is to examine the relations between matchings and alternating
paths.

Definition 10.11. Let G = (V, E) be a graph with a bipartition (A, B).


Let M ⊆ E be a matching in G.
1. Let X0 be the set of M -unsaturated vertices in A.
2. Let Z be the set of vertices in V that are reachable from a vertex
in X0 by an M -alternating path.
3. Let X = Z ∩ A and Y = Z ∩ B.

Proposition 10.12. Let G = (V, E) be a graph with a bipartition (A, B).


Let M ⊆ E be a matching in G. Define the subsets X and Y as in Definition
10.11.
(a) If y ∈ Y is unsaturated then G has an M -augmenting path.
(b) There are no edges of G between X and B r Y .
(c) There are no edges of M between Y and A r X.

Proof. For part (a), let P = (v0 v1 ... vk ) be an M -alternating path with v0 ∈ X0
and vk = y ∈ Y . If y is M -unsaturated then P is an M -augmenting path.
For part (b), suppose that e = xb ∈ E is an edge with x ∈ X and b ∈
B r Y . Then there is an M -alternating path (v0 v1 ... vk ) with v0 ∈ X0 and
vk = x ∈ A. since v0 ∈ A and vk ∈ A and G is bipartite, it follows that k
is even. Now, since v0 is M -unsaturated and the path is M -alternating and
k is even, it follows that vk−1 vk ∈ M is a matching edge. Thus, vk b 6∈ M is
not a matching edge. But now (v0 v1 ... vk b) is an M -alternating path, so that
b ∈ Y , a contradiction.
214 Bipartite Matching. Section 10.2

Figure 10.2: A matching in a bipartite graph.

For part (c), suppose that e = ay ∈ M is a matching edge with a ∈ A r X


and y ∈ Y . As in part (b), there is an M -alternating path (v0 v1 ... vk ) with
v0 ∈ X0 and vk = y ∈ B. Also as in part (b) by parity and bipartiteness,
vk−1 vk 6∈ M is not a matching edge. Since ay ∈ M it follows that (v0 v1 ... vk a)
is an M -alternating path, so that a ∈ X, a contradiction.

Proof of König’s Theorem. Let M be a maximum matching in a graph G =


(V, E) with bipartition (A, B). Construct the sets X0 , X, and Y as in Defini-
tion 10.11. Since M is a maximum matching, Propositions 10.6 and 10.12(a)
imply that every vertex in Y is M -saturated. By Proposition 10.12(c), the
edges of M saturating Y provide a bijection between the sets Y and X r X0 .
By Proposition 10.12(b), the set C = Y ∪ (A r X) is a cover of G. Finally,
|C| = |Y | + |A r X| = |X r X0 | + |A r X| = |A r X0 | = |M |,
so that C is a cover of G of the same size as M .

Example 10.13. Let m, dmax ≥ 1 be integers. Let G = (V, E) be a bipartite


graph with m edges, in which every vertex has degree at most dmax . Then
G has a matching with at least m/dmax edges. To see this, consider a
maximum matching M of G. By König’s Theorem, G has a (minimum)
cover C of the same size: |M | = |C|. Each vertex is incident with at most
Section 10.2 Bipartite Matching. 215

dmax edges, so that C is incident with at most dmax |C| edges. Since C is a
cover, we conclude that m = |E(G)| ≤ dmax |C| = dmax |M |, from which
the result follows.

10.2.2 A bipartite matching algorithm.

The proof of Theorem 10.10 can be adapted to provide an algorithm for


finding a maximum matching in a bipartite graph. We first describe a “sub-
routine” which certifies whether or not a given matching is maximum, and
then include this in the main algorithm. This description is slightly ab-
stract, requiring you to think abut how to implement it in your favourite
computer language. While constructing the sets X and Y of Definition
10.11, Algorithm 10.14 also constructs a (partially defined) “parent func-
tion” pr : V → V ∪ {null} for reasons which will become clear.

Algorithm 10.14 (The “XY-algorithm”).


Input: a graph G = (V, E) with bipartition (A, B) and matching M ⊆ E;
let U be the set of M -unsaturated vertices in A;
for each x ∈ U , let pr(x) := null;
let X := U ; let Y := ∅;
let flag := cover;
while U 6= ∅ do:
{ let U 0 := ∅;
for b ∈ B r Y do:
{ if N (b) ∩ U 6= ∅ then
{ choose any x ∈ N (b) ∩ U ;
let Y := Y ∪ {b}; let pr(b) := x;
if b is M -unsaturated then { let flag := path; let y := b; break; }
else { let ba ∈ M ; let U 0 = U 0 ∪ {a}; let pr(a) := b; }
}
}
let X := X ∪ U ; let U := U 0 ;
}
if flag = cover then Output (cover, Y ∪ (A r X));
else
{ let σ := y;
216 Bipartite Matching. Section 10.2

while pr(y) 6= null do: { let y := pr(y); let σ := σ y; }


Output (path, (σ)).
}

Informally, Algorithm 10.14 does the following. The first five lines ini-
tialize the data. The “do while” loop starting on line six grows the sets X
and Y in stages, starting from the initial set of M -unsaturated vertices in
A. At each stage, the set U is the set of vertices in X which have just been
added, and U 0 is the set of vertices which will be added to X in the next
stage. When U 0 = ∅, no new vertices will be added to X, and the loop ends.
Inside the loop, if the break command is executed then the algorithm jumps
out of the loop immediately. After this loop is the output section: the value
of flag indicates whether the output is a cover or an M -augmenting path.
(The last “do while” loop produces the M -augmenting path from the vertex
y and the parent function.)

Example 10.15. We apply Algorithm 10.14 to the graph and matching in


Example 10.1. When we add a vertex v to Y or U , the notation v → w
means that pr(v) = w.

U Y U0
b, h 2 → b, 4 → b, 5 → h, 8 → h a → 2, d → 4, e → 5, g → 8
a, d, e, g 1 → a, 3 → a break c→1

Output: (path, (3 a 2 b)).

Algorithm 10.16 (Maximum bipartite matching).


Input: a graph G = (V, E) with bipartition (A, B);
let M := ∅; let flag := path;
while flag = path do:
{ apply Algorithm 10.14 to G and M to get output (flag, Q);
if flag = path then let M := M 4E(Q);
}
Output: (M, Q).
Section 10.3 Bipartite Matching. 217

Proposition 10.17. Let G = (V, E) be a graph with bipartition (A, B). Let
(M, Q) be the output when Algorithm 10.16 is applied to the input G. Then
M is a maximum matching and Q is a minimum cover of G.

Proof. Exercise 10.9

10.3 Hall’s Theorem.

Shawn is especially interested in the cases when all the work teams can be
assigned jobs. For instance, after a close look at the graph in Figure 10.1
one sees that the five teams {B , D , E , G , H} are among themselves only
qualified to do the four jobs {2, 4, 5, 8}. So there is no way to get all the
teams working on jobs they are qualified for. Hall’s Theorem 10.18 states
that obvious “bottlenecks” like this are the only problems which could arise.
Let G = (V, E) be a graph. For S ⊆ V , let the neighbourhood of S be

N (S) = {v ∈ V : vw ∈ E for some w ∈ S}.

Also, a matching M is S-saturating when every vertex of S is M -saturated.


Thus, a matching is perfect if and only if it is V -saturating.

Theorem 10.18 (Hall’s Theorem, 1935). Let G = (V, E) be a graph with


a bipartition (A, B). Then G has an A-saturating matching if and only if for
all S ⊆ A, |N (S)| ≥ |S|.

Proof. First, we see that the condition is necessary. Let M be an A-saturating


matching of G. For any subset S ⊆ A, since M saturates S, the edges of M
incident with vertices in S provide an injective function from S to N (S), so
that |S| ≤ |N (S)|. Conversely, assume that G does not have an A-saturating
matching. Let M be a maximum matching of G, and notice that |M | < |A|.
By König’s Theorem 10.10, there is a cover C of G of the same size as M ; that
is, |C| = |M |. Now consider the subset S = A r C of A. Since C is a cover,
there are no edges between A r C and B r C. Therefore, N (S) ⊆ B ∩ C.
218 Bipartite Matching. Section 10.4

Now

|S| = |A r C| = |A| − |A ∩ C| = |A| − |C r B|


= |A| − (|C| − |B ∩ C|) > |B ∩ C| ≥ N (S).

This completes the proof.

Corollary 10.19. Let G = (V, E) be a k-regular bipartite graph. Then the


edges of G can be partitioned into k pairwise disjoint perfect matchings.

Proof. Let G have bipartition (A, B). The case k = 0 is trivial, and the case
k = 1 is when G is itself a matching. We continue by induction on k. By
Exercise 5.5, |A| = |B|, so that a matching in G is perfect if and only if it is
A-saturating. For the induction step, we first find an A-saturating matching
in G. To do this we verify Hall’s Condition. Consider any subset S ⊆ A.
Recall the boundary ∂S of S, and notice that ∂S ⊆ ∂N (S). Now

k · |S| = |∂S| ≤ |∂N (S)| = k · |N (S)|.

Since k ≥ 1 it follows that |S| ≤ |N (S)|. By Hall’s Theorem 10.18, there is


an A-saturating matching M in G. Now G r M is a (k − 1)-regular bipartite
graph, and we invoke the induction hypothesis to complete the proof.

Example 10.20. The Petersen graph has exactly six perfect matchings.
Any two perfect matchings of the Petersen graph have exactly one edge
in common. In particular, it is not possible to partition the edges of the
Petersen graph into three pairwise disjoint perfect matchings.

10.4 Exercises.

Exercise 10.1.
(a) Show that a tree has at most one perfect matching.
(b) For which values of r, s ∈ N does the grid Pr  Ps have a perfect
matching?
Section 10.4 Bipartite Matching. 219

Exercise 10.2.
(a) For each n ∈ N, how many perfect matchings are there in Kn ?
(b) For each r, s ∈ N, how many perfect matchings are there in Kr,s ?

Exercise 10.3.
(a) Let G be a graph with a bipartition (A, B) and a Hamilton cycle.
Let a ∈ A and b ∈ B. Show that Gr{a, b} has a perfect matching.
(b) Show that if two squares of opposite colours are removed from
a (standard 8-by-8) chessboard, then the remaining squares can
be covered usng 31 dominoes

Exercise 10.4. In the game of Slither (Example 10.3), show that if the
graph G has a perfect matching then the first player can always win.

Exercise 10.5. Show that C is a cover in a graph G if and only if V r C


induces an edgeless subgraph of G.

Exercise 10.6. Define the “gap” of a graph to be the minimum size of


a cover minus the maximum size of a matching. (See Example 10.9.)
(a) For each k ∈ N, find a connected graph with gap k.
(b) For each k ∈ N, find a connected graph with gap k and with no
bridges.

Exercise 10.7. Let G be a graph with bipartiton (A, B), and let C and
C 0 be covers in G.
(a) Show that Cb = ((C ∩ C 0 ) ∩ A) ∪ ((C ∪ C 0 ) ∩ B) is also a cover.
(b) Show that if C and C 0 are minimum covers in G then C b is also a
minimum cover.
220 Bipartite Matching. Section 10.4

Figure 10.3: Graph for Exercise 10.8(a).

Figure 10.4: Graph for Exercise 10.8(b).

Figure 10.5: Graph for Exercise 10.8(c).


Section 10.4 Bipartite Matching. 221

Exercise 10.8. For each part, find a maximum matching and a mini-
mum cover in the pictured graph, by repeated application of the XY-
algorithm beginning with the indicated matching.
(a) Figure 10.3.
(b) Figure 10.4.
(c) Figure 10.5.

Exercise 10.9. Prove Proposition 10.17.

Exercise 10.10. Find graph with the following properties: it has 16


edges; it has a bipartition (A, B) with |A| = |B| = 5; every vertex has
degree at least 2; it does not have a perfect matching. Explain why
your example does not have a perfect matching.

Exercise 10.11. Let G be a graph with bipartition (A, B). Assume that
there are no vertices of degree zero in A. Also assume that for every
edge ab ∈ E, with a ∈ A and b ∈ B, we have deg(a) ≥ deg(b). Show
that G has an A-saturating matching.

Exercise 10.12. Let G = (V, E) be a graph with bipartition (A, B).


Assume that for every proper subset ∅ 6= S ( A of A, we have
|N (S)| > |S|. Let e ∈ E be any edge. Show that G has an A-saturating
matching that contains e.

Exercise 10.13. (This is difficult.) Let m, k, dmin ≥ 1 be integers. Let


G be a graph with m edges, with a bipartition (A, B) such that |A| =
|B| = k, and such that every vertex has degree at least dmin . Assume
that k > dmin . Show that G has a matching of size at least the mini-
mum of k and (m − d2min )/(k − dmin ).
Exercise 10.14.
(a) Show that König’s Theorem 10.10 and Hall’s Theorem 10.18 and
Corollary 10.19 are also valid more generally for multigraphs in
place of graphs.
(b) Deal the 52 cards of a standard deck into an array with 4 rows
and 13 columns. Show that it is possible to rearrange the four
cards within each column in such a way that each of the four
rows contains a card of each rank: 2, 3, ..., Q, K, A.

Exercise 10.15. Let G = (V, E) be a graph and v ∈ V a vertex. A


splitting of G at v is any graph H obtained as follows. Let S1 , S2 be
nonempty subsets of N (v) such that S1 ∩ S2 = ∅ and S1 ∪ S2 = N (v).
Let z1 , z2 be new vertices not in V . Then

V (H) = (V ∪ {z1 , z2 }) r {v}

and

E(H) = E(G r v) ∪ {z1 w : w ∈ S1 } ∪ {z2 w : w ∈ S2 }.

(a) Let d be a positive integer such that d divides the degree of every
vertex of G. Prove that one can obtain a d-regular graph starting
from G by repeatedly splitting vertices.
(b) A graph G = (V, E) with bipartition (A, B) is (k, `)-biregular
when every vertex in A has degree k and every vertex in B has
degree `. Let m, a, b ≥ 1 be integers, and let G be a (ma, mb)-
biregular bipartite graph. Prove that G contains an (a, b)-biregular
spanning subgraph.

Exercise 10.16. Prove the claims in Example 10.20.

Exercise 10.17. Fix k ∈ N. Let G = (V, E) be a graph with |V | = 2k


vertices, in which each vertex has degree at least k. Show that G has
a perfect matching. [Hint: show that any matching that is not perfect
has an augmenting path of length 1 or 3.]

You might also like