Bertrand Guenin - MATH 239 - Introduction To Combinatorics (Lecture Notes) - University of Waterloo (2015)
Bertrand Guenin - MATH 239 - Introduction To Combinatorics (Lecture Notes) - University of Waterloo (2015)
Chris Thomson
1
Contents
1 Introduction, Permutations, and Combinations 4
1.1 Course Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.2 Sample Counting Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.3 Sample Graph Theory Problems . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.4 Permutations and Combinations . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.4.1 Set Notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.4.2 Permutations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.4.3 Application: Binomial Theorem . . . . . . . . . . . . . . . . . . . . . . 6
4 Binary Strings 21
4.1 Generating Functions for Strings . . . . . . . . . . . . . . . . . . . . . . . . . 22
4.2 Counting Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
4.2.1 Recursive String Definitions . . . . . . . . . . . . . . . . . . . . . . . . 25
2
7.5.4 Bridges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
8 Trees 52
8.1 More on Bipartite Graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
8.2 Graph Colouring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
9 Planar Graphs 57
9.1 Platonic Graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
9.2 Review of Planar Graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
9.3 Planar Solids . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
9.4 Non-Planar Graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
9.5 Kuratowski’s Theorem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
9.6 Graph Colouring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
9.7 Dual Graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
10 Matching 75
10.1 Application: co-op . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
10.2 Saturation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
10.2.1 Algorithm for Maximum Matching . . . . . . . . . . . . . . . . . . . . 79
10.3 Vertex Covers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
10.4 XY-Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
10.4.1 Algorithm For Finding a Maximum Matching and Minimal Vertex Cover 82
10.5 Hall’s Theorem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
3
1 Introduction, Permutations, and Combinations
← January 7, 2013
1.1 Course Structure
The grading scheme is 50% 55% final, 30% midterm, 10% quizzes 5% participation marks
(clicker questions), and 10% assignments. There are ten quizzes and ten assignments. The
quizzes will not be announced in advance, and each quiz consists of a single clicker question.
Assignments are typically due on Friday mornings at 10 am. in the dropboxes outside of
MC 4066. The midterm exam is scheduled for March 7, 2013, from 4:30 pm - 6:20 pm.
There is no textbook for the course, but there are course notes available at Media.doc in
MC, and they’re highly recommended.
MATH 239 is split into two parts: counting (weeks 1-5) and graph theory (weeks 6-12).
See the course syllabus for more information – it’s available on Waterloo LEARN.
This is a finite problem. You could count all of the possibilities manually in this case.
However, this problem could be made more complicated to a point where manually count-
ing all possibilities would become quite cumbersome, as is the case in the next problem.
Problem 1.2 (Cuts). How many ways are there to cut a string of size 372,694 into parts
of sizes 3, 17, 24, and 96?
Definition. A positive integer n has a composition (m1 , m2 , . . . , mk ), where m1 , . . . , mk
are positive integers and where n = m1 + m2 + . . . + mk . m1 , . . . , mk are the parts of the
composition.
Problem 1 could be rephrased as looking for the number of compositions of 5 where all parts
are 1 or 2.
Problem 1.3. How many compositions of n exist such that all parts are odd?
Problem 1.4 (Binary Strings). Let S = a1 , a2 , . . . , an where ai ∈ {0, 1}. How many strings
S exist?
For each ai , there is the choice between 0 or 1, and that choice is independent for each
character of the string (for each ai ). So, there are 2n binary strings of length n.
Problem 1.5. How many binary strings of size n exist that do not include the substring
1100?
4
For example: 10101100101 6∈ S.
Problem 1.6. How many binary strings of size n exist such that there is no odd-length
sequences of zeroes?
For example: 100100100011 6∈ S.
Problem 1.7 (Recurrences). How many times does a recursive function get called for a
particular input n?
We will also be using one piece of notation you may not be familiar with: [n] := {1, 2, . . . , n}.
1.4.2 Permutations
Definition. A permutation of [n] is a rearrangement of the elements of [n]. The number
of permutations of a set of n objects is n × (n − 1) × . . . × 1 = n!.
For example: the number of permutations of 6 objects is 6×5×4×3×2×1 = 6! permutations.
Why is this the case? Simple: there are n choices for the first position, (n − 1) choices
for the second position, (n − 2) choices for the third position, and so on, until there’s 1
choice for the nth position.
5
1.4.3 Application: Binomial Theorem
← January 9, 2013
n
X n k
(1 + x)n = x
k
k=0
1 2 3
z }| { z }| { z }| { 3 3 3 2 3 3
(1 + x) = (1 + x) (1 + x) (1 + x) = 1 + 3x + 3x2 + x3 =
3
+ x+ x + x
0 1 2 3
Proof.
1 2 n
z }| { z }| { z }| {
n
(1 + x) = (1 + x) (1 + x) · · · (1 + x)
n
In order to get xk , we need to choose x in k of {1, . . . , n}. There are k ways of doing
this.
6
n n−1 n−1
Proposition. = +
k k k−1
Proof. Let S be the set of k-subsets of [n]. Then |S| = nk . Partitioning S, let S1 be the
n = 0: 1
n = 1: 1 1
n = 2: 1 2 1
n = 3: 1 3 3 1
n = 4: 1 4 6 4 1
r
q+r X q+i−1
Proposition. =
q i=0
q−1
5 2 3 4
For example: let q = 3, r = 2. Then we have: = + + .
3 2 2 2
Xr
|S| = |Si |
|{z}
q+r i=0
( q ) | {z }
(q+i−1
q−1 )
7
Definition. The function f is onto (or a surjection) if for all y ∈ T , there exists x ∈ S
such that f (x) = y. That is, all elements in the codomain T are the image of an element in
S. Multiple elements in S can map to the same element in T .
Definition. The function f is a bijection if it is both injective and onto. That is, there is
a one-to-one mapping between elements in S and T , and vice versa.
Aside: suppose n = 5 and k = 2. Then, the bijection could be {1, 3} → {2, 4, 5} (the
complement function).
The bijective function is f (A) = [n]\A (the complement function). Check: f is its own
inverse (let g = f ).
8
3.1.1 A General Counting Problem
Let S be the set of objects σ. Each object σ has a weight w(σ). We want to know how
many objects of S have some weight k.
Example 3.2. Let σ ⊆ [n], w(σ) = |σ|. The question becomes: how many k-subsets of [n]?
Example 3.3. Let σ be a set of coins (1¢, 5¢, 10¢, 25¢, $1, $2), and let w(σ) be the total
value of the coins in σ.
The question becomes: how many sets of coins have total value k? In other words, how
many ways are there to give k amount of change?
σ w(σ) xw(σ)
∅ 0 1
{1} 1 x
{2} 1 x
{3} 1 x
{1, 2} 2 x2
{1, 3} 2 x2
{2, 3} 2 x2
{1, 2, 3} 3 x3
φS (x) = 1 + 3x + 3x2 + x3 = (1 + x)3 is the generating function. Notice that the coefficients
of each term are the number of objects who have that the weight indicated by the exponent
of the x in that term.
Remember: the generating function for S with weights w is φS (x) = k≥0 ak xk , where
P
ak is the number of objects of size k in S.
← January 14, 2013
Example 3.5. Let S be the set of subsets of [n], and w(σ) = |σ|.
X n
φS (x) = xk = (1 + x)n
k
k≥0
Note that nk is included because that’s the number of k-subsets of [n]. φS (x) = (1 + x)n
9
2. φ0S (1) = sum of the weight of all the objects in S.
Together, we get:
φ0S (1)
= average weight of objects in S
φS (1)
Considering the previous example again, we know that |S| = 2n and the average weight is
clearly n2 . We can verify that with this proposition.
In order to work further with generating functions, we’ll first need to learn how to manipulate
power series generally.
A(x) = a0 + a1 x + a2 x2 + · · ·
B(x) = b0 + b1 x + b2 x2 + · · ·
Note that this definition is consistent with the definition of addition for polynomials.
10
Definition. We define multiplication of power series as follows.
n
!
X X
A(x)B(x) := ak bn−k xn
n≥0 k=0
Example 3.6.
(1 + x + x2 + x3 + · · · )(1 − x)
= 1 · 1 + (1 · −1 + 1 · 1)x + (1 · 1 + 1 · −1)x2 + · · ·
=1
1
We will use the notation B(x) = A(x) to indicate that B(x) is the inverse of A(x), and
vice versa.
Example 3.7. The inverse of (1 + x + x2 + · · · ) is (1 − x), as shown in the previous example.
Question: does every power series have an inverse? No. For example, (x + x2 ) does not
have an inverse.
Proof. Suppose (x+x2 ) has an inverse. If (x+x2 ) has an inverse, there would exist constants
bi such that
(x + x2 )(b0 + b1 x + b2 x2 + b3 x3 + · · · ) = 1
Clearly, this is impossible. In order to equal 1, b0 must multiply by some constant term,
however there is no other constant term. Therefore, our assumption was incorrect, meaning
(x + x2 ) does not have an inverse.
Remark: if a power series does not have a constant term then it has no inverse, and vice
versa.
Theorem. If the constant term of A(x) is non-zero, then A(x) has an inverse, and we can
find it.
Notation: given a power series A(x), we say [xk ]A(x) represents the coefficient of xk .
Example 3.8. Find the inverse of 1 − x + x2 − x3 + x4 − · · · .
(1 − x + x2 − x3 + x4 − · · · )(b0 + b1 x + b2 x2 + · · · ) = 1
| {z }
(?)
[x0 ](?) = 1 =⇒ 1 · b0 = 1 =⇒ b0 = 1
[x1 ](?) = 0 =⇒ 1 · b1 − 1 · b0 = 0 =⇒ b1 = b0 = 1
[x2 ](?) = 0 =⇒ 1 · b2 − 1 · b1 + 1 · b0 = 0 =⇒ b2 = b1 − b0 = 0
11
3.3.1 Finding Inverses
← January 16, 2013
Given:
X
A(x) = an xn where (a0 6= 0)
n≥0
We want to find:
X
B(x) = bn x n
n≥0
3.3.2 Compositions
Definition. Let A(x) and B(x) be formal power series defined by:
X X
A(x) = an xn B(x) = bn x n
n≥0 n≥0
Example 3.9. Let A(x) = 1 + x + x2 + x3 + · · · and B(x) = 2x. Then the composition is
A(B(x)) = 1 + 2x + 4x2 + 8x3 + · · · .
Question: is the composition of two formal power series a formal power series itself? No.
Example 3.10. Suppose we pick A(x) = 1 + x + x2 + x3 + · · · and B(x) = 1 + x.
12
Example 3.11. Suppose we pick A(x) = 1 + x + x2 + x3 + · · · and B(x) = x + x2 .
Theorem. Let A(x) and B(x) be formal power series, and [x0 ]B(x) = 0 (B(x)’s constant
is zero). Then A(B(x)) is a formal power series.
Aside:
A(B(x)) = 1 + (x + x2 )1 + (x + x2 )2 + (x + x2 )3 + · · ·
| {z } | {z } | {z }
x(1+x) x(1+x) x(1+x)
Proof. We need to show that for any fixed k, [xk ]A(B(x)) is finite.
We made the last sum finite because we’re interested in the coefficient of xk only. Note that
this last line shows we can determine the coefficient in a finite number of steps, since k is
finite.
A × B := {(a, b) a ∈ A, b ∈ B}
13
3.4 The Sum and Product Lemmas
Let’s consider a bin of two red marbles – one large marble (denoted R), and one small
marble (denoted r). We define A to be the set of all selections of ≥ 1 marbles. We know:
A = {{r}, {R}, {r, R}}
w(σ) = |σ|
φA (x) = x + x + x2 = 2x + x2
Let’s now consider a bin of green marbles – two large marbles (denoted G). We define B to
be the set of all selections of ≥ 1 marbles. We know:
B = {{G}, {G, G}}
w(σ) = |σ|
φB (x) = x + x2
Note: you can think of a generating series as the sum of all objects’ xw(σ) , or you can
think of it as the sum of all ak xk .
φS (x) = x2 + x2 + x3 + x3 + x3 + x4
= 2x2 + 3x3 + x4
= (x + x + x2 )(x + x2 )
= φA (x) · φB (x)
14
This works in general.
Each term in φA (x) corresponds to an object in A, and each term in φB (x) corresponds
to an object in B. When you find the product, it automatically does the counting for you,
due to exponentiation laws.
Theorem (Product Lemma). Let A be a set where objects have weight α, and let B be a
set where objects have weight β. Let S = A × B be a set of all objects (a, b) ∈ S, where
w[(a, b)] = α(a) + β(b). Then:
Proof.
X
φS (x) = xw[(a,b)]
(a,b)∈S
X
= xα(a)+β(b)
(a,b)∈S
X X
= xα(a) · xβ(b)
a∈A b∈B
| {z } | {z }
φA (x) φB (x)
Suppose n = 3 and k = 2. You’ll have (0, 3), (1, 2), (2, 1), and (3, 0) – four possibilities
(notice order matters).
N appears k times
z 0 }| {
Now, let S = N0 × N0 × . . . × N0 . The objects in S are sequences of form (m1 , m2 , . . . , mk ),
where mi ≥ 0, mi ∈ Z. We define w[(m1 , m2 , . . . , mk )] = m1 + m2 + . . . + mk .
1
φS (x) = [φN0 (x)]k = by the product lemma
(1 − x)k
generating functions for now, and find a combinatorial proof for this.
When you use the product lemma, you need to ensure:
1. Ensure it’s used on something found by taking the cartesian product.
15
2. The weight is equal to the sum of the weights.
Example 3.15. Let n = 5 and k = 3. We have:
(1, 2, 2): • | • • | • •
(2, 3, 0): • • | • • • |
We always want two bars because k = 3. In general, we always want k − 1 bars. We want
n dots. The combination above is formed by the need to place k − 1 bars among all of the
positions.
By combining the previous two examples, we have proven the following theorem.
Theorem (Theorem 1.6.5).
n 1 n+k−1
[x ] =
(1 − x)k k−1
xk
φS (x) = [φN (x)]k =
(1 − x)k
1
We’re interested in finding [xn ]xk (1−x) k. ← January 21, 2013
1 1
[xn ]xk k
= [xn−k ]
(1 − x) (1 − x)k
(n − k) + k − 1
=
k−1
n−1
=
k−1
16
Example 3.17. We now want to know the number of compositions of n (where n ≥ 1)
where we have an arbitrary number of parts. We have: S = N ∪ N2 ∪ N3 ∪ N4 ∪ N5 ∪ . . ..
The weight function is the same as before – the sum of the parts. That gives us:
X X x k
φS (x) = φNk (x) =
1−x
k≥1 k≥1
We want:
X x k
[xn ]
1−x
k≥1
X x k x
x
= 1−xx =
1−x 1 − 1−x 1 − 2x
k≥1
x
We still need to figure out the coefficient [xn ] 1−2x .
x 1
[xn ] = [xn−1 ] (1)
1 − 2x 1 − 2x
= [xn−1 ](1 + y + y 2 + . . .) (2)
n−1 2
= [x ](1 + (2x) + (2x) + . . .) (3)
n−1
=2 (4)
(1) is a common, useful trick. We eliminate any instances of x that are simply multiplied
by something, by reducing the power of the coefficient we’re looking for. (4) is true since
every term is in the form (2x)k .
We might be able to avoid generating functions in some cases by using a combinatorial proof.
Now, we’ll look at an arbitrary, convoluted example where a combinatorial proof would not
suffice. This aims to show that generating functions are solid and can apply in many more
situations than combinatorial proofs.
Example 3.18. We want to find the number of compositions of n with 2k parts, where the
first k parts are ≤ 5 and the last k parts are ≥ 3.
17
A specific instance of this problem is when n = 22 and k = 3, we have:
(|{z}
. . . , |{z}
... )
≤5 ≥3
(1, 3, 5, 3, 6, 4)
| {z } | {z }
≤5 ≥3
It’s useful to think about what you’re counting. In this case, you’re counting the k-tuples,
so this is the cartesian product of six sets (the first three being the set of positive integers
≤ 5 and the last three being the set of integers ≥ 3).
N≤5 = {1, 2, 3, 4, 5}
N≥3 = {3, 4, 5, . . .}
S = (N≤5 )k × (N≥3 )k
The weight is the sum of the six individual numbers in the tuple, since N≤5 and N≥3 ’s
weights are both defined by w(a) = a, which gives us:
φN≤5 (x) = x + x2 + x3 + x4 + x5
φN≥3 (x) = x3 + x4 + x5 + . . .
← January 23, 2013
We can expand the generating functions φN≤5 (x) and φN≥3 (x).
φN≤5 (x) = x + x2 + x3 + x4 + x5
= x(1 + x + x2 + x3 + x4 )
1 − x5
=x
1−x
φN≥3 (x) = x3 + x4 + x5 + . . .
= x3 (1 + x + x2 + . . .)
x3
=
1−x
Now, we have S = (N≤5 )k ×(N≥3 )k with weight function w[(a1 , . . . , a2k )] = a1 +a2 +. . .+a2k .
By the product lemma, we get:
5 k
3 k
k 1−x x
φS (x) = x
1−x 1−x
= x4k (1 − x5 )k (1 − x)−2k
We’re still interested in finding [xn ]φS (x). This becomes tedious, but the general idea is:
[xn ] x4k
|{z} · (1 − x5 )k · (1 − x)−2k
| {z } | {z }
collapse into [xn ] to become [xn−4k ] expand with binomial theorem use formula [xn ] 1
(1−x)k
18
After much tedious work, you’ll discover that the final result is:
b n−4k
5 c
n
X k
i n − 5i − 2k − 1
[x ]φS (x) = (−1)
i=0
i 2k − 1
This couldn’t have been found with a combinatorial proof. That’s why generating functions
are powerful – they work even in convoluted situations like this one.
Example 3.19. We’re interested in the number of compositions of n where all parts are
odd. There can be an arbitrary number of parts.
We have Nodd = {1, 3, 5, 7, . . .}, with its weight function defined to be w(a) = a for any
a ∈ Nodd . That gives us its generating function:
φNodd (x) = x + x3 + x5 + x7 + . . . (1)
2 4 6
= x(1 + x + x + x + . . .) (2)
2 3 2
= x(1 + y + y + y + . . .) where y = x (3)
x
= (4)
1−y
x
= (5)
1 − x2
(3) is an acceptable composition because x2 has a constant term of zero.
[
Now, we have that S = () Nkodd . By the sum and product lemmas, the generating
k≥1
function for S is:
X
φS (x) = 1 + φkNodd (x) (1)
k≥1
X k
x
=1+ (2)
1 − x2
k≥1
X x k
= (3)
1−x
k≥0
x
= 1 + z + z 2 + z 3 + . . . where z = (4)
1 − x2
1
= (5)
1−z
1
= x (6)
1 − 1−x 2
1 − x2
= (7)
1 − x − x2
19
x
(4) is a valid composition because 1−x2 has a constant term of zero.
2
1−x
What is [xn ] 1−x−x 2 ? (Don’t think of assigning values to x. Just focus on canceling them
out.)
1 − x2 X
2
= an xn
1−x−x
n≥0
1 − x = (1 − x − x2 )(a0 + a1 x + a2 x2 + . . .)
2
= a0 + a1 x + a2 x2 + a3 x3 + . . . − a0 x − a1 x2 − a2 x3 − a3 x4 − . . . − a0 x2 − a1 x3 − a2 x4 − a3 x5 − . . .
= a0 + (a1 − a0 )x + (a2 − a1 − a0 )x2 + (a3 − a2 − a1 )x3 + . . .
We know a0 = 1 and (a1 − a0 ) = 0, and so on. We can express a recurrence relation for this.
a0 = 1
a1 − a0 = 0 =⇒ a1 = 1
a2 − a1 − a0 = −1 =⇒ a2 = −1 + a1 + a0 = 1
a3 − a2 − a1 = 0 =⇒ a3 = a1 + a2 = 2
a4 = a3 + a2 = 3
a5 = a4 + a3 = 5
..
.
For all n ≥ 3, we have that an = an−1 + an−2 . This defines the fibonacci numbers.
a+b
Definition. The golden ratio is a pair of integers a and b such that a = ab . It’s a ratio
that comes up in nature a lot, and is aesthetically pleasing.
an
You can approximate the golden ratio with the Fibonacci numbers. an−1 approaches the
golden ratio as n → ∞.
Example 3.20. Let Sn be the set of compositions into odd numbers of n. |Sn | = |Sn−1 | +
|Sn−2 | for n ≥ 2. Sn is partitioned by Sn−1 and Sn−2 . Is there a bijection between Sn and
Sn−1 ∪ Sn−2 ?
Notice that each element in Sn−1 and Sn−2 can be obtained from Sn by either removing the
last element entirely, or by subtracting 2 from the last element. That’s the bijection we’re
looking for, which we will now define more formally as f : Sn → Sn−1 ∪ Sn−2 :
(
(a1 , . . . , ak−1 ) ak = 1
f (a1 , . . . , ak ) =
(a1 , . . . , ak−2 ) ak ≥ 3
20
Note that f (a1 , . . . , ak ) is undefined for 1 < k < 3, but that’s okay because we’re only
interested in odd natural numbers.
4 Binary Strings
Definition. A binary string is a string composed of 0s and 1s. For example, 011001110011
is a binary string.
Definition. We define the operation of concatenation of two binary strings a1 , a2 as
a1 a2 . For example, if a1 = 110 and a2 = 011, the concatenation a1 a2 = 110011.
Definition. The concatenation AB of two sets (A and B) of binary strings is de-
fined as all possible strings formed as concatenations of one string from set A followed
by one string from set B. For example, if A = {011, 11} and B = {10, 0}, then AB =
{01110, 0110, 1110, 110}.
Definition. Suppose A is a set of strings. Then Ak = AAAAA
| {z . . . A}.
k times
? 2 3
Definition. We define A = {} ∪ A ∪ A ∪ A ∪ . . ., where represents the empty string.
?
Example 4.1. What is {0, 1} ? It’s the set of all binary strings.
5 5 5
Example 4.2. What’s {0, 1} ? {0, 1} = {0, 1}{0, 1}{0, 1}{0, 1}{0, 1}. {0, 1} is the set of
all binary strings of length 5.
Example 4.3. Describe the set S of all binary strings with no three consecutive 1s. For
example: a = 01100011101001 6∈ S, b = 011110 6∈ S, but c = 0110010011011 ∈ S. We aim
to express S using expression-? concatenation.
11 ∈ S
c = 0, 110, 0, 10, 0, 110, |{z}
| {z }
(1) (2)
?
1. A sequence of at most two ones followed by zero, repeated: {0, 10, 110}
2. A sequence of zero, one, or two ones: {, 1, 11}.
? ?
Therefore, S = {0, 10, 110} {, 1, 11}. Note that is an element of {anything} .
Definition. A block in a binary string is equal to the maximum sequence of 0s or 1s.
Example 4.4. List all the blocks in the string 1100011110110101.
11 |{z}
|{z} 000 1111 0 |{z}
|{z } |{z} 11 |{z}
0 |{z}
1 |{z}
0 |{z}
1
21
Example 4.5. Describe the set S of strings with no blocks of length 2. For example,
a = 1011000101 6∈ S, but b = 1110111000101000 ∈ S.
b = |{z} 000 ∈ S
111 , 0111, 0001, 01, |{z}
| {z }
(1) (2) (3)
1. A sequence of ones, of any length other than length 2: {, 1, 111, 1111, 11111, . . .}.
2. A sequence of zeroes (of any non-zero length other than length 2), followed by a se-
quence of ones (of any non-zero length other than length 2), repeated: [{0, 000, 0000, . . .}{1, 111, 1111, . . .}]? .
3. A sequence of zeroes, of any length other than length 2: {, 0, 000, 0000, 00000, . . .}.
?
It’s important to note that {1, 111, 1111, . . . , 0, 000, 0000, . . .} does not work because you
could pick two zeroes or two ones consecutively, which is not allowed. You have to be very
careful that you don’t generate strings that you don’t want to generate.
Let S be the set of binary strings. Then the generating function for S is defined as:
X
φS (x) = an xn where an is the number of strings of length n ∈ S
n≥0
← January 28, 2013
Example 4.6. Let A = {0, 01} and B = {0, 10}. Their generating functions are φA (x) =
φB (x) = x + x2 . What is the generating function for AB?
It’s easy to see that AB = {00, 010, 0110}, which gives us φAB (x) = x2 + x3 + x4 . Also note
that:
φA (x) · φB (x) = (x + x2 ) · (x + x2 )
= x2 + 2x3 + x4
Therefore, in this case, φAB (x) 6= φA (x)·φB (x). Why is this? A×B = {(0, 0), (01, 0), (0, 10), (01, 10)}.
Note that the string for (01, 0) and (0, 10) is the same (010), but it’s only going to be included
in AB once. That’s where the trouble is.
Definition. A, B is ambiguous if all three of these properties hold:
• (a1 , b1 ), (a2 , b2 ) ∈ A × B
• (a1 , b1 ) 6= (a2 , b2 )
• a1 b1 = a2 b2
In the previous example, (0, 10)(01, 0) ∈ A × B and (0, 10) 6= (10, 0), but 010 = 010.
22
Theorem (Product Lemma for Strings). Let A, B be sets of binary strings. If A, B are
unambiguous, then φAB (x) = φA (x) · φB (x).
Proof. In order to prove this theorem, we need to show that under the given assumptions,
|AB| = |A × B|, which we can show by showing there is a bijection between AB and A × B.
Let Sn be the set of strings of length n of AB, and let Tn be the set of pairs (a, b) ∈ A × B
such that length(a) + length(b) = n. Our claim is that f [(a, b)] = ab, f : Tn → Sn is a
bijection.
Theorem (Sum Lemma for Strings). Let S be a set of binary strings. Let A, B be partitions
of S. Then φS (x) = φA (x) + φB (x).
The proof of the sum lemma for strings is the same as the proof of the sum lemma for
generating functions in general.
Definition. An expression is unambiguous if there exists a unique way of writing every
string according to the expression.
?
For example: {0, 10, 110} {, 1, 11} is the set of strings with no more than two consecutive
ones. Let’s examine the arbitrary string 0001101011001. If we split the string after every
zero, we get 0, 0, 0, 110, 10, 110, 0, 1, which is a unique way of breaking down the string.
1
Proposition. Suppose A? is unambiguous and 6∈ A. Then φA? (x) = 1−φA (x) .
23
Note that the composition used in this proof is valid because 6∈ A, so the constant of φA (x)
is zero as required. That is, [x0 ]φA (x) = 0 makes the composition acceptable.
We have:
φ{0,10,110} (x) = x + x2 + x3
1
φ{0,10,110}? (x) = by proposition
1 − x − x2 − x3
φ{,1,11} (x) = 1 + x + x2
φS (x) = φ{0,10,110}? (x) · φ{,1,11} (x) by the product lemma for strings
1 + x + x2
=
1 − x − x2 − x3
Example 4.8. Let S be the set of binary strings where no block has length 2. Recall from
before:
S = ABC
A = {, 1, 111, 1111, . . .}
B = ({0, 000, 0000, . . .}{1, 111, 1111, . . .})?
f = x + x3 + x4 + x5 + . . .
= x + x2 + x4 + x5 + . . . − x2 by adding and removing x2
= x(1 + x + x2 + . . .) − x2
x
= − x2
1−x
Now, we can easily state the generating functions for A, B, and C:
φA (x) = 1 + f
1
φB (x) =
1 − f2
φC (x) = 1 + f
24
We can now use the product lemma on ABC to find φS (x).
One might attempt to describe S as {, 0, 1}S, however that is ambiguous. S = {}∪{0, 1}S
is unambiguous. Since there are two terms of length 1, applying the sum & product lemmas,
we get:
Note that [xn ]φS (x) = 2n because the number of strings with length n is 2n .
Example 4.10. Let S be the set of all binary strings with no three consecutive ones (111).
In order to check this, we must verify that the two sides of the union are disjoint. That’s
easy to confirm: the elements on the left have no zeroes in them, and all elements on the
25
right have a zero. Therefore, the sum lemma applies.
Idea:
1. Write two equations relating S and F . This is the trickiest part.
2. Write two equations relating φS (x) and φF (x).
3. Solve and get an expression for φS (x).
The first equation relating S and F is {} ∪ S{0, 1} = S ∪ F . We need to verify this by
showing both directions of the equality.
Showing {} ∪ S{0, 1} ⊆ S ∪ F : let a ∈ {} ∪ S{0, 1}. We need to show that a ∈ S or a ∈ F .
Showing S{11010} ⊇ F : let a ∈ F . Then we know that the string a with its last character
truncated off is an element of S (it no longer can contain the forbidden string). Therefore,
the prefix to 11010 is also an element of S, as required.
Showing S{11010} ⊆ F : let a ∈ S{11010}. We need to show that the string ends in 11010,
and that the forbidden string does not occur elsewhere. But what if the forbidden string is
partially in the ∈ S part and partially in the 11010 part? Shifting the forbidden string to the
left by one character several times shows that it is not possible to construct the forbidden
string partially from the prefix and partially from the suffix (11010), for all shifts.
Now, let’s find the generating functions of both sides of these two equations.
The intersection of {} and S{0, 1} is empty, so the sum lemma applies. We’ll also apply the
26
product lemma to S{0, 1}. The generating function for {}∪S{0, 1} is therefore 1+φS (x)2x.
On the other side of equation 1, we get φF (x) + φS (x) by the sum lemma, since it’s a par-
tition (F only contains elements ending in the forbidden string, and S does not contain the
forbidden string at all). So, for the first equation we have 1 + φS (x)2x = φF (x) + φS (x).
By the product lemma, we get the generating function for S{11010} to be φS (x)x5 . The
other side of equation 2 has a generating function of φF (x). So, for equation 2 we have
φS (x)x5 = φF (x).
Next, we’ll substitute φF (x) from equation 2 into the generating function for equation 1:
The first equation is {} ∪ S{0, 1} = S ∪ F , as before. There is nothing about this specific
forbidden string in this equation, so it applies generally.
?
The second equation we’d logically like to try is S{1010} = F . Let’s see if that works.
Let A ∈ S{1010}. If we’re unlucky, then the prefix of 1010 will be 10, which means the
forbidden string will occur with 10 in the prefix and 10 in the suffix (forming 1010). So,
S{1010} =6 F.
We could instead use S{1010} = F ∪ F {10}. Note that in the case where the forbid-
den string occurs partially in the prefix and partially in the suffix, we could say that is an
instance of a forbidden string followed by an additional 10, which is what this equation is ex-
pressing. We would also need to check the opposite direction, ∈ F ∪ F {10} =⇒ ∈ S{1010},
but we’ll omit that here.
Finding the generating functions, we get 1 + φS (x)2x = φS (x) + φF (x) (for equation 1)
and φS (x)x4 = φF (x) + φF (x)x2 (for equation 2), which gives us:
x4
φF (x) = · φS (x)
1 + x2
Substituting φF (x) into the generating function for equation 1 gives us:
−1
x4
φS (x) = 1 − 2x +
1 + x2
Example 4.13. Let S be the set of strings where there is no odd block of 0s that is imme-
diately followed by an odd block of 1s. For example, 010001011 6∈ S, but 111011000 ∈ S.
First, let A be the set of a block of zeroes followed by a block of ones. That is, strings
27
in A are composed of at least one 0 followed by at least one 1. We can express A by
? ?
A = {0}{0} {1}{1} .
Next, let B be the set of an odd block of zeroes followed by an odd block of ones. We
? ?
can express B as B = {0}{00} {1}{11} .
Next, let C be the set of a block of zeroes followed by a block of ones where both blocks
cannot be odd simultaneously (one can be odd, but not both of them). C can be expressed
as C = A \ B.
? ?
We then have that S = {1} (A \ B)? {0} .
Suppose deg(f ) ≥ deg(g), which implies f (x) = q(x)·g(x)+r(x), where q(x) is a polynomial
and r(x) is a polynomial of a lower degree than f . Dividing both sides by g(x) gives:
f (x) r(x)
= q(x) +
g(x) g(x)
f (x) r(x)
[xn ] = [xn ]q(x) + [xn ]
g(x) g(x)
Example 5.1.
We need A + B = 1 and −3A − 2B = −5. After solving this system of two equations in two
unknowns, you’ll get A = 3 and B = −2. So, we now have:
1 − 5x 1 1
= 3[xn ] −2[xn ]
1 − 5x + 6x2 1 − 2x 1 − 3x
| {z } | {z }
1+(2x)1 +(2x)2 +... 1+(3x)1 +(3x)2 +...
n n
=3·2 −2·3
28
a2 x) . . . (1 − ak x) where a1 , . . . , ak are distinct. We can only apply this partial fractions
method if all the roots are distinct (there are subtle differences if the roots aren’t distinct).
We know that:
f (x) c1 c2 ck
= + + ... +
g(x) 1 − a1 x 1 − a2 x 1 − ak x
1
However, note that 1−a1 x = 1 + (a1 x) + (a1 x)2 + . . .. So, we have:
f (x)
[xn ] = c1 an1 + c2 an2 + . . . + ck ank
g(x)
The previous example used this generalized form but with k = 2, c1 = A = 3, and c2 = B =
−2, which made a1 = 2 and a2 = 3 (from the denominators).
Example 5.2. Suppose we want to find the n-th coefficient of:
1 + 4x2
(?) =
1 − 6x + 12x2 − 8x3
1 + 4x2
=
1 + 3(−2x) + 3(−2x)2 + 1(−2x)3
1 + 4x2
= (binomial coefficients)
(1 − 2x)3
1 + 4x2
[xn ](?) = [xn ]
(1 − 2x)3
n A B C
= [x ] + +
1 − 2x (1 − 2x)2 (1 − 2x)3
After solving for A, B, and C, you’ll discover that A = 1, B = −2, and C = 2. Therefore,
we’re now looking for:
1 1 1
[xn ](?) = [xn ] − 2[xn ] + 2[xn ]
1 − 2x (1 − 2x)2 (1 − 2x)3
| {z } | {z } | {z }
(1) (2) (3)
1. 2n , as before.
2. Recall:
1 X n + p − 1
= yn
(1 − y)p p−1
n≥0
29
3. Consider y = 2x again. We get:
n+3−1 n+2 n
2n = 2
3−1 2
Remark:
f (x)
[xn ] = an × (polynomial of n of degree k − 1)
g(x)
← February 11, 2013
f (x) A B C
[xn ] 2
= [xn ] + [xn ] 2
+ [xn ]
(x − 3) (x + 2) (x − 3) (x − 3) x+2
= (polynomial of n of degree ≤ 1) · 3n + (constant) · (−2)n
(1 − 3x + 2x2 )(a0 + a1 x + a2 x2 + . . .) = c0 + c1 x
30
We want a polynomial of degree at most 1 on the right-hand side.
We know that [xn ]LHS = [xn ]RHS, so for n ≥ 2, [xn ]RHS = 0. Multiplying out, we
get (?). We can say that for n ≥ 2, (1 − 3x + 2x2 )(a0 + a1 x + . . .) = c0 + c1 x encodes (?).
Let’s continue:
So, we have that an = A · 2n + B · 1n . We can solve for A and B using the given val-
ues for a0 and a1 .
a0 = 1 =⇒ A · 20 + B · 10 = 1
a1 = 4 =⇒ A · 21 + B · 11 = 4
=⇒ A = 3, B = −2
Substituting the values for A and B back into our equation from earlier, we get an = 3·2n −2.
Let’s now look at a more efficient (lazy) approach to this.
q(x) = 1 − 3x + 2x2
= (1 − 2x)(1 − 1x)
Now, we will define p(x) such that it is a polynomial with roots 2 and 1.
2 1
p(x) = x q
x
2 1 1
=x 1−2 1−
x x
= (x − 2)(x − 1)
Now, we’re just interested in the roots of p(x) instead of coefficients within the factored
form of q(x), which is much cleaner.
Definition. A homogeneous recurrence relation is an + c1 an−1 + c2 an−2 + . . . +
cm an−m = 0 with initial conditions a0 , a1 , . . . , am−1 (m initial terms).
Strategy:
1. Find the general form for an .
2. Use the initial conditions a0 , a1 , . . . , am−1 .
31
We have the characteristic polynomial:
p(x) = xm + c1 xm−1 + . . . + cm x0
Theorem. If p(x) has m distinct roots β1 , . . . , βm then the general form for an is:
A1 β1n + A2 β2n + . . . + Am βm
n
Example 6.2. We have the Fibonacci sequence an − an−1 − an−2 = 0 for n ≥ 2. The initial
conditions are a0 = 0 and a1 = 1.
We have:
p(x) = x2 − x − 1 = 0
√
1± 5
=⇒ x =
2
The general form is:
√ n √ n
1+ 5 1− 5
(?) = A1 + A2
2 2
n = 0 =⇒ A1 + A2 = 0
√ √
1+ 5 1− 5
n = 1 =⇒ A1 + A2 =1
2 2
1
=⇒ A1 = √
5
1
=⇒ A2 = − √
5
Substituting these values for A1 and A2 into (?) we get:
√ n √ n
1 1+ 5 1 1− 5
√ −√
5 2 5 2
=⇒ a20 = 4181
Example 6.3. We have the recurrence relation an + 3an−1 − 4an−3 = 0 for n ≥ 3. The
initial conditions are a0 = 0, a1 = 4, and a2 = 2.
We have:
p(x) = x3 + 3x2 − 4
= (x + 2)2 (x − 1)
32
Note that we cannot use the previous theorem here. Instead, let’s pick:
(1 + 3x − 4x3 )(a0 + a1 x + a2 x2 + . . .) = f (x)
(for n ≥ 3 where f (x) is of degree 2)
We know that [xn ]LHS = [xn ]RHS = 0, and we know that the LHS is an + 3an−1 − 4an−3 .
So, we get:
X f (x)
a n xn =
1 + 3x − 4x3
n≥0
f (x)
=
(1 + 2x)2 (1 − x)
We know that an = (A+Bn)·(−2)n +C·1n . Solving, we get that A = −2, B = 1, and C = 2. ← February 13, 2013
First, we’ll write the characteristic polynomial, which will be of degree 3 since we have
an−3 included as one of the terms:
p(x) = x3 + 3x2 + 3x + 1 = (1 + x)3 by binomial theorem
There is one root of p(x), -1, with multiplicity 3. The general form of an is:
an = (A + Bn + Cn2 )(−1)n
33
6.1 Non-homogeneous Recurrences
Example 6.5. Suppose we have the recurrence relation (?1 ) = an + 3an−1 − 4an−3 = 6 × 2n
for n ≥ 3. The initial conditions are a0 = 5, a1 = 3, and a3 = 25.
Let’s ignore the initial conditions for now. Let’s take a guess and pick an = α2n , where α
is some constant that we’ll decide on later.
We still haven’t satisfied the initial conditions though. We want to find bn such that (?2 ) =
bn + 3bn−1 − 4bn−3 = 0 (which is the same relation as before, but = 0). Then:
an is a solution to (?1 ), ignoring the initial conditions. If bn is a solution to (?2 ), then an +bn
is a solution to (?1 ).
bn = (A + Bn )(−2)n + C
an + bn = (A + Bn )(−2)n + C + 3 × 2n
Example 6.6. Suppose we have the recurrence relation an + an−1 − 2an−2 = 9, with initial
conditions a0 = 2 and a1 = 2.
?
We’ll guess that an = α (a constant). We’d then have that α + α − 2α = 9, but 0 6= 9, so
this won’t work for any value of α. It was a bad guess.
That guess didn’t work, so we’ll try a higher degree. Our second guess is an = αn for
some constant α, which would give us:
αn + α(n − 1) − 2α(n − 2) = 9
α=3
34
7 Introduction to Graph Theory
← February 15, 2013
Definition. A graph G is defined as G = (V, E), where V is a finite set of vertices and E
is a set of edges, in the form of a set of unordered pairs of V .
Example 7.1. Let’s say we have the graph G = (V, E), where V = {1, 2, 3, 4, 5} and
E = {12, 13, 14, 23, 34, 25, 45}. Note that for edges, we’re using the shorthand of xy to mean
{x, y} (for example: edge 12 = {1, 2}).
5
1 2
2 4
3
1 3
4 5
Definition. The complement of the graph G, denoted G, is the graph with V (G) = V (G)
and edges uv ∈ E(G) if and only if uv 6∈ E(G).
Definition. Given the following graph:
i j
If ij ∈ E, we say i and j are endpoints of ij. We also say that i, j are adjacent, and that
edge ij is incident to i and j.
a b
5
4 d c 6
e f g
1 3
2
The endpoints of f are 2 and 5. 1 and 2 are adjacent. c, d, and f are the edges incident to
5. The neighbours of 2 are 1, 3, and 5.
Example 7.3. If we were to represent a street map as a graph, V would be the set of
intersections and E would be the set of streets.
35
Example 7.4. If we were to represent a network of people, V would be a set of individuals
and E would be the various relationships between those people (sets of friends).
Example 7.5. Let V be the set of binary strings of length n.
010 011
110 111
100 101
000 001
The overlaps are the edges. We can represent the same graph as:
1 2
4 3
36
7.1 Isomorphism
Are the following two graphs the same?
1 2
4 3
a b
d c
φ(1) = a
φ(2) = b
φ(3) = c
φ(4) = d
a f
1 4
d b
2 5
3 6 e c
37
Yes! There exists a bijection φ:
1→a
2→b
3→e
4→f
5→d
6→c
There is no general algorithm for finding a bijection. In this case, you could see that 1, 2,
and 3 have no edges and a, b, and e also have no edges.
Example 7.8. Are the following graphs isomorphic?
1 2 a c
5 e
4 3 b d
No. 1, 4, and 5 are pairwise adjacent but there are no corresponding vertices on the second
graph.
deg 3
deg 3
deg 3 deg 3
deg 2
38
Example 7.10. Given the following table:
Individuals # of friends among {a, . . . , i}
a 6
b 3
c 4
d 1
e 5
f 3
g 7
h 2
i 4
There are 5 odd numbers of friends. One of them must be lying.
← February 25, 2013
b (deg 2)
d (deg 1)
a (deg 2) c (deg 3)
Note that each edge appears exactly twice in the above equation – once for each endpoint.
This is the general idea behind the proof for the previous theorem.
Proof. For each edge ab ∈ E, ab contributes 1 to (?) for deg(a) and ab contributes 1 to (?)
for deg(b).
Definition. A graph in which every vertex has degree k (for some fixed k) is called a
k-regular graph.
Definition. A complete graph is a graph in which all pairs of distinct vertices are adjacent
to each other. That is, each vertex is joined to every other vertex. The complete graph with
p vertices is denoted Kp (where p ≥ 1).
39
Example 7.12. Is the following graph bipartite?
1 4
2 5
3 6
Yes, this graph is bipartite because V1 could be the vertices on the left-hand side (1, 2, and
3), and V2 could be the vertices on the right-hand side (4, 5, and 6).
Example 7.13. Is the following graph bipartite?
No, this graph is not bipartite as shown. This is the simplest graph that is not bipartite, in
fact.
Example 7.15. Is the following graph bipartite, and is the partitioning unique?
Yes, this graph is bipartite, however its partitioning is not unique. We can flip the colours
(of both the squares of the graph) and still show the graph to be bipartite. So, in general,
the partitioning of V into V1 and V2 is not unique.
40
Definition. The n-cube is the graph G = (V, E) where V is the set of binary strings of
length n and uv is an edge if u and v differ in exactly one position.
For n = 2, we have the following n-cube:
10 11
00 01
Note that we can split u and v each into two pieces, split on the single element (char-
acter) that differs between u and v. Corresponding pieces of u and v are the same.
The parity of the number of ones in u is different from the number of ones in v, since
aside from that single character difference, the parity of ones is the same between u and v.
Therefore, u and v are not both in V1 or both in V2 . So, the n-cube is bipartite.
Proposition. Let G = (V, E) be a bipartite graph with partition V = V1 , V2 . Then:
X X
deg(v) = deg(v) = |E|
v∈V1 v∈V2
| {z } | {z }
(1) (2)
Each edge has one endpoint in V1 and one endpoint in V2 , which is why this intuitively
makes sense. Let’s state this more formally.
Proof. Consider any edge ab ∈ E. Then ab contributes 1 to (1) and ab contributes 1 to
(2).
Corollary. If |V1 | = |V2 |, then the average degree of vertices in V1 is equal to the average
degree of vertices in V2 .
start end
41
Definition. A cycle occurs if v0 , v1 , . . . , vn−1 are distinct but v0 = vn (the start and ending
vertices are the same).
Example 7.16. We have the following graph:
a 4 b
1 7
s 2 6 t
3 8
c 5 d
In this graph, we’ve visualized a path P (in orange) and a cycle C (in blue). We can express
P as P = s1a2c5d8t and we can express C similarly as C = b7t8d6b.
x Vi Vj y
Heading from x to y, while going through the nodes in the triangle in the middle, is a walk.
However, if we were to skip visiting the Vi -th node entirely, we would have a path.
Proof. Among all walks from x to y, pick a walk W with as few edges as possible. We would
pick:
W = V0 e1 V1 e2 V2 . . . en Vn where V0 = x1 and Vn = y
We need to show that V0 , V1 , . . . , Vn are all distinct. Suppose for a contradiction that there
exists Vi = Vj for some i < j. That would mean:
W = V0 . . . ei Vi ei+1 . . . ej Vj ej+1 . . . Vn
| {z }
cut off
=⇒ W 0 = V0 . . . ei Vj ej+1 . . . Vn
W 0 is still a walk from x to y. But W 0 has fewer edges than W , which is a contradiction.
Corollary. If there exists a path from x to y and there exists a path from y to z, then there
exists a path from x to z.
42
This corollary is not as trivial to show as you might initially think. You can’t just join the
two paths, because the two paths may share some vertices.
Proof. The path from x to y followed by the path from y to z is a walk from x to z (not a
path). By the previous result, there exists a path from x to z.
This graph does clearly not have a cycle, but it’s not a terribly interesting graph. This more
complicated graph also does not have a cycle:
But what if every vertex has degree at least 2? In that case, it is not possible to create a
graph that does not have a cycle. In order for each vertex to have degree of at least 2, it
must loop back somewhere.
Proposition. Let G = (V, E). If for all v ∈ V , deg(v) ≥ 2, then G has a cycle.
Proof. Among all paths, pick a path P with as many edges as possible. We have:
P = V0 e1 V1 e2 . . . en Vn
Since deg(Vn ) ≥ 2, there exists Vn w 6= en . Since P is the longest path, w = Vi for some
i ∈ {0, . . . , n − 2}. Then we have the cycle C:
C = Vi ei Vi+1 . . . en Vn en+1 Vi
Note that it doesn’t necessarily have to loop back to the “first” vertex because you may have
a graph like this:
43
Definition. The girth of a graph G, denoted g(G), is the length of the shortest cycle in
G. If G has no cycles, then g(G) is infinite.
44
|V |
Theorem (Dirac’s Theorem). Let G = (V, E). If for all v ∈ V , deg(v) ≥ 2 , then there
exists a Hamiltonian cycle.
Is there a path from s to t? No. The two sets of vertices have no edges between them.
Definition. A pair of paths is edge disjoint if the paths do not share an edge.
Example 7.22. Given the following graph:
s t
Are there two edge disjoint paths from s to t? Yes. There is no edge that is both blue and
green, so the two paths are disjoint.
Example 7.23. Given the following graph:
45
s
Are there two edge disjoint paths from s to t? No. For the same reason as the two examples
above, the center edge must be used in all paths because it is the only edge that connects
two otherwise disjoint sets of vertices.
Example 7.24. Given the following graph:
s
s t
This is an example of a graph with two disjoint paths but not three. There are just two
edges connecting two otherwise disjoint sets of vertices.
Definition. Let G = (V, E), and let S ⊆ V, S 6= ∅, S 6= V (we pick a proper subset of
vertices). The cut induced by S is:
We say it’s a cut because if we removed (cut) those edges, we would get two sets of edges
with no edges connecting the two sets, so the graph would fall apart.
46
a
c d
s
t
b
a f
c e
Equivalently, if you have an st-cut of size less than k, you cannot find k disjoint paths
from s to t.
Proof. Let δ(S) be an st-cut (s ∈ S, t 6∈ S). Let i ∈ {1, . . . , k}. Follow Pi from s to t. Let
vi be the last vertex in S of Pi , and let wi be the first vertex not in S of Pi . Then ei = vi wi
is an edge of Pi and ei ∈ δ(S). This implies {e1 , e2 , . . . , ek } ⊆ δ(S).
Since P1 , P2 , . . . , Pk are edge disjoint, e1 , e2 , . . . , ek are all different. This implies that
|δ(S)| ≥ k. Since δ(S) was an arbitrary cut, we have shown that all st-cuts have at least k
edges.
The converse is also true, which is known as Menger’s Theorem.
Theorem (Menger’s Theorem). Let G = (V, E) be a graph, and s, t ∈ V (s 6= t). If for all
st-cuts δ(S), |δ(S)| ≥ k, then there exist edge disjoint paths P1 , . . . , Pk from s to t.
47
Proof. The proof of Menger’s Theorem is by performing induction on |E| + |V |. The base
case is where you have two vertices and no edge between them, as seen here:
s t
2. Say, k = 3, for instance. Divide the graph in two, and shrink the vertices from half the
graph into a single consolidated vertex. Then apply the same logic for the other half
of the graph. By induction, we can find three paths on both of the smaller graphs.
We want to combine these two smaller paths, which we can do by connecting the
corresponding paths of the two sub-graphs.
← March 4, 2013
Corollary. There exists a path from s to t (1) if and only if for all S ⊆ V, s ∈ S, δ(S) 6= ∅
(2).
Proof. Let us prove that (2) implies (1).
Informally, we know we have a path from s to a. We can take that path and add the
edge ab to get us a path from s to b. However, then b should be in U as well, because there
exists a path from s to b.
s t
48
This corollary follows immediately from our characterization of st-cuts:
Corollary. G is connected (1) if and only if for all X ⊆ V, X 6= ∅, X 6= V, δ(X) 6= ∅ (2).
Definition. H = (VH , EH ) is a subgraph of G = (VG , EG ) if VH ⊆ VG and EH ⊆ EG .
Example 7.30. The highlighted portion of this graph is a subgraph:
Note that in order to keep an edge in a subgraph, we must keep both of its vertices. When
we discard a vertex, we must discard all edges that have that vertex as an endpoint.
Definition. A component of a graph is a maximal connected subgraph H of G. That is,
H is connected and no subgraph of G that properly contains H is connected.
Example 7.31. Given the following graph G (considered as a whole):
Each of these three obviously-disjoint subgraphs are components. The highlighted portion
is not itself a component (as expected), because it is not a maximal subgraph.
Corollary. G is connected if and only if G has a single component.
49
Example 7.32. Let S be the set of all integers. Pick some integer m ≥ 1. A sample
equivalence relation would be a ∼ b if a − b is a multiple of m.
You can always partition your set S into equivalence classes.
Example 7.33. Let G = (V, E) be a graph. Given a, b ∈ V , a ∼ b if a = b or there exists
a path from a to b. We propose that ∼ is an equivalence relation, and we want to prove it.
Proof. We have to prove all three parts of the definition of equivalence relations.
(2) is true because if there exists a path from a to b, then there exists a path from b to
a.
(3) is true because if there exists a path from a to b and there exists a path from b to
c, then there exists a path from a to c (by theorem).
Exercise: look at set S (the set of all possible graphs). We propose that G ∼ H if G
is isomorphic to H. Prove that ∼ is an equivalence relation.
Remark: it’s useful to think of paths and cycles as sets of edges. Reflexivity makes a
lot more sense under this interpretation, for instance. Cycles become a set of edges of a
connected subgraph where every vertex has degree two. Paths are edges of a connected
subgraph where two vertices have degree one and every other vertex degree two.
7.5.4 Bridges
Definition. Let G = (V, E) be a graph, and e ∈ E. Then, G\e is the graph obtained from
G by deleting edge e. We say e is a bridge of G if G\e has more components than G.
Example 7.34. Given the following graph:
x y
The edge xy is a bridge, because if it was removed the number of components will increase
from one to two. If this edge was removed, x and y would be in different components. This
can be proven by transitivity.
50
← March 6, 2013
Proposition. If e = xy is a bridge of G, then x and y are in distinct components of G\e.
Proof. There exists ab such that a and b are in the same component of G, but a and b are
in distinct components of G\e. This implies that there exists a path P in G between a and
b that uses e.
Suppose for a contradiction that x and y are in the same component of G\e. We know:
• a and x are in the same component of G\e (because of P ).
• b and y are in the same component of G\e (because of P ).
By transitivity, a and b must be in the same component, which is a contradiction.
Proposition. Let G = (V, E) be a connected graph, and let e be a bridge of G. Then G\e
has exactly two components.
Proof. Let X be the vertices in the component of G\e that contains x. Let Y = V \X. We
need to show that any two vertices in Y are connected by a path in G\e.
The fact that e = xy is not a bridge implies that there exists a path P between x and
y in G\e. Then, P ∪ {e} is a cycle.
If e is in a cycle C, then C\e is a path between x and y. This implies that e is not a
bridge, otherwise x and y are in distinct components of G\e, as proven earlier.
Proposition. Let G = (V, E) be a graph. Let a, b ∈ V (where a 6= b). Suppose there exists
paths P1 , P2 between a and b where P1 and P2 are distinct. Then G has a cycle.
We want to show that there is a cycle that uses the edge e. So, we need to show that there
exists a path from x to y that does not use the edge e.
51
Proof. Since P1 is distinct from P2 , there exists an edge e = xy in P2 that is not in P1 .
After possibly interchanging a and b, we know:
• a and x are in the same component of G\e (because of P2 ).
• y and b are in the same component of G\e (because of P2 ).
• a and b are in the same component of G\e (because of P1 ).
Using those facts, by transitivity we know there exists a path P between x and y in G\e.
Then P ∪ {e} is a cycle.
8 Trees
Definition. A graph G is a tree if G is connected and G has no cycle.
Example 8.1. This graph is not a tree because it contains cycles:
Example 8.2. This graph (considered as a whole) is not a tree because it is disconnected:
Example 8.3. This graph is a tree because it is connected and has no cycles:
52
Example 8.4. This graph is also a tree:
Keep this graph (just one vertex with no edges) in mind when doing inductive proofs in-
volving trees.
← March 8, 2013
Proposition. If G is a tree, then:
1. Any two distinct vertices are joined by a unique path.
2. Every edge is a bridge.
Proof. We will prove each part of this proposition in turn.
1. Since the tree is connected, there exists at least one path. If there exists two distinct
paths between a pair of vertices, then there exists a cycle, which is a contradiction.
2. If an edge is not a bridge, then that edge is in a cycle, which is a contradiction.
Proposition. Let H = (V, E) be a tree. Let a, b ∈ V be two distinct vertices with no edge
between them. Let G be the graph obtained from H by adding the edge ab. Then G has
exactly one cycle.
Example 8.6. Let’s add the edge ab to the following tree:
a
According to the previous proposition, this graph should contain only one cycle.
Proof. C is a cycle of G if and only if C\{e} is a path of H between a and b. We know that
there exists a unique such path.
You could add an edge to create a cycle, then remove any edge from within the cycle to
get a different tree. This technique could be used by shipping companies to find the most
optimal cost-efficient route to ship a package.
Definition. Let G0 = (V 0 , E 0 ) be a subgraph of G = (V, E). G0 is a spanning subgraph
if V 0 = V .
53
Example 8.7. This is not a spanning subgraph because one vertex in V is not included in
V 0:
Example 8.10. We have to specify that G contains a spanning tree because otherwise we
would say the following graph (considered as a whole) is connected (which it is not):
Proof. We’ll first prove that (2) implies (1). For all a, b ∈ V (a 6= b), there exists a path
between a and b in the spanning tree. But this is also a path of G.
54
Now, we’ll prove that (1) implies (2). Among all spanning subgraphs of G that are con-
nected, pick one with as few edges as possible. Call that subgraph T .
• T does not contain a cycle, otherwise any edge on that cycle could be removed while
still keeping the graph connected (edges in cycles are not bridges).
Assume |V | ≥ 2. We claim that there exists a vertex v of degree 1 (otherwise there ex-
ists a cycle). So, v is adjacent to a unique vertex w.
Let G0 = (V 0 , E 0 ) be the graph obtained from G by deleting the edge wv and the ver-
tex v. Note that G0 is a tree because the degree of v is one in G.
55
_
¨
There are a couple of different proof techniques we could use to prove this proposition.
1. We could call one vertex V1 and then define even/odd vertices based on whether their
distance from V1 is even or odd (since there exists a unique path from V1 to any other
vertex in a tree).
2. More simplistically, we could build up the partition recursively. As we add an addi-
tional edge, each endpoint of the edge should be in the opposite partition.
We’ll use approach (2) to prove this proposition.
Proof. Let T = (V, E). We’re going to perform induction on |V |.
Let T 0 be obtained by removing uv and u. Note that T 0 is still a tree. We can verify
that fact by seeing that we’re certainly not adding any cycles (not possible when removing
56
an edge) and since u has degree 1, the tree remains connected.
By induction, there exists a partition X 0 , Y 0 of the vertices of T 0 such that every edge
of T 0 has one end in X 0 and one end in Y 0 .
Due to the proposition from earlier, we may assume G is connected, without loss of gener-
ality. This implies that G contains a spanning tree T = (V, E 0 ).
This implies that the cycle P ∪ {ab} is an odd cycle, which is a contradiction.
What graphs can be coloured with three colours? No clue. There’s no efficient or reli-
able way of colouring an arbitrary graph with any constant (even very large) number of
colours.
9 Planar Graphs
We will allow:
• Loops:
• Parallel edges:
57
Definition. A planar embedding is a drawing of a graph where no two edges cross.
Example 9.1. This is not a planar embedding of a graph G because two edges cross:
1
5
2
4
3
2 4
Observation: the same graph can have many different planar embeddings. We’ll formally
define “different” a bit later.
Example 9.2. Here are two planar embeddings of the same graph G1 :
1 5 1
5
2 4 6 2 6 4
7
3 7 3
Example 9.3. Here are two planar embeddings of the same graph G2 that look similar,
except the edges are labeled differently:
58
5 2
1 2 1 5
4 6 3 6
3 4
59
G is a planar graph because a planar embedding exists for G. In particular, the following is
one planar embedding of G (no two edges cross):
inside
outside
F5
F4
F1 F2 F3
60
Definition. The Jordan Curve Theorem implies that a planar embedding partitions the
plane into connected components, called faces.
F3 : infinite face
F1
F2
Theorem. G has an embedding on the plane if and only if G has an embedding on the
sphere.
The truthfulness of this theorem is easy to see. To show an embedding on a plane implies
an embedding on the sphere, place your plane flat on the ground, then it’s a plane on a
sphere (Earth). For the opposite direction, just imagine a sphere so huge that the entire
graph appears on a portion of the sphere that appears like a flat plane.
Definition. For any face F , the boundary walk of F is the closed walk obtained by
following the edges bounding the face.
Suppose we have this graph G:
1 5
F4
2 F1 4 F2 7 F3 10
3 6
F1 : 1, 3, 2
F2 : 5, 7, 6
F3 : 8, 10, 9, 7 (in green above)
F4 : 1, 4, 5, 8, 10, 9, 6, 4, 3, 2
Note that in the boundary walk for F4 , the edge 4 appears twice. This is acceptable under
the usual definition of walks.
Definition. For a face F , deg(F ) is equal to the number of edges in the boundary walk of
F.
61
For example, we have deg(F1 ) = 3, deg(F2 ) = 3, deg(F3 ) = 4, and deg(F4 ) = 10. Note that
in deg(F4 ), we must count the edge “4” twice.
Notice:
4
X
deg(Fi ) = deg(F1 ) + deg(F2 ) + deg(F3 ) + deg(F4 )
i=1
= 20
= 2 × number of edges
This is similar to a theorem proven when we talked about degrees under the earlier definition
for degrees. That’s why we defined the degree of a face in the way we did.
X
Theorem. Consider a planar embedding of G = (V, E). Then (?) = deg(F ) = 2|E|.
F ∈faces
Why is this true? Each edge contributes to two faces, except edge “4” which is only in the
boundary walk of F4 . However, edge “4” occurs twice in that boundary walk so it’s still
counted twice. We’ll state this proof more formally now.
Proof. We want to show that every edge e is counted twice in (?). There are two cases.
Case 1: suppose e is not a bridge. Then e appears in exactly two different faces.
Case 2: suppose e is a bridge. Then e appears in one face but twice in the boundary
walk for that face.
Let p be the number of vertices, q be the number of edges, and f be the number of faces.
Here are G1 , G2 , G3 , and G4 :
G1 G2 G3
G4
62
Proof. We’ll prove this theorem by performing induction on q.
Otherwise, let e ∈ E be an edge in a cycle (we can assume this because we aren’t in
our base case). Let G0 = G\e.
=⇒ 2q ≥ 3f
≥ 3(2 − p + q)
≥ 6 − 3p + 3q
=⇒ 6 − 3p + q ≤ 0
Euler’s formula can be used as a general trick when we want to compare two of these
quantities.
2. Now, let’s also exclude triangles (cycles of length 3). We have:
X
2q = deg(F )
| {z }
F ∈faces ≥4
=⇒ 2q ≥ 4f
≥ 4(2 − p + q)
≥ 8 − 4p + 4q
=⇒ q ≤ 2p − 4
63
Let Kn denote the complete graph with n vertices. Is K5 planar?
Well, how many edges can a planar graph with 5 vertices have? Note that # of edges
≤ 3 × 5 − 6 = 9. But K5 has 52 = 10 edges. So, no, K5 is not planar.
Let Km,n denote the complete bipartite graph with m vertices and n vertices in each part
of the partition. Is K3,3 planar?
64
The platonic graph where k = 3, l = 4 is:
There are also two more graphs (k = 3, l = 5 and k = 5, l = 3), which we won’t show here
for simplicity.
• Euler’s Formula:
p−q+s=1+c
(where p is the number of vertices, q is the number of edges, s is the number of faces
(earlier, we denoted this as f ), and c is the number of components.)
65
9.3 Planar Solids
There are solids that correspond to the five platonic graphs. What do they have in common?
Every vertex has the same degree and every face has the same degree.
Which values of (k, l) are possible? If we try drawing the graphs for (4, 4) and (5, 4),
we’ll see that as we’re constructing them, they’d each need to be infinite in size to satisfy
the k and l constraints. Since these graphs cannot be finite, we say (4, 4) and (5, 4) are two
particular instances of (k, l) for which the constraints are not satisfied.
Idea: use the facts about planar graphs to constrain (k, l).
P
• By the handshake lemma, deg(v) = kp = 2q.
P 2q
• By the dual handshake lemma, deg(f ) = ls = 2q. This implies that p = k =s=
2q
l . This is known as the duality of graphs.
• By Euler’s formula, p − q + s = 2.
(k − 2)(l − 2) < 4
=⇒ k − 2, l − 2 ≥ 1 and k − 2, l − 2 < 4
=⇒ k, l ≤ 5
66
• If k = 5, then l can only be 3.
Theorem. If G is a platonic graph, then (k, l) must be one of (3, 3), (3, 4), (3, 5), (4, 3),
or (5, 3).
Does each of these possibilities of (k, l) occur for a platonic graph? That is, we know these
are all possibilities, but are they all actually possible? For any choice of (k, l), how many
platonic graphs are there?
Claim: each of the five possibilities for (k, l) can be achieved by a platonic graph.
Proof. Just use the five platonic solids that we know.
2
=⇒ q = 2 2
k −1
+ l
2kl
=
2l + 2k − kl
2q
=⇒ s =
l
4k
=
2l + 2k − kl
12
We can verify this. If (k, l) = (3, 5), then s = 10+6−15 = 12, as expected.
67
9.4 Non-Planar Graphs
← March 20, 2013
K5 K3,3
K5 and K3,3 are non-planar because they have edges that unavoidably must cross. Are
there any other planar graphs? Yes! You can just add more edges to K5 or K3,3 . We could
also add some vertices in the middle or edges, if we’d like.
The two following graphs are also non-planar, and are built by adding more edges and
vertices to K5 .
In addition, the following is not a subdivision of G because a vertex was introduced where
there was previously a crossing:
68
Theorem. If G has a subgraph that is a subdivision of K5 or K3,3 , then G is not planar.
Example 9.7. Consider the following graph, G.
Katz claims he has a bridge in New York and some cheap land in Florida to sell you, and
he claims he has a planar embedding for G. Why must he be lying?
Essentially, we know he’s lying about having a planar embedding for G, since then he could
erase subdivisions and get a planar embedding for K3,3 . Let’s state that more formally.
Proof. Suppose G is planar. Then, take a planar embedding of G. Since H is a subgraph
of G, we get a planar embedding of H. Undo that subdivision. Then we get a planar
embedding of K3,3 or K5 , and that’s “unpossible.”
It’s generally hard to compute crossing numbers. It’s an open question to d the crossing
number of Km,n , since we’d have to check all possible drawings.
69
Example 9.8. This is K4 :
Since every vertex of K4 has an edge to every other vertex, every edge needs its own colour.
Note: Kn needs n colours. You must colour every vertex differently.
We only consider simple graphs when discussing graph colouring. We can’t colour loops, for
instance.
We can expand on the four colour theorem and also introduce two very similar theorems.
Theorem (Five Colour Theorem). Every simple planar graph can be 5-coloured.
Theorem (Six Colour Theorem). Every simple planar graph can be 6-coloured.
We know that simple planar graphs cannot have too many edges. This implies that there
exists a vertex of low degree. We’ll use this information to derive a lemma.
Theorem. Let G = (V, E) be a simple graph. There exists a vertex v ∈ V of degree < k.
(k = 6)
Proof. Assume that for all v ∈ V , deg(v) ≥ k. We have:
X
2q = deg(v) ≥ pk
| {z }
v∈V ≥k
We also know that q ≤ 3p − 6, since G is a simple planar graph. That means 2q ≤ 6p − 12.
Combining these expressions, we get that pk ≤ 2q, so pk ≤ 6p − 12. We get a contradiction
for k ≥ 6.
So, we can update our lemma’s statement with k = 6.
70
Proof. Let G = (V, E) be a simple planar graph. By induction on k = |V |:
Assume for k ≥ 2 that we can 6-colour every simple planar graph with ≤ k − 1 vertices.
By the lemma we just introduced, there exists some v ∈ V such that deg(v) ≤ 5.
Let H = G\v be the graph obtained by deleting v from G. Note that H is a simple
planar graph. By induction, there exists a 6-colouring of H.
Since deg(v) ≤ 5, one colour, say c, does not appear among the vertices adjacent to v.
Pick colour c for v.
Before we can prove the five colour theorem, we need one more ingredient: contraction.
Definition. Let G = (V, E) be a graph, and e = uv ∈ E. Then G/e is the graph obtained
by identifying u and v in G and deleting e. We call this contracting the edge.
Example 9.9. Consider the following graph.
When you apply contraction, you could introduce loops into the graph. Be careful.
Example 9.10. We’ll take a graph and then contract edge 5, then contract edge 6. Notice
that this introduces a loop into the graph.
1 1
5 1
2 4 2 4 6 2 4
6 3
3 3
71
Proposition. If G is planar, then G/e is planar.
Our goal is to 5-colour a planar graph. We can do this by taking a graph with five vertices,
removing a vertex, applying colours, then adding back the vertex that we removed.
Example 9.11. We’re going to 5-colour the following graph.
First, we’ll remove the vertex in the middle and colour the remaining vertices:
1 2
3 4
Then, we’ll put the middle vertex back and give it the remaining colour:
1 2
3 4
Example 9.12. Let’s now look at a slightly more complex graph – a graph with six vertices.
We’re going to contract the edges indicated in red, and then assign colours to the remaining
vertices.
72
1
3 2
4 1
5
4
3 2
Note that in this example, it could’ve been possible for a loop to be created, if the two
endpoints of the red path had an edge.
We know there must exist a pair of vertices that do not have an edge between them. Oth-
erwise, we’d have K5 , but we were told the graph is planar.
Assume for k ≥ 2 that every simple planar graph with ≤ k − 1 vertices is 5-colourable.
Let H = G\v be the graph obtained by deleting v from G. Note that H is a simple
planar graph. By induction, there exists a 5-colouring of H.
Since deg(v) ≤ 5, one colour, say c, does not appear among the vertices adjacent to v.
Pick colour c for v.
We claim that there exists a, b ∈ V , adjacent to v, such that a, b are not adjacent (oth-
erwise, G contains K5 , so G would not be planar).
73
Let H = (G/av)/vb. Because of our claim, H has no loop. By induction, there exists
a 5-colouring of H.
Extend the colouring of H to G such that vertices a, b of G are assigned the same colour as
the vertex a = b = v in H.
Thus, we have coloured all vertices of G except v, and the same colour appears twice among
the neighbours of v. We can pick colour c, unused among the neighbours of v, to colour
v.
Here, we started with five faces, and created one new vertex per face (including the infinite
face). The faces in the original planar graph correspond to vertices in the dual (indicated
as the green graph, above). For each edge in the boundary walk of each face, draw an edge
between the two faces. We call this second graph the dual graph.
If we had a bridge in our original graph, we could create an edge with both endpoints being
the same, but the edge would have to cross the bridge visually. That is, we make an edge
that is a loop.
Definition. Let G = (V, E) be a graph with a planar embedding and faces F1 , F2 , . . . , Ff .
The dual graph G? is the graph where:
• Vertices of G? are F1 , F2 , . . . , Ff .
74
Remark: G? is planar, but G? need not be simple even if G is simple. Consider the case
when G is a triangle. Then G? is one edge connecting the face with the infinite face, as
well as two additional parallel edges, which prevents G? from being simple. Or, if G is just
two vertices joined by an edge, G? is just a single loop, which is not allowed in simple graphs.
where q is the number of edges of G. We will now provide an alternate proof of this using
dual graphs.
Proof. Consider the graph G? . We have:
X
2q = deg(v)by the handshake lemma
v∈V (G? )
X
= deg(f )
f ∈faces(G)
How do colourings work with dual graphs? Let’s look at the four colour theorem, stated in
a different way.
Theorem (Four Colour Theorem – Face Version). Let G be a graph with a planar embedding.
Assume G is connected and has no bridge. Then we can colour the faces of G with four
colours such that any two faces sharing an edge are assigned distinct colours.
Proof. Let G? be the dual of G. Since G has no bridge, G? has no loop. By the vertex
version of the four colour theorem, there exists a 4-colouring of the vertices of G? , which
gives a 4-colouring of the faces of G.
That’s all we’re going to discuss about planar graphs.
10 Matching
We will assume graphs are simple for the rest of the course.
Definition. Let G = (V, E) be a graph. The matching M of G is a subset of the edges
such that no two edges of M share an endpoint.
It’s trivial to see that ∅ is a matching, as is any single edge in the graph.
Example 10.1. The highlighted edges in the following graph form a matching because no
two edges share a vertex.
75
Our goal for the remainder of the course: we want to find an algorithm to produce a match-
ing with as many edges as possible. That’s a tough goal, so we will restrict ourselves to
finding a maximum matching in bipartite graphs only.
Ideally, the algorithm will be fast and easily verifiable. We need to be able to quickly
produce a result, and we need to be able to easily convince someone that it is indeed a
maximum matching.
Definition. A maximum matching is a matching with as many edges as possible in G.
Definition. A matching is said to be maximal if adding any additional edge will result in
a set that is no longer a matching.
← March 27, 2013
Example 10.2. Find a maximum matching (a matching with as many edges as possible)
for the following graph.
The red edges represent a matching that is not maximum. The green edges represent a
maximum matching, as required.
Suppose A = {alice, bob, carol} and J = {1, 2, 3, 4}. We also have that:
• Alice is qualified for jobs 1 and 3.
• Bob is qualified for jobs 2 and 4.
• Carol is qualified for jobs 1, 2, and 4.
76
We want to assign applicants to jobs such that:
• No applicant is assigned two or more jobs.
• No job is assigned two or more applicants.
We want to represent this as a graph problem. Note that it’s a bipartite graph, as illustrated
here:
alice 2
bob 3
carol 4
The edges represent all cases where a particular applicant is considered to be qualified for a
job. The vertices are partitioned into applicants and jobs.
10.2 Saturation
In order for us to move on, we need a few definitions.
Definition. Let G be a graph with matching M . Vertex v is saturated if v is the endpoint
of an edge of M . Otherwise, v is said to be unsaturated.
77
Suppose you’re given Kn,m (a complete bipartite graph). How many perfect matchings are
there? Well, we have two cases:
1. n 6= m. Zero perfect matchings exist. One vertex will not have any corresponding
vertex in the other partition.
2. n = m. n! perfect matchings exist. For the first vertex, we have n choices, n − 1
choices for the second vertex, and so on.
Writing down every matching to determine a maximum matching is probably not a great
idea. Factorials become large very quickly.
s t
In this graph, the red edges are a smaller, non-perfect matching, and the green edges repre-
sent a perfect matching.
To get a larger matching, we need to remove something and add something – we can’t
just add an edge. In the red path, the first and last edges are not in the matching, and
they’re alternating. We can just shift our matching over to add that additional edge (which
is what the green matching represents). This will result in matching that is larger by one
edge.
Definition. Let G be a graph with matching M , and let P = e1 , e2 , . . . , ek be a path
between vertices s and t. P is alternating if for all i = 1, . . . , k − 1, exactly one of ei , ei+1
is in M .
Definition. P is augmenting if it is alternating and s and t are unsaturated.
Remark: let G be a graph, and let M be a matching of G. Let P be an augmenting
path. Let M 0 = M ∆P (where M ∆P = (M ∪ P )\(M ∩ P )). Then M 0 is a matching and
|M 0 | = |M | + 1.
78
10.2.1 Algorithm for Maximum Matching
← April 1, 2013
A high-level algorithm for finding a maximum matching is as follows.
M = ∅;
while (loop) do
if M is maximum then STOP;
else
find an augmenting path P ;
M := M ∆P ;
end
end
This algorithm is a nice idea, but it is not nearly precise enough – you couldn’t program it
currently. How do we know if M is maximum? We can’t simply enumerate all matchings,
that’d get out of hand quickly. Also, how do we find an augmenting path P ?
We will determine how to know if M is maximum, and how to find an augmenting path P ,
on bipartite graphs.
79
The minimum vertex cover problem is where you aim to find a vertex cover with as
few vertices as possible.
Let’s examine the size of a graph’s maximum matching with the size of its minimum vertex
cover.
Example 10.7. Consider the following graph.
80
We’ll use these results to introduce a lemma.
Theorem. Let M be a matching, and let C be a cover. Then |M | ≤ |C|.
To prove this lemma, just look at the edges in the matching. At least one vertex is needed
for every edge in the matching, and those vertices are all distinct. Let’s formalize this proof.
Proof. Let M = {e1 , . . . , ek } be a matching. Since C is a cover, for every edge ei , C contains
one endpoint, say wi , of ei .
As C ⊇ {w1 , . . . , wk }, |C| ≥ k.
Now, how can we convince someone that a particular matching is a maximum matching?
We can note that there exists a cover of a certain size, which implies that no matching of a
greater size exists, according to the lemma we just introduced.
Theorem. Let M be a matching, and let C be a cover. Suppose |M | = |C|. Then:
1. M is a maximum matching.
2. C is a minimum cover.
Proof. For (1): let M 0 be any matching. We know that |M 0 | ≤ |C|, by the previous theorem,
and we know that |C| = |M | (by definition in this lemma). Therefore, |M 0 | ≤ |M |.
For (2): let C 0 be any cover. We know that |C 0 | ≥ |M |, by the previous theorem, and
we know that |M | = |C| (by definition in this theorem). Therefore, |C 0 | ≥ |C|.
Note that the second theorem we just introduced implies that max{|M | : M is a matching} ≤
min{|C| : C is a cover}. However, is this ≤, or is it always =? It turns out, if the graph
contains an odd cycle, then |M | =
6 |C|.
Theorem (König’s Theorem). In a bipartite graph, max{|M | : M is a matching} ≤ min{|C| :
C is a cover} holds with equality.
That is, König’s Theorem states that the size of the maximum matching of a bipartite graph
is equal to the size of the smallest cover of that graph.
Before we can discuss the proof of König’s Theorem, we’ll need to introduce some addi-
tional terminology.
10.4 XY-Structures
Let G = (V, E) be a bipartite graph with partition A, B of V . Let M be a matching of G.
Definition. A vertex v is special if:
1. v ∈ A and v is not saturated, or
2. There exists an alternating path P (v) where one endpoint is v and the other is of type
(1).
81
← April 3, 2013
Definition. Let X denote the special vertices in partition A, and let Y denote the special
vertices in partition B.
We aim to show:
1. C is a cover.
2. |C| = |M |.
Let’s start with (1). Suppose C is not a cover. Then there exists an edge uv with u ∈ X
and v ∈ B\Y .
Case 1: u is unsaturated. The edge uv implies that v must be special, which implies that
v ∈ Y , which is a contradiction.
Case 2: u is the endpoint of P (u). Then P (u) together with uv is an alternating path.
This implies that v is special, which means v ∈ Y , which is a contradiction.
For (2), we want to show that |C| = |M |. Intuitively, we want to show that |M | =
|Y | + |A\X|, since |Y | + |A\X| = |C|. In order to prove this, we really need to prove
these three things:
(i) Edges of M are between X and Y and between A\X and B\Y .
(ii) Vertices in A\X are saturated.
(iii) Vertices in Y are saturated.
Let’s start with (i). Suppose (i) does not hold. Then there exists an edge uv ∈ M where
u ∈ Y and v ∈ A\X. Since v is special, there exists an alternating path P (u). The alternat-
ing path obtained by adding uv to P (u) implies that v is special, which implies that v ∈ X,
which is a contradiction.
The proof for (ii) is very simple. (ii) holds because unsaturated vertices of A are in X.
Finally, let’s prove (iii). Suppose there exists u ∈ Y where u is not saturated. Then
P (u) is an alternating path. This is a contradiction since M is a maximum matching.
We’ll use a similar approach to that of this proof for the algorithm we need.
10.4.1 Algorithm For Finding a Maximum Matching and Minimal Vertex Cover
Input: a bipartite graph G = (V, E) with partition A, B.
82
Output: a matching M and a cover C where |M | = |C|.
1 5
2 6
3 7
4 8
X is defined as all unsaturated vertices in A and all vertices accessible to such vertices via
an alternating path. The definition of Y is similar, but on partition B.
So, we have:
X Y X Y
2 5 1
4 8 3
7
We now have that 7 ∈ Y is unsaturated. P (7) = 48, 83, 37. We now have M 0 :
M 0 = {15, 38}∆{48, 38, 37} = {15, 48, 37}
83
We now have to repeat the process with our new matching M 0 .
A B
1 5
2 6
3 7
4 8
X Y X
2 5 1
We have that X = {1, 2} and Y = {5}. Y contains only saturated vertices, so we stop. The
cover we found is:
1 6 3 8
5 2 7 4
This is a bipartite graph with partitions A = {1, 2, 3, 4} (red) and B = {5, 6, 7, 8} (green).
84
X Y X Y X
8 3 6 1
7 2 5
We now have 5 ∈ Y which is an unsaturated vertex. P (5) = 47, 72, 25. We now have M 0 :
M 0 = M ∆P (5) = {16, 38, 27}\{47, 72, 25} = {16, 38, 47, 25}
1 6 3 8
5 2 7 4
C = (A\X) ∪ Y = A = {1, 2, 3, 4}
A B
Does this graph have a perfect matching? No, since there exists a cover of size 3 (indicated
in blue).
85
Let’s look at another reason we wouldn’t have a perfect matching. Look at the vertices
indicated in green. One of these vertices will not be covered by a matching.
We need at least the same number of vertices in N (S) (the neighbours of S), otherwise
a perfect matching is not possible.
Definition. Let G = (V, E) be a bipartite graph with partitions A and B. Let S ⊆ A.
Then N (S) = {v ∈ V |∃uv ∈ E, u ∈ S}. That is, N (S) denotes the neighbours of S.
Example 10.12. Consider the following graph.
A B
1 4
2 5
3 6
In this graph, if S = {1}, N (S) = {4, 5}. Similarly, if S = {2, 3}, N (S) = {4, 6}.
Proposition. Suppose the bipartite graph G = (V, E) has a perfect matching. Then:
1. |A| = |B|.
2. ∀S ⊆ A, |N (S) ≥ |S|.
((1) and (2) are necessary conditions.)
Proof. Let M be a perfect matching.
1. This is like a function, because each vertex in A should map to exactly one vertex in
B. More formally, M defines a bijection between A & B. Therefore, |A| = |B|.
2. Let S = {v1 , . . . , vk }. Since M is a perfect matching, there exist edges of M vi wi
for i = i, . . . , k. This implies that w1 , . . . , wk ∈ N (S), since wi , . . . , wk are distinct.
Therefore, |N (S)| ≥ k = |S|.
Theorem (Hall’s Theorem). A bipartite graph G = (V, E) with partitions A and B has a
perfect matching if and only if |A| = |B| and for all S ⊆ A, |N (S)| ≥ |S|.
← April 8, 2013
Proof. We proved the forwards direction of this statement in the previous proposition.
For the reverse direction, assume |A| = |B| and suppose there does not exist a perfect
matching. We need to show that there exists S ⊆ A such that |N (S)| < S (that is, we’re
aiming to prove the contrapositive).
Since there does not exist a perfect matching, we know that the size of the maximum
86
matching is less than |A|. By König’s theorem, we know there exists a cover C where
|C| < |M |.
|N (A\C)| ≤ |B ∩ C|
≤ |B ∩ C| + |A ∩ C| −|A ∩ C|
| {z }
|C|
87
Clicker Questions
← January 21, 2013
• How many bijections are there from {1, . . . , n} to {1, . . . , n}? n!, since you can’t map
two elements in the first set to the same one element in the second set.
• Let S be a set of objects with weight function w. Suppose that S = A ∪ B. Does
φS (x) = φA (x) + φB (x)? No, not always. The sum lemma only applies when A and
B are partitions of S.
• Let S = {(a, b)|a, b ≥ 1 ∈ Z}, w[(a, b)] = a − b. What is the generating function for
S? There is no generating function for S, since it is not a power series. There are an
infinite number of pairings – that is, there are an infinite number of objects with the
same weight.
x2
1
x2 + x3 + x4 + x5 + . . . = x2 (1 + x + x2 + . . .) = x2 =
1−x 1−x
1
• Is A(B(x)) a power series for A(x) = 1 + x + x2 + . . . and B(x) = 1−x ? No! We can
0 1 2
only get a power series if [x ]B(x) = 0, but B(x) = 1−x = 1 + x + x + . . ..
1 9
• What is the coefficient of x3 for (1−x) 7 ? The coefficient is 2 . This could be found
using the formula:
1 n+k−1
[xn ] =
(1 − x)k k−1
• The number of ways of spending exactly $237 to buy oranges ($1 each) and/or mangos
($2 each) is. . . ? It’s [x237 ](1 + x + x2 + x3 + . . .)(1 + x2 + x4 + x6 + . . .).
You can represent this as a pair, (a, b), where a is the number of oranges and b is
the number of mangos. Define a weight function w[(a, b)] = a + 2b. We also have
S = {(a, b)}, A = {0, 1, . . .}, B = {0, 1, . . .}. Also, define weight functions for A and
B: w(a) = a, w(b) = 2b. The generating series are φA (x) = 1 + x + x2 + . . . and
φB (x) = 1 + x2 + x4 + . . .. Finally, use the product lemma on φA (x) · φB (x).
• The set of binary strings without consecutive zeroes can be described as. . . ? The set
can be described as ({, 0}{1})? {, 0}.
We have to make sure this expression does not generate anything that is not in the set.
Then we think about how to generate any arbitrary string contained in the set we’re
trying to express. There is a unique way to generate each string with the expression.
88
← February 27, 2013
• The general solution of the recurrence relation an − 4an−2 = 0 is given by an =
c1 2n + c2 (−2)n .
an−2 indicates that the degree of the characteristic polynomial is 2. So, we get that
p(x) = x2 − 4 = (x + 2)(x − 2), which has roots -2 and 2.
• Suppose an = (c1 n + c2 )3n . Then it is the general solution to the recurrence an −
6an−1 + 9an−2 = 0.
Note that 3 corresponds to the root, which appears with multiplicity 2. The char-
acteristic polynomial is p(x) = (x − 3)2 = x2 − 6x + 9.
• How many vertices are there in a 4-regular graph with 40 edges? 20.
P
Recall that v∈V deg(v) = 2|E| (by theorem), so we get:
X
deg(v) = 2|E|
v∈V
4|V | = 2|40|
4|V | = 80
|V | = 20
a b x y
c d z w
a→x
d→y
c→z
b→w
a 2 b
1 3 5
c 4 d
89
← March 15, 2013
• Let T be a tree with 123 vertices. How many bridges does it have? 122, since no edge
is in a cycle in a tree, and the number of edges is equal to the number of vertices minus
one (in a tree).
• Let G be a graph with p vertices and q edges. Suppose G has 17 components and no
cycles. Then q = p + 17. Each of the 17 components is a tree, and every tree has one
more vertex than edges.
• Let G be a bipartite graph with partitions X, Y . Suppose G is k ≥ 1 regular. Is
|X| = |Y | true? Yes, always, since |X|k is equal to the number of edges, which equals
|Y |k.
• Is the following graph G planar?
1 2
8 3
6 F 7 4
90
No. There is a subdivision of K5 in this graph, which makes it non-planar.
• What is the minimum number of colours needed to colour this graph (not shown here)?
Four, because this was contained within the graph:
2 2
4
4
5 5
1 3 1 3
7
7
6 6
No. There are no boundary walks of length five in the first graph, but there are in the
second. The planar duals are not the same. Note that the dual is of the drawing, not
of the graph itself.
• How many faces does a connected planar graph with 30 vertices and 100 edges have?
By Euler’s formula, p − q + f 2, we get that f = 2 − p + q = 2 − 30 + 100 = 72.
• What is the minimum number of edges you need to remove from this graph to make
it planar?
91
6
3. Note that the number of edges is 2 = 15. A planar graph with six vertices can
only have 3 · 6 − 6 = 12 edges.
• Do the red edges in the following form a matching?
Yes.
92