Introduction To Combinatorics, Course Notes PDF
Introduction To Combinatorics, Course Notes PDF
1 Combinatorial Analysis 1
1.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Sums and Products . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.3 Binomial Coefficients . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.4 Bijections (One-to-One Correspondence) . . . . . . . . . . . . . . . 4
1.5 Combinatorial Proofs . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.6 Generating Series . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
1.7 Formal Power Series . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
1.8 The Sum and Product Lemmas . . . . . . . . . . . . . . . . . . . . . 24
iii
iv CONTENTS
5 Trees 125
5.1 Trees . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
5.2 Spanning Trees . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
5.3 Characterizing Bipartite Graphs . . . . . . . . . . . . . . . . . . . . 130
5.4 Breadth-First Search . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
5.5 Applications of Breadth-First Search . . . . . . . . . . . . . . . . . . 139
5.6 Minimum Spanning Tree . . . . . . . . . . . . . . . . . . . . . . . . 140
6 Codes 145
6.1 Vector Spaces and Fundamental Cycles . . . . . . . . . . . . . . . . 145
6.2 Graphical Codes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
8 Matchings 185
8.1 Matching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
8.2 Covers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
8.3 König’s Theorem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
8.4 Applications of König’s Theorem . . . . . . . . . . . . . . . . . . . . 197
8.5 Systems of Distinct Representatives . . . . . . . . . . . . . . . . . . 198
8.6 Perfect Matchings in Bipartite Graphs . . . . . . . . . . . . . . . . . 200
8.7 Edge-colouring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202
8.8 An Application to Timetabling . . . . . . . . . . . . . . . . . . . . . 204
vi CONTENTS
Chapter 1
Combinatorial Analysis
1.1 Introduction
Our goal in the first half of this course is to learn how to solve a number of
interesting counting problems.
We offer some examples. A composition of a non-negative integer n is a
sequence (m 1 , . . . , m r ) of positive integers such that
m 1 + · · · + m r = n.
The numbers m 1 , . . . , m r are the parts of the composition. We define the weight
of a composition to be the sum of its parts. For example, the number of different
ways we can cut a piece of string of length n centimetres into pieces of length 1
and 2 cm is the number of compositions with weight n where all parts are equal
to 1 or 2. (We will often use weight where the word “size” would do, because
sometimes there is more than one way of defining size.)
Other questions we might ask about compositions include
(a) How many different compositions of n are there?
(c) How many compositions of n are there where all parts of the composition
are odd?
A second important class of counting problems involves binary strings. A
binary string of length n is a sequence a 1 · · · a n where each a i is 0 or 1. Clearly
there are 2n binary strings of length n (so that’s solved). But there are other
questions:
1
2 CHAPTER 1. COMBINATORIAL ANALYSIS
(a) How many binary strings of length n are there that do not contain an odd
string of 0’s as a maximal substring? (So 1001 is OK, but 10001 is not.)
(b) How many binary strings of length n are there that do not contain 0101 as
a substring?
(c) How many binary strings of length n are there that contain exactly k 1’s?
A ∪ B := {x : x ∈ A or x ∈ B }.
|A ∪ B | = |A| + |B |.
A = {1, 2, 3, 4, 5, 6}
(a 1 , . . . , a n ), a i ∈ {0, 1}.
1.3. BINOMIAL COEFFICIENTS 3
|L | = n(n − 1) · · · (n − k + 1).
|L | = x(k!).
Hence
n(n − 1) · · · (n − k + 1)
x= ,
k!
as required.
We define nk , which we read as “n choose k”, to be the number of k-element
¡ ¢
product of zero numbers to be one; for example, 52 = 5·5 = 25, 5¡1 = 5 and 50 = 1,
n¢
the product of zero 5’s, is 1. With this interpretation, 0! = 1 and 0 = 1.
The numerical values of the binomial coefficients form a structure known
as Pascal’s triangle. A few rows of the Pascal’s triangle are given here.
4 CHAPTER 1. COMBINATORIAL ANALYSIS
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
At first this seems surprising, but it follows easily from the definitions. Indeed,
the number of ways of selecting k elements from an n–element set is the same
as the number of ways of discarding (n − k) elements from the set. We can for-
malize this relation using a bijection, which is described in the next section.
f f f
a
1 1 1 a
a
b
2 2 2 b
c b
3 3 3 c
d
S T S T S T
The functions that you have seen in high school or calculus are typically
defined for f : R → R. For example, f (x) = e x is 1-1, but not onto; f (x) = x 3 − x
is onto, but not 1-1; and f (x) = 2x + 1 is both 1-1 and onto, hence a bijection.
In combinatorics, we use mappings to compare the cardinalities of finite
sets S and T . If there exists a mapping f : S → T that is 1-1, then |S| ≤ |T |. This
is because the |S| elements of S must be mapped to distinct elements in T , so
there must be at least |S| distinct elements in T . On the other hand, if there
exists a mapping f : S → T that is onto, then |S| ≥ |T |. This is because for the |T |
elements in T , each must be mapped to by a distinct element in S. Therefore, if
there exists a bijection f : S → T , then |S| = |T |, as f is both 1-1 and onto.
In addition to showing that two sets have equal size, bijections have the nice
property that they “pair up” elements of S with elements of T exactly. This gives
a correspondence between elements of S and T .
We can prove that a function is a bijection by going through the definition
of 1-1 and onto. Alternatively, we could show that the mapping is “reversible”,
that is, there exists an inverse function. For f : S → T , the inverse (if it exists) of
f is a function f −1 : T → S such that for all x ∈ S, f −1 ( f (x)) = x, and for all y ∈ T ,
f ( f −1 (y)) = y.
Usually if a bijection is clear, its inverse is also clear. So in most cases, in-
stead of proving that a function is 1-1 and onto (which can be tedious), we can
simply provide the inverse function.
Problem 1.4.2. For some 0 ≤ k ≤ n, let S be the set of k-subsets of {1, . . . , n}, and
let T be the set of (n − k)-subsets of {1, . . . , n}. Find a bijection between S and T .
f : S → T, f (A) = {1, . . . , n} \ A ∀ A ∈ S.
S T
{1, 2} ←→ {3, 4, 5}
{1, 3} ←→ {2, 4, 5}
{1, 4} ←→ {1, 3, 5}
{1, 5} ←→ {2, 3, 4}
{2, 3} ←→ {1, 4, 5}
{2, 4} ←→ {1, 3, 5}
{2, 5} ←→ {1, 3, 4}
{3, 4} ←→ {1, 2, 5}
{3, 5} ←→ {1, 2, 4}
{4, 5} ←→ {1, 2, 3}
Problem 1.4.3. Let S be the set of all subsets of {1, . . . , n}, and let T be the set of
all binary strings of length n. Find a bijection between S and T .
½
0 i 6∈ A
ai =
1 i∈A
f −1 (t ) = {i ∈ {1, . . . , n} | b i = 1}.
S T
; ←→ 000
{1} ←→ 100
{2} ←→ 010
{3} ←→ 001
{1, 2} ←→ 110
{1.3} ←→ 101
{2, 3} ←→ 011
{1, 2, 3} ←→ 111
This is also known as the binomial theorem. We first give the main idea of
the proof: In the expansion of (1 + x)n , each term in the expansion consists of
a product of n items, each one being either 1 or x. So each term is a product
a 1 a 2 · · · a n where each a i ∈ {1, x}. This term is equal to x k whenever exactly k
of these a i ’s are x’s. The coefficient of x k is then the number of ways that this
happens, which ¡n ¢ is essentially the same as choosing subsets of¡ {1, . . . , n} of size
k n¢
k. There are k of these subsets, hence the coefficient of x is k . For example,
when n = 3,
(1 + x)n = (1 + x)(1 + x) · · · (1 + x)
à !à ! à !
X X X
= a1 a2 · · · an
a 1 ∈{1,x} a 2 ∈{1,x} a n ∈{1,x}
X X X
= ··· a1 a2 · · · an
a 1 ∈{1,x} a 2 ∈{1,x} a n ∈{1,x}
X
= a1 a2 · · · an .
(a 1 ,a 2 ,...,a n )∈{1,x}n
Define S k to be the set of elements of {1, x}n where exactly k of the n terms are
x’s. So if (a 1 , . . . , a n ) ∈ S k , then a 1 a 2 · · · a n = x k . Also,
{1, x}n = S 0 ∪ S 1 ∪ · · · ∪ S n .
This is a disjoint union of sets, so we can break up the sum at the end of the
equation above to get
à !
n
n
X X
(1 + x) = a1 a2 · · · an
k=0 (a 1 ,a 2 ,...,a n )∈S k
à !
n
xk
X X
=
k=0 (a 1 ,a 2 ,...,a n )∈S k
n
|S k |x k .
X
=
k=0
Let Tk be the set of all subsets of {1, . . . , n} of size k. Then there is a bijection
between S k and Tk : define f : S k → Tk by f (a 1 , a 2 , . . . , a n ) = {i | a i = x}. (This¡ is¢
similar to the bijection defined in Problem 1.4.3.) This gives us |S k | = |Tk | = nk .
Therefore, Ã !
n n
(1 + x)n = xk .
X
k=0 k
Solution:
¡n ¢ Let S be the set of all k-subsets of {1, . . . , n}. By Theorem 1.3.1, |S| =
k
.
We now count |S| in a different way. Partition S into two sets S 1 and S 2 where
S 1 contains all k-subsets of {1, . . . , n} which include the element n, and S 2 con-
tains all k-subsets of {1, . . . , n} which do not include the element n. Since S 1 and
S 2 are disjoint, |S| = |S 1 | + |S 2 |.
¡n−1¢ element of S 1 consists of n and a (k − 1)-subset of {1, . . . , n¡n−1
Now each − 1},
¢
so |S 1 | = k−1 . Each element of S 2 is a k-subset of {1, . . . , n − 1}, so |S 2 | = k .
Hence nk = n−1
¡ ¢ ¡ ¢ ¡n−1¢
k−1 + k .
Solution: Let S denote the set of all n–element subsets of {1, . . . , n + k}. By
Theorem 1.3.1,
à !
n +k
|S| = .
n
Note that for any set A ∈ S, the largest element of A is at least n. Now, for each
i ∈ {0, . . . , k}, let S i be the set of all sets in S whose largest element is n + i . Thus,
(S 0 , S 1 , . . . , S k ) is a partition of S, so
|S| = |S 0 | + |S 1 | + · · · + |S k |.
Hence,
|S| = |S 0 | + |S 1 | + · · · + |S k |
à ! à ! à !
n −1 n n +k −1
= + +···+
n −1 n −1 n −1
à !
X k n +i −1
= .
i =0 n −1
Thus, Ã ! Ã !
n +k X k n +i −1
= ,
n i =0 n −1
as required.
(a) Give a combinatorial proof of this identity. (Hint: Find a bijection be-
tween the even and odd subsets of {1, . . . , n}.)
(b) Give an algebraic proof for the identity. (Hint: Expand (1 − 1)n .)
¡m ¢ We could also use min{k, m} as the upper limit of this sum. Be-
(Remark:
cause i = 0 whenever i > m, k is also a valid upper limit of this sum.)
(a) Give a combinatorial proof of this identity. (Hint: The left side counts
the number of ways of choosing k elements from a set of (m + n) ele-
ments — determine a similar interpretation for the right side.)
(b) Give an algebraic proof for the identity. (Hint: Expand both sides of the
equation (1 + x)m+n = (1 + x)m (1 + x)n using Theorem 1.5.1.)
Pn ¡ n ¢ n−1
3. Consider the identity i =0 i i = n2 .
12 CHAPTER 1. COMBINATORIAL ANALYSIS
Problem 1.6.1. Suppose that S is a set of “configurations” and, for each config-
uration σ ∈ S, we have a non–negative integer weight w(σ). For a given integer
k, how many elements of S have weight k?
Consider, for example, the problem from the previous section of counting
subsets. Let S be the set of all subsets of {1, . . . , n}. For each subset σ ∈ S, we
¡ ¢its weight to be w(σ) = |σ|. Thus, the number of elements of S of weight
define
k is nk , the number of k element subsets of {1, . . . , n}.
ak x k ,
X
=
k≥0
where a k denotes the number of elements in S with weight k. That is, the coef-
ficient of x k in ΦS (x) counts the number of elements of weight k in S.
Consider, again, the set S of all subsets of {1, 2, . . . , n}. Let the weight of set
σ ∈ S be |σ|. Then
à ! à ! à ! à ! à !
n n n 2 n n X n n
Φs (x) = + x+ x +···+ x = x k = (1 + x)n .
0 1 2 n k=0 k
Consider the case where S is the set of all integer pairs (a, b) where a ∈
{1, 3, 5}, b ∈ {2, 4, 6} and the weight of (a, b) is defined as a + b. Thus,
ΦS (x) = x 1+2 + x 1+4 + x 1+6 + x 3+2 + x 3+4 + x 3+6 + x 5+2 + x 5+4 + x 5+6
= x 3 + 2x 5 + 3x 7 + 2x 9 + x 11 .
ΦS (x) = x 1+2 + x 1+4 + x 1+6 + x 3+2 + x 3+4 + x 3+6 + x 5+2 + x 5+4 + x 5+6
= (x 1 + x 3 + x 5 )(x 2 + x 4 + x 6 ).
Now, for any integer k ≥ 0, let N≥k be the set of all integers ≥ k; thus N≥k =
{k, k + 1, k + 2, . . .}, and the weight of a number is its value. Then
In the first example above the generating series is just a polynomial, since
S is finite. In the second example, N≥k is infinite, so the generating series is a
“formal power series”; we discuss these in greater detail in the next section.
14 CHAPTER 1. COMBINATORIAL ANALYSIS
Theorem 1.6.3. Let ΦS (x) be the generating series for a finite set S with respect
to a weight function w. Then,
(a) ΦS (1) = |S|,
(b) the sum of the weights of the elements in S is Φ0S (1), and
Thus,
Φ0S (1) =
X
w(σ),
σ∈S
which proves (b). Finally, (c) follows immediately from (a) and (b).
Consider again the example in which S is the set of all subsets of {1, . . . , n},
¡n ¢ set σ ∈ S , we define its weight to be w(σ) = |σ|. By definition,
and for each
there are k elements of S of weight k. Thus,
à !
n n
ΦS (x) = x k = (1 + x)n .
X
k=0 k
Now,
ΦS (1) = (1 + 1)n = 2n .
That is, there are 2n subsets of {1, . . . , n}. Now,
as expected.
1.6. GENERATING SERIES 15
2. Do the same for five letter words over the same alphabet, but, preferably,
without listing all the words separately.
3. Two six–sided dice, one red, one blue, are thrown. Consider all 36 combi-
nations of faces showing. Taking the weight of a throw to be the sum of the
spots showing (the usual score, in other words), make a table showing the
number of throws of each possible weight.
4. Construct a table, as in problem 3, for the case where the weight of a throw is
defined to be the absolute value of the difference between the faces showing.
6. If M (x) is the generating series for a finite set S of objects, obtain an expres-
sion for the sum of the squares of the weights of the elements of the set S in
terms of M 0 (1) and M 00 (1).
7. (a) Let s be a subset of {1, 2, 3, 4, 5}. The weight w(s) of s is defined to be the
number of pairs of consecutive integers in s. (For example, {1, 2, 4, 5}
has 2 pairs of consecutive integers, namely {1, 2} and {4, 5}, so w({1, 2, 4, 5}) =
2). Let S be the set of all subsets of {1, 2, 3, 4, 5}. Find the generating se-
ries f (x) of S with respect to w.
(b) Calculate f (1), and justify your answer.
(a n + b n )x n ,
X
A(x) + B (x) =
n≥0
and à !
n
a k b n−k x n .
X X
A(x)B (x) =
n≥0 k=0
In the case that A(x) and B (x) are polynomials, these definitions are consis-
tent with their familiar usage. Indeed, this is easy to see for addition, and for
multiplication
à !à !
i j
X X
A(x)B (x) = ai x bj x
i ≥0 j ≥0
ai b j x i + j ,
XX
= (now, let k = i and n = i + j )
i ≥0 j ≥0
à !
n
a k b n−k x n .
X X
=
n≥0 k=0
We need to be a bit careful when performing infinite sums and products, but
here there is no ambiguity, since there are only finitely many terms contributing
to any given coefficient. Thus, A(x) + B (x) and A(x)B (x) are well defined.
In many of the problems that we will encounter, we will need to solve linear
equations; given two formal power series P (x) and Q(x) we will want to find a
formal power series A(x) such that Q(x)A(x) = P (x). For example, suppose that
1.7. FORMAL POWER SERIES 17
Problem 1.7.1. Show that the following equation has a solution and that the
solution is unique:
(1 − x − x 2 )A(x) = 1 + x. (1.7.1)
a 0 + (a 1 − a 0 )x + (a 2 − a 1 − a 0 )x 2 + (a 3 − a 2 − a 1 )x 3 + · · · = 1 + x. (1.7.2)
Recall that two formal power series are equal if and only if they have the same
sequence of coefficients. Therefore, by equating coefficients on either side of
Equation 1.7.2, we have equality if and only if:
• a 0 = 1,
• a 1 − a 0 = 1, and
a n = a n−1 + a n−2 .
From this recurrence relation and the two initial conditions, we can uniquely
determine the sequence {a n }n≥0 . Therefore, Equation 1.7.1 has a solution and
the solution is unique.
We can extend the method developed in Problem 1.7.1 to solve any linear
equation Q(x)A(x) = P (x) so long as the constant term of Q(x) is non-zero.
Q(x)A(x) = P (x)
a n = p n + q 1 a n−1 + q 2 a n−2 + · · · + q n a 0 .
18 CHAPTER 1. COMBINATORIAL ANALYSIS
a n − (q 1 a n−1 + q 2 a n−2 + · · · + q n a 0 ) = p n .
Corollary 1.7.3. Let P (x) and Q(x) be formal power series. If the constant term
of Q(x) is non-zero, then there is a formal power series A(x) satisfying
Q(x)A(x) = P (x).
Proof: If Q(0) 6= 0, then, by dividing both P (x) and Q(x) by Q(0), we may assume
that Q(0) = 1. Then we can write Q(x) = 1 − q 1 x − q 2 x 2 − · · · and P (x) = p 0 +
p 1 x + p 2 x 2 + · · · . Now, by Theorem 1.7.2, A(x) = a 0 + a 1 x + a 2 x 2 + · · · satisfies
Q(x)A(x) = P (x) if and only if for each n ≥ 0,
a n = p n + q 1 a n−1 + q 2 a n−2 + · · · + q n a 0 .
Thus a 0 = p 0 and, for each n > 0, we can determine a n uniquely from a 0 , . . . , a n−1 .
So a solution exists and it is unique.
A(x)B (x) = 1;
1
we denote this by B (x) = A(x)−1 or by B (x) = A(x) .
1 + x + x2 + x3 + · · ·
(1 − x)(1 + x + x 2 + · · · ) = (1 + x + x 2 + · · · ) − (x + x 2 + x 3 + · · · ) = 1,
as required.
1.7. FORMAL POWER SERIES 19
xB (x) = b 0 x + b 1 x 2 + b 2 x 3 + · · ·
b 0 x + b 1 x 2 + b 2 x 3 + · · · = 1 + 0x + 0x 2 + · · ·
Theorem 1.7.8. A formal power series has an inverse if and only if it has a non-
zero constant term. Moreover, if the constant term is non-zero, then the inverse
is unique.
Proof: Let Q(x) be a formal power series. Then a formal power series A(x) is the
inverse of Q(x) if and only if it satisfies the linear equation
Q(x)A(x) = 1. (1.7.3)
If Q(0) 6= 0, then, by Corollary 1.7.3, Equation 1.7.3 has a unique solution. Hence
Q(x) has an inverse and it is unique. If Q(0) = 0, then the constant term on the
right side of Equation 1.7.3 is 1 but the constant term on the left is Q(0)A(0) = 0,
so there is no solution and, hence, Q(x) does not have an inverse.
As with polynomials, we can also consider the composition of formal power
series.
We can use the formula for the inverse of 1 − x to compute other inverses.
Problem 1.7.11. Determine the inverse of 1 − x + 2x 2 .
Solution: Let P (x) = 1 − x. Note that 1 − x + 2x 2 = 1 − (x − 2x 2 ) = P (x − 2x 2 ). In
Problem 1.7.5 we showed that
P (x)−1 = 1 + x + x 2 + · · ·
Therefore
(1 − x + 2x 2 )−1 = P (x − 2x 2 )−1
= 1 + (x − 2x 2 ) + (x − 2x 2 )2 + · · ·
(We could further simplify this expression, but we only wish to demonstrate the
method of computing inverses via composition.)
22 CHAPTER 1. COMBINATORIAL ANALYSIS
2. (a) Write out the first 5 terms and the nth term of the following power se-
ries:
(i) (1 − x)−1
(ii) (1 + x)−1
(iii) (1 − x)−2
(iv) (1 + x)−2
(v) (1 − x)−3
(vi) (1 + x)−3
(b) Determine the appropriate coefficient in each case.
(i) [x 8 ](1 − x)−1 ,
(ii) [x 5 ](1 + x)−1 ,
(iii) [x 6 ](1 − 3x 2 )−1 ,
(iv) [x 12 ](1 − x)−2 ,
(v) [x 9 ](1 + 4x 3 )−3 ,
(vi) [x 8 ](1 − 2x 3 )−2 .
(c) Write each of the following power series in closed form.
(i) 1 − 2x + 3x 2 − 4x 3 + 5x 4 − 6x 5 + . . .
(ii) 1 + 3x + 6x 2 + 10x 3 + 15x 4 + 21x 5 + . . .
(iii) 1 − x 3 + x 6 − x 9 + x 12 − x 15 + . . .
(iv) 1 + 2x 2 + 4x 4 + 8x 6 + 16x 8 + 32x 10 + . . .
1.7. FORMAL POWER SERIES 23
3. Show that
¡n+2k−1¢
(a) [x n ](1 − 2x + x 2 )−k = n
¡i +k−1¢¡ n−i
2 +k−1
(b) [x n ](1 − x − x 2 + x 3 )−k =
P ¢
i ≥0 n−i
n−i ≡0 (mod 2)
i
2
1−x 2 1
4. (a) Prove that 1+x 3
= x 2 .
1+ 1−x
(b) By expanding each side of the identity in (a) as a power series, and con-
sidering the coefficient of x N , prove that
¯ Ã !¯ ½
¯X N − k − 1 ¯
0 if N ≡ 1 (mod 3)
¯ (−1)k ¯=
¯ ¯
¯k≥0 N − 2k ¯ 1 otherwise.
5. Calculate [x n ](1 + x)−2 (1 − 2x)−2 , and give the simplest expression you can
find.
r n+r −1 m
P ¡ ¢¡ ¢ ¡m−n ¢
6. Prove that r +s=t (−1) r s = t .
8. Let S be a set of configurations with weight function w. Show that for any
non–negative integer n,
ΦS (x)
[x n ]
1−x
counts the number of configurations in S with weight at most n.
(a) Show that if A(x)B (x) = 0, then A(x) = 0 or B (x) = 0. (Hint: If A(x) 6= 0
then we can write A(x) = x k Â(x) where Â(x) has a non–zero constant
term.)
(b) Show that if A(x)2 = B (x)2 , then A(x) = ±B (x).
24 CHAPTER 1. COMBINATORIAL ANALYSIS
Proof:
ΦS (x) = x w(σ)
X
σ∈S
x w(σ) + x w(σ)
X X
= (since (A, B ) partitions S)
σ∈A σ∈B
= Φ A (x) + ΦB (x),
as required.
More generally, if A and B are sets where A ∩ B need not be empty, then
Recall that, given sets A and B , the cartesian product of A and B is the set
A × B = {(a, b) : a ∈ A, b ∈ B }.
as required.
1.8. THE SUM AND PRODUCT LEMMAS 25
Problem 1.8.3. Let k, n be fixed non-negative integers. How many solutions are
there to t 1 + · · · + t n = k, where t 1 , . . . , t n = 0 or 1?
= (1 + x)n
expected.
Problem 1.8.4. Let S be the set of all k-tuples (a 1 , . . . , a k ) where each a i is a non-
negative integer. The weight of a k-tuple σ = (a 1 , . . . , a k ) is defined as w(σ) =
a 1 + · · · + a k . Show that ΦS (x) = (1 − x)−k .
Therefore,
µ ¶k
1
ΦS (x) = .
1−x
as required.
We define f : S n → Tn as follows: For a k-tuple A = (a 1 , . . . , a k ) in S n ,
where 0ai represents a i 0’s in a row. Notice that f (A) is a string with exactly k −1
1’s, and the length of the string is a 1 +· · ·+a k +(k −1) = n +k −1 (note that A ∈ S n ,
hence a 1 + · · · + a k = n). Therefore f (A) ∈ Tn .
We can easily find the inverse of f : Any binary string in Tn has the form
0 10a2 1 · · · 10ak where a 1 +· · ·+a k = n. So the inverse of f is f −1 : Tn → S n where
a1
Solution: Let C k = {0, k, 2k, 3k, 4k, . . .}. Each collection of coins can be repre-
sented by a 5-tuple (n, d , q, l , t ) ∈ C 5 × C 10 × C 25 × C 100 × C 200 . Let S = C 5 × C 10 ×
C 25 ×C 100 ×C 200 . We define the weight of any 5-tuple in S to be w(n, d , q, l , t ) =
n + d + q + l + t , which represents the value of this collection of coins in cents.
Using the weight function αk (a) = a for the set C k , we see that the generat-
ing series for C k is
1
ΦC k (x) = 1 + x k + x 2k + x 3k + · · · = .
1 − xk
Notice that for our set S, the weight function w(n, d , q, l , t ) = α5 (n) + α10 (d ) +
α25 (q) + α100 (l ) + α200 (t ), so we can apply the Product Lemma. The generating
series for S is then
The number of collections that are valued at n cents is then [x n ]ΦS (x).
2. Extend the sum lemma to any finite number of sets. That is, if A 1 , A 2 , . . . , A k
are disjoint sets whose union is S, prove that
3. Extend the product lemma to any finite number of sets. That is, if S = B 1 ×
B 2 × · · · × B k with weight functions w 1 , . . . , w k respectively, the elements of S
28 CHAPTER 1. COMBINATORIAL ANALYSIS
4. (a) Prove that there are n! permutations of n distinct objects (n! = n(n −
1) · · · 2 · 1), by establishing a 1-1 correspondence between these permu-
tations and Nn × Nn−1 × · · · × N1 , where Ni = {1, 2, . . . , i }, i ≥ 1.
(b) Prove that there are nk = k!(n−k)! n!
¡ ¢
subsets of size k in a set of n dis-
tinct objects, by establishing a 1-1 correspondence between P n and
P k × P n−k × B n,k , where P i is the set of all permutations of i distinct
objects, i ≥ 1, and B n,k is the set of all k-subsets of a set of n distinct
objects.
The compositions of 4 are (4), with 1 part; (3, 1), (2, 2), (1, 3), with 2 parts;
(2, 1, 1), (1, 2, 1), (1, 1, 2), with 3 parts; and (1, 1, 1, 1), with 4 parts. Thus these are
eight compositions of 4, one with 1 part, three with 2 parts, three with 3 parts,
and one with 4 parts.
Let N = {1, 2, 3, 4, . . .} be the set of all positive integers. Then each part of a
composition is in N.
Problem 2.1.2. How many compositions of n are there with k parts, for n ≥ k ≥
1?
29
30 CHAPTER 2. COMPOSITIONS AND STRINGS
1. Find the set S of all compositions that satisfy these properties (without
regard for what n is);
2. Find the generating series for S (the weight of a composition is the sum
of its parts, so we can apply the Sum and Product Lemmas); and
Problem 2.1.3. How many k-part compositions of n are there in which each
part is an odd number?
Solution: In this case let S = Nkod d , where Nod d = {1, 3, 5, 7, . . .}. Then the re-
quired compositions are the elements of S of weight n, so the required generat-
2.1. COMPOSITIONS OF AN INTEGER. 31
ing series is
The coefficient is zero if n−k is odd. If n−k is even then the required coefficient
occurs for i = n−k
2
, and is
à ! à !
n−k n+k−2
2
+k −1 2
= .
k −1 k −1
Thus this is the number of k-part compositions of n in which each part is odd.
Problem 2.1.4. How many compositions of n are there with k parts, each part
at most 5?
Solution: In this case let S = {1, 2, 3, 4, 5}k , and the required compositions are
the elements of S of weight n. Thus the required generating series is
= (x 1 + x 2 + x 3 + x 4 + x 5 )k
¢k
= x(1 − x 5 )(1 − x)−1 , by finite Geometric Sum
¡
= x k (1 − x 5 )k (1 − x)−k .
32 CHAPTER 2. COMPOSITIONS AND STRINGS
à ! à !
k j + k − 1
[x n ]x k (1 − x 5 )k (1 − x)−k = [x n−k ] (−x 5 )i xj,
X X
i ≥0 i j ≥0 k − 1
à ! à !
k j + k − 1
= [x n−k ] (−1)i x 5i + j
X X
i ≥0 j ≥0 i k − 1
à ! à !
X k i j +k −1
= (−1)
n
i ≥0, j ≥0 i k −1
5i + j =n−k
b n−k
5 c
à ! à !
X k i n − k − 5i + k − 1
= (−1) ,
i =0 i k −1
j k
n−k n−k
where 5
is the “integer part" of 5
(we use j = n − k − 5i , so j ≥ 0 gives
n−k
i≤ 5 ).
Solution: Here we let S = ∪k≥0 Nk , where the term k = 0 is the empty compo-
sition (of 0). Then the compositions of n are elements of S of weight n, so the
generating series is
1
= , by Geometric Series
1 − x(1 − x)−1
1−x
= , multiplying by 1 − x on top and bottom
1−x −x
1 − 2x + x
=
³ 1 − 2xx ´
= 1+ .
1 − 2x
Hence the number of compositions is
à !
³ x ´
[x n ] 1 + = [x n ] 1 + x (2x)i , by Geometric Series
X
1 − 2x i ≥0
à !
= [x n ] 1 + 2i x i +1
X
i ≥0
(
1, n = 0;
=
2n−1 , n ≥ 1
Problem 2.1.6. How many compositions of n are there where each part is odd?
(The number of parts is not restricted.)
Solution: Let Nod d = {1, 3, 5, 7, . . .}. The set of all compositions where each part
is odd is [ k
S= Nod d .
k≥0
ΦS (x) = Φ Nk
X
od d
k≥0
X³ x ´k
= 2
k≥0 1 − x
1
= x by Geometric Series
1 − 1−x 2
1 − x2
= .
1 − x − x2
2
1−x
The answer to our question is [x n ] 1−x−x 2.
Here we could not use existing tools to figure out an explicit formula for
1−x 2
the coefficient of 1−x−x 2 . But let’s derive a recurrence based on the method
described in Problem 1.7.1. If we let ΦS (x) = n≥0 a n x n , then we get
P
1 − x 2 = (1 − x − x 2 ) a n x n = a 0 + (a 1 − a 0 )x + (a n − a n−1 − a n−2 )x n .
X X
n≥0 n≥2
Other than a 0 , the rest are terms in the Fibonacci sequence. So for n ≥ 1, the
number of compositions of n where each part is odd is the n-th term in the
Fibonacci sequence.
We will now give a combinatorial proof of the recurrence. Let S n be the set
of all compositions of n where each part is odd. The recurrence a n = a n−1 +a n−2
for n ≥ 3 means that |S n | = |S n−1 | + |S n−2 |. So we can prove the recurrence by
finding a bijection between S n and S n−1 ∪ S n−2 . Here is one possible bijection.
Let f : S n → S n−1 ∪ S n−2 where for each composition (a 1 , . . . , a k ) ∈ S n ,
½
(a 1 , . . . , a k−1 ) ak = 1
f (a 1 , . . . , a k ) =
(a 1 , . . . , a k−1 , a k − 2) a k ≥ 3
This means that if the last part is 1, we remove that part to get a composition of
n − 1; if the last part is 3 or more, we subtract 2 from it to get a composition of
n − 2. Either composition still consist of parts that are odd, so they are in S n−1
and S n−2 respectively.
2.1. COMPOSITIONS OF AN INTEGER. 35
2. Let k be a fixed integer. How many compositions of n with k parts are there
where each part is congruent to 1 modulo 5? Determine an explicit formula.
Problem 2.2.1. How many k-subsets of Nn are there which contain no two con-
secutive integers?
2.2. SUBSETS WITH RESTRICTIONS. 37
(For example, when n = 6 and k¡=¢ 3, these subsets are {1,3,5}, {1,3,6}, {1,4,6}
and {2,4,6} - considerably less than 63 = 20.)
To specify an example of such a subset we can list its elements in increasing
order, as above, say as a vector α = (α1 , α2 , . . . , αk ) where α1 < α2 < · · · < αk ; but
this is not enough. We must also indicate the value of n. (The subsets listed
above, for example, could just as well be subsets of N7 or N519 ). Accordingly we
define a set C k consisting of elements (α, n) where n is a positive integer and
α represents a subset of Nn in the manner just described. For example, when
k = 3, then ({1, 3, 5}, 6), ({1, 4, 6}, 6) and ({1,4,6},13) are all in C 3 (though ({1,3,5},4)
and ({2,5,6},10) are not).
Suppose that we let the weight of σ = (α, n) be w(σ) = n. Then Problem
2.2.1 can be rephrased as
Restatement of Problem 2.2.1: How many configurations of weight n are there
in C k ?
Thus the required number is [x n ]ΦC k (x), and we show how the product
lemma can be used to obtain ΦC k (x).
For an arbitrary element σ = ({α1 , . . . , αk }, n) in C k consider the vector of
differences d (σ) = (α1 , α2 − α1 , . . . , αk − αk−1 , n − αk ). Thus for σ = ({1, 3, 6}, 6),
we have d (σ) = (1, 3 − 1, 6 − 3, 6 − 6) = (1, 2, 3, 0). Note that σ can be uniquely
recovered from d (σ). In the present example, σ = ({1, 1 + 2, 1 + 2 + 3}, 1 + 2 +
3 + 0) = ({1, 3, 6}, 6), and in general, if d (σ) = (d 1 , . . . , d k+1 ), then σ = ({d 1 , d 1 +
d 2 , . . . , d 1 + · · · + d k }, d 1 + · · · + d k+1 ). Note that d 1 is any positive integer, d k+1
is any non-negative integer, and d 2 , . . . , d k are positive integers greater than 1.
(Since we don’t allow any pairs of consecutive integers). Thus there is a 1-1 cor-
respondence, or bijection, between elements of C k of weight n and solutions to
t 1 +· · ·+t k+1 = n, with t 1 ≥ 1, t k+1 ≥ 0, t 2 , . . . , t k ≥ 2. Thus the required generating
series is
ΦC k (x) = ΦN (x){ΦN≥2 (x)}k−1 ΦN≥0 (x)
= (x + x 2 + . . .) (x 2 + x 3 + . . .)k−1 (1 + x + x 2 + . . .)
↑ ↑ ↑
Power of x gives Power of x gives Power of x gives
smallest element of difference between difference between (2.2.1)
subset successive pairs in n and largest
subset element in subset
of Nn
Problem 2.2.2. (The Terquem Problem) How many subsets α of Nn are there,
which have size k, and in which αi ≡ i (mod 2) for i = 1, . . . , k? (i.e. the odd
positions in the subset contain odd numbers, and the even positions contain
even numbers.)
Solution: The first element in such a subset must be odd, and the difference
between successive pairs must also be odd. The difference between n and the
largest element in the subset can be any non-negative integer. Thus we modify
(2.2.1) to obtain the required number as
The two cases can be unified by using the notation b n−k2 c, the “integer part”
of 2 , which is defined to be the greatest integer which is not larger than n−k
n−k
2
.
n−k
Thus i = b 2 c both when n − k = 2i and n − k = 2i + 1. The answer to problem
¡b n−k
2 c+k
¢
2.2.2 is therefore n−k . When n = 7, k = 3, the subsets are {1,2,3}, {1,2,5},
b 2 c
{1,2,7}, {1,4,5},{1,4,7}, {1,6,7}, {3,4,5},{3,4,7},{3,6,7},
¡2+3 ¢ ¡5¢ {5,6,7}, which verifies the for-
mula, since b 7−32
c = 2, and 2
= 2
= 10.
Problem 2.2.3. How many subsets α of Nn are there, which have size k, and in
which the difference between successive pairs of elements is at least c, but less
than d , where c < d ? (i.e. c ≤ αi +1 − αi < d for i = 1, . . . , k − 1).
j k+i k−1
P ¡ ¢¡ ¢
= i +(d −c) j =n−c(k−1)−1 (−1) i j
.
This answer is not as compact as the two previous ones but is still a finite
summation with single index j (since i can be determined from j by the re-
striction relating i and j ), and is easier to calculate than actually counting the
subsets.
40 CHAPTER 2. COMPOSITIONS AND STRINGS
2. How many subsets of Nn are there which have size k, and in which the dif-
ference between successive pairs of elements is at least c?
3. How many subsets of Nn are there which have size k, contain no consecutive
integers, and in which the i t h smallest element is congruent to i ( mod 5), for
i = 1, . . . , k?
5. Show that the number of subsets of Nn , which have size k, and in which the
difference between successive pairs of elements is never equal to 2, is
à !à !
k−1
X k −1 n −k −i +1
.
i =0 i n − 2i − k
6. Show that the number of subsets of N2m of size k, in which the difference
between any pair of elements is never equal to 2, is
à !à !
X k m −i +1 m −k +i +1
.
i =0 i k −i
For example, 01101 is a binary string of length five. We will use `(α) to de-
note the length of a string α. There is a single string, ε, of length 0, called the
empty string. Now there are clearly 2n binary strings of length n, since there
are 2 choices, 0 or 1, for each of the n symbols in a string of length n. In this
section, we count the number of binary strings of length n subject to various
2.3. BINARY STRINGS 41
restrictions. For example, we might consider strings that have no three consec-
utive ones. Since we will always be interested in the number of strings of a given
length, the generating series for strings in this section will all use the length of
a string as the weight function. Thus, for a set A of binary strings, we have
X `(a)
Φ A (x) = x .
a∈A
We will build up longer binary strings by piecing together short binary strings.
If a 1 and a 2 are binary strings, then a 1 a 2 is the string formed by concatenating
a 1 and a 2 . For example, if a 1 = 0100 and a 2 = 001, then a 1 a 2 = 0100001. Further,
if A and B are sets of binary strings, we define
AB = {ab : a ∈ A, b ∈ B }.
We also define
A ∗ = {ε} ∪ A ∪ A A ∪ A A A ∪ · · ·
= {ε} ∪ A ∪ A 2 ∪ A 3 ∪ · · · .
So A ∗ is the set of strings formed by concatenating any number of strings in A.
For example, in this notation, the set of all binary strings is given by {0, 1}∗ .
For {0, 1}-strings a, b, we say that b is a substring of a if a = cbd for some
{0, 1}-strings c, d . Our problems will often be expressed in terms of the blocks
of a binary string, which are maximal nonempty substrings consisting of only
0’s or only 1’s. For example, the string 00111001 has four blocks: (00, 111, 00, 1).
Problem 2.3.2. Let a n be the number of {0, 1}-strings of length n which contain
no three consecutive 1’s (or, which contain no substring “111”). Prove that
1 + x + x2
a n = [x n ] , for n ≥ 0.
1 − x − x2 − x3
Solution: Let S be the set of {0, 1}-strings with no three consecutive 1’s. We will
decompose each string by decomposing it after every occurrence of 0. For ex-
ample, the string σ1 = 00011010100 decomposes into (0, 0, 0, 110, 10, 10, 0) and
the string σ2 = 10111001 decomposes into (10, 1110, 0, 1). This decomposition
has two important properties. First, each string is decomposed uniquely. Sec-
ond, the decomposition does not separate consecutive ones, so a string is in S
if and only if no piece in the decomposition contains three consecutive ones.
So, just by examining the pieces, we see that S contains σ1 but not σ2 . When
42 CHAPTER 2. COMPOSITIONS AND STRINGS
we decompose a string in S, each piece will be in {0, 10, 110}, except possibly for
the last peice which can be 1 or 11. So we can write S as
Since the length is additive under composition, we can use this expression for
S together with the Sum and Product Lemmas to compute ΦS (x). Note that
Moreover,
{0, 10, 110}∗ = {ε} ∪ {0, 10, 110} ∪ {0, 10, 110}2 ∪ · · · .
So
¢2
Φ{0,10,110}∗ (x) = 1 + Φ{0,10,110} (x) + Φ{0,10,110} (x) + · · ·
¡
1
= .
1 − Φ{0,10,110} (x)
Therefore
1
ΦS (x) = Φ{ε,1,11} (x)
1 − Φ{0,10,110} (x)
1 + x + x2
= ,
1 − x − x2 − x3
as required.
AB = {ab : (a, b) ∈ A × B }.
will not have Φ AB (x) = Φ A (x)ΦB (x). For example, if A = {0, 01} and B = {0, 10},
then A × B = {(0, 0), (0, 10), (01, 0), (01, 10)} and AB = {00, 010, 0110}. So Φ AB (x) =
x 2 + x 3 + x 4 whereas Φ A (x)ΦB (x) = Φ A×B (x) = x 2 +2x 3 + x 4 . The problem here is
that the string 010 was created by concatenating two distinct pairs, (0, 10) and
(01, 0), in A × B .
We say that the expression AB is ambiguous if there exist distinct pairs
(a 1 , b 1 ) and (a 2 , b 2 ) in A × B with a 1 b 1 = a 2 b 2 —otherwise we say that AB is
an unambiguous expression. In other words, AB is unambiguous if each
string uniquely decomposes into a string in A concatenated with a string in
B . Note that if A and B are finite sets, then AB is unambiguous if and only if
|AB | = |A × B |.
We will use similar terminology for other constructions of binary strings.
For example, the expression A ∪ B is unambiguous when A ∩ B = ;. More gen-
erally, we will compose expressions for sets of strings using concatenation and
union of smaller sets; such an expression is unambiguous when each concate-
nation operation and each union operation is unambiguous. Thus A ∗ is unam-
biguous if the sets {ε}, A, A 2 , . . . are disjoint and, for each i ∈ N≥0 , A i is unam-
biguous.
It is important to note that it is the description of the set of strings using
sum, concatenation and the ∗-operation which might be ambiguous. A set of
strings itself is never ambiguous or unambiguous.
S = {0, 1}∗ .
• Decompose a string after each block of 0s. Each piece in the decomposi-
tion, except possibly the first and last pieces, will consist of a block of 1s
followed by a block of 0s. The first piece may consist only of a block of 0s
and the last piece may consist only of a block of 1s. This gives rise to the
expression
S = {0}∗ ({1}{1}∗ {0}{0}∗ )∗ {1}∗ .
Φ A ∗ (x) = (1 − Φ A (x))−1 .
2.7. DECOMPOSITION USING BLOCKS 45
Proof:
(a)
Φ AB (x) = x `(s)
X
s∈AB
x `(ab)
X X
=
a∈A b∈B
(b)
Φ A ∗ (x) = Φ A k (x),
X
k≥0
by the Sum Lemma, since A ∗ is unambiguous. Note that ε 6∈ A, so the
constant term of Φ A (x) is 0. Now Φ A k (x) = (Φ A (x))k from part (a), so
by Geometric Series.
1 − x2 + x3
b n = [x n ] , n ≥ 0.
1 − 2x + x 2 − x 3
46 CHAPTER 2. COMPOSITIONS AND STRINGS
Solution: Let B be the set of all {0, 1}-strings in which no block has length ex-
actly two. Consider decomposing a string after each block of 1s. Except possibly
for the first and last piece, each piece has the form
The first piece may consist only of 1s and the last piece may consist only of 0s.
This gives the expression
B = {ε, 1, 111, 1111, · · · }({0, 000, 0000, · · · }{1, 111, 1111, · · · })∗ {ε, 0, 000, 0000, · · · }.
(1 + x + x 3 + x 4 + · · · )2
ΦB (x) =
1 − (x + x 3 + x 4 + · · · )2
3
x
(1 + x + 1−x )2
= 3
, by geometric series
x
1 − (x + 1−x )2
3
x
1 + x + 1−x (1 + A)2 1 + A
= , since =
x
1 − (x + 1−x
3
) 1 − A2 1− A
1 − x2 + x3
= , multiplying top and bottom by 1 − x.
1 − 2x + x 2 − x 3
Problem 2.7.2. Find the generating series with respect to length for {0, 1}-strings
in which an odd block of 0’s is never followed by an odd block of 1’s.
Solution: Let S be the set of all {0, 1}-strings in which an odd block of "0"s is
never followed by an odd block of "1"s. We decompose a binary string after each
block of 1s, so a string has the required property if and only if each of the pieces
has. Decomposing all {0, 1}-strings in this way gives rise to the unambiguous
expression
{0, 1}∗ = {1}∗ ({0}{0}∗ {1}{1}∗ )∗ {0}∗ .
We are excluding pieces of the form {0}{00}∗ {1}{11}∗ . So
S = {1}∗ M ∗ {0}∗
2.8. RECURSIVE DECOMPOSITIONS OF BINARY STRINGS 47
where
M = {0}{0}∗ {1}{1}∗ \ {0}{00}∗ {1}{11}∗ .
Thus
x x x x
ΦM (x) = −
1 − x 1 − x 1 − x2 1 − x2
x 3 (2 + x)
=
(1 − x 2 )2
and the required generating series is
¶−1
x 3 (2 + x)
µ
1 1
Φ 1∗ M ∗ 0∗ = 1− 2 2
1−x (1 − x ) 1−x
2
(1 + x)
= .
1 − 2x 2 (1 + x)
Such a definition, in which the set S is defined in terms of itself, is called a re-
cursive definition. This leads immediately to the recursive decomposition
Here the right side gives an unambiguous expression for S and so from this we
obtain
ΦS (x) = 1 + Φ{0,1} (x)ΦS (x).
Solving for ΦS (x) gives
1 − Φ{0,1} (x) ΦS (x) = 1,
¡ ¢
48 CHAPTER 2. COMPOSITIONS AND STRINGS
so ¢−1 X n n
ΦS (x) = 1 − Φ{0,1} (x) = (1 − 2x)−1 =
¡
2 x ,
n≥0
n
as expected (since there are 2 binary strings of length n).
Below we give a different solution to Problem 2.3.2 based on a recursive de-
composition; we restate the problem here for convenience.
Problem 2.8.1. Let a n be the number of {0, 1}-strings of length n which contain
no three consecutive 1’s. Prove that
1 + x + x2
a n = [x n ] , for n ≥ 0.
1 − x − x2 − x3
Solution: Let S be the set of all {0, 1}-strings that do not contain three con-
secutive 1s. Consider decomposing a string after the first occurrence of 0. The
strings {ε, 1, 11} are indecomposable. Every other string σ ∈ S can be written as
σ = σ1 σ2 where σ1 ∈ {0, 10, 110} and σ2 ∈ S. This gives rise to the expression
In the previous problem we forbade the substring 111. The technique used
does not adapt well to more complicated forbidden substrings, but such prob-
lems can be handled using the method outlined in the following two problems.
Problem 2.8.2. Let L denote the set of binary strings which do not contain 11010
as a substring. Find the generating series for L.
Solution: Let M be the set of binary strings that contain exactly one copy of
11010, at their right end or (in other words) as a suffix. We have two equations:
{ε} ∪ L{0, 1} = L ∪ M ,
L{11010} = M .
2.8. RECURSIVE DECOMPOSITIONS OF BINARY STRINGS 49
For the first equation, if we append a bit to ε or a string in L, the resulting string
is either in L or M , which shows that {ε} ∪ L{0, 1} ⊆ L ∪ M . To show the other
inclusion, let α ∈ L ∪ M . If α ∈ L, then α is either the empty string, or we can
remove the last bit to obtain another string in L, so α ∈ L{0, 1}. If α ∈ M , then
by removing the last bit from α, it destroys the only copy of 11010 in α. The
remaining string is in L, so α ∈ L{0, 1} as well. This shows that {ε}∪L{0, 1} ⊇ L∪M ,
hence equality holds.
For the second equation, it should be clear that if α ∈ M , then α ∈ L{11010},
which shows that L{11010} ⊇ M . On the other hand, if α ∈ L, then α11010 cer-
tainly contains 11010 as a substring, but it takes a little effort to verify that it
does not contain a second occurrence of 11010. Since α does not contain 11010,
a second copy of 11010 would have to use some digits from the end of α and
some digits from the start of the appended sequence 11010. We can consider
cases depending upon the size of the overlap of the two copies of 11010.
µ ¶
∗ ∗ ∗ ∗ 1 1 0 1 0
• Overlap in 1 digit: · · · . This cannot hap-
1 1 0 1 0 ∗ ∗ ∗ ∗
pen, since 1 6= 0.
µ ¶
∗ ∗ ∗ 1 1 0 1 0
• Overlap in 2 digits: · · · . This cannot happen,
1 1 0 1 0 ∗ ∗ ∗
since 11 6= 10.
µ ¶
∗ ∗ 1 1 0 1 0
• Overlap in 3 digits: · · · . This cannot happen,
1 1 0 1 0 ∗ ∗
since 110 6= 010.
µ ¶
∗ 1 1 0 1 0
• Overlap in 4 digits: · · · . This cannot happen, since
1 1 0 1 0 ∗
1101 6= 1010.
Consequently
Therefore
1
ΦL (x) = .
1 − 2x + x 5
Problem 2.8.3. Let L denote the set of binary strings which do not contain 1010
as a substring. Find the generating series for L.
Solution: Let M be the set of binary strings that contain exactly one copy of
1010, at their right end. We have two equations:
{ε} ∪ L{0, 1} = L ∪ M ,
L{1010} = M ∪ M {10}.
The argument to establish the first equation is similar to the case in Problem
2.8.2. For the second equation, it should be clear that L{1010} ⊇ M ∪ M {10}. On
the other hand, if α ∈ L, then α1010 certainly contains 1010 as a substring, but
it can contain two copies. For example, 0110010 ∈ L and 01100101010 contains
a second copy of 1010 as shown: 01100(1010)10. More generally, if α ∈ L and
α1010 contains two copies of 0101, then α1010 ends with 101010 and if we drop
the last 10 we get a string in M .
If we convert our two equations to generating series, we get
Consequently
x4
ΦM (x) = ΦL (x)
1 + x2
2.8. RECURSIVE DECOMPOSITIONS OF BINARY STRINGS 51
and therefore
1
ΦL (x) = 4
.
x
1 − 2x + 1+x 2
2. Let A = {00, 101, 11} and B = {00, 001, 10, 110}. Prove that A ∗ is unambiguous,
and that the B ∗ is ambiguous. Find the generating series for A ∗ with respect
to length.
(a) The {0, 1}-strings that have no substring of 0s with length 3, and no sub-
string of 1s of length 2.
(b) The {0, 1}-strings that have no block of 0s of size 3, and no block of 1s of
size 2.
(c) The set of {0, 1}-strings in which the substring 011 does not occur.
(d) The set of {0, 1}-strings in which the substring 0110 does not occur.
(e) The set of {0, 1}-strings where the 0-blocks have even lengths and the
1-blocks have odd lengths.
52 CHAPTER 2. COMPOSITIONS AND STRINGS
(f) The set of all {0, 1}-strings where each odd-length block of 0s is followed
by a non-empty even block of 1s and each even-length block of 0s is
followed by an odd-length block of 1s.
5. (a) Show that the generating series by length for binary strings in which
every block of 0’s has length at least 2 and every block of 1’s has length
at least 3, is
(1 − x + x 3 )(1 − x + x 2 )
.
1 − 2x + x 2 − x 5
(b) Obtain a recurrence relation for the coefficients in this generating se-
ries.
6. (a) Let a n be the number of {0,1}-strings of length n such that each even
block of 0’s is followed by exactly one 1 and each odd block of 0’s is
followed by exactly two 1’s. Show that
1+x
a n = [x n ] .
1 − x 2 − 2x 3
9. Find the generating series, with respect to length, for {0,1}-strings in which
no block has length greater than m.
10. Find the generating series, with respect to length, for {0,1}-strings in which
no block of 0’s has length greater than m, and no block of 1’s has length
greater than k.
11. Show that the generating series by length for the number of binary strings in
which the substring 01110 does not occur is
1 + x4
.
1 − 2x + x 4 − x 5
12. (a) Let s n be the number of {0, 1}-strings of length n in which every block of
0’s is followed by a block of 1’s of the same parity in length (i.e. a block
with an even number of 0’s is followed by a block with an even number
of 1’s, etc.). Determine the generating series Φ(x) = n≥0 s n x n .
P
n
(b) Show that if n ≥ 2 then s n = 2 · 3b 2 c−1 .
13. Let A i be the set of {0,1}-strings with no occurrences of substring “00” whose
first symbol is an i , for i = 0, 1.
˙
A 0 = {0}∪{0}A 1
˙
A 1 = {1}∪{1}(A ˙ 0 ).
1 ∪A
14. Let b n be the number of {0, 1}-strings of length n in which every block of 0’s is
followed by a block of 1’s of the same length. (For example, 111010001110011
and 100000111110011 are strings of length 15 of this kind.)
(b) Evaluate b n , n ≥ 0.
1
[x m y n ] .
1 − (x + y)
Problem 2.9.1. Let B (x, u) denote the multivariate generating series where [x n u k ]B (x, u)
counts the number of binary strings with length n and k occurrences of the sub-
string 001. Show that
1
B (x, u) = .
1 − 2x − (u − 1)x 3
Solution: Let S be the set of all {0, 1}-strings. We use the decomposition
This gives
1
B (x, u) = (1 + x + x 2 + . . .)
1 − (x + x 2 + ux 3 + ux 4 + · · · )
1 1
= 3 3
x−x
1−x 1−
1−x
−u x 1−x
1
= ,
1 − 2x − (u − 1)x 3
as required.
Problem 2.9.2. Let A(x, y, u) denote the multivariate generating series where
[x m y n u k ]A(x, y, u) counts the number of binary strings with m ones, n zeros,
and k blocks. Show that
(1 + (u − 1)x)(1 + (u − 1)y)
A(x, y, u) = .
1 − x − y − (u 2 − 1)x y
Solution: Let S be the set of all {0, 1}-strings. We use the decomposition
S = {ε, 1, 11, . . .}({0, 00, . . .}{1, 11, . . .})∗ {ε, 0, 00, . . .}.
This gives
(1 + ux + ux 2 + . . .)(1 + u y + u y 2 + . . .)
A(x, y, u) =
1 − (u y + u y 2 + · · · )(ux + ux 2 + · · · )
¡ ux
¢³ uy
´
1 + 1−x 1 + 1−y
= ³ ´
u y ¡ ux ¢
1 − 1−y 1−x
((1 − x) + ux)((1 − y) + u y)
=
(1 − x)(1 − y) − u 2 x y
(1 + (u − 1)x)(1 + (u − 1)y)
= ,
1 − x − y − (u 2 − 1)x y
as required.
By making appropriate variable substituitions we can extract other interest-
ing generating series. For example, A(x, y, 1) gives the generating series where
x marks occurrences of 1 and y marks occurrences of 0, and A(x, x, u) gives the
56 CHAPTER 2. COMPOSITIONS AND STRINGS
generating series where x the length of a string and u marks each block. By
Problem 2.9.2,
1
A(x, y, 1) =
1 − (x + y)
and
(1 + (u − 1)x)2
A(x, x, u) =
1 − 2x − (u 2 − 1)x 2
(1 + (u − 1)x)2
=
(1 − (u − 1)x)(1 + (u − 1)x)
1 + (u − 1)x
= .
1 − (u − 1)x
Bivariate generating series are useful for finding averages, using the follow-
ing result, where “Property P " would be specified in any particular example. We
will use F u (x, u) as an abbreviation for
∂
F (x, u).
∂u
Theorem 2.9.3. Let R be a set of {0, 1}-strings, and c n,k be the number of strings
in R of length n with k occurrences of property P , n, k ≥ 0. Let µn be the aver-
age number of occurrences of property P among the {0, 1}-strings in R of length
n, and let
c n,k x n u k .
X X
F (x, u) =
n≥0 k≥0
Then
[x n ]F u (x, 1)
µn = , n ≥ 0.
[x n ]F (x, 1)
Proof: The total number of strings in R of length n is k≥0 c n,k . The total num-
P
P
ber of occurrences of property P is strings of length n is k≥0 kc n,k . Therefore,
N
µn = ,
D
P P
where D = k≥0 c n,k and N = k≥0 kc n,k . Now
c n,k x n ,
X X
F (x, 1) =
n≥0 k≥0
2.9. BIVARIATE GENERATING SERIES 57
so
kc n,k x n .
X X
F u (x, 1) =
n≥0 k≥0
³ ´
∂
Since N = [x n ] ∂u
F (x, u) |u=1 , the result follows.
Problem 2.9.4. (a) Let c n,k be the number of {0, 1}-strings of length n with k
blocks. Prove that
1 − x + ux
c n,k = [x n u k ] , n, k ≥ 0.
1 − x − ux
(b) Let µn be the average number of blocks among {0, 1}-strings of length n.
Determine µn , n ≥ 0.
c n,k x n u k
X X
F (x, u) =
n≥0 k≥0
is the generating series for {0, 1}∗ with x marking length and u marking blocks,
so
³ ux ´ ³ ux ux ´−1 ³ ux ´
F (x, u) = 1 + 1− 1+
1−x 1−x 1−x 1−x
¶−1
ux ux
µ
³ ´2 ³ ´ 2
= 1+ 1−
1−x 1−x
³ ux ´2 ³³ ux ´ ³ ux ´´−1
= 1+ 1− 1+
1−x 1−x 1−x
ux
1 + 1−x
= ux
1 − 1−x
1 − x + ux
= ,
1 − x − ux
58 CHAPTER 2. COMPOSITIONS AND STRINGS
and so (
0, n = 0;
µn = n+1
2 , n ≥ 1.
Problem 2.9.5. (a) Let a n,k be the number of {0, 1}-strings of length n with k
occurrences of 0011 as a substring. Prove that
and note that 0011 occurs as a substring whenever a block of 2 or more 0’s is
immediately followed by a block of 2 or more 1’s. Thus
¶¾−1
x x x2 x2 x2 x2
½ µ
1 1
A(x, u) = 1− − +u
1−x 1−x 1−x 1−x 1−x 1−x 1−x 1−x
2 2 4 4 −1
= {(1 − x) − (x − x + ux )} ,
= {1 − 2x − (u − 1)x 4 }−1 .
( j + 1)2 j x j +4 .
X
=
j ≥0
60 CHAPTER 2. COMPOSITIONS AND STRINGS
Thus (
0, n = 0, 1, 2, 3;
[x n ]F u (x, 1) = n−4
(n − 3)2 , n ≥ 4.
so (
0, n = 0, 1, 2, 3,
µn = n−3
16 , n ≥ 4.
2. (a) Let a n,k be the number of binary strings of length n containing exactly
k singleton 1’s, i.e. blocks consisting of a single 1. Show that
(1 − x)−1 + x(t − 1)
a n,k x n t k =
X
.
n≥0 1 − x − x 2 (1 − x)−1 − x 2 (t − 1)
k≥0
(b) Hence find the average number of singleton 1’s in strings of length n.
5. Find the generating series, by numbers of 0’s and 1’s, for {0,1}-strings which
satisfy both of the following conditions:
6. Find the generating series, with respect to number of 0’s and number of 1’s,
for {0,1}-strings in which each block of 0’s immediately following a block of
1’s of length k has length at least k and at most 2k − 1 for all k ≥ 1.
7. (a) Find the generating series for {0,1}-strings with respect to length and
with respect to numbers of occurrences of “011” as a substring.
(b) Find the average number of occurrences of “011” as a substring in {0,1}-
strings of length n.
(c) A gambler offers you the following proposition: First, you give him $50.
Then, you flip a fair coin 100 times. Each time you get a tail immedi-
ately followed by two heads, he gives you back $4. On average, how
much money do you win or lose in this game?
8. Let S be the set of all binary strings that do not contain the substring 000.
9. (a) Prove that the generating series for the number c(n, k) of {0,1}-strings
of length n with k occurrences of a block of 3 0’s immediately followed
by a block of two 1’s is
1
c(n, k)x n u k =
X
.
k,n≥0 1 − 2x + (1 − u)x 5 (1 − x)2
(b) Prove that the average number of occurrences of a block of three 0’s
immediately followed by a block of 2 1’s in {0,1}-strings of length n is
1
128 (n − 2) for n > 5.
62 CHAPTER 2. COMPOSITIONS AND STRINGS
(a) Using a similar decomposition, find the generating series by length for
{0,1,2}-strings with no “22” substring. (You may assume that the gener-
ating series by length for {0, 1}∗ is (1 − 2x)−1 .)
(b) Let a n be the number of strings from (a) with length n. Find a recur-
rence relation for a n .
(c) Find a formula for a n by the method of partial fractions.
12. (a) A Dyck word in {0, 1}∗ is a string ε or σ1 · · · σ2n such that (i) σ1 = 0; (ii)
σ1 + · · · + σi ≤ i /2 for i = 1, . . . , 2n − 1; (iii) σ1 + · · · + σ2n = n. Let D be the
set of all Dyck words. Prove that
D − {ε} = 0D1D
1 −2 3
= + .
(1 − 2x)(1 − 3x) 1 − 2x 1 − 3x
(You would not be expected to guess this, but certainly you can easily check
that it is correct.) It follows that
−2 3
a n = [x n ]Φ A (x) = [x n ] + [x n ]
1 − 2x 1 − 3x
1 1
= (−2)[x n ] + 3[x n ]
1 − 2x 1 − 3x
= −2n+1 + 3n+1 .
63
64 CHAPTER 3. RECURRENCES, BINARY TREES AND SORTING
Suppose now that deg( f ) < deg(g ), let the polynomial b 1 (x) be the remainder
when we divide f (x)a 1 (x) by g 2 (x) and let the polynomial b 2 (x) be the remain-
der when we divide f (x)a 2 (x) by g 1 (x). Then modulo g (x) = g 1 (x)g 2 (x) we have
since both sides have degree less than the degree of g , they are equal.
3.2. SOLUTIONS TO RECURRENCE EQUATIONS 65
The previous two lemmas yield the following theorem. Note that the num-
bers θi are the reciprocals of the zeros of g (x) and the integer m i is the multi-
plicity of θi−1 as a zero of g (x).
Theorem 3.1.3. Suppose f and g are polynomials such that deg( f ) < deg(g ). If
for i = 1, . . . , k there are complex numbers θi and positive integers m i such that
g (x) = (1 − θi x)mi
Y
i
f (x) X k
[x n ] = P i (n)θin .
g (x) i =1
rence
c n + q 1 c n−1 + · · · + q k c n−k = 0, (n ≥ k). (3.2.1)
If
g (x) := 1 + q 1 x + · · · + q k x k ,
there is a polynomial f (x) with degree less than k such that
f (x)
C (x) = .
g (x)
Proof: From the rule for the coefficients of a product of power series, if n ≥ k
then
c n + q 1 c n−1 + · · · + q k c n−k = [x n ](1 + q 1 x + · · · + q k x k )C (x).
So [x n ]g (x)C (x) = 0 if n ≥ k and therefore g (x)C (x) = f (x) for some polynomial
f (x) of degree less than k.
The recurrence in Equation 3.2.1 is called a homogeneous equation be-
cause the right-hand side of the equation is zero. (The term ‘homogeneous’
was used in the same way in your linear algebra courses.) The polynomial
h(x) = x k g (x −1 ) in this theorem is called the characteristic polynomial of the
recurrence. Using Theorem 3.1.3 we have at once:
66 CHAPTER 3. RECURRENCES, BINARY TREES AND SORTING
Theorem 3.2.2. Suppose (c n )n≥0 satisfies the recurrence equation (3.2.1). If the
characteristic polynomial of this recurrence has root βi with multiplicity m i ,
for i = 1, . . . , j , then the general solution to (3.2.1) is
where P i (n) is a polynomial in n with degree less than m i , and these polynomi-
als are determined by the c 0 , . . . , c k−1 .
Recall that to find roots of a polynomial, we use the Factor Theorem:: if F (x)
is a polynomial and F (a) = 0 then x − a is a factor of F (x).
x 3 − 4x 2 + 5x − 2 = (x − 1)2 (x − 2)
1 = A + C
1 = A + B + 2C
2 = A + 2B + 4C
A = 0, B = −1, C = 1.
c n = 2n − n, (n ≥ 0).
3.2. SOLUTIONS TO RECURRENCE EQUATIONS 67
x 3 + 4x 2 − 3x − 18 = (x − 2)(x + 3)2
0 = A + B
2 = 2A − 3B − 3C
13 = 4A + 9B + 18C
A = 1, B = −1,C = 1.
c n = 2n + (n − 1)(−3)n , (n ≥ 0).
(a) c n = a n2 .
(b) d n = a n2 + b n2 .
(c) e n = a n b n .
(d) f n = b n + 5.
68 CHAPTER 3. RECURRENCES, BINARY TREES AND SORTING
Initial conditions are obtained from the formula for c n above, which gives c 0 =
0, c 1 = 1, c 2 = 25.
(b) We have d n = 2·9n +2·4n , so d n satisfies the linear recurrence equation with
characteristic polynomial
Initial conditions are obtained from the formula for d n above, which gives d 0 =
4, d 1 = 26.
(c) We have e n = 9n −4n , so e n satisfies the linear recurrence equation with char-
acteristic polynomial
Initial conditions are obtained from the formula for e n above, which gives e 0 =
0, e 1 = 5.
(d) We have f n = 3n +2n +5 = 3n +2n +5·1n , so f n satisfies the linear recurrence
equation with characteristic polynomial
Initial conditions are obtained from the formula for f n above, which gives f 0 = 7,
f 1 = 10, f 2 = 18.
3.2. SOLUTIONS TO RECURRENCE EQUATIONS 69
3. Solve the recurrence relation c n+4 = 5c n+3 −9c n+2 +7c n+1 −2c n = 0 with initial
values c 0 = 1, c 1 = 0, c 2 = 1, c 3 = 0.
4. Consider the recurrence c n = 5c n−1 −7c n−2 +3c n−3 with the initial conditions
c 0 = 3, c 1 = 8, c 2 = 21.
6. Consider the recurrence c n+5 = 5c n+4 − 10c n+3 + 10c n+2 − 5c n+1 + c n , n ≥ 0,
with c 0 = 1, c 1 = 5, c 2 = 15, c 3 = 35, c 4 = 70. Determine c n explicitly, n ≥ 0.
Solution: If we suppose that some solution to (3.3.2) has the form b n = α(−1)n ,
for some choice of constant α, then substituting b n = α(−1)n on the left side of
(3.3.2), we obtain
and from the RHS of (3.3.2), we deduce that 12 α = 24, so α = 2, and thus b n =
2(−1)n is a solution to (3.3.2). Now, from the solution to Problem (3.2.4) and the
result above, we find that the general solution to (3.3.2)is
b n = 2 (−1)n + A + B n +C · 2n , n ≥ 0,
where A, B,C are constants, whose values can be determined from the initial
conditions:
−1 = 2 + A + 0 · B +C
−3 = −2 + A + B + 2C
2 = 2 + A + 2B + 4C .
Solving this system gives (check this) A = −2, B = 3, C = −1, so the solution to
the recurrence is
b n = 2 (−1)n − 2 + 3n − 2n , (n ≥ 0).
and from the RHS of (3.3.3), we deduce that −16α = 2 and 56α − 16γ = 1, so
α = −1/8, γ = −1/2, and thus b n = −(n + 4)/8 is a solution to (3.3.3). Now, from
the solution to Problem 3.2.4 and the result above, we have the general solution
to (3.3.3) as
n +4
bn = − + A · 2n + (B +C n)(−3)n , n ≥ 0,
8
where A, B,C are constants, whose values can be determined from the initial
conditions:
1
0 = − + A +B
2
27 5
= − + 2A − 3B − 3C
8 8
67 3
− = − + 4A + 9B + 18C ,
4 4
and solving this system gives (check this) A = 1/2, B = 0, C = −1, so the solu-
tion to the recurrence is
n +4
bn = − + 2n−1 − n(−3)n , (n ≥ 0).
8
3.4 Aysmptotics
We say that c n is asymptotic to g (n) as n → ∞, written c n ∼ g (n), if
cn
lim = 1.
n→∞ g (n)
3.5. OTHER RECURRENCE RELATIONS 73
For example, suppose that the roots β1 , . . . , β j in (3.2.2) are all real, and that
β1 has the largest absolute value of β1 , . . . , β j . Then
cn A 2 β2 n A j βj n
µ ¶ µ ¶
= 1+ +···+
A 1 βn1 A 1 β1 A 1 β1
and
cn
lim = 1+0+···+0
n→∞ A 1 βn
1
β βj
since β21 , . . . , β1 all have absolute value less than 1. Thus we have c n ∼ A 1 βn1 . For
a more compact result, here we have
A 1 = b 11 + b 12 n + · · · + b 1m1 n m1 −1 .
So, if b 1m1 6= 0,
cn
lim = 1,
n→∞ b 1m n m 1 −1 βn
1 1
and we also write
c n ∼ b 1m1 n m1 −1 βn1 .
This answers the question, “Roughly how fast does c n grow as n increases?”
Example 3.4.1. In Problem 3.2.3, with c n = 2n − n, we have c n ∼ 2n . In Problem
3.2.4, with c n = 2n + (n − 1)(−3)n , we have c n ∼ (n − 1)(−3)n and c n ∼ n(−3)n .
tion, i.e. the ratio of two polynomials then we can easily deduce a linear ho-
mogeneous recurrence equation of fixed order, with constant coefficients, by
simply multiplying on both sides of
P (x)
C (x) =
Q(x)
74 CHAPTER 3. RECURRENCES, BINARY TREES AND SORTING
by Q(x). Also we can obtain an exact form for c n for such generating functions
by considering the partial fraction expansion or by repeated use of the binomial
theorem. Another method of deducing a recurrence equation is by looking at
the derivatives of a generating function.
By way of example, consider F (x) = m≥0 f m x m = (1 − x)−k . Suppose we
P
have forgotten the binomial theorem and wish to find a recurrence relation for
f n . Now
F 0 (x) = m f m x m−1 = k(1 − x)−k−1
X
n≥0
so F (x) = k(1 − x) F (x), or (1 − x)F 0 (x) = kF (x).
0 −1
b n − 3b n−1 + 4b n−3 = 3 · 2n
(b) a tree with a fixed root vertex such that each vertex has a left branch and
a right branch (either of which may be empty).
Below, for example, we list all binary trees with three vertices.
We let ² denote the empty tree and we let • denote the tree with one vertex.
Let T be the set of all binary trees. For a tree T ∈ T , we let n(T ) be the number
of vertices in T . We let T (x) denote the generating function for T with respect
to the weight function n. Thus [x n ]T (x) is the number of binary trees with n
vertices. The following problem detemines T (x) implicitly.
Solution: For any binary tree T 6= ², we can decompose T into (•, T1 , T2 ), where
T1 and T2 are, respectively, the left and right branches of the root vertex of T .
76 CHAPTER 3. RECURRENCES, BINARY TREES AND SORTING
1 2n
¡ ¢
The numbers n+1 n
are called the Catalan numbers; these arise in many
other counting problems.
3. Show that the number of ways we can fills the entries of a 2 × n matrix with
the integers 1, . . . , 2n such that entries increase as we move from right to left
along a row, and as we move down a column, is the n-th Catalan number.
inverses, square–roots are not uniquely determined since (−B (x))2 = B (x)2 . We
3
can extend this interpretation to other rational powers. For example, (1 + x) 2 =
1 3
³ ´ 3 3
(1 + x) 2 , and (1 + x)− 2 is the inverse of (1 + x) 2 . Similarly, for any rational
number a, we can interpret (1 + x)a as a formal power series.
For any real number a and non–negative integer k we define
à !
a a(a − 1) · · · (a − k + 1)
= ;
k k!
à !
a
X a k
(1 + x) = x .
k≥0 k
We will not prove the Binomial Theorem; though, the reader should recog-
nize this, from Calculus, as the MacLaurin series expansion of (1+x)a . In Calcu-
lus, we place additional conditions on x since we view power series as functions
of x. Here, on the other hand, we do not evaluate formal power series; instead,
we are concerned with the sequence of coefficients. Therefore, we need not
address questions of convergence.
We show below that the Binomial Theorem is consistent with Theorems 1.5.1
¢ consider the case that a = n for some non–negative integer n.
and 1.8.5. ¡ First
Note that nk = 0 when n < k. Thus, by the Binomial Theorem,
à !
n n
n
xk ,
X
(1 + x) =
k=0 k
as expected.
3.7. THE BINOMIAL SERIES 79
Now consider the case that a = −n for some positive integer n. Thus,
à !
−n (−n)(−n − 1) · · · (−n − k + 1)
=
k k!
(n + k − 1)(n + k − 2) · · · n
= (−1)k
à ! k!
n +k −1
= (−1)k
k
à !
n + k − 1
= (−1)k .
n −1
à !
X −n
(1 − x)−n = (−x)k
k≥0 k
à !
X n +k −1 k
= x ,
k≥0 n −1
as expected.
1
We can use the Binomial Theorem to compute (1 − 4x) 2 , which we needed
to enumerate binary trees; see Theorem 3.6.2.
Lemma 3.7.2.
à !
1 X 1 2n n+1
(1 − 4x) = 1 − 2
2 x .
n≥0 n + 1 n
80 CHAPTER 3. RECURRENCES, BINARY TREES AND SORTING
as required.
3. (a) Write out the first 5 terms and the nth term of the following power se-
ries:
(i) (1 − x)−1
(ii) (1 + x)−1
(iii) (1 − x)−2
(iv) (1 + x)−2
(v) (1 − x)−3
(vi) (1 + x)−3
(b) Determine the appropriate coefficient in each case.
(i) [x 8 ](1 − x)−1 , Answer: 1
5 −1
(ii) [x ](1 + x) , Answer: −1
(iii) [x 6 ](1 − 3x 2 )−1 , Answer: 27
12 −2
(iv) [x ](1 − x) , Answer: 13
9 3 −3
(v) [x ](1 + 4x ) , Answer: −640
8 3 −2
(vi) [x ](1 − 2x ) . Answer: 0
(c) Write each of the following power series in closed form.
(i) 1 − 2x + 3x 2 − 4x 3 + 5x 4 − 6x 5 + . . .
(ii) 1 + 3x + 6x 2 + 10x 3 + 15x 4 + 21x 5 + . . .
(iii) 1 − x 3 + x 6 − x 9 + x 12 − x 15 + . . .
(iv) 1 + 2x 2 + 4x 4 + 8x 6 + 16x 8 + 32x 10 + . . .
(v) 1 − 4x 2 + 12x 4 − 32x 6 + 80x 8 − 192x 10 + . . .
(vi) 1 + 6x + 24x 2 + 80x 3 + 240x 4 + 672x 5 + . . .
82 CHAPTER 3. RECURRENCES, BINARY TREES AND SORTING
4. The coefficient notation can be extended to series of more than one variable.
Thus [x n y k ] denotes the coefficient of x n y k in the expansion of the series
that follows.
Find [x n y k ] 1x y . [Hint: Treat y as a constant, and find the coefficient of x n ;
1− 1−y
then find the coefficient of y k in the result.]
5. Show that
¡n+2k−1¢
(a) [x n ](1 − 2x + x 2 )−k = n
¡i +k−1¢¡ n−i
2 +k−1
(b) [x n ](1 − x − x 2 + x 3 )−k =
P ¢
i ≥0 n−i
n−i ≡0 (mod 2)
i
2
1−x 2 1
6. (a) Prove that 1+x 3
= x 2 .
1+ 1−x
(b) By expanding each side of the identity in (a) as a power series, and con-
sidering the coefficient of x N , prove that
¯ Ã !¯ ½
k N −k −1 ¯ 0 if N ≡ 1 (mod 3)
¯X ¯
¯ (−1) ¯=
¯
¯k≥0 N − 2k ¯ 1 otherwise.
7. Calculate [x n ](1 + x)−2 (1 − 2x)−2 , and give the simplest expression you can
find.
R1 1
11. By using the fact that 0 x i d x = i +1 for i ≥ 0, show that
1 n 1
(a) ni=0 i +1 n+1
P ¡ ¢
i = n+1 {2 − 1}.
Pn (−1)i ¡n ¢ Pn 1
(b) i =1 i i = − k=1 k
i +1 ¡ ¢
(c) ni=0 2i +1 ni = n+11
{3n+1 − 1}.
P
3.8. THE QUICKSORT ALGORITHM 83
(a) Let F (x) = (i 1 ,...,i k )∈S g (i 1 , . . . , i k )x h(i 1 ,...,i k ) , where h(i 1 , . . . , i k ) is an integer-
P
12.
valued function of i 1 , . . . , i k and g (i 1 , . . . , i k ) is independent of x. Show
that
[x n ]F (x) =
X
g (i 1 , . . . , i k ).
n
(i 1 ,...,i k )∈S
h(i 1 ,...,i k )=n
b n3 c b n−3k
2 c
à !à !
3n−2 j −3k a + j − 1 2a
5j
X X
= .
k=0 j =0 (n − 2 j − 3k)! j k
2. Repeat (1) for each of these lists unless their length is 0 or 1. This is called
“Quicksort”, and is implemented as follows.
STEP 1.
23 895
smaller bigger
84 CHAPTER 3. RECURRENCES, BINARY TREES AND SORTING
STEP 2.
2 8
3 5 9
and we’re finished. We have constructed a binary tree, which will be discussed
later.
Problem 3.8.2. Assuming the original list is in random order (i.e. all n! possi-
ble orderings are equiprobable), what is the average number of comparisons
needed by this algorithm to completely sort a list of n distinct numbers?
1X n
an = n − 1 + (a i −1 + a n−i ). (3.8.1)
n i =1
n−1
X
na n = n(n − 1) + 2 aj, n ≥ 1.
j =0
n−1
na n x n−1 = n(n − 1)x n−1 + 2 x n−1
X X X X
aj
n≥1 n≥1 n≥1 j =0
∞
na n x n−1 = x n(n − 1)x n−2 + 2 x n−1 ,
X X X X
aj
n≥1 n≥2 j ≥0 n= j +1
3.8. THE QUICKSORT ALGORITHM 85
since
X n−1
X X X X X
= = .
n≥1 j =0 n≥ j j ≥0 j ≥0 n> j
Now let
an x n
X
A(x) =
n≥0
so that
A 0 (x) = na n x n−1 .
X
n≥1
xj
A 0 (x) = x n(n − 1)x n−2 + 2
X X
aj
n≥2 j ≥0 1−x
which gives
A 0 (x) = 2x(1 − x)−3 + 2(1 − x)−1 A(x).
Hence we must solve the differential equation
dy
+ P (x)y = Q(x)
dx
where P and Q are functions of x alone. There is a standard method of solution
for such equations.
The equation is essentially the same if we multiply both sides by any func-
tion of x, say µ(x). We get
dy
µ(x) + µ(x)P (x)y = µ(x)Q(x) (3.8.3)
dx
Now the left hand side of (3.8.3) starts off like the derivative of the product of
two functions µ(x) and y. We would have
d dy
[µ(x)y] = µ(x) + µ0 (x)y.
dx dx
86 CHAPTER 3. RECURRENCES, BINARY TREES AND SORTING
In fact, if we choose µ(x) so that µ0 (x) = µ(x)P (x) then the left hand side of
(3.8.3) would be the derivative of µ(x)y. So let us take
µ0 (x)
= P (x)
µ(x)
or, on integrating, log µ(x) = P (x)d x. Then provided we can integrate P (x) we
R
= 2 log(1 − x)
or
d 2x
dx
[(1 − x)2 A(x)] = 1−x
2
= 1−x −2
Integrating, we have
Hence
A(x) = {−2 log(1 − x) − 2x + c}(1 − x)−2 .
We know that A(0) = 0, so c = 0. To find a n , we expand A(x) in powers of x.
A(x) = {2 log(1 − x)−1 − 2x}(1 − x)−2
xk
+ 1)x i .
P P
=2 k≥2 k i ≥0 (i
3.8. THE QUICKSORT ALGORITHM 87
Hence
i +1
a n = [x n ]A(x) = 2
P P
k≥2 i ≥0 k
i +k=n
Pn n−k+1 1
© Pn ª
=2 k=2 k
= 2(n + 1) k=2 k
− 2(n − 1) .
Thus ( )
Xn 1
a n = 2(n + 1) − 4n ,
k=1 k
is the average number of comparisons needed. This might not give you much
feel for how big a n is, but a result from advanced calculus (which we won’t go
into) tells us that nk=1 k1 is asymptotically log n+γ where γ is a constant, known
P
a n ∼ 2n log n.
Exercise: Although the result just quoted is outside the scope of this course, it
is fairly easy to show that
1 1
log(n + 1) < 1 + + · · · + < log n + 1
2 n
by considering the area under the curve y = x1 . (Use the integral test for series
convergence in first year calculus).
2. Suppose that
X xn
A(x) = an
n≥0 n!
satisfies the differential equation
with A(0) = 2. Find the recurrence relation for a n , n ≥ 0 together with initial
conditions.
3. If
X xn
F (x) = fn
n≥0 n!
satisfies the differential equation
with F (0) = 1, F 0 (0) = 2, find a recurrence for f n , together with initial condi-
tions.
4. Suppose
∞
X xk
f (x) = fk
k=0 k!
satisfies the differential equation
2. Sort these two groups individually by applying stage (1) to them and re-
peat, until each group has size 1. When these groups are sorted, merge
them to create an ordered list.
3.9. THE MERGESORT ALGORITHM 89
4 9
2 8 3 5
4 28 9 35
STEP 2.
248 359
STEP 3. 2 3 4 5 8 9.
We wish to find a n , the number of comparisons needed to sort such a list. Then,
from the algorithm,
most n − 1, so
an ≤ n − 1 + ab n c + ad n e (3.9.1)
2 2
90 CHAPTER 3. RECURRENCES, BINARY TREES AND SORTING
t n = n − 1 + t b n c + t d n e , n ≥ 2,
2 2
tn x n = (n − 1)x n + (t b n c + t d n e )x n ,
X X X
2 2
n≥2 n≥2 n≥2
P n
and letting T (x) = n≥1 t n x , t 1 = 0, gives
i −1
T (x) = x 2 2m
+ t k+1 )x 2k+1
P P P
i ≥0 i x + m≥1 2t m x + k≥1 (t k
i −1
= x2 + 2T (x 2 ) + xT (x 2 ) + x −1 T (x 2 ), since t 1 = 0
P
i ≥0 i x
= x 2 (1 − x)−2 + (2 + x + x −1 )T (x 2 )
Hence
T (x) = x 2 (1 − x)−2 + x −1 (1 + x)2 T (x 2 ),
and we must solve this functional equation. First let S(x) = x −2 (1 − x)2 (T (x), so
that S(x 2 ) = x −4 (1 − x 2 )2 T (x 2 ). The equation for T (x) becomes
= 1 + x(1 + x 2 (1 + x 4 (. . .)))
= 1 + x + x3 + x7 + · · ·
P 2i −1
= i ≥0 x ,
2i −1
T (x) = x 2 (1 − x)−2
P
i ≥0 x
2i −1
= x2 + 1)x j
P P
j ≥0 ( j i ≥0 x .
t n ∼ n log2 n,
since n ≤ 2m+1 ≤ 2(n − 1). Finally, recall that this gives an upper bound on the
average number of comparisons needed by MERGESORT.
If you take a Computer Science course on the analysis of algorithms, you
will spend a lot of time developing asymptotic results of the above types (though
by quite different methods).
92 CHAPTER 3. RECURRENCES, BINARY TREES AND SORTING
Chapter 4
4.1 Definitions
Graph theory is the study of mathematical objects known as “graphs" — a word
to which graph theorists have given a rather special meaning. So we must start
by defining exactly what a graph is.
V (G) = {1, 2, 3, 4, 5}
and
E (G) = {{1, 2}, {1, 3}, {1, 4}, {2, 3}, {2, 5}, {3, 4}, {3, 5}, {4, 5}}.
For the sorts of results with which we are concerned, it is most convenient to
consider the following geometric representation or diagram or drawing of a
graph. On the page we draw a small circle to correspond to each vertex. For
each edge we then draw a line between the corresponding pair of vertices. The
only restriction on such a line is that it does not intersect the circle correspond-
ing to any other vertex. For example, the above graph is represented in Figure
4.1(i), (ii) and (iii) in three ways.
If e = {u, v} then we say that u and v are adjacent vertices, and that edge e
is incident with vertices u and v. We can also say that the edge e joins u and v.
93
94 CHAPTER 4. INTRODUCTION TO GRAPH THEORY
2
2 2
1 1
1 3 5
3 3
5 5
4
4 4
(i) (ii) (iii)
Example 4.1.3. Given the street map of a city, one can define a street map graph
as follows. There is a vertex for each street intersection, and an edge for each
part of a street joining two intersections and traversing no other intersections.
An example is given in Figure 4.3, where intersections are numbered to make
the correspondence clear. Such graphs are useful in solving certain kinds of
routing and scheduling problems, such as garbage pickup, or delivery of news-
papers to carriers.
4.1. DEFINITIONS 95
rat
ran
cat eat
run
ear
sun
can car
1 2 Euler Way 3 1 2 3
Queen St
King St
Jack St
4 5 Main St 6 4 5 6
7 Erb St 8 7 8
Example 4.1.4. Another way to obtain a graph from a map, is to begin with a
political map, such as the map of the countries of a continent. There is a vertex
for each country and two countries are adjacent if they share a boundary. One
of the most famous problems in graph theory arose from the question of how
many colours are needed to colour such maps so that adjacent countries are
not assigned the same colour. Figure 4.4 shows the graph obtained from South
America.
Gu
Su
Ve FG
Co
Br Ur
Ec
Pa
Pe Bo Ar
Ch
Example 4.1.5. Graphs are often defined from other mathematical objects. For
example, we can define the graph S n,k to have V (S n,k ) equal to the set of k-
element subsets of {1, 2, . . . , n}. Two such subsets are adjacent if they have ex-
actly k − 1 elements in common. Figure 4.5 shows a drawing of the graph S 4,2 .
Some important points arise from our definition of a graph.
(1) Edges are unordered pairs of vertices. Thus the edge {v 1 , v 2 } is not from v 1
to v 2 or vice versa; it is simply “between" v 1 and v 2 . If we change Definition
4.1.1 to read “ordered pairs" we obtain the definition of a different kind of
graph, a directed graph or digraph.
(2) E (G), being a set, either contains a pair {v 1 , v 2 } or it does not. Thus we
do not allow the possibility of “multiple edges” such as exist between the
vertices a and b in Figure 4.6.
4.1. DEFINITIONS 97
{1, 2}
{2, 3} {2, 4}
{3, 4}
{1, 3} {1, 4}
d a
c e
f b
(3) The edges are pairs of distinct vertices. Hence we cannot have a loop, i.e.,
an edge joining a vertex to itself as shown in Figure 4.6 at vertex c. Neverthe-
less in some circumstances it can be convenient to consider loops and/or
multiple edges. If we wish to allow loops and multiple edges we will use the
term multigraph instead of graph. (In some texts “graph” is used to mean
“multigraph”, and if loops and multiple edges are not allowed the term ”sim-
ple graph” is used.)
(4) Note that V (G), and hence E (G), is a finite set. If we remove this condition
we find ourselves in the realm of infinite graphs—and that is a whole new
ballgame!
4.2 Isomorphism
Figure 4.7(i) is the diagram of the graph G, where
V (G) = {p, q, r, s}, E (G) = {{p, q}, {p, r }, {q, r }, {q, s}}.
The graphs G and H are not the same—G has vertices p, q, r, s and H has ver-
tices a, b, c, d —but for almost all purposes they are indistinguishable. We make
this idea precise.
p c
q s a b
r d
(i) (ii)
Definition 4.2.1. Two graphs G 1 and G 2 are isomorphic if there exists a bijec-
tion f : V (G 1 ) → V (G 2 ) such that vertices f (u) and f (v) are adjacent in G 2 if and
only if u and v are adjacent in G 1 . (We might say that f preserves adjacency.)
Figure 4.8 shows two other graphs, G and H , that are isomorphic. One iso-
morphism is the mapping f : V (G) → V (H ) given by
1 a
b i
6
5 2
8 9 c h
j
10 7
d g
4 3
e f
G H
in its isomorphism class have the property. Thus we generally regard isomor-
phic graphs as ‘the same’ even if formally they might not be equal. Even if G
has only one vertex, there are infinitely many graphs in its isomorphism class.
Fortunately though, the number of isomorphism classes of graphs with a given
finite set of vertices is finite. For example, there are exactly 11 isomorphism
classes of graphs on 4 vertices, pictured in Figure 4.9. Note that in this figure,
the vertices of the graphs are not given explicitly, because however we assign
vertices to the drawing, we will still get a graph in the same isomorphism class.
The identity map on V (G) is an isomorphism from the graph G to itself. An
isomorphism from G to itself is called an automorphism of G.
4.3 Degree
The number of edges incident with a vertex v is called the degree of v, and is
denoted by deg(v). For example in G of Figure 4.7 we have deg(p) = deg(r ) =
2, deg(q) = 3, deg(s) = 1; in G of Figure 4.8, all vertices have degree 3. In what
follows we generally use ‘p’ for the number of vertices and ‘q’ for the number
of edges.
4.4. BIPARTITE GRAPHS 101
Proof: Each edge has two ends, and when we sum the degrees of the vertices,
we are counting the edges twice, once for each end.
This is known as the Handshaking Lemma or the Degree-Sum Formula.
Corollary 4.3.2. The number of vertices of odd degree in a graph is even.
Proof: The sum of all vertex degrees is 2q, an even number. The sum of the
vertices of even degrees is even. Hence the sum of the vertices of odd degrees
is also an even number. This implies that there must be an even number of
vertices with odd degree.
Figure 4.10: K 4
Definition 4.4.1. For n ≥ 0, the n-cube is the graph whose vertices are the {0, 1}-
strings of length n, and two strings are adjacent if and only if they differ in ex-
actly one position.
Problem 4.4.2. Determine the numbers of vertices and edges in the n-cube, for
n ≥ 0.
n2n = 2q,
so the n-cube has q = n2n−1 edges, for n ≥ 0.
4.4. BIPARTITE GRAPHS 103
000 001
010 011
100 101
110 111
Solution: Let V be the set of all {0, 1}–strings of length n; V is the vertex set of
the n-cube. Partition V into the set A of strings containing an even number of
ones and the set B of strings containing an odd number of ones. If vertices x
and y are adjacent then the strings x and y differ in exactly one position. Thus,
exactly one of x and y contain an even number of ones. Therefore (A, B ) is a
bipartition and hence the n-cube is bipartite.
2. A cubic graph is one in which every vertex has degree three. Find all the
nonisomorphic cubic graphs with 4, 6 and 8 vertices.
3. For the subset graph S n,k defined in Example 4.1.5, find the number of ver-
tices and the number of edges.
4. The odd graph O n is the graph whose vertices are the n-subsets of a (2n +1)-
set, two such subsets being adjacent if and only if they are disjoint.
104 CHAPTER 4. INTRODUCTION TO GRAPH THEORY
G1 G2 G3
5. The line-graph L(G) of a graph G is the graph whose vertex set is E (G) and
in which two vertices are adjacent if and only if the corresponding edges of
G are incident with a common vertex.
6. For integer n ≥ 0, define the graph G n as follows: V (G n ) is the set of all binary
strings of length n having at most one block of 1’s. Two vertices are adjacent
if they differ in exactly one position.
(a) Find |V (G n )|
(b) Make drawings of G 3 and G 4 .
(c) Find |E (G n )|.
8. The complement of the graph G, denoted Ḡ is the graph with V (Ḡ) = V (G)
and the edge {u, v} ∈ E (Ḡ) if and only if {u, v} 6∈ E (G).
(a) Let G have vertices 1, 2, 3, 4 and edges {1, 2}, {2, 3}, {3, 4}, {1, 4}. Draw Ḡ.
(b) Find a 5-vertex graph that is isomorphic to its complement.
(c) Prove that no 6-vertex graph is isomorphic to its complement.
(d) Let G 1 and G 2 be two graphs. Prove that G 1 is isomorphic to G 2 if and
only if Ḡ 1 is isomorphic to G¯2 .
(e) Find all 2-regular non-isomorphic graphs on 6 vertices (prove that these
are the only ones).
(f) Prove that there are only two 3-regular non-isomorphic graphs on 6
vertices.
9. Make drawings of the 15 nonisomorphic graphs having six vertices and six
edges, such that every vertex has degree at least one.
10. Are the graphs in Figure 4.14 isomorphic? Justify your answer.
106 CHAPTER 4. INTRODUCTION TO GRAPH THEORY
1 2 a b
8 3 h c
7 4 g d
6 5 f e
11. For n a positive integer, define the prime graph B n to be the graph with
vertex set {1, 2, . . . , n}, where {u, v} is an edge if and only if u + v is a prime
number. Prove that B n is bipartite.
12. (a) Are the two graphs in Figure 4.15 isomorphic? Prove your claim.
(b) Are the two graphs in Figure 4.16 isomorphic? Prove your claim.
1 2 A B
8 3 H C
7 4 G D
6 5 F E
1 2 A B
7 3 G C
6 4 F D
5 E
Clearly A is a symmetric matrix and, since we do not allow loops, its diago-
nal elements are all zero.
To define an incidence matrix we must name the edges of G; we shall call
them e 1 , e 2 , . . . , e q .
For i 6= j this sum is the number of edges incident with both v i and v j ; for i = j
it is the number of edges incident with v i , which is deg(v i ). Thus
Another way of specifying a graph is to give, for each vertex, a list of the
vertices adjacent to it. For example:
e1 e4
e2 e3
5 6 7 2
e5 e6 e7
e8 e9 e11 e12
4 3
e10
Figure 4.17: Graph for problem 1
which begins with vertex v 0 , ends with vertex v n and, for 1 ≤ i ≤ n, edge e i =
{v i −1 , v i }. Such a walk can also be called a v 0 , v n -walk. Note that the length of a
walk is the number of edges in it (in this case, n). Also, because we can reverse a
walk to get a walk from v n to v 0 , we refer, where convenient, to a walk between
a pair of vertices, instead of from one to the other. A walk is said to be closed if
v0 = vn .
A path is a walk in which all the vertices are distinct. A path that starts at
v 0 and ends at v n is called a v 0 , v n -path. Observe that since all the vertices in a
path are distinct, so are all the edges.
Figure 4.19 shows (by heavy lines) a path in a graph, from vertex 1 to vertex
2.
Since graphs have no multiple edges, consecutive vertices v i −1 and v i de-
termine the edge e i of a walk. Hence, in describing a walk we often omit the
edges.
5 6
1 4
2 3
8
7 9
10
since graphs have no loops, a graph has no cycle of length one. A cycle of length
2 has two vertices, v 0 and v 1 , and two distinct edges, called multiple edges, join-
ing v 0 and v 1 . Therefore, a graph has no cycle of length two. Thus the shortest
possible cycle in a graph is a 3-cycle, often called a triangle.
Note that for a cycle with n ≥ 3 vertices, v 0 , . . . , v n−1 , then v i v i +1 . . . v n−1 v 0 . . . v i
and v i v i −1 . . . v 0 v n−1 . . . v i are both closed walks for each i = 0, . . . , n − 1, and in
this way there are 2n closed walks of length n associated with a given n-cycle.
Figure 4.20 shows (by heavy lines) an 8-cycle in a graph.
5 6
1 4
2 3
8
7 9
10
In a cycle, every vertex has degree exactly 2. There’s one condition that guar-
antees that a graph contains a cycle.
Theorem 4.6.4. If every vertex in G has degree at least 2, then G contains a cycle.
The girth of a graph G is the length of the shortest cycle in G, and is denoted
by g (G). If G has no cycles, then g (G) is infinite (but you may choose to ignore
this fact).
4.6. PATHS AND CYCLES 113
4. Let G be the graph whose set of vertices is the set of all “lower 48” states of
the United States, plus Washington, DC, with two vertices being adjacent if
they share a boundary. (For example, California is adjacent to Arizona.) Let
H be the subgraph of G whose vertices are those of G whose first letter is one
of W, O, M, A, N, and whose edges are the edges of G whose ends have this
property. (For example, California is not a vertex of H , but Arizona and New
Mexico are, and they are adjacent in H .) Find a path in H from Washington
to Washington, DC.
7. Prove that the complete bipartite graph K m,n has a Hamilton cycle if and
only if m = n and m > 1.
8. Show that if there is a closed walk of odd length in the graph G, then G con-
tains an odd cycle (that is, G has a subgraph which is a cycle on an odd num-
ber of vertices).
9. A diagonal of a cycle in a graph is an edge that joins vertices that are not
consecutive in the cycle.
(a) Prove that a shortest cycle (if one exists) has no diagonal.
(b) Prove that a shortest odd cycle (if one exists) has no diagonal.
(c) Give an example of a graph in which a shortest even cycle has a diago-
nal.
10. (a) Prove that a k-regular graph of girth 4 has at least 2k vertices (k ≥ 2).
(b) For k = 2, 3, find a k-regular graph of girth 4 with precisely 2k vertices.
Generalize these examples, i.e. find one for each k ≥ 2.
(c) Prove that a k-regular graph of girth 5 has at least k 2 + 1 vertices (k ≥ 2).
Remark: The only values of k for which such a graph with exactly k 2 +1
vertices can exist are k = 2, 3, 7, 57. This surprising result can be proved
using elementary matrix theory (i.e., what you study in MATH 235). Ex-
amples are known for k = 2, 3, 7, but no example has yet been found for
k = 57. Such a graph would have 572 + 1 = 3250 vertices.
t
(d) Prove that a k-regular graph of girth 2t , where t ≥ 2, has at least 2(k−1)
k−2
−2
vertices.
(e) Prove that a k-regular graph of girth 2t + 1, where t ≥ 2, has at least
k(k−1)t −2
k−2 vertices.
(f) For k = 2, 3, give an example of a k-regular graph of girth five with ex-
actly k 2 + 1 vertices.
4.7. EQUIVALENCE RELATIONS 115
You have met equivalence relations in your first algebra course, but these are
important in nearly all areas of mathematics, including graph theory.
Formally, if S and T are sets, then a relation R between S and T is a subset
of S × T . The idea is that if a ∈ S and b ∈ T , then a and b are related if and only
if (a, b) belongs to the subset. If a and b are related we may say that they are
incident. Thus if G is a graph, then “is contained in” is a relation on V (G)×E (G).
We will be most concerned with the case where S = T . In this case we usu-
ally refer to a relation on S, and do not mention S × S. By way of example, “is
adjacent to” is a relation on the vertices of a graph. A relation on S is reflexive if
each element of S is related to itself. So “is adjacent to” is not a reflexive relation
on the vertex set V (G) of a graph G. However this relation is symmetric, that is,
if a is related to b then b is related to a. On the integers, the relation “divides” is
reflexive but not symmetric.
There is a third important property a relation may have. Suppose that we
are given a relation on a set V and, if a, b ∈ V , we write a ≈ b to denote that a
and b are related. We say the relation is transitive if whenever a ≈ b and b ≈ c,
then a ≈ c. The relation “divides” on the integers is transitive, as is the relation
≤ on R. The relation “is a subgraph of” on the subgraphs of G is reflexive and
transitive.
We say a relation is an equivalence relation if it is reflexive, symmetric and
transitive.
As an example, the relation “is joined by a walk to” on the vertices of a graph
G is an equivalence relation—each of the three properties is very easy to verify.
The canonical example is equality. Another example you have met is “con-
gruent modulo m” on the integers. We generally use equivalence relations to
partition things. Thus the equivalence relation “congruent mod 5” splits the in-
tegers into five classes. The key is that if ≈ is an equivalence relation on a set V
and C (a) is the set
{v ∈ V : v ≈ a}
then any two elements of C (a) are equivalent, and any element of v that is
equivalent to something in C (a) is itself an element of C (a). Hence if b ∈ V
then either C (a) = C (b) or C (a) ∩C (b) = ;.
116 CHAPTER 4. INTRODUCTION TO GRAPH THEORY
4.8 Connectedness
Definition 4.8.1. A graph G is connected if, for each two vertices x and y, there
is a path from x to y.
Theorem 4.8.2. Let G be a graph and let v be a vertex in G. If for each vertex w
in G there is a path from v to w in G, then G is connected.
Proof: For any vertices x and y in G, there is a path from v to x and a path from
v to y. If we reverse the path from v to x we obtain a path from x to v, and now
Corollary 4.6.3 implies that there is a path from x to y in G, so G is connected
by Definition 4.8.1.
If G is a graph on n vertices, then to certify that G is connected
¡n ¢ according
to the definition of connected, we must provide a total of 2 paths. The above
theorem reduces the workload: only n paths are needed.
Solution: We use Theorem 4.8.2, and prove that there is a path from vertex
v 0 = 0 . . . 0 (with n 0’s) to x for all other vertices x in the n-cube. Now x is a {0, 1}-
string of length n, and suppose that x has k 1’s in positions i 1 , . . . , i k , where
1 ≤ i 1 < . . . < i k ≤ n, with 1 ≤ k ≤ n. Now let v j be the {0, 1}-string with 1’s in
positions i 1 , . . . , i j , and 0’s elsewhere for j = 1, . . . , k. Then v 0 v 1 . . . v k is a path
from 0 . . . 0 to x, so the n-cube is connected, by Theorem 4.8.2.
(a) C is connected.
Figure 4.21 shows a graph having three components. Note that there are
paths between every pair of vertices in the same component, but not between
pairs of vertices in different components.
While it is easy to convince someone of the existence of a path between two
vertices (show them the path), it is less clear how you might convince them that
a path does not exist. We introduce a convenient way of doing this.
If we are given a partition (X , Y ) of V (G) such that there are no edges having
an end in X and an end in Y , then there is no path from any vertex in X to any
vertex in Y . So, if X and Y are both nonempty, G is not connected. Given a
subset X of the vertices of G, the cut induced by X is the set of edges that have
exactly one end in X .
Theorem 4.8.5. A graph G is not connected if and only if there exists a proper
nonempty subset X of V (G) such that the cut induced by X is empty.
The question is that can a resident of the city leave home, cross every bridge
exactly once, and then return home? We can formulate the layout of the city as
a graph: Create 4 vertices representing the land areas (two shores and two is-
lands), and create an edge for each bridge, joining the vertices representing the
two land areas on either side of the bridge. In this case, we obtain the following
graph (with multiple edges):
In terms of graph theory, the question becomes “is there a closed walk that
uses every edge exactly once?” We use a definition for this type of walk.
4.9. EULERIAN CIRCUITS 119
v2
v1
vk
120 CHAPTER 4. INTRODUCTION TO GRAPH THEORY
C2
C1
C3
va 2
va 1
W2
W1
W3
va 3
va 2
va 1
W2
W1
v2
W3
va 3
v1
vk
4.10 Bridges
If e ∈ E (G), we denote by G −e (or by G\e) the graph whose vertex set is V (G) and
whose edge set is E (G)\{e}. (So G − e is the graph obtained from G by deleting
the edge e.)
Proof: Let e = {x, y}. If e is a bridge, then G − e has at least two components. Let
Vx be the set of vertices in the same component of G −e as x. Let z be any vertex
of G − e not in Vx . Because there exists a path from x to z in G but not in G − e,
every path from x to z in G contains edge e and so must be of the form
xe ye 2 v 2 e 3 v 3 · · · v n−1 e n z.
x, e 1 , v 1 , e 2 , v 2 , . . . , v n−1 , e n , y, e, x
in G. Then
x, e 1 , v 1 , e 2 , v 2 , . . . , v n−1 , e n , y
is a path from x to y in G −e. Hence e is not a bridge of G by Lemma 4.10.2. This
establishes the implication.
To complete the proof, we must establish the converse – if edge e is not a
bridge of graph G, then e is an edge of some cycle. Suppose e = uv is not a
bridge. Then u and v must lie in the same component of G − e, and so there is
a path P that joins them. Together with e this path forms a cycle that contains
e.
Corollary 4.10.4. If there are two distinct paths from vertex u to vertex v in G,
then G contains a cycle.
x i , x i −1 , . . . , x 0 = u = y 0 , y 1 , . . . , y m = v = x n , x n−1 , . . . , x i +1 .
It is a walk from x i to x i +1 that does not use the edge e. So it is also a walk in
G − e, hence x i , x i +1 are in the same component in G − e. By Lemma 4.10.2, e is
not a bridge. By Theorem 4.10.3, e must be part of a cycle. Hence G contains a
cycle.
We will often use the contrapositive form of this result: If graph G has no
cycles, then each pair of vertices is joined by at most one path.
2. Prove that, if G is connected, any two longest paths have a vertex in com-
mon.
3. Which graphs, with at least one edge, have the property that every edge is a
bridge?
4. If every vertex of a graph H with p vertices has degree at least p/5, prove that
H cannot have more than 4 components.
7. Let A n be the graph whose vertices are the {0, 1}-strings of length n, and
edges are between strings that differ in exactly two positions, n ≥ 2.
8. Let B n be the graph whose vertices are the {0, 1}-strings of length n, and
edges are between strings that differ in exactly two consecutive positions,
n ≥ 2.
124 CHAPTER 4. INTRODUCTION TO GRAPH THEORY
9. Let G be a graph in which exactly two of the vertices u, v have odd degree.
Prove that G contains a path from u to v.
Trees
5.1 Trees
A very special and important kind of graph is a tree.
Definition 5.1.1. A tree is a connected graph with no cycles.
Figure 5.1 shows a typical tree.
Lemma 5.1.2. There is a unique path between every pair of vertices u and v in
a tree T .
125
126 CHAPTER 5. TREES
Proof: For any 2 vertices u and v in T , there is at least 1 path joining them since
T is connected. Since T has no cycles, there is at most one path by Corollary
4.10.4. This establishes the result.
Theorem 5.1.4. A tree with at least two vertices has at least two vertices of de-
gree one.
Proof: Find a longest path w 0 w 1 w 2 . . . w n in the tree T , say between vertices
u = w 0 and v = w n . This path has length at least one, since any edge in the
non-trivial tree is a path of length one, so u 6= v.
Thus one vertex adjacent to v is in the path, namely w n−1 . If deg(v) > 1
there must be another vertex, w, adjacent to v. Vertex w cannot be in the path,
since this would imply a cycle in T , whereas T has no cycles. Since w is not
in the path, we can extend the path by adding edge {v, w} to it, and we get a
longer path w 0 w 1 . . . w n w. This is a contradiction. Hence d eg (v) = 1. Similarly
d eg (u) = 1, which proves the theorem.
This proof works if, instead of choosing a longest path, we choose a path
which is not a subgraph of a path in T with more edges. (We might say that
our path is “maximal under inclusion”.) The advantage of this choice is that it
is easier to decide if a path is maximal under inclusion than to decide if it is a
longest path—for to do the latter we must consider all paths in the tree.
One main property of trees is that any tree with p vertices have the same
number of edges: p − 1.
Theorem 5.1.5. If T is a tree, then |E (T )| = |V (T )| − 1.
Proof: The proof is by mathematical induction on p, the number of vertices.
When p = 1 there is just one tree. It has one vertex and no edges. It is called the
“trivial" tree, and the theorem holds for it.
Suppose that the theorem is true for trees on fewer than p vertices, and let T
be any tree with p vertices, for p ≥ 2. By the previous theorem, there is a vertex
u in T with degree one. Let v be the neighbor of u in T and let e be the edge
{u, v}. Since e is a bridge, T \ e is not connected and, by Lemma 4.10.2, it has
exactly two components, one of which is the vertex u. The other component is
a connected graph on p − 1 vertices with no cycles. Therefore it is a tree and, by
induction, it has exactly p − 2 edges. This implies that |E (T )| = p − 1.
5.1. TREES 127
In Theorem 5.1.4, we proved that every tree has at least two vertices of de-
gree one. The following alternative proof gives more detailed information about
how many vertices of degree one a tree can have given the degrees of other ver-
tices.
Alternate proof of Theorem 5.1.4: Let T be a tree and let n r denote the number
of vertices of degree r in T . Set p = |V (T )| and assume p ≥ 2. By Theorem 4.3.1
we have X
2p − 2 = deg(v)
v∈V (T )
and therefore
X n−1
X
−2 = (deg(v) − 2) = n r (r − 2).
v r =0
In the last sum, n 0 = 0 (because trees are connected) and so we find that
X
−2 = −n 1 + (r − 2)n r .
r ≥3
Therefore X
n1 = 2 + (r − 2)n r .
r ≥3
is the smallest possible number, and by giving a tree which has this many
vertices of degree 1.
4. Find the smallest number r of vertices in a tree having two vertices of degree
3, one vertex of degree 4, and two vertices of degree 6. Justify your answer by
proving that any such tree has at least r vertices, and by giving an example
of such a tree with exactly r vertices.
5. A cubic tree is a tree whose vertices have degree either 3 or 1. Prove that a
cubic tree with exactly k vertices of degree 1 has 2(k − 1) vertices.
6. A forest is a graph with no cycles. Prove that a forest with p vertices and q
edges has p − q components.
Proof: (“if” part.) We are given that G has a spanning tree T . Then Lemma 5.1.2
implies that there is a path in T between every pair of vertices of T . But each
of these paths is also contained in G, and G has the same vertices as T , so from
Definition 4.8.1 we conclude that G is connected.
(“only if” part.) We are given that G is connected. If G has no cycles, then
G itself is a spanning tree of G. Otherwise G has a cycle. Remove any edge e of
some cycle. Then G − e is connected, by Theorem 4.10.3, and has fewer cycles
than G.
Repeat this process, removing an edge on a cycle at each stage, until we have
a connected, spanning subgraph with no cycles. This subgraph is a spanning
tree of G.
5.2. SPANNING TREES 129
5 6
1 4
2 3
8
7 9
10
To show that a graph is connected, using the definition, you need to give
a path between any pair of vertices. However, Theorem 5.2.1 provides a much
more succinct method: give a spanning tree.
Proof: Let e = {u, v}. Any cycle in T +e must use e, since T has no cycles. Such a
cycle consists of e along with a u, v-path in T . By Lemma 5.1.2, there is a unique
u, v-path in T , hence there is exactly one cycle C in T + e.
If e 0 is any edge in C , then e 0 is not a bridge (Theorem 4.10.3). So T + e − e 0 is
still connected. Since it has n − 1 edges, by Corollary 5.2.2, it is a tree.
130 CHAPTER 5. TREES
{−k, −k + 1, . . . , k}
Proof: Given Lemma 5.3, it suffices to prove that if G is not bipartite, then it
contains an odd cycle.
Since G is not bipartite, at least one component H of G is not bipartite. (If
all components are bipartite, then we could find a bipartition of G by combin-
ing the bipartitions of the individual components.) Since H is connected, by
Theorem 5.2.1, there exists a spanning tree T in H .
Trees are bipartite (see Problem Set 5.1, Problem 2), so let (A, B ) be a bipar-
tition of T . Since H is not bipartite, (A, B ) is not a bipartition of H and therefore
there exists an edge {u, v} of H such that both u and v are in A, or both are in B .
By swapping A and B if needed, we may assume that u, v ∈ A.
Since T is connected, there exists a u, v-path P in T , with vertices x 0 x 1 . . . x n
where u = x 0 and v = x n . Since x 0 = u ∈ A and T is bipartite, the vertices along P
must alternate between A and B . So x 0 , x 2 , x 4 , . . . ∈ A and x 1 , x 3 , x 5 , . . . ∈ B . Since
x n ∈ A, n must be even, hence P has even length. However, x 0 x n = uv ∈ E (H ),
so P + {u, v} is an odd cycle in H , which is in G. Hence G contains an odd cycle,
as claimed.
Claim:
If |V (D)| = |V (G)| when the algorithm terminates, then D is a spanning tree
of G. If |(D)| < |V (G)| when the algorithm terminates, then G is not connected
and so, from Theorem 5.2.1, G has no spanning tree.
Proof:
We begin by using mathematical induction on the number of iterations to
show that the subgraphs D produced by the algorithm are subtrees of graph G.
Basis Case: Initially, D is a tree with 1 vertex.
5.4. BREADTH-FIRST SEARCH 133
r
pr(r) = φ
pr(u) = r
pr(y) = r
u y
pr(v) = u
pr(w) = u
pr(x) = u
v w x
the tree is exhausted if it is not adjacent to a vertex outside the tree. Of course,
if a vertex is exhausted at any stage, then it will remain exhausted at all later
stages. In Algorithm 5.4.1, we can ignore edges incident with exhausted vertices,
since the only possible edges that will allow the tree to increase in size must be
incident with an unexhausted vertex in the tree. Now we consider a refinement
of Algorithm 5.4.1 called breadth-first search, in which the unexhausted vertex
u at each stage is chosen in a special way.
Algorithm 5.4.2. Breadth-first search. Follow Algorithm 5.4.1 with the follow-
ing refinement: At each stage consider the unexhausted vertex u that joined
the tree earliest among all unexhausted vertices (called the active vertex), and
choose an edge incident with this vertex and a vertex v not in the tree.
1 2 3 4
5 6 G
7 8 9 10
3 8 10
B
4 2 7 5 6
new vertex joining the queue on the right). Now vertex 9 is exhausted, so it is
removed from the queue, and vertex 3 becomes active. Next, vertices 4 and 2
are added to B , with pr(4) = pr(2) = 3, and so vertices 4 and 2 are at level 2, and
the queue becomes 3, 8, 10, 4, 2. Vertex 3 is now exhausted, so it is removed
from the queue, vertex 8 becomes active, and we add vertices 7, 5, 6 to B in
that order, so the queue becomes 8, 10, 4, 2, 7, 5, 6. Now vertices 8, 10, 4 are
all exhausted, so the queue becomes 2, 7, 5, 6, and vertex 1 is added to B , at
level 3. Finally, all vertices of G are now in B , so all vertices in the queue are
exhausted, and we stop. In Figure 5.5, we have placed the vertices at each level
from left to right, in the order that they joined the breadth-first search tree B .
As a summary, note that the order in which the vertices of G joined B is 9, 3, 8,
10, 4, 2, 7, 5, 6, 1.
In Figure 5.5, the edges of B have an arrow to specify the parent. The edges
of G that are not contained in the breadth-first search tree B (called non-tree
edges) have been added to the drawing of B , without arrows. This gives a re-
drawing of G that will illustrate the primary property of breadth-first search,
given below. First we need a preliminary lemma.
Proof: We prove this by induction on the number of vertices in the tree at each
stage of the algorithm. The first vertex in the tree is the root vertex, with level 0,
and the result is true for this first stage.
Now we make the induction hypothesis, that the result is true for the first
m vertices in the tree, m ≥ 1, and consider the next vertex v, that joins the tree
at stage m + 1. Now pr(v) = u, where u is active when v joins the tree, and
level(v) = level(u) + 1. Consider any other non-root vertex x in the tree at stage
m + 1. Then pr(x) = y, and level(x) = level(y) + 1. But either y = u or y is ac-
tive before u. In the latter case, y joined the tree before u, so by the induction
hypothesis, in either case we have level(y) ≤ level(u). Thus we have
so level(v) ≥ level(x) for all other vertices x in the tree at stage m + 1, so the
result is true at stage m + 1.
Hence, the result is true by mathematical induction.
For example, it is easy to check that Lemma 5.4.3 holds for the breadth-first
search tree B given in Figure 5.5.
5.4. BREADTH-FIRST SEARCH 137
This result allows us to establish the following important fact about breadth-
first search.
Proof: Suppose that vertices u and v are joined by an edge, and without loss of
generality, that u joins the tree before v. Thus u is active before v, and there are
two cases:
Case 1. v is in the tree when u first is active. Then u and v are joined by a non-
tree edge, and pr(v) = w, where w joined the tree before u. Thus level(w) ≤
level(u), by Lemma 5.4.3, so we have
But also level(v) ≥ level(u), by Lemma 5.4.3, so we conclude in this case that u
and v are joined by a non-tree edge with
2. Consider a graph G with V (G) = {3, 4, 5, . . . , 25} and with {p, q} ∈ E (G) if and
only if either p|q or q|p. (Definition: p|q if and only if q = pr for some
integer r .) Give a spanning forest of G with the largest number of edges and
hence determine the number of components of G.
138 CHAPTER 5. TREES
3. Construct a breadth-first search tree for the graph below, taking vertex la-
belled 1 as root. When considering the vertices adjacent to the vertex being
examined, take them in increasing order of their labels.
1 2 5
13 14 6 4
11 10 7 3
12 9 8
4. What graphs have the property that, for a suitable choice of root, the breadth-
first search algorithm yields a tree in which all vertices (except the root) are
at level 1?
5. Explain why the search tree, rooted at d and indicated by dotted lines in the
graph below is not a breadth-first search tree.
a b c
d e f g
h i j
6. Prove that if a non-tree edge joins vertices u and v in adjacent levels, say
level (v) = level (u)+1, then the parent of v is at the same level as u, and was
active before u.
5.5. APPLICATIONS OF BREADTH-FIRST SEARCH 139
Proof: (i) Suppose G has a non-tree edge joining distinct vertices u, v at the
same level in T . Then the paths from u and v to the root vertex first meet at a
vertex (possibly the root vertex) which is m levels less than u and v, for some
m ≥ 1. Then the path in T between u and v has length 2m, and together with
the non-tree edge {u, v} this gives a cycle of length 2m + 1 in G, so G has an odd
cycle. (ii) If G has no non-tree edge joining vertices at the same level, then G is
bipartite, with bipartition into sets of vertices A = {v ∈ V (G) : level(v) is odd },
B = {v ∈ V (G) : level(v) is even}. All edges in G are incident with vertices whose
levels differ by one; hence one level must be even and one must be odd, so
every edge of G is incident with one vertex in A and one vertex in B . But, from
Lemma 5.3, this means that G has no odd cycles.
To find an odd cycle in a connected graph G, we need not construct the
entire breadth-first search tree and then look for an edge between vertices at
the same level. Instead, we can look for these edges when the tree is being built.
At each stage, when we examine the vertex at the head of the queue to see if it is
exhausted, we check if there is an edge joining it to a vertex already in the tree,
at the same level.
Theorem 5.5.1 illustrates an important application of breadth-first search
dealing with parity of cycle lengths. We now consider an application of breadth-
first search dealing with shortest paths.
Proof: From the primary property of breadth-first search trees we know that no
edge of G joins vertices that are more than one level apart. If vertex v is at level
k in a breadth-first search tree rooted at u, then there is a path (in the tree) of
length k from u to v. There can be no shorter path from u to v in G, since such
a path would have to contain an edge joining vertices more than one level apart.
The length of the shortest path between two vertices is often called the dis-
tance between the vertices. Theorem 5.5.2 implies that we can determine the
distance between vertex u and any other vertex in a connected graph G by find-
ing a breadth-first search tree of G rooted at u.
2. The diameter of a graph is the largest of the distances between the pairs of
vertices in the graph. Let G be a connected graph of diameter three with
exactly 20 vertices at distance three from a given vertex v. Prove that G has
some spanning tree T with exactly 20 vertices of degree one at level three.
5. Suppose that a connected graph G has a breadth-first search tree T for which
every non-tree edge joins vertices at equal levels. Prove that every cycle of G
contains an even number of tree edges.
For example, in the graph to the left, we have a connected graph with the
edges being labelled with their weights. In the graph to the right, we have a
spanning tree of total weight 31. But is there another spanning tree of smaller
weight?
a 9 a 9
b b
4 8 4 8
5 8 7 5 8 7
c d c d
8 3 8 3
e f e f
7 7
Prim’s algorithm:
a 9 a 9
b b
4 8 4 8
5 8 7 5 8 7
c d c d
8 3 8 3
e f e f
7 7
a 9 a 9
b b
4 8 4 8
5 8 7 5 8 7
c d c d
8 3 8 3
e f e f
7 7
a 9 a 9
b b
4 8 4 8
5 8 7 5 8 7
c d c d
8 3 8 3
e f e f
7 7
Codes
0· H = Z , 1· H = H.
The set of all spanning subgraphs of G forms a vector space under the oper-
ation of mod 2 sum.
Proof: Look up the definition of a vector space in your linear algebra text. You
will find that the scalar multiplication and vector addition defined above must
satisfy a list of axioms. These are all easy to verify.
145
146 CHAPTER 6. CODES
Z ⊕ H = H ⊕ Z = H,
H ⊕H = Z,
so each element of S(G) has an additive inverse, namely itself. We have defined
0·H = Z,
1 · H ⊕ 1 · H = H ⊕ H = Z = 0 · H = (1 ⊕ 1) · H .
Proving that all the axioms of a vector space are satisfied by S(G) is left as an
exercise.
Suppose that the edges of G are e 1 , e 2 , . . . , e q , and let A i be the element of
S(G) that contains edge e i , and no other edges, for i = 1, 2, . . . , q.
Theorem 6.1.3. {A 1 , A 2 , . . . A q } forms a basis for S(G).
Proof: The graphs A 1 , A 2 , . . . A q are all contained in S(G). To prove that they
form a basis for S(G), it is sufficient to prove that they (i) span S(G) and (ii) form
a linearly independent set.
(i) The elements of S(G) are uniquely specified by their edges. For H ∈ S(G),
if H contains edges e i 1 , e i 2 , . . . , e i k , then H can be written as the linear com-
bination
H = α1 A 1 ⊕ · · · ⊕ αq A q
where αi 1 = αi 2 = · · · = αi k = 1, and all other α’s are equal to 0. Thus
{A 1 , A 2 , . . . , A q } spans S(G).
β1 A 1 ⊕ · · · ⊕ β q A q = Z .
If β j = 1 for some j , then the graph on the LHS contains edge e j . But the
graph on the RHS contains no edges, so for equality to hold, we must have
β j = 0 for all j = 1, . . . , q. Thus {A 1 , A 2 , . . . , A q } is a linearly independent
set.
6.1. VECTOR SPACES AND FUNDAMENTAL CYCLES 147
This means that S(G) is a vector space of dimension q and contains 2q ele-
ments. Now we look at a subspace of S(G).
Definition 6.1.4. A graph in which all degrees are even non-negative integers is
called an even graph.
Let C (G) be the set of even spanning subgraphs of a graph G, so C (G) is a
subset of S(G).
Theorem 6.1.5. The set C (G) forms a vector space over GF (2). (This is a sub-
space of S(G).)
Proof: Clearly Z ∈ C (G), so C (G) is not empty. Thus, to prove that C (G) is a
subspace of S(G), it is sufficient to prove that (i) C (G) is closed under scalar
multiplication and (ii) C (G) is closed under addition.
(i) Suppose H ∈ C (G). Then 1 · H = H ∈ C (G), and 0 · H = Z ∈ C (G), since Z
has all vertex degrees equal to zero, which is an even non-negative inte-
ger.
(ii) Suppose H1 , H2 ∈ C (G), and let d 1 (v) and d 2 (v) denote the degree of v in
H1 and H2 , respectively, for all v ∈ V (G). Let m(v) be the number of edges
incident with v that are contained in both H1 and H2 . Then the degree of
v in H1 ⊕ H2 is
which is even, since both d 1 (v) and d 2 (v) are even, and non-negative,
since d 1 (v) ≥ m(v) and d 2 (v) ≥ m(v). Thus H1 ⊕ H2 ∈ C (G).
Edges e as described in the above result are called non-tree edges. If G has
q edges and p vertices, then T has p − 1 edges, so G has q − (p − 1) = q − p + 1
non-tree edges. Suppose that the non-tree edges are e 1 , e 2 , . . . , e q−p+1 . Let C i
be the spanning subgraph of G whose edges are the edges of the unique cycle
in T + e i , for i = 1, . . . , q − p + 1. Then C i is called a fundamental cycle, and
{C 1 ,C 2 , . . . ,C q−p+1 } is the set of fundamental cycles of G determined by T .
Lemma 6.1.7. For a fixed spanning tree T of a connected graph G, no two ele-
ments of C (G) contain exactly the same set of non-tree edges.
Proof: We have C i ∈ C (G), for i = 1, . . . q −p +1, since the vertex degrees in C i are
either 2 (for vertices on the cycle in T +e i ) or 0 (for the remaining vertices). Thus,
to prove that {C 1 , . . . ,C q−p+1 } forms a basis for C (G), it is sufficient to prove that
(i) it spans C (G) and (ii) it is a linearly independent set.
(i) From Lemma 6.1.7, the elements of C (G) are uniquely specified by their
non-tree edges. For H ∈ C (G), where H contains non-tree edges e i 1 , e i 2 , . . . , e i m ,
then H can be written as the linear combination
If β j = 1 for some j , then the graph on the LHS contains non-tree edge e j ,
since C j is the only fundamental cycle containing non-tree edge e j . But
the graph on the RHS contains no edges, so for equality to hold, we must
have β j = 0 for all j = 1, . . . , q − p + 1. Thus {C 1 , . . . ,C q−p+1 } is a linearly
independent set.
This means that C (G) has dimension q −p +1 and contains 2q−p+1 elements.
The cycles of G (together with some isolated vertices) are elements of C (G) and
thus can be uniquely expressed as a mod 2 sum of fundamental cycles. We call
C (G) the cycle space of G. The number q − p + 1 is known as the cyclomatic
number of G.
e3 e4 e5 e6
e7 e8
e9 e10 e11 e12
e13 e14
1. (a) Find the fundamental cycles corresponding to the spanning tree T with
edges
e 1 , e 2 , e 5 , e 7 , e 10 , e 11 , e 14
in the above graph. (List their edges.)
(b) Express the spanning even subgraphs with the following edge sets as
modulo 2 sums of fundamental cycles from (a):
(i) E (H1 ) = {e 1 , e 2 , e 4 , e 5 , e 7 , e 8 , e 10 , e 11 , e 13 , e 14 }
(ii) E (H2 ) = {e 3 , e 7 , e 9 , e 11 , e 12 , e 14 }
2. (a) Let T be the spanning tree given by dotted lines in the graph below.
Write down the edges in each of the fundamental cycles determined by
T.
150 CHAPTER 6. CODES
1
e1 e7 e2
6
5 e6 e12 e13 2
8 9 e8
e11 e14
e5 e15 e3
10 7
e10
e9
4 3
e4
3. In the graph shown below, let T be the spanning tree with edges
e 1 , e 5 , e 6 , e 8 , e 9 , e 10 , e 13 , e 14 , e 15 .
Write down the fundamental cycles determined by T . Also, express the cycle
C , whose edges are
e 2 , e 7 , e 12 , e 11 , e 15 , e 14 , e 8
e1 e7 e2
e6 e12 e13 e8
e11 e14
e5 e15 e3
e10
e9
e4
4. (a) In the graph below, a spanning tree has been constructed. Find the fun-
damental cycles C a ,C b and C c that are determined by the edges a, b
and c.
13 16
12 17
14 15
10 11 18 19
a
1 9
b 8 7 6
2 3 4 5
6. Prove that a graph which is connected, with 13 vertices and 18 edges, must
have at least 6 distinct cycles. Can you find such a graph with 6 edge-disjoint
cycles (edge-disjoint means that no edge may belong to more than one of
the cycles)?
9. Let F(G) be the set of spanning subgraphs with an even number of edges of
a graph G. (The spanning subgraph containing no edges belongs to F(G).
Note: F(G) is not the set of even spanning subgraphs of G.)
We can equally well speak about the Hamming distance between subgraphs,
using their characteristic vectors.
We have essentially proved the following:
Lemma 6.2.2. In the cycle space of a graph G, any two distinct vectors have
Hamming distance at least three.
Now let us see how to use this observation. Suppose that two people want
to communicate over a “channel” (such as a telephone line), capable of send-
ing 0, 1-sequences, but this channel on rare occasions introduces an error by
transmitting a 0 when a 1 was intended, or vice versa.
The two people, say Alice and Bob, can agree on a graph G = (V, E ) and
a labelling E = {e 1 , . . . , e q } of its edges, and further agree only to transmit as
messages the characteristic vectors of even subgraphs of G. Suppose that Alice
sends a message m to Bob and that Bob receives a message m 0 ; both m and m 0
are binary vectors of length q. Bob can check whether m 0 is an even subgraph
easily, but can he be sure that the message m 0 is in fact the message m? If m 0 is
not an even subgraph, Bob is absolutely sure that m 0 6= m (naturally, assuming
that Alice is playing by the rules and transmitting an even subgraph). But if m 0
is an even subgraph, Bob can only be sure that either
- m 0 is indeed m; or
Lemma 6.2.3. If fewer than t errors are made in the transmission of a code-
word, then the received message is either the original codeword, or it is not a
codeword at all.
Lemma 6.2.5. The cycle space of a connected graph G on p vertices and q edges
is a
(q, q − p + 1, t )-code for some t ≥ 3.
This code is called the even graphical code of G. What is the distance of
such a code?
If G has a cycle of length `, this cycle has Hamming distance ` from the void
graph Z . So evidently the girth g of G is an upper bound on the distance. Can
two even subgraphs S 1 and S 2 have Hamming distance less than g ? Consider
S 1 ⊕ S 2 . If S 1 6= S 2 , then S 1 ⊕ S 2 is an even subgraph, and hence it contains a
cycle. But all cycles have at least g edges, and so
Lemma 6.2.6. The distance of the even graphical code of G equals the girth of
G.
As an aside, let’s observe that we can extend our definition of cycle space to
multigraphs in which repeated edges are permitted. If we choose the two vertex
multigraph with q edges between the vertices, the cycle space is just the set of
all binary vectors of length q with an even number of 1’s. This is the standard
even parity code.
We are left with a significant question: correcting errors. Suppose that an
even subgraph M is transmitted, but that a subgraph S is received which is not
even. Now S = M ⊕ E , where E marks the positions in which a transmission
error was made; equivalently, M = S ⊕ E . Both E and M are unknown to us;
however, we do know all of the valid codewords, and when G has girth g , we
g −1
assume that at most b 2 c errors were introduced. Under this assumption, E
cannot contain a cycle (why?). To find E , let’s observe that a vertex v has odd
degree in S if and only if it has odd degree in E (for it surely has even degree
in M ). So E is a subgraph of G with a specified set of odd degree vertices and
as few edges as possible. There is only one candidate for E , since if S ⊕ E 1 and
6.2. GRAPHICAL CODES 155
2. Produce all codewords in the even graphical code of K 3,3 . Determine the
length, distance and dimension.
3. Prove that every connected graph on an even number of vertices has a span-
ning subgraph in which all vertices have odd degree. (Hint: consider modulo
2 sums of paths.)
5. Using Problem 4, extend the (15, 6, 5)-code from the Petersen graph to a
(15, 7, 5)-code. Describe all codewords.
156 CHAPTER 6. CODES
Chapter 7
Planar Graphs
7.1 Planarity
Definition 7.1.1. A graph G is planar if it has a drawing in the plane so that its
edges intersect only at their ends, and so that no two vertices coincide. The
actual drawing is called a planar embedding of G, or a planar map.
For example, the 3-cube, which we previously considered in Figure 4.12, is a
planar graph, with a planar embedding given in Figure 7.1. A planar graph may
have a number of essentially different embeddings.
000 001
010 011
110 111
100 101
It is clear that a graph is planar if and only if each of its components is planar.
So it is often sufficient to consider only connected planar graphs and connected
157
158 CHAPTER 7. PLANAR GRAPHS
planar embeddings.
A planar embedding partitions the plane into connected regions called faces;
one of these regions, called the outer face, is unbounded. For example, the pla-
nar embedding given in Figure 7.2 has 4 faces, identified as f 1 , f 2 , f 3 , f 4 in the
diagram. In this case, the outer face is f 4 .
f4
f1 f3
f2
W f = (v 0 , e 1 , v 1 , e 2 , v 2 , . . . , v n−1 , e n , v n )
In Figure 7.1, all faces have degree 4. Note that a bridge of a planar embedding
is incident with just one face, and is contained in the boundary walk of that
face twice, once for each side. Thus a bridge contributes 2 to the degree of
the face with which it is incident. On the other hand, if e is an edge of a cycle
7.2. EULER’S FORMULA 159
Proof: Each edge has two sides, and when we sum the degrees of the faces we
are counting the edges twice, once for each side.
Note the similarity between Theorem 7.1.2 and Theorem 4.3.1. This the-
orem is colloquially known as the Faceshaking Lemma or the Handshaking
Lemma for Faces. We shall make a direct link between these results later when
we consider the dual of a planar embedding.
Corollary 7.1.3. If the connected graph G has a panar embedding with f faces,
the average degree of a face in the embedding is 2|Ef(G)| .
p − q + f = 2.
Proof: For each positive integer p, we prove this result by induction on q. Since
G is a connected, it has a spanning tree and so q ≥ p − 1.
As a tree has no cycles, any planar embedding of a tree has just one face,
and the theorem holds.
160 CHAPTER 7. PLANAR GRAPHS
So assume q > p − 1, and assume inductively that Euler’s formula is true for
any connected graph on p vertices with fewer than q edges. Suppose that we
have a planar embedding of G with f faces. Since q ≥ p we see that G is not
a tree and therefore it has an edge e = {u, v} that is not a bridge. Then we also
have a planar embedding of G \ e (the graph we get from G by deleting the edge
e). Since G \ e has p vertices and q − 1 edges and is connected, it follows by
induction that if it has f 1 faces, then
p − (q − 1) + f 1 = 2
|V (G)| − |E (G)| + q + 2 − p = p − q + q + 2 − p = 2.
Theorem 7.3.1. A graph is planar if and only if it can be drawn on the surface of
a sphere.
Any drawing on the plane can be converted to a drawing on the sphere via
stereographic projection. Let the sphere be tangent to the plane at point A,
and let B be antipodal to A on the sphere. In stereographic projection, the im-
age of each point x on the plane is the unique point x 0 on the surface of the
sphere that lies on the line between x and B . This is illustrated in Figure 7.3.
If we apply stereographic projection to a planar embedding, we obtain a
drawing of the graph on the surface of the sphere (with no edges crossing), in
which all faces are bounded, and B is in the interior of a face.
7.3. STEREOGRAPHIC PROJECTION 161
B
x0
A
On the other hand, given any face f of an embedding G on the sphere, stere-
ographic projection provides a way to obtain a planar embedding H in which
the outer (unbounded) face corresponds to f —turn the sphere so that point B
lies in face f , and then project the embedding G to the plane to get H . If we
redraw an embedding so that a different face becomes the outside face, we con-
sider this to be the same as the original embedding. Roughly speaking, we have
the same graph, and the same faces, and the same faces are incident with the
the same edges, so they are essentially the same embedding. In particular the
number of faces of degree i in two embeddings related in this way will be equal.
A graph may have a number of essentially different planar embeddings. Fig-
ure 7.4 exhibits two embeddings of a planar graph. In the first embedding there
are two faces of degree three and two of degree five; in the second, there are two
faces of degree three, one of degree four and one of degree six. It is reassuring
to note that in both embeddings there are four faces (so Euler is happy) and the
sum of the faces degrees is 16 in both embeddings, as it should be by Theorem
7.1.2.
2. Prove that each of the graphs shown in Figure 7.5 is planar, by exhibiting a
planar embedding.
162 CHAPTER 7. PLANAR GRAPHS
5 5
1 2 1 2
4 3 4 3
a f
a b
b g
f g c
c h
i h
d i
e d
e
(a) (b)
Let f n be the number of regions into which the interior of the n-gon is di-
vided by this process. (So f 3 = 1, f 4 = 4, f 5 = 11.) Use Euler’s Formula to find
f n . (Hint: any set of 4 corner points of the n–gon uniquely determines a pair
of intersecting lines in the interior.)
see Figure 7.8. We call a graph platonic if it admits a planar embedding in which
each vertex has the same degree d ≥ 3 and each face has the same degree d ∗ ≥ 3.
We will show that the only platonic graphs are those given in Figure 7.8, from
which it is easy to deduce that there are just five platonic solids.
Lemma 7.4.2. Let G be a planar embedding with p vertices, q edges and s faces,
in which each vertex has degree d ≥ 3 and each face has degree d ∗ ≥ 3. Then
(d , d ∗ ) is one of the five pairs
Proof: Assume p = |V (G)|, q = |E (G)| and that there are exactly f faces in the
embedding. From Euler,
p − q + f = 2.
Since G is regular with degree d , we have 2q = d p by Theorem 4.3.1. Since
each face of the embedding has degree d ∗ , we have 2q = d ∗ f by Theorem 7.1.2.
Hence p = 2q/d and f = 2q/d ∗ . So we can write Euler’s equation as
µ ¶
2q 2q 2 2
2= −q + ∗ = q −1+ ∗ .
d d d d
(d) (e)
Figure 7.8: (a) the tetrahedron; (b) the octahedron; (c) the cube;(d) the icosahe-
dron; (e) the dodecahedron
166 CHAPTER 7. PLANAR GRAPHS
If d = 3 and d ∗ ≥ 6, then
2 2 2 2
+ ∗ ≤ + = 1.
d d 3 6
If d = 4 and d ∗ ≥ 4, then
2 2 2 2
+ ∗ ≤ + = 1.
d d 4 4
If d = 5 and d ∗ ≥ 4, then
2 2 2 2 18
+ ∗≤ + = < 1.
d d 5 4 20
Finally, if d ≥ 6 and d ∗ ≥ 3, then
2 2 2 2
+ ∗ ≤ + = 1.
d d 6 3
It follows that (d , d ∗ ) must be one of the five pairs in the statement of lemma.
Lemma 7.4.3. If G is a platonic graph with p vertices, q edges and f faces, where
each vertex has degree d and each face degree d ∗ , then
2d d ∗
q=
2d + 2d ∗ − d d ∗
and p = 2q/d and f = 2q/d ∗ .
Case 2: d = 3, d ∗ = 4.
2·3·4
Thus q = 2·3+2·4−3·4 = 12, p = 2·12 2·12
3 = 8, and s = 4 = 6. Consider a planar
embedding G with these parameters. Since each face has degree 4, no vertex
can be repeated in a boundary walk, so each face boundary is a 4–cycle. Let
C = (v 1 , v 2 , v 3 , v 4 , v 1 ) be the boundary of one of the faces of G. If v 1 is adjacent to
v 3 then (v 2 , v 3 , v 1 , v 2 ) is part of some boundary walk. This contradicts that each
face is bounded by a 4–cycle. Therefore, v 1 is not adjacent to v 3 , and, similarly,
v 2 is not adjacent to v 4 . Since each vertex has degree 3, v i has a unique neigh-
bour u i not in C , for i = 1, 2, 3, 4. Note that u 1 , v 1 , v 2 , u 2 is part of the boundary
walk of some face, so u 1 6= u 2 and u 1 u 2 is an edge. Similarly u 2 u 3 , u 3 u 4 , and
u 4 u 1 are also edges. If u 1 = u 3 then u 4 is only incident with two faces, namely
(u 4 , v 4 , v 1 , u 1 , u 4 ) and (u 4 , v 4 , v 3 , u 1 , u 4 ). This contradicts that u 4 has degree 3,
and, hence, u 1 6= u 3 . By symmetry, u 2 6= u 4 . Therefore G is the 3–cube.
2. Show that there is a unique planar embedding in which each vertex has de-
gree 3 and each face has degree 5.
3. Show that there is a unique planar embedding in which each vertex has de-
gree 5 and each face has degree 3.
W f = (v 0 , e 1 , v 1 , e 2 , v 2 , . . . , v n−1 , e n , v 0 )
be the boundary walk of H . Since the edge e 1 is incident with both f and g , it is
contained in W f precisely once.
The edge e 1 is not a bridge of H because
(v 1 , e 2 , v 2 , . . . , v n−1 , e n , v 0 )
2q ≥ d ∗ s ≥ d ∗ (q + 2 − p) = d ∗ q + 2d ∗ − d ∗ p.
e1
e2
u . v
.
.
eq
Theorem 7.5.3 gives an inequality that holds for all planar graphs. Therefore,
if a graph does not satisfy the inequality, then it is not planar. We illustrate this
idea below on K 5 .
Proof: We have à !
5
|E (K 5 )| = = 10.
2
But 3p − 6 = 15 − 6 = 9, so for K 5 we have
q = 10 > 9 = 3p − 6,
and the inequality q ≤ 3p − 6 does not hold. We conclude from Theorem 7.5.3
that K 5 is not a planar graph.
170 CHAPTER 7. PLANAR GRAPHS
q ≤ 4(p − 2)/(4 − 2) = 2p − 4.
Proof: We have
|E (K 3,3 )| = 3 · 3 = 9.
But 2p − 4 = 2 · 6 − 4 = 8, so for K 3,3 we have
q = 9 > 8 = 2p − 4
and the inequality q ≤ 2p − 4 does not hold. We conclude from Theorem 7.5.6
that K 3,3 is not a planar graph.
The proof of this lemma shows that if G is a planar graph with girth at least
four, then
|E (G)| ≤ 2|V (G)| − 4
and thus if p = |V (G)|, then the average degree of a vertex is
8
4− .
p
You might prove that if this bound holds with equality, then all faces have de-
gree four. (The 3-cube provides an example.)
Theorem 7.6.1. A graph is not planar if and only if it has a subgraph that is an
edge subdivision of K 5 or K 3,3 .
(We omit the proof of this result as it is beyond the scope of our current
study.)
Note that Kuratowski’s Theorem has the following surprising consequence.
Suppose we begin with a nonplanar graph G and do the following operation
as long as it is possible. Delete a vertex v or an edge e whose deletion leaves
0
a nonplanar graph. When this process ends, what will the final graph G be?
0
According to Kuratowski’s Theorem, G must be an edge subdivision of K 5 or
K 3,3 !
For example, in Figure 7.11, the graph M 5 has subgraph G, and G is an edge
subdivision of H . Also, H is actually K 3,3 , where the vertices in the two vertex
classes are {1, 5, 8} and {3, 6, 10}. Thus we conclude from Kuratowski’s Theorem
that M 5 is nonplanar. Figure 7.11 illustrates one convenient strategy when look-
ing for an edge subdivision of K 3,3 or K 5 : first find a long cycle in the graph – in
this case the cycle has 10 vertices; then find edges or paths (subdivided edges)
across the cycle – in this case edges {1, 10} and {5, 6}, together with any one of
edges {2, 7}, {3, 8}, {4, 9}, would create an edge subdivision of K 3,3 .
Note that M 5 has 10 vertices, 15 edges and girth 4, so our counting results
are not strong enough to prove that M 5 is not planar.
7.6. KURATOWSKI’S THEOREM 173
1 2 3 4 5
M5
6 7 8 9 10
1
6 2
7 3
G
8 4
9 5
10
6 3
8 5
10
2. Let G be a connected planar graph with p vertices and q edges and girth k.
Show that
k(p − 2)
q≤ .
k −2
Show also that if equality holds, all faces of G have degree k.
3. Prove that the Petersen graph is nonplanar, without using any form of Kura-
towski’s theorem.
5. Prove that the n-cube is not planar when n ≥ 4, without using any form of
Kuratowski’s theorem.
(a) Find the largest value k such that G k is planar and give a planar embed-
ding of G k .
(b) Prove that G k+1 is not planar using Kuratowski’s Theorem.
(c) Find n < 50 so that G n has K 5 as a subgraph.
(d) Find n < 40 so that G n has K 3,3 as a subgraph.
1
1 8
11 2
2 9 10 3
3 10 9 4
4 11
8 5
7 6
5 12
(b)
6 13
a f
7 14
b g
(a)
a
j c h
b
i c
d i
h d
e j
g e
f
(c) (d)
Figure 7.12:
176 CHAPTER 7. PLANAR GRAPHS
9. Prove that every planar bipartite graph G has a vertex of degree at most three.
10. Let G denote the graph below. (You may assume, without proof, that G has
girth six.)
(a) Let H be any graph obtained from G by deleting two edges. Prove that
H is not planar.
(b) Prove that there exist three edges that can be deleted from G so that the
resulting graph is planar.
a b
n c
m d
l e
k f
j g
i h
11. Prove that every planar graph having girth at least six has a vertex of degree
at most two. Prove that this is false if the girth is five.
12. Prove that if G is a planar graph in which every vertex has degree at least five,
then |V (G)| ≥ 12. Find such a graph with |V (G)| = 12.
(b) Prove that if G has p ≥ 11 vertices, then at least one of G and Ḡ is non-
planar.
For example, Figure 7.14 gives a 4-colouring of a graph. The colours in this
case are the integers 1, 2, 3, 4, and the colour assigned (by the function) to each
vertex is written beside the vertex in the diagram.
1 2 3
4 3 4
1 2
5 2 5 2
13
e
−→
4 3 4
G G/e
Figure 7.15: Contraction
−→
e
K3,3 K3,3/e
Figure 7.16: Contraction
It is important to note that the converse of this result does not hold. For ex-
ample, from Theorem 7.7.3 we know that K 5 is not 4-colourable, so it is correct
to deduce from the Four Colour Theorem that K 5 is not planar. However, from
7.8. DUAL PLANAR MAPS 181
Theorem 7.7.2 we know that K 3,3 is 2-colourable (and thus 4-colourable), but
we know already from Corollary 7.5.7 that K 3,3 is not planar.
(b) Without using Theorem 7.7.7, prove that every planar graph without a
triangle is 4-colourable.
2. Prove that if G is a planar graph with girth at least six, then G is 3-colourable.
(You may use the result of Problem 11 in Problem Set 7.6.)
4. Let G be a connected planar embedding in which every face has even degree.
Prove that G is a bipartite graph.
6. Show that a planar graph with p > 2 vertices and 2p−3 edges is not 2-colourable.
8. Show that K 5 can be obtained by contracting five edges of the Petersen graph.
Hence deduce from the nonplanarity of K 5 and the remark following the def-
inition of edge-contraction, that the Petersen graph is nonplanar.
184 CHAPTER 7. PLANAR GRAPHS
Chapter 8
Matchings
8.1 Matching
A matching in a graph G is a set M of edges of G such that no two edges in
M have a common end. (Another way to express the condition is that in the
spanning subgraph of G with edge set M , every vertex has degree at most 1.) So
M matches certain pairs of adjacent vertices—hence the name. The thick edges
in Figure 8.1 form a matching. We say that a vertex v of G is saturated by M , or
that M saturates v, if v is incident with an edge in M . Of course, every graph has
a matching; for example the empty set ; is always a matching. The question we
will be most interested in is to find a largest matching in G, called a maximum
matching of G. In Figure 8.1 the matching M indicated there has size 3, and
therefore is not a maximum matching, since it is easy to find a matching of size
4. A special kind of maximum matching is one having size p/2, that is, one that
saturates every vertex, called a perfect matching. Of course, not every graph
has a perfect matching.
We will be concentrating on matching problems for bipartite graphs. Here
is a way to restate the problem in case G is bipartite.
Job assignment problem. We are given a set A of workers and a set B of jobs,
and for each job, the set of workers capable of doing the job. We want to as-
sign as many jobs as possible to workers able to do them, but each worker is to
be assigned to at most one job, and each job is to be assigned to at most one
worker.
For example, suppose that A = {a, b, c, d , e, f } and B = {g , h, i , j , k, l }, and the
lists of workers that can do the jobs are:
185
186 CHAPTER 8. MATCHINGS
a b c d
i h g e
For g : c, e
For h : a, c
For i : a, b, c, d , f
For j : c, e
For k : c, e
For l : b, d , f
Why is the job assignment problem equivalent to the maximum matching prob-
lem of bipartite graphs? From the data of the job assignment problem we can
construct a bipartite graph G with vertex set A ∪ B and with u ∈ A adjacent to
v ∈ B if and only if worker u can do job v. (The graph corresponding to the sam-
ple data above is shown in Figure 8.2.) Conversely, given a bipartite graph with
bipartition A, B we make a worker for each element of A and a job for each ele-
ment of B and declare worker u to be able to do job v if and only if {u, v} ∈ E (G).
The condition that jobs be assigned to workers that can do them, means that an
assignment is a set of edges. The condition that each worker be assigned to at
most one job and that each job be assigned to at most one worker, corresponds
to the condition that the assigned edges form a matching.
If we have a matching M of G, certain kinds of paths are useful for obtaining
a larger matching. We say that a path v 0 v 1 v 2 . . . v n is an alternating path with
respect to M if one of the following is true:
{v i , v i +1 } ∈ M if i is even and {v i , v i +1 } ∉ M if i is odd
{v i , v i +1 } ∉ M if i is even and {v i , v i +1 } ∈ M if i is odd.
8.2. COVERS 187
A a b c d e f
B g h i j k l
That is, edges of the path are alternately in and not in M . In the graph of Figure
8.1, with respect to the matching indicated there, the following are examples
of alternating paths: (i) ahbg , (ii) i ahg b, (iii) i ahbg f . An augmenting path
with respect to M is an alternating path joining two distinct vertices neither of
which is saturated by M . The path (iii) above is an augmenting path in Figure
8.1. Note that augmenting paths have odd length because they begin and end
with nonmatching edges.
8.2 Covers
A cover of a graph G is a set C of vertices such that every edge of G has at least
one end in C . In Figure 8.1 {a, h, g , c, e} is a cover. It is easy to find large covers,
just as it is easy to find small matchings. For example, in any graph G, V (G) is a
cover. Also, if G is bipartite with bipartition A, B , then A is a cover, and so is B .
A very useful observation about matchings and covers is the following.
Proof: For each edge {u, v} of M , u or v is in C . Moreover, for two different edges
of M , any vertices of C they saturate must be different, since M is a matching.
Therefore, |M | ≤ |C |.
Sometimes we can use a cover to prove that a matching is maximum.
|M 0 | ≤ |C | = |M |.
3. How many perfect matchings has the graph L n of Figure 8.3? (There are n
vertical edges.) (Hint: where a n denotes the number of perfect matchings of
L n , find a recurrence relation for a n .)
6. Show that if two opposite corner squares of a chessboard are removed, then
the resulting board cannot be covered with 31 dominoes.
7. Let G be a graph with even number of vertices. Prove that if G has a Hamilton
cycle, then G has a perfect matching.
8.2. COVERS 189
···
Figure 8.3: L n
9. Show that if two squares of the chessboard having opposite colours are re-
moved, then the resulting board can be covered by 31 dominoes. Hint: Use
the previous exercise.
10. Consider the prime graph B n introduced in Problem 11 of Problem Set 4.4.
Use induction on n to show that, if n is even, B n has a perfect matching. You
may use without proof the fact that there is a prime number between k and
2k for k ≥ 2.
11. Prove that C is a cover of G if and only if V (G) \ C is a set of pairwise nonad-
jacent vertices.
12. Show that it is not always true that there exist a matching M and a cover C
of the same size.
14. In the previous problem interpret the meaning of a cover of the bipartite
graph in terms of the matrix N .
15. Find a bipartite graph G with bipartition A, B where |A| = |B | = 5, and having
the following properties. Every vertex has degree at least 2, the total number
190 CHAPTER 8. MATCHINGS
of edges is 16, and G has no perfect matching. Why does your graph not have
a perfect matching?
16. Suppose that for some n ≥ 1, graph G with p vertices satisfies p = 2n and
d eg (v) ≥ n for every vertex v. Prove that G has a perfect matching. (Hint:
Prove that if M is a matching that is not perfect, then there exists an aug-
menting path of length 1 or 3.)
17. Suppose that M is a matching of G that is not contained in any larger match-
ing, and that M 0 is a maximum matching of G. Prove that |M 0 | ≤ 2|M |.
(b) Y = B ∩ Z .
For example, in the graph of Figure 8.2 we have
X 0 = {b, d }, X = {a, b, c, d , e, f }, Y = {g , h, i , j , k, l }.
As a second example, consider the same graph but with a different matching,
shown in Figure 8.4. Then we have
X 0 = {d }, X = {d , b, f }, Y = {i , l }.
8.3. KÖNIG’S THEOREM 191
A a b c d e f
B g h i j k l
Notice that any alternating path P (v) has even length if v ∈ X and odd
length if v ∈ Y . Since the first edge of any alternating path beginning at a ver-
tex in X 0 is not a matching edge, and every second edge is a matching edge, it
follows that
(b) C = Y ∪ (A \ X ) is a cover of G;
Proof: Suppose that (a) is false, and let u ∈ X , v ∈ B \ Y , {u, v} ∈ E (G). Then
adding v to the even-length alternating path P (u) from X 0 to u, gives us an
odd-length alternating path to v, which implies that v ∈ Y , a contradiction.
192 CHAPTER 8. MATCHINGS
For (b), the only edges of G that are not incident with an element of C are
those from X to B \ Y . However, no such edges exist by part (a), so C is a cover.
Now suppose that (c) is false, and let u ∈ Y , v ∈ A\X , {u, v} ∈ M . Then adding
v to the odd-length alternating path P (u) from X 0 to u, gives us an even-length
alternating path to v, which implies that v ∈ X , a contradiction.
For (d ), from part (c), every edge of M joins a vertex in Y to a vertex in X , or
joins a vertex in A \ X to a vertex in B \ Y . The number of edges of the first type
is |Y | − |U |. Also, by the fact that X 0 ⊆ X , every vertex in A \ X is saturated by M ,
so the number of edges of the second type is |A \ X |. It follows that
|M | = |Y | − |U | + |A \ X | = |C | − |U |.
Finally, (e) is easy—if such a vertex v exists, then P (v) is an augmenting path.
We can check that the conclusions of Lemma 8.3.2 are satisfied in the two
examples above. Notice in particular, that in Figure 8.2 we have U = {g , j }, and,
for example, augmenting paths to g and j are given by bi c g and bi c j . If we use
the latter path to get a larger matching, then we get the matching of Figure 8.4.
In Figure 8.4, there are no unsaturated vertices in Y , so U = ;.
Proof of Theorem 8.3.1: Let M be a maximum matching of G. Then from
Lemma 8.1.1 and part (e) of Lemma 8.3.2, U must be the empty set, so |U | = 0.
Therefore, from parts (b) and (d ) of Lemma 8.3.2, C = Y ∪ (A \ X ) is a cover of G
with |C | = |M |, and the result follows immediately from Lemma 8.2.2.
Notice in the example of Figure 8.4 that there is no unsaturated vertex in
Y . The construction of the proof of König’s Theorem then gives the cover C =
Y ∪ (A \ X ) = {a, c, e, i , l }. It has size 5, and therefore shows that the matching
shown there is maximum.
Problem 8.3.3. Let G be a bipartite graph with bipartition A, B , where |A| =
|B | = n. Prove that if G has q edges, then G has a matching of size at least q/n.
Solution: Notice that what is needed, is to prove that the maximum size of
a matching is at least q/n. By König’s Theorem, it is enough to show that the
minimum size of a cover is at least q/n. Suppose that C is a cover of G. There
can be at most n edges incident to any element of C , so there can be at most
n|C | edges incident with one or more elements of C . But C is a cover, so every
edge must be incident with one or more elements of C . Therefore, n|C | ≥ q,
or |C | ≥ q/n. Since every cover contains at least q/n vertices, therefore, the
minimum size of a cover is at least q/n, and we are done.
8.3. KÖNIG’S THEOREM 193
1 2 3 4
5 6 7 8
(q + 1)/n. (In other words, show that the value q/n is the best possible in
Problem 8.3.3.)
5. Find a maximum matching and a minimum cover in the graph of Figure 8.6,
by applying the algorithm, beginning with the matching indicated.
A 1 2 3 4 5
B a b c d e
6. Find a maximum matching and a minimum cover in the graph of Figure 8.7,
by applying the algorithm, beginning with the matching indicated.
7. Find a maximum matching and a minimum cover in the graph of Figure 8.8,
by applying the algorithm, beginning with the matching of size 18 consisting
of all the edges oriented from northwest to southeast.
8. Let G be bipartite with bipartition A, B . Suppose that C and C 0 are both cov-
ers of G. Prove that Ĉ = (A ∩C ∩C 0 ) ∪ (B ∩ (C ∪C 0 )) is also a cover of G.
9. In the previous exercise, prove that if C and C 0 are minimum covers, then so
is Ĉ .
196 CHAPTER 8. MATCHINGS
|N (D)| ≥ |D|.
Let D = A \ C . Then
A A\C C ∩A
B C ∩B B\C
q i ∈ Q i for i = 1, 2, . . . , n.
8.5. SYSTEMS OF DISTINCT REPRESENTATIVES 199
1 2 3 4
a b c d
|N (D)| ≥ |D|.
Proof: Clearly, if |A| 6= |B |, then G has no perfect matching. On the other hand,
if |A| = |B |, then G has a perfect matching if and only if it has a matching satu-
rating every vertex in A, and then the result follows from Hall’s Theorem.
Another application is to regular bipartite graphs. We can show that these
always have perfect matchings, since it is easy to show that they always satisfy
the condition of Corollary 8.6.1. This result will be used in the next section,
when we discuss edge-colouring.
Proof: Let A, B be a bipartition of G. Then since every edge has one end in A
P P
and the other in B , we have v∈A d eg (v) = v∈B d eg (v). It follows that k|A| =
k|B |, and therefore, since k > 0, that |A| = |B |. Now let D ⊆ A. Then since every
edge incident with a vertex in D has its other end in N (D), we have
X X
d eg (v) ≤ d eg (v).
v∈D v∈N (D)
It follows that k|D| ≤ k|N (D)|, and therefore (again, since k > 0) that |N (D)| ≥
|D|. Now by Corollary 8.6.1, G has a perfect matching.
Note: Theorem 8.6.2 works even if G contains multiple edges.
8.6. PERFECT MATCHINGS IN BIPARTITE GRAPHS 201
2. In the graph of Problem Set 8.3, #7, find a set D of vertices such that
|N (D)| < |D|.
5. Let G be a bipartite graph with bipartition A, B such that |A| = |B |, and for
every proper nonempty subset D of A, we have |N (D)| > |D|. Prove that
for every edge e ∈ E (G) there is a perfect matching containing e.
6. Check that the proof of Theorem 8.6.2 works even for bipartite multi-
graphs. (Note that a bipartite multigraph can have multiple edges, but
is not allowed to have loops.)
12. Let G be a bipartite graph with bipartition A, B where |A| = |B | = 2n. Sup-
pose that, for every subset X ⊆ A and every subset X ⊆ B such that |X | ≤ n,
|N (X )| ≥ |X |. Prove that G has a perfect matching.
202 CHAPTER 8. MATCHINGS
8.7 Edge-colouring
An edge k-colouring of a graph G is an assignment of one of a set of k colours
to each edge of G so that two edges incident with the same vertex are assigned
different colours. Consider the set of edges M that are assigned a particular
colour. Then for any vertex v, there can be at most one edge of M incident
with v. That is, M is a matching, and so an edge k-colouring of G amounts to
a partitioning of the edges of G into k matchings. Figure 8.11 shows an edge
3-colouring of a graph, where the colours are indicated by different ways of
drawing the edges.
Note that the proof of Lemma 8.7.2 suggests a modification of the matching
algorithm which will efficiently find a matching saturating all vertices of max-
imum degree. Therefore, since the proof of Theorem 8.7.1 just requires us to
find and delete such a matching and repeat, there is an efficient algorithm for
finding an edge ∆-colouring of a given bipartite graph.
204 CHAPTER 8. MATCHINGS
The answer turns out to be the smallest integer that is at least q/m and also
is at least ∆. This follows from the next result.
Theorem 8.8.1. Let G be a graph with q edges, and suppose k, m are positive
integers such that
8.8. AN APPLICATION TO TIMETABLING 205
(b) q ≤ km.
Then G has an edge k-colouring in which every colour is used at most m times.
Proof: Suppose that the colouring does not already have the desired property,
so that some colour, say red, is used at least m + 1 times. If every other colour is
used at least m times, then
a contradiction. So there exists a second colour, say blue, that is used at most
m − 1 times.
Now the red edges and the blue edges form disjoint matchings M and M 0 of
G. Consider the spanning subgraph H of G having edgeset M ∪ M 0 . Then every
vertex of this graph has degree 0 or 1 or 2. Therefore, each component of H
consists of a path or a cycle with edges alternately in M and M 0 . Moreover, any
cycle is even. Since |M | > |M 0 |, there must exist a component of H containing
more edges of M than of M 0 . Such a component must consist of an augmenting
path for M 0 . If we use that path to make M 0 larger by one and to make M smaller
by one, then we have a new edge k-colouring of G such that red is used fewer
times, and blue is still used at most m times. We can repeat this argument until
we find a colouring with the desired property.
Now we can solve the bounded edge-colouring problem for bipartite graphs by
combining Theorems 8.7.1 and 8.8.1.
(a) ∆ ≤ k, and
(b) q ≤ km.
3. Prove that a k-regular bipartite graph has an edge k-colouring, using Theo-
rem 8.6.2.
5. Show that Theorem 8.8.1 does not work for vertex-colouring. That is, show
that if a graph can be k-coloured and mk ≥ p, it is not necessarily true that
there is a k-colouring in which each colour is used at most m times.
207
208 INDEX
Terquem Problem, 38
tree, 125
Unambiguous expression, 43
unique, 153
vertices, 93
walk, 110
XY-construction, 190