You are on page 1of 82

Introduction to

Discrete Mathematics
MAT202H5 Course Notes, Fall 2019

University of Toronto Mississauga

t.j. yusun
MAT202H5F - Discrete Mathematics (Fall 2019) CONTENTS

Contents

1 Review of MAT102 3
1.1 Sets and Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2 Logic and Proof Techniques . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.3 Integers and Divisibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.4 Reading and Writing Proofs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

2 Counting Techniques 11
2.1 The Basic Counting Principles . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.2 Permutations and Combinations . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
2.3 Binomial Coefficients . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
2.4 The Balls in Bins Formula . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
2.5 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
2.6 Additional Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

3 Pigeonhole and Inclusion-Exclusion 28


3.1 The Pigeonhole Principle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
3.2 Principle of Inclusion-Exclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
3.3 Additional Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36

4 Congruence Modulo n 38
4.1 Equivalence Relations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
4.2 Congruence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
4.2.1 Solving congruences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
4.3 Euler’s Theorem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
4.3.1 Proof of Euler’s Theorem . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
4.4 The Chinese Remainder Theorem . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
4.5 The RSA Cryptosystem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
4.6 Additional Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54

5 Graph Theory 57
5.1 Modeling using Graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
5.2 Definitions and Eulerian Graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
5.3 Isomorphisms and Subgraphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
5.4 Connectedness and Trees . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71

1 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) CONTENTS

5.5 Bipartite and Hamiltonian Graphs . . . . . . . . . . . . . . . . . . . . . . . . . . 75


5.6 Additional Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79

2 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019)

1 Review of MAT102

The word discrete in the title of our course means separate; something that is not smooth. In
the study of discrete mathematics we will typically concern ourselves with discrete objects such
as the integers, graphs, finite and countable sets. (In contrast, excluded from this are objects
that may vary continuously, such as those ones covered in trigonometry, calculus, and Euclidean
geometry.)
Many of the concepts you learned in your MAT102 course will be useful in MAT202; in this
chapter we briefly review some definitions and results, and present some exercises to warm up
for the rest of the course!1

1.1 Sets and Functions

A set is just a collection of objects (where the order in which the objects are listed does not
matter). The following set operations should be familiar to you:

• Intersection A ∩ B • Complement Ac • Cartesian product A × B


• Union A ∪ B • Set difference A \ B

We also recall that proving the set A is a subset of the set B simply necessitates showing that
any element of A can also be found in B.

Definition 1.1 (Set inclusion and equality)


If A and B are sets in some universe U , then we say A is a subset of B, denoted by
A ⊆ B, if
(∀x ∈ U )(x ∈ A ⇒ x ∈ B).
We say that A and B are equal as sets if A ⊆ B and B ⊆ A both hold. This means that

(∀x ∈ U )(x ∈ A ⇔ x ∈ B).

Exercise 1.2. Define

A = {k ∈ Z : k = 6s + 3 for some s ∈ Z} and B = {m ∈ Z : m = 3t for some t ∈ Z}.

Prove that A ⊆ B holds.

We will use the standard notation for these sets of numbers:

• N = {1, 2, 3, . . .} • R = (−∞, ∞), the set of real numbers

• Z = {. . . , −2, −1, 0, 1, 2 . . .} • Intervals of real numbers (a, b), [a, b], and
other combinations, possibly with −∞ or
• Q, the set of rationals ∞ as one or both of the endpoints.

Note: Interval notation is used to refer to sets of real numbers. It is incorrect, for instance, to
say that (−2, 4) = {−1, 0, 1, 2, 3}, or that {0, 1, 2, 3, . . .} = [0, ∞). Watch your notation!
1
The material in Sections 1.1 to 1.3 is from MAT102H5 Introduction to Mathematical Proofs by Shay Fuchs.

3 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 1.1 Sets and Functions

A function f : A → B takes elements from its domain A and assigns to each one an element
from the codomain B.

Definition 1.3
A function f : A → B is

(a) injective if for every x1 6= x2 ∈ A, f (x1 ) 6= f (x2 ).

(b) surjective if for every y ∈ B, there exists an x ∈ A so that f (x) = y.

(c) bijective if it is both injective and surjective.

Exercise 1.4. For each function, determine if it is injective, surjective, bijective, or


none of these:

(a) f : R → (0, +∞), f (x) = x2 + 1

(b) g : N → N, g(m) = 3m + 7m2


ab(b − 1)
(c) h : Z × Z → Z, h(a, b) =
2

Definition 1.5 (Compositions)


Given two functions f : A → B and g : B → C, the composition g ◦ f : A → C is
defined as (g ◦ f )(x) = g(f (x)) for all x ∈ A.

Theorem 1.6
The composition of two (injections, surjections, bijections) is an (injection, surjection,
bijection).

Exercise 1.7. Prove Theorem 1.6.

Later in the course we will learn techniques for counting objects and proving that two sets have
the same number of elements; the notion of cardinality will be a useful tool to remember.

Definition 1.8
Two sets A and B are said to have the same cardinality, written as |A| = |B|, if there
exists a bijection between them.
We also say A has cardinality less than or equal to the cardinality of B, written as
|A| ≤ |B|, if there exists an injective function from A to B.

Exercise 1.9. Prove that the set of odd integers O = {. . . , −3, −1, 1, 3, . . .} has the
same cardinality as N.

4 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 1.2 Logic and Proof Techniques

Definition 1.10 (Power set)


Let A be a set. The power set of A, denoted by P (A), is the set

P (A) = {X : X ⊆ A},

that is, it contains all subsets of A.

Exercise 1.11. Prove that if A is finite, then |P (A)| = 2|A| .

1.2 Logic and Proof Techniques

Mathematical statements can typically be phrased as an implication

P ⇒ Q, read as ‘if P , then Q,’

where P or Q may be complex statements themselves that involve conjunctions (and), disjunc-
tions (or), and the like. There are various ways in which an implication can be proven true,
and there is no hard and fast rule that dictates which proof method to use given a particular
problem. In MAT102 you were introduced to the following proof techniques:

• Direct proof: Assume P is true, then prove Q is true.

• Contrapositive: Assume ¬Q is true, then prove ¬P is true.

• Contradiction: Assume the conclusion is false, then use this to arrive at a statement that
contradicts one of the assumptions.

Exercise 1.12. Prove each statement, noting which proof technique you used.
(a) The sum of two odd numbers is even.

(b) The square of an even number is divisible by 4.

(c) The equation x3 + x + 1 = 0 has no rational solutions.

(d) For integer n, if n3 + 5 is odd, then n is even.

(e) There is no smallest positive rational number.

(f) Every multiple of 4 can be written as 1 + (−1)n (2n − 1) for some n ∈ N.

(g) The sum of a rational number and an irrational number is irrational.

(h) A three-digit natural number is divisible by 9 if and only if the sum of its digits is
divisible by 9.

(i) If A and B are defined as in Exercise 1.2, then B is not a subset of A.

5 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 1.2 Logic and Proof Techniques

Many of these statements are quantified universally, which means it involves some variable (say
n), and you need to prove the claim holds for all relevant values of the variable (say n ∈ N).
For (a), (b), and (d) for example, the relevant quantities are integers; the statements need to be
proven for all integers.
We can use mathematical induction to prove that a statement is true for all natural numbers.

Theorem 1.13 (Principle of Mathematical Induction)


Let P (n) be a predicate defined for n ∈ N. If the following conditions hold:

(a) P (1) is true;

(b) For all k ∈ N, P (k) ⇒ P (k + 1) is true.

then P (n) is true for all n ∈ N. One can also replace (b) with the following:

(b*) For all k ∈ N, [P (1) ∧ P (2) ∧ · · · ∧ P (k)] ⇒ P (k + 1) is true.

This is called strong induction, where one assumes the induction step holds for all
natural numbers from 1 to k in order to prove the claim for k + 1.

Depending on what is being proved, one may need to make slight modifications to the standard
technique: e.g. changing/adding to the base case, or ‘skipping’ from k to k + 2 in the case when
one only has to prove the claim for every other natural number.

Exercise 1.14. Prove the following statements using induction:

(a) 12 + 22 + 32 + · · · + n2 = 16 n(n + 1)(2n + 1) for all n ∈ N.

(b) 2n ≥ n2 for all n ∈ N, n ≥ 4. (c) 42n − 1 is divisible by 5 for every n ∈ N.

Exercise 1.15. The Fibonacci sequence {Fn } is defined recursively as



Fn = Fn−1 + Fn−2 , n ≥ 3
 F =F =1
1 2

 √ n  √ n
√1 1+ 5 √1 1− 5
Prove that Fn = 5 2 − 5 2 using strong induction.

Exercise 1.16. Let Tn be the number of ways one can tile a 2 × n grid with 1 × 2
rectangles. For example, T2 = 2 since there are two tilings of a 2 × 2 grid using only
1 × 2 rectangles:
Find a recurrence relation for Tn
and prove that Tn = Fn+1 as de-
fined in Exercise 1.15.

6 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 1.3 Integers and Divisibility

1.3 Integers and Divisibility

For completeness we restate here the definition of divisibility and the Division Algorithm.

Definition 1.17 (Divisibility)


Let a ∈ Z and b ∈ Z \ {0}. We say that a is divisible by b, or b divides a, denoted by
b | a, if there exists m ∈ Z such that a = bm.
If b is not divisible by a, then we write b - a.
We say that the natural number p is a prime number if the only natural numbers that
divide p are 1 and p.

Theorem 1.18 (The Division Algorithm)


Let a, b ∈ N. Then there exist unique q and r that satisfy all of the following:

a = qb + r, q ≥ 0, 0 ≤ r < b.

Exercise 1.19. Find q and r that satisfy the Division Algorithm for the following pairs
of numbers a and b:

(a) a = 140, b = 22 (b) a = 22, b = 140 (c) a = 735, b = 21

Definition 1.20 (GCD)


Given integers a and b not both zero, their greatest common divisor, denoted by
gcd(a, b), is the largest integer that divides both numbers.
We say that a and b are relatively prime if gcd(a, b) = 1.

There are a number of ways to determine the GCD of two numbers a and b:

• Listing all factors of a and b, then finding the largest one they have in common
• Writing out the prime factorizations of a and b, then collecting all common prime factors
• The Euclidean Algorithm (repeated division)

Exercise 1.21. Apply the three techniques above to compute gcd(220, 360).

Theorem 1.22 (Bezout’s Identity)


Let a, b ∈ Z, not both zero. Then there exist m, n ∈ Z such that am + bn = gcd(a, b).

Exercise 1.23. Find a pair of integers x and y such that 13x + 11y = 2.
Then explain why the equation 13x + 11y = 2 has infinitely many solutions. Can you
characterize all such solutions?

7 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 1.4 Reading and Writing Proofs

Exercise 1.24. Prove that the equation 14x − 35y = 9 has no integer solutions.

Exercise 1.25. Let a, b, d ∈ N. Prove that ax + by = d has integer solutions x and y


if and only if gcd(a, b) | d.

Lemma 1.26 (Euclid’s Lemma)


If p is prime, and a and b are integers such that p | ab, then either p | a or p | b (or both).

Exercise 1.27. Prove Euclid’s Lemma using Bezout’s Identity (Theorem 1.22).

Exercise 1.28. Let m, a, b ∈ N. Using Bezout’s Identity (Theorem 1.22), prove that
if m | ab and gcd(a, m) = 1, then m | b.

1.4 Reading and Writing Proofs

Proofs are a form of communication. They are used to argue (that a claim holds true); and
sometimes explain (why a claim is true).
When writing proofs, one needs to be clear, complete, and correct. Comment on the three proofs
below. Which one(s) is/are

• convincing? • missing steps? • easiest to read? • correct?

Statement: Let m ∈ Z. Then m is even if and only if m3 is even.

Proof 1: (⇒) m = 2k ⇒ m3 = 8k 3 = 2(4k 3 ), so m3 is even.

(⇐) By contradiction. Assume m3 is even but m is odd.

Then m = 2k + 1 ⇒ m3 = (2k + 1)3 = 8k 3 + 12k 2 + 6k + 1, which is odd. Contradiction,


so m must be even.

So m even ⇐⇒ m3 even.

Proof 2:
m even ⇐⇒ m = 2k ⇐⇒ m3 = 8k 3 ⇐⇒ m3 = 2(4k 3 ) ⇐⇒ m3 even, hence
proven.

8 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 1.4 Reading and Writing Proofs

Proof 3: We want to prove that

m is even ⇐⇒ m3 is even.

(⇒) First, we show m even ⇒ m3 even.


If m is even, then we can write m = 2k for some k ∈ Z. Then

m3 = (2k)3 = 8k 3 = 2(4k 3 ).

Since k ∈ Z, then 4k 3 ∈ Z as well, and so m3 is even.

(⇐) Next, we prove that m3 even ⇒ m even. To do this we prove the contrapositive: If
m is odd, then m3 is odd.

If m is odd, then there is a k ∈ Z such that m = 2k + 1. Then

m3 = (2k + 1)3 = 8k 3 + 12k 2 + 6k + 1 = 2(4k 3 + 6k 2 + 3k) + 1.

Since k ∈ Z, then 4k 3 + 6k 2 + 3k ∈ Z as well. Therefore m3 is odd.

This completes the proof.

The use of English words makes proofs more approachable and understandable. Here are some
commonly-used phrases in mathematical proofs. Note the use of the plural we instead of the
singular I.

Declare intentions Clarify implications

• We will prove . . . by . . . • Since. . . then. . .

• We want to show that. . . • Because. . . , we have . . .

• In order to prove . . . we . . . • Therefore/thus/hence. . .

• At this point we need to find . . . • This means that. . .

• We consider the following cases . . . • The previous statement implies. . .

Explain steps

• By assumption, we know that . . .

• By simplification/manipulation/rearranging, . . .

• Because of [property/theorem/definition], we have . . .

9 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 1.4 Reading and Writing Proofs

Exercise 1.29. Write a complete and convincing proof of the following claim that uses
the mathematical statements given below. Note: This is a proof by contradiction.
Claim: Let A, B be subsets of some universal set U . Prove that if (A ∪ B)c = Ac ∪ B c ,
then A ⊆ B.

• x ∈ A. • x ∈ Ac ∪ B c .

• x 6∈ B. • x ∈ A ∪ B.

• x ∈ Bc. • x 6∈ (A ∪ B)c .

10 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019)

2 Counting Techniques

Objectives:

• State the Sum Rule and the Product Rule, and use them to solve counting problems.

• Derive the formulas for permutations and combinations (of n objects taken k at a time),
multi-permutations, and permutations and combinations with repetition allowed

• Given a word problem, recognize which of the above techniques is applicable, and use it
to solve the problem.

• Prove simple combinatorial identities.

2.1 The Basic Counting Principles

In this chapter we will develop techniques for counting! When you hear the word count you
probably think about listing or enumerating objects. For example:

• How many siblings do you have?

• Count the number of students enrolled in MAT202 this term.

• How many buildings are there on the UTM campus?

Often we are also interested in counting the number of different ways some given scenario or
condition can happen. For instance, consider the following example:

Example 2.1. In the game Kiss, Marry, Kill a , you are given three different names,
and you must decide which one among them to kiss/marry/kill (with the understanding
that you can’t kiss the person you marry, and the person you kiss, you can only kiss
one time).
How many possible ways can you answer?
Solution:
Suppose the three names are A, B, and C. We can just list all possibilities to find that
there are 6 ways:

Kiss A A B B C C
Marry B C A C A B
Kill C B C A B A

a
You may know this game by a different name.

11 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 2.1 The Basic Counting Principles

Example 2.1 is small enough that we can count the number of possibilities by listing them. Can
you do the same for the following exercise? What do you notice about your answer to part (a)?

Exercise 2.2. Three friends (Mina, Lisa, and Wendy) were able to get three seats
together in a row at a Coldplay concert.

(a) How many ways can they choose to sit?

(b) How many ways can they sit if Lisa insists on sitting in the middle?

The techniques we will develop will help us count when the number of possibilities is too large
that we can’t simply list them all! Here is one example where listing all possibilities seems like
a bad idea:

Example 2.3. There are 10 dogs up for adoption at your local animal shelter. You
and 9 other friends decide to adopt one dog each.
How many ways can you assign dogs to people?
Solution (sort of ): If we first fix you and your friends in some specified order (human
1, human 2, human 3, and so on) and name the dogs A, B, C, up to J, then each
adoption arrangement corresponds to an ordering of the letters A to J in a list, where
the position of each letter corresponds to the person adopting that dog.
For example, the arrangement

J I H G F E D C B A
↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
1 2 3 4 5 6 7 8 9 10
means that dog J is assigned to human 1, dog I is assigned to human 2, and so on,
while the arrangement DJABECIHGF means dog D is assigned to human 1, dog J to
human 2, and so on..
You should quickly realize there are too many combinations to list!

When possible, it is a good idea to exploit the structure of what we are counting! Two rules
for counting will help us get started: the Sum Rule and the Product Rule.

Definition 2.4 (Partitions)


Let A be a finite set. We say that B1 , B2 , . . . , Bm form a partition of A if:

• Bi ∩ Bj = ∅ for all i 6= j, and

• B1 ∪ B2 ∪ · · · ∪ Bm = A.

12 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 2.1 The Basic Counting Principles

Counting Principle 2.5 (Sum Rule)


If B1 , B2 , . . . , Bm form a partition of A, then
n
X
|A| = |Bi | = |B1 | + |B2 | + · · · + |Bm |.
i=1

Exercise 2.6. You plan to move to a new apartment by the end of the month, and
while packing your clothes, you note that you have 3 pairs of black socks, 4 pairs of
white socks, and 2 pairs of blue socks.
How many pairs of socks do you have in total?

Exercise 2.7. TJ is an avid Twitter user, where he manages the following accounts:

• A personal account with 100 followers;

• A K-pop stan Twitter account with 2500 followers;

• A third account with 12000 followers that tweets a picture of a puppy every hour.

Can you determine the total number of unique followers TJ has? Explain whether or
not the Sum Rule is applicable to this problem.

Counting Principle 2.8 (Product Rule)


If a certain operation takes k steps to accomplish, and if there are:

• r1 ways of performing step 1,

• r2 ways of performing step 2 (regardless of how step 1 was performed),

• r3 ways of performing step 3 (regardless of how step 2 was performed),

• and so on. . .
k
Y
Then, there are ri = r1 · r2 · . . . · rk ways of performing steps 1 to k.
i=1

Exercise 2.9. You are deciding what outfit to wear to school today. You have been
putting off doing laundry, so you only have 3 clean shirts and 2 clean pairs of pants.
Also, you have 8 pairs of shoes to choose from.
How many different outfits can you wear to school today? (Assume you cannot go to
school shirtless, pantless, or barefoot!)

Exercise 2.10. Use the Sum Rule to prove the Product Rule. (Hint: induction on k)

13 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 2.2 Permutations and Combinations

Example 2.11. A multiple-choice exam has 20 questions and 4 choices for each ques-
tion. How many possible combinations of correct responses are there?

Exercise 2.12. Apply the Product Rule to answer (a) and (b) of Exercise 2.2, then
generalize this method to count the number of ways to sit n people in a row of n seats.

Definition 2.13 (Factorial)


For integer n ≥ 0, the factorial of n, denoted by n!, is
n
Y
n! = i = n · (n − 1) · (n − 2) · . . . · 2 · 1.
i=1

By convention we define 0! = 1.

Example 2.3 (again): In the dog adoption example, the operation is the assignment
of dogs to humans. There are 10 steps: the first human can pick any one out of the 10
dogs, then the second has 9 choices left, and so on. . .
So, by the Product Rule, there are 10! = 3628800 ways that 10 humans can adopt 10
dogs so that each one gets exactly one dog.
That is, there are 10! possible rearrangements of the letters ABCDEFGHIJ to form a
10-letter word.

2.2 Permutations and Combinations

Definition 2.14 (Permutations)


We define a permutation to be a bijection from a finite set S to itself.
If |S| = n, then there are n! bijections S → S. Equivalently,

• There are n! ways to arrange n distinct objects in a row.

• There are n! rearrangements of a word with n distinct letters. Each rearrangement


is said to be a permutation of the n letters.

Tip: For problems where the answer involves a factorial, it is fine to leave the factorial in your
answer without computing the actual value.

Example 2.15. Let S = {a, b, c, d}. Then the function f : S → S defined by

f (a) = b, f (b) = d, f (c) = c, f (d) = a

is one example of a bijection from S to S. By Definition 2.14, there are a total of


4! = 24 bijections from S to itself.

14 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 2.2 Permutations and Combinations

What if we wanted to rearrange k of the n distinct objects (i.e. only a subset)?

Exercise 2.16. How many four-letter words can be formed using the letters of the
word EQUATION?
(Hint: How many choices do you have for the first letter? the second? etc.)

Exercise 2.17. Use the Product Rule to count the number of ways we can arrange k
objects (taken from a set of n distinct objects) in a row.
Then express your answer in terms of factorials, and complete the statement of Propo-
sition 2.18 below.

Proposition 2.18 (k-permutations of an n-set)


If k ≤ n, the number of permutations of k distinct elements from a set of size n is:

In some textbooks the above quantity is denoted by P (n, k) or n Pk . When solving problems you
may use either notation and leave your answer in that form.

Example 2.19. How many ways can a class of 45 students elect a president, vice-
president, and secretary to represent them on student council?
Solution: This corresponds to the number of permutations of 45 objects taken 3 at a
time, so the total is 45 · 44 · 43 = 85140.
One can also imagine the solution using the Product Rule: there are three steps to this
operation,

(45 choices) (44 choices) (43 choices)

elect a president elect a vice-president elect a secretary.

Then the number of ways to do so is 45 · 44 · 43.

Exercise 2.20. (a) Count the number of three-letter words that can be formed from
the letters of the word ZAHLEN.

(b) How many of the words from part (a) contain only consonants?

(c) How many of the words from part (a) contain exactly one vowel?
(Hint: Product Rule)

15 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 2.2 Permutations and Combinations

The next example shows that having distinct objects is crucial in the statement of Definition 2.14.

Example 2.21. Count the number of arrangements of the letters in the word YEET.
Solution: A misguided attempt to apply Definition 2.14 will yield 4! = 24 possible
arrangements of the word YEET. However, we see that there are only 12 possibilities
when we list them all:

YEET YETE YTEE TYEE TEYE TEEY


EETY EEYT ETYE ETEY EYET EYTE

This is because the letters in the word YEET are not distinct! If we distinguish each
letter E in the word by calling them E1 and E2 , then we see that each arrangement
above actually came from two arrangements, for instance:

YE1 E2 T and YE2 E1 T → YEET


YE1 TE2 and YE2 TE1 → YETE
.. ..
. .

Thus while Definition 2.14 predicts 4! = 24 arrangements, each one is counted twice:
either E1 is somewhere to the left, or somewhere to the right of E2 . Dividing by two
to account for this overcounting gives the correct number, 4!/2 = 12.

What if three letter E’s are repeated? Following the same reasoning, we can distinguish them
first as E1 , E2 , and E3 , then apply Definition 2.14. We will get a number that overcounts the
actual answer by a factor of 6 this time, since there are 3! = 6 ways to arrange these letters:

E1 E2 E3 E1 E3 E2 E2 E1 E3 E2 E3 E1 E3 E1 E2 E3 E2 E1 .

We generalize this to Proposition 2.22, which gives a way to count rearrangements of words when
some letters are repeated. (We say the letters are elements of a multiset, which generalizes sets
to allow for multiple instances of elements.)

Proposition 2.22 (Permutations of a multiset)


Let S be a set with n (not necessarily distinct) objects, such that there are n1 objects of
type 1, n2 objects of type 2, . . ., and nk objects of type k, where n1 + n2 + · · · + nk = n.
Then the number of arrangements of these objects is
n!
.
n1 !n2 ! · · · nk !

Example 2.23. How many arrangements can be formed using the letters of the word
MISSISSAUGA?
Solution: In the word MISSISSAUGA there are 1 M, 2 I, 4 S, 2 A, 1 U, and 1 G,
which is a total of 11. So the number of rearrangements of the word MISSISSAUGA is
11! 11!
= = 415800.
1! 2! 4! 2! 1! 1! 2! 4! 2!

16 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 2.2 Permutations and Combinations

Exercise 2.24. Count the number of ways the letters of the word MATHEMATICS
can be arranged so that

(a) The two M’s are beside each other. (b) The two M’s are not beside each other.
(c) The word MATH appears somewhere in the arrangement.

Exercise 2.25. UTM Athletics is sending a team of 7 players to represent the university
at an Ontario e-sports tournament called The Provincial. Suppose that a total of 30
students tried out for the team.

(a) How many possible teams can be formed from the students who tried out?
(Hint: Each student either makes the team, or doesn’t. Express each possible team
as a sequence of 30 labels, one for each student who tried out.)

(b) Suppose further that there are different positions in the team, as follows:

• 1 carry player • 1 offlane player • 2 reserve players


• 1 mid player • 2 support players
How many possible teams can be formed from the students who tried out? Assume
everyone who tried out can play every position. (Not usually the case in reality. . . )

The scenario in part (a) of Exercise 2.25 is an example where the order in which the students
are picked does not matter – the team is just a collection (set) of 7 players. Here’s a smaller
example:

Example 2.26. Adele is getting married soon, and due to space constraints at the
venue, needs to pick exactly two of her five best friends (Mel B., Mel C., Emma, Geri,
and Victoria) to be her bridesmaids. How many possible combinations are there?
Solution: Each combination of bridesmaids corresponds to a rearrangement of the
symbols ◦ ◦ × × ×, given a fixed arrangement of the five names in a row; for instance,

Mel B. Mel C. Emma Geri Victoria


◦ × × ◦ ×

means that Mel B. and Geri will be bridesmaids, while

Mel B. Mel C. Emma Geri Victoria


× × × ◦ ◦

corresponds to Geri and Victoria being chosen. Applying Proposition 2.22, we see that
5!
there are exactly = 10 possible combinations.
2! 3!

17 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 2.2 Permutations and Combinations

When the usual formula for k-permutations from an n-set (Proposition 2.18) is applied to the
5!
previous example, we get a total of = 60, which is incorrect. The reason is that this
(5 − 3)!
formula treats the pairs
(Geri, Victoria) and (Victoria, Geri)
as different outcomes, while for this problem they both correspond to the same combination of
{Geri, Victoria} being chosen as bridesmaids.
This may remind you of the difference between an ordered n-tuple and a set of n elements –
where the triples (1, 2, 3) and (3, 1, 2) are not equal in R3 , but the sets {1, 2, 3} and {3, 1, 2} are
the same set.
Hence when picking k elements from a set of n, and if order does not matter, we have to divide
by an extra factor of k! to deal with the overcounting.

Proposition 2.27 (Combinations)


A combination of k elements taken from a set S of size n is any k-element subset of S.
The number of such combinations, denoted by nk (read as ‘n choose k’), is
 
n n! n Pk
= = .
k (n − k)! k! k!

Example 2.28. A standard deck of cards consists of 52 cards, which come in 13


ranks (A/ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, J/jack, Q/queen, K/king) of four cards each,
one for each suit: clubs ♣ (a black suit), spades ♠ (black), hearts ♥ (red), diamonds
♦ (red).

(a) How many outcomes (or hands) are possible when you draw five cards at random
from the deck?

(b) How many of these five-card hands comprise only numbered cards?

(c) How many of these five-card hands have exactly two red and three black cards?

Solution: (a) There are 52 distinct cards in the deck, and we are drawing five of them
at random. Each outcome only depends on which cards are drawn, so the order in
52 52!

which we draw them does not matter. Therefore there are 5 = 47! 5! = 2598960
possible five-card hands.
(b) The ranks 2 to 10 are the numbered cards; there are a total of 36 numbered cards
in a deck (9ranks times 4 suits each). The number of five-card hands drawn from these
cards is 36
5 .
(c) The process of forming such a five-card hand can be broken down into two steps:

Step 1: Pick two red cards Step 2: Pick three black cards

These two steps are independent of one another.


 26There are 26 black and 26 red cards,
so the Product Rule tells us that there are 26

2 3 five-card hands with this property.

18 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 2.3 Binomial Coefficients

Exercise 2.29. Solve part (a) of Exercise 2.25 using Proposition 2.27.
Then solve part (b) (and express your answer) using only combinations.

Exercise 2.30. A straight is a hand of five different ranks in consecutive order. For
example: 4♦ 5♥ 6♣ 7♣ 8♦.
Straights can start with an ace (A-2-3-4-5) or 10 (10-J-Q-K-A) or any other numbered
card, but not with any face card (J, Q, or K). How many straights can be formed?

Exercise 2.31. A flush is a hand of five cards, all of the same suit. For example, the
five-card hand 4♠ 5♠ 8♠ J♠ K♠ is a flush.

(a) How many flushes can be formed?

(b) How many flushes are also straights? (This hand is called a straight flush.)

n n
 
Exercise 2.32. Explain why k is equal to n−k by counting the number of k-subsets
of {1, 2, . . . , n} in two ways.

2.3 Binomial Coefficients


n

We discuss the quantity k in more detail and explore some nice related identities and applica-
tions.

Theorem 2.33 (Binomial Theorem)


For k ≤ n, the quantities nk are called binomial coefficients, and is equal to the


coefficient of xn−k y k in the expansion of (x + y)n . That is,


n  
n
X n
(x + y) = (x + y)(x + y) · · · (x + y) = xn−k y k .
| {z } k
n times k=0

Proof. Each factor in the product (x+y)n = (x+y)(x+y) · · · (x+y) contributes either an x or a
y in the resulting expansion. We can express each term in the answer as a sequence of n symbols,
each either an x or a y; for example, picking x from each (x + y) term gives xx · · · x} = xn .
| {z
n times

Hence the number of times xn−k y k appears in the final expansion is precisely the number of
rearrangements of the word
x · · · x} y y · · · y ,
| x{z | {z }
n − k times k times
n! n

which is exactly equal to (n−k)!k! = k by Proposition 2.22.

Exercise 2.34. Determine the coefficient of x4 y 7 in the product (x + y)11 .

19 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 2.3 Binomial Coefficients

Example 2.35. On the xy-plane, a lattice path is a path that moves from integer
point to integer point by taking only steps of length one to the right or upwards. For
instance, the following are three different paths to the point (4, 2):

(4, 2)

(0, 0)

Each path above can be represented as a sequence of 4 R’s and 2 U’s:

RRUURR UURRRR RRRURU

so the total number of lattice


 paths from (0, 0) to (4, 2) is the same as the number of
6 6!
such sequences, which is 4 = 2! 4! .

Example 2.35 illustrates a useful technique in counting problems: by representing what is be-
ing counted (lattice paths) in a different way (sequences of R’s and U’s), we can uncover the
combinatorial structure of these objects, making them easier to count.

Exercise 2.36. Count the number of lattice paths ending at (a, b) for integer a, b ≥ 0.

Exercise 2.37. Determine the number of lattice paths that end at:

(a) (5, 4). (b) (4, 4). (c) (5, 3).

Simplify your answers to arrive at a single number for each part. How are your answers
related?

Theorem 2.38 (Pascal’s Formula)


If n ≥ 1, then      
n n−1 n−1
= + .
k k k−1

Exercise 2.39. Prove Pascal’s Formula using an idea from Exercise 2.37.

Exercise 2.40. Prove Pascal’s Formula by counting the number of size-k subsets of
{1, 2, . . . , n}.
(Hint: Two cases – either the k-subset contains the number 1, or it does not.)

20 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 2.4 The Balls in Bins Formula

Pascal’s Triangle is a triangular array of numbers where the nth row contains the binomial
coefficients nk for k = 0, 1, 2, . . . , n. One can construct it easily following Pascal’s Formula:


start with a 1 in the 0th row, and two 1’s in the 1st row. Then each new row starts and ends
with a 1, while each value in between is obtained by adding the numbers to its upper left and
upper right.
1 coefficients of
1 1 (x + y)1

1 2 1 (x + y)2

1 3 3 1 (x + y)3

1 4 6 4 1 (x + y)4

Exercise 2.41. In the above space, complete Pascal’s Triangle up to the 7th row and
use it to determine the coefficient of x3 y 4 in the expansion of (x + y)7 .

n  
X n
Exercise 2.42. Prove that = 2n for n ≥ 0. (Hint: Stare at Theorem 2.33
k
k=0
until you see it.)

2.4 The Balls in Bins Formula

Consider the following example similar to Exercise 2.11:

Example 2.43. A standardized multiple-choice test for high school students has 40
questions and 5 choices each (A to E).
How many possible ways can the test be answered?
Solution: For each question, there are 5 options, so using the Product Rule, there are
a total of 540 possible ways to complete the test.

This is called a permutation where repetition is allowed, since

• The order in which the answers are picked matters (i.e. A-B-A is different from B-A-A).
• Answers can be repeated – imagine a bag with five balls labeled A to E; for each question
we draw a ball from the bag, record the answer, and put it back.

It is easy to count the number of possibilities here for the general case.

Theorem 2.44 (Permutations with repetition)


If repetition is allowed, the number of permutations of k objects taken from a set of size
n is nk .

There is also a counterpart for combinations in which the order does not matter, which the next
example illustrates.

21 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 2.4 The Balls in Bins Formula

Example 2.45. Ten participants are recruited to join a focus group discussion on rice,
after which they are asked to indicate their preferred type of rice among the following
options:

(a) Arborio (b) Basmati (c) Jasmine (d) Koshihikari (e) Milagrosa

The participants gave their preferences anonymously so the researchers only know how
many participants responded with each option.
How many combinations of answers can the researchers obtain from the study?
Solution: Since we are only concerned with the survey results, outcomes look like
the following, where we only record how many respondents picked the corresponding
option:
Arborio – 3, Basmati – 5, Jasmine – 2
and
Koshihikari – 9, Milagrosa – 1
are examples of possible outcomes; we need to count how many there are in total.
Note that we cannot simply take permutations and then divide by an overcounting
factor since how much we overcount by depends on the actual distribution of answers.
Instead, we envision the process of collecting survey responses as placing balls into
bins with labels ‘Arborio,’ ‘Basmati,’ and so on. (Imagine the participants physically
placing their survey forms into one of five ballot boxes!)
For example, the outcome [Arborio – 3, Basmati – 5, Jasmine – 2] corresponds to the
following distribution of balls into bins:

••• ••••• ••

Arborio Basmati Jasmine Koshihikari Milagrosa

This can also be represented concisely as the pattern

• • • | • • • • • | •• ||

where the four vertical lines denote ‘dividers’ in between each pair of adjacent bins.
Hence the problem of counting the number of possible outcomes is reduced to counting
14! 14
the number of arrangements of 10 • and 4 | symbols, which is 10! 4! = 4 .

Exercise 2.46. Following Example 2.45, express each survey outcome as a pattern of
dots • and bars |, or vice-versa.

(a) Jasmine – 3, Basmati – 3, Arborio – 1, Milagrosa – 3 (b) Koshihikari – 10

(c) • • || • • • • • • || • • (d) || • • • • • | • | • • • •

22 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 2.4 The Balls in Bins Formula

This is called a combination where repetition is allowed, since

• The order in which objects are picked does not matter (i.e. A-B-A is the same as B-A-A).

• Objects can be repeated.

As we saw in Example 2.45, the number of k-combinations taken from a set of size n when
repetition is allowed is equal to the number of ways we can distribute k balls into n bins. This
gives the following formula:

Theorem 2.47 (Combinations with repetition/The Balls in Bins Formula)


If repetition is allowed, the number of combinations of k objects taken from a set of size
n is    
n+k−1 n+k−1
= .
k n−1
This is also equal to the number of ways one can distribute k indistinguishable balls into
n bins.

Proof. The total number of these combinations is equal to the number of ways to arrange k
bullets (• symbols; one for each object), and n − 1 bars (| symbols; to delineate bins):

•| • {z· · · •} | | · · · | ,
| {z }
k copies n−1 copies

k+n−1 k+n−1
 
which is k or n−1 by Proposition 2.22.

Exercise 2.48. A teacher has 20 apples that are to be handed out to 9 students.

(a) How many different ways are there of distributing the apples?

(b) How many different ways are there of distributing the apples so that
each student receives at least one apple?
(Hint: Give one apple to each student to begin, then distribute the rest.)

A nice application of the Balls in Bins Formula is counting the number of nonnegative integer
solutions to equations of the form x1 + x2 + · · · + xn = k.

Example 2.49. Count the number of nonnegative integer solutions to

x1 + x2 + x3 + x4 + x5 = 10.

Solution: The number of solutions is equal to the number of ways to distribute k = 10


balls into n = 5 bins. For example, the solution (x1 , x2 , x3 , x4 , x5 ) = (3, 5, 2, 0, 0)
corresponds to the pattern • • • | • • • • • | • • | |
Hence the total is 10+5−1

10 . (Note the similarities with Example 2.45.)

23 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 2.5 Summary

Corollary 2.50 (Nonnegative integer solutions to x1 + x2 + · · · + xk = n)


The number of nonnegative integer solutions to x1 + x2 + · · · + xk = n is
 
n+k−1
.
k

Exercise 2.51. Determine the number of integer solutions to the system



x1 + x2 + x3 + x4 + x5 + x6 = 15
 x ,x ,x ,x ,x ,x ≥ 0
1 2 3 4 5 6

Exercise 2.52. Determine the number of integer solutions to the equation


x1 + x2 + x3 + x4 = 77 such that:
(a) x1 , x2 , x3 , x4 are nonnegative.

(b) x1 ≥ 4, x2 ≥ 0, x3 ≥ 12, and x4 ≥ 9. (Hint: Exercise 2.48 part (b).)

(c) 0 ≤ x1 ≤ 30, and x2 , x3 , x4 ≥ 0.


(Hint: Solve the problem with x1 ≥ 31 first then subtract from part (a).)

2.5 Summary

In this chapter we developed techniques applicable to a wide variety of counting problems. One
should be able to decide which technique to use by determining if order matters or not; if
repetition is allowed or not; if the underlying set is a multi-set or not. The following table
summarizes these considerations:

Permutation of. . . Combination of. . .


(order matters) (order does not matter)
 
. . . k objects from an n-set, n! n n!
n Pk = =
repetition not allowed (n − k)! k (n − k)! k!

Prop 2.18 Prop 2.27


 
. . . k objects from an n-set, k
n+k−1 (n + k − 1)!
n =
repetition allowed k (n − 1)! k!

Prop 2.44 Thm 2.47

. . . a multiset of size n, with n!


ni objects
Pk of type i and –––––––
n1 ! n2 ! · · · nk !
1 ni = n

Prop 2.22

24 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 2.6 Additional Exercises

2.6 Additional Exercises

Exercise 2.53. The latest album release from the worldwide famous Kpop group ONCE has
four different versions for sale: versions L, O, V, and E. Preorder numbers by version as reported
by Korean newspaper Dispatched are as follows:

• L: 20,000 • O: 25,000 • V: 22,500 • E: 30,000

How many units did ONCE ’s album move in preorders? Can we also determine how many
people preordered the album?

Exercise 2.54. The local bank Factorial Financials enforces the following restrictions on its
online banking passwords:

• Should only contain alphanumeric characters (A-Z, 0-9)

• Should be exactly 8 characters in length

• Should start and end with a letter


How many possible passwords can be created?

Exercise 2.55. A new format for passenger vehicle licence plates issued in the province is being
proposed, that adheres to the following conditions:

• Pattern is AB123-4CD (or letter-letter-digit-digit-digit–digit-letter-letter).

• The letters G, I, O, Q and U cannot be used.

• The first digit cannot be a zero.

• The last two letters must be different.


How many licence plates combinations are possible that satisfy all these conditions?

Exercise 2.56. How many arrangements of the word PANINI


(a) end with the letter P?

(b) start with three vowels?

(c) have all letters in alphabetical order?

(d) have all vowels in alphabetical order (but not necessarily beside each other)?

Exercise 2.57. You can’t spell awesome without me. –Taylor Swift ft. Brendon Urie (2019)
How many arrangements of the word AWESOME do not have the string ME?

Exercise 2.58. Write your own problem where the answer is 72 . Be as creative as you can!


Exercise 2.59. Determine the coefficient of the term x3 y 2 in each product:

(a) (x + y)5 (b) (3x + 2y)5 (c) (2x − y)5 (d) (7x + 7y)5

25 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 2.6 Additional Exercises

Exercise 2.60. Given a standard deck of cards (see Example 2.28), a full house is a five-card
hand with three cards of the same rank, plus two other cards of the same rank. For example,
7♥ 7♦ 7♣ J♥ J♠ is a full house.
How many five-card hands are full houses?

Exercise 2.61. How many ways are there to draw a three-card hand from a standard deck of
cards such that:
(a) all of them are face cards (J, Q, K)?

(b) there are at least two numbered cards?

(c) there are at least two numbered cards, and exactly two red cards?

Exercise 2.62. Count the number of rectangles that can be formed using the edges of a 3 × 3
grid with (0, 0) as one of its vertices. Here are some examples:

Exercise 2.63. Generalize Exercise 2.62 to an m × n grid.

Exercise 2.64. Count the number of rectangles that can be formed using the edges of an m × n
grid (with no restrictions on the vertices). For example, if m = 2 and n = 1, there are 3 possible
rectangles:

Exercise 2.65. Count the number of lattice paths from (0, 0) to (5, 4) that:
(5, 4)
(a) Pass through the point (2, 2).

(b) Avoid the point (3, 3).

(c) Pass through the point (2, 2) and avoid


the point (3, 3). (0, 0)

Exercise 2.66. The Greater Toronto Area has a population of about 6 million. Suppose that
each resident has a jar with 100 coins, consisting of nickels, dimes, quarters, loonies ($1), and
toonies ($2). Prove that two residents must have identical jars.

Exercise 2.67. Count the number of ways to distribute 30 identical balls into 9 different boxes
so that each box is nonempty.

Exercise 2.68. Count the number of ways 2n people can be grouped into pairs.
For example, when n = 2 and there are four people A, B, C, and D, then there are three ways
to pair them up: AB/CD, AC/BD, AD/BC.

26 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 2.6 Additional Exercises

Exercise 2.69. Find the number of integer solutions to each system:


(a) x1 + x2 + x3 = 30, x1 , x2 , x3 ≥ 0

(b) x1 + x2 + x3 + x4 = 2019, x1 ≥ 30, x2 ≥ 40, x3 ≥ 50, x4 ≥ 100

(c) x1 + x2 + x3 + x4 = 2019, x1 ≥ 300, x2 ≥ 400, x3 ≥ 500, x4 ≥ 1000

(d) x1 + x2 + x3 = 12, 3 ≤ x1 ≤ 5, 1 ≤ x2 , 1 ≤ x3 ≤ 7

Exercise 2.70. Find the number of integer solutions to x1 +x2 −x3 = −4 such that x1 , x2 , x3 ≥ 0
and x3 ≤ 10. (Hint: Let y3 = 10 − x3 .)

Exercise 2.71. Find the number of nonnegative integer solutions to x1 + x2 + · · · + xk ≤ n.

Exercise 2.72. Prove the identity k nk = n n−1


 
k−1 for integer 0 ≤ k ≤ n by counting the
number of ways to form a k-person committee from a group of n people, and elect a chair of the
committee.

Exercise 2.73. Prove the identity nk=0 nk = 2n from Exercise 2.42 by counting the subsets
P 

of a set of size n.
2
Exercise 2.74. Prove the identity nk=0 nk = 2n
P 
2 by counting the number of subsets of size
n of the set {a1 , a2 , . . . , an , b1 , b2 , . . . , bn }.

27 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019)

3 Pigeonhole and Inclusion-Exclusion

Objectives:

• State the Pigeonhole Principle and the Principle of Inclusion-Exclusion and apply them
to problems as appropriate.

3.1 The Pigeonhole Principle

The Pigeonhole Principle is not a counting technique per se, but a way to prove that a set of
objects satisfies some existence or extremal property. Before we state the principle formally let’s
look at two examples.

Example 3.1. If six friends order and finish eating a pizza that is divided into 8 slices,
show that one of them gets at least 2 slices.
Proof : Towards a contradiction, suppose that each person gets at most one slice only.
Then they will eat at most only 6 slices among them, leaving the pizza unfinished. This
is a contradiction, so there must be one person who eats at least two slices.

y y Observe that this proof does not deny the possi-


bility of multiple people getting two slices: it is

y y quite possible that four of the friends ate a slice


each, and the two others ate two slices each. It
is also possible that one person ate three slices,
y y while the five remaining friends ate a slice each.

In either case, one person ate at least two slices.


That’s one large pizza!

Example 3.2. A class of 20 students got their quiz scores back, and their instructor
told them the average for the test was 8 out of a maximum of 10. Prove that someone
in the class must have scored at least an 8/10.
Proof : Denote the scores of the students by x1 , x2 , and so on until x20 .
Assume that nobody scored at least an 8/10; that is, xi < 8 for all i = 1, 2, . . . , 20.
Adding all these inequalities and dividing by 20, we obtain
x1 + x2 + · · · + x20 160
x1 + x2 + · · · + x20 < 160 ⇒ < ⇒ class average < 8,
20 20
which is a contradiction.

For both the previous examples, we argued that there is no other way but for the required
property to hold, regardless of how the pizza slices/points are actually distributed among people.

28 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 3.1 The Pigeonhole Principle

We call this kind of proof a non-constructive proof or an existence proof, since it shows that
the property holds without actually giving an example (or an algorithm to create an example).
This is typical of proofs that utilize the Pigeonhole Principle.

Theorem 3.3 (Pigeonhole Principle/PHP)


Placing more than kn objects (pigeons) into n classes (pigeonholes) puts more than k
objects into some class.

Exercise 3.4. Prove Theorem 3.3 following the proof of Examples 3.1, 3.2.

Setting k = 1 in the statement of the principle results in:

Corollary 3.5 (Pigeonhole Principle with k = 1)


If more than n objects are placed into n classes, then some class must have at least 2
objects.

Exercise 3.6. Given any set of eleven natural numbers, prove that there must be two
of them with the same last digit.
(Hint: What last digits are possible? )

Exercise 3.7. Given any set of eleven natural numbers, prove that there must be a
pair of elements whose difference is divisible by 10.
(Hint: Use the previous exercise.)

Often it is not immediately obvious what the pigeons and pigeonholes should be when we
attempt to apply PHP to a problem. Moreover one needs also to give a rule that assigns pigeons
to pigeonholes, such that:

• There are fewer pigeonholes (n) than pigeons (> kn)


• The desired property is satisfied when more than k objects is put into any class

Example 3.8. If five numbers are selected from the set {1, 2, 3, 4, 5, 6, 7}, prove that
two of these numbers must sum to 8.
Solution: Define pigeonholes to be the sets {1, 7}, {2, 6}, {3, 5}, {4}. Then picking five
numbers from {1, 2, . . . , 7} is the same as placing 5 pigeons into these 4 pigeonholes:

{1, 7} {2, 6} {3, 5} {4}

Note that the last pigeonhole by definition can only contain at most one pigeon – this
does not affect the proof. By PHP, there is a pigeonhole with two pigeons. That is,
two numbers are selected from one of these sets; these two numbers must sum to 8.

29 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 3.1 The Pigeonhole Principle

We say that the number five is best possible in this example since it is possible to select four
numbers and not have any pair sum to 8 (for instance, pick 1, 2, 3, and 4). But selecting any 5
numbers guarantees the property is satisfied.

Exercise 3.9. Generalize Example 3.8. That is, if n + 1 numbers are selected from
the set {1, 2, . . . , 2n − 1}, prove that two of these numbers must sum to 2n.

Example 3.10. Given any set of six integers, show that there is a pair among them
whose sum or difference is divisible by 8.
Solution: If a pair of integers a, b among the six have the same remainder when
dividing by 8, then their difference a − b is divisible by 8.
So assume that all six integers have distinct remainders when dividing by 8. Construct
the five pigeonholes {0}, {1, 7}, {2, 6}, {3, 5}, {4} and place each of the six numbers in
the pigeonhole corresponding to its remainder.
By PHP, one of these pigeonholes must have two numbers. That is, summing those
two numbers gives a sum that is divisible by 8.

Note that Example 3.10 is best possible, since we can construct a set of five integers for which
no pair has a sum or difference divisible by 8. For instance, the set {0, 1, 2, 3, 4} (or any set with
the same remainders – one each from 0 to 4) will have no pair that satisfies the desired property.
But in any set of six integers, such a pair exists.

Exercise 3.11. Prove this generalization of Example 3.10:


Given any set of n + 2 integers, there is a pair among them whose sum or difference is
divisible by 2n.

Example 3.12. Prove that in any group of people, there must be two of them with
the same number of friends in the group.
Solution: Suppose there are n people in the group. Then each person can have
0, 1, . . . , or n − 1 friends among the group. This is still n pigeonholes, so we cannot
apply PHP yet.
Observe that it cannot happen that someone has 0 friends, and someone else has n − 1
friends. (Why?) Hence there are only n − 1 possible numbers of friends among the n
people, which means two of them must have the same number of friends, by the PHP.

Exercise 3.13. Prove that any (n + 1)-subset of {1, 2, . . . , 2n} contains two numbers
such that one divides the other.
(Hint: Pigeonholes are {1}, {3}, {5}, . . . , {2n−1}; assign each number to the pigeonhole
that contains its largest odd divisor. If two numbers are in the same pigeonhole, why
should one divide the other? )

30 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 3.2 Principle of Inclusion-Exclusion

Exercise 3.14. Over a two-week period (14 days), you kept track of how many showers
you took. Your records show that you showered at least once every day, and that you
showered a total of 17 times.
By following the steps below, prove that there was a period of consecutive days during
which you showered exactly 10 times.
(a) Define variables xi to be the number of times you took a shower on day i
(1 ≤ i ≤ 14), and define yi = x1 + x2 + · · · + xi to be the partial sums. Explain
why it suffices to prove yi = yj + 10 for some i, j.

(b) Explain why the set {y1 , y2 , . . . , y14 , y1 + 10, y2 + 10, . . . , y14 + 10} can only contain
numbers from 1 to 27.

(c) Apply the PHP to prove the desired property. What are the pigeons and pigeon-
holes?

3.2 Principle of Inclusion-Exclusion

Consider the following example:

Example 3.15. How many integers in U = {1, 2, . . . , 25} are not divisible by 3?
Solution: We first count the number of integers in the set that are divisible by 3:
there are b 25
3 c = 8 of them (where bnc denotes the floor function, which returns the
largest integer that is less than or equal to n.)
Subtracting, we get 25 − 8 = 17 integers in the set U that are not divisible by 3.
(Check that this is the correct number!)

Note that this solution could be phrased in terms of sets: if U = {1, 2, . . . , 25} is the universe,
and A is the set of integers in U divisible by 3, then the desired quantity is |Ac |, and

|Ac | = |U | − |A|.

What if we added a second condition to avoid?

Example 3.16. How many numbers in U = {1, 2, . . . , 25} are not divisible by 3 or 4?
Solution: Following the previous example, there are 8 integers in U that are divisible
by 3. Also, there are b 25
4 c = 6 integers in U not divisible by 4.
However, after subtracting 25−8−6 = 11, we’ve actually removed some numbers twice:
those numbers that are divisible by both 3 and 4 (i.e. divisible by 12). This means we
need to ‘add them back in’ again.
There are b 25
12 c = 2 of these numbers, so the correct total is 20 − 8 − 6 + 2 = 13 integers
in the set that are neither divisible by 3 nor by 4.

31 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 3.2 Principle of Inclusion-Exclusion

We can again write the solution to Example 3.16 in terms of sets:

• U = {1, 2, . . . , 25}
• A1 = integers in U divisible by 3 = {3, 6, 9, 12, 15, 18, 21, 24}
• A2 = integers in U divisible by 4 = {4, 8, 12, 16, 20, 24}
• A1 ∪ A2 = integers in U divisible by either 3 or 4 = {3, 4, 6, 8, 9, 12, 15, 16, 18, 20, 21, 24}
• Desired set: (A1 ∪ A2 )c = integers in U divisible by neither 3 nor 4.

U Observe that when we subtract |A1 | and |A2 |


A1 A2
from |U |, we are subtracting the elements in the
3 6 9 4 8 intersection A1 ∩ A2 = {12, 24} two times. So
12
15 18 to determine the quantity |(A1 ∪ A2 )c | we com-
24 16 20
21 puted:

|(A1 ∪ A2 )c | = |U | − |A1 | − |A2 | + |A1 ∩ A2 |.


1 2 5 7 10 11 13 14 17 19 22 23 25

Note: Do not confuse the operations |A| − |B| and A \ B. The first is a difference of two
numbers, while the second is a set operation that also results in a set. In fact, it is not the case
that |A| − |B| = |A \ B| in general. (Can you come up with a counterexample?)

Exercise 3.17. How many integers in {1, 2, 3, . . . , 2019} are not divisible by 7 or 11?

Now suppose we add a third condition to avoid, that is, a third set A3 to remove. Consider the
problem of determining the number of elements in the set (A1 ∪ A2 ∪ A3 )c .

The idea now is to replicate the 2-set scenario


by first subtracting |A1 | + |A2 | + |A3 | from
A1 A2 |U |, then to add back what was removed more
than once. This means we have to add back
|A1 ∩ A2 |, |A1 ∩ A3 |, and |A2 ∩ A3 |.

However, elements in the intersection of all three


sets A1 ∩ A2 ∩ A3 have been removed three times
and added back three times at this point. This
A3 means we should subtract |A1 ∩ A2 ∩ A3 | one
U more time so that we remove all the elements
we need to remove.

To summarize: (note the alternating signs)


|(A1 ∪A2 ∪A3 )c | = |U | −|A1 | − |A2 | − |A3 | + |A1 ∩ A2 | + |A1 ∩ A3 | + |A2 ∩ A3 | − |A1 ∩ A2 ∩ A3 |
| {z } | {z } | {z }
single sets intersections of pairs intersection of three

Exercise 3.18. How many integers in {1, 2, . . . , 2019} are not divisible by 3, 7, or 11?

32 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 3.2 Principle of Inclusion-Exclusion

Now we can state the Principle of Inclusion-Exclusion in full generality:

Theorem 3.19 (Principle of Inclusion-Exclusion)


Given a universe U of items and subsets A1 , A2 , . . . , An of the items, the number N of
items belonging to none of these subsets is given by

X \
N= (−1)|S| Ai
S⊆{1,2,...,n} i∈S
X n X X
= |U | − |Ai | + |Ai ∩ Aj | − |Ai ∩ Aj ∩ Ak | + · · ·
i=1 1≤i<j≤n 1≤i<j<k≤n

There are a number of ways to prove this, but the usual method is to show that each item
belonging to none of the Ai ’s contribute 1 to the total; while all other items contribute 0 to the
total.

Proof. Suppose that the element x is in none of the Ai ’s. Then it is counted exactly once in the
sum, in the first term |U |.
Now suppose that the element y is in some collection of Ai ’s. Let T = {i : y ∈ Ai } be the set of
indices of sets that contain y. (For example, if y is in A1 , A3 , and A4 , then T = {1, 3, 4}.) Then
for each subset S of T , there is a corresponding term in the formula above.
Note that the formula contributes a +1 for intersections of even numbers of sets (or for |S| even);
and a −1 for intersections of odd numbers of sets (for |S| odd). Hence the total contribution for
the element y is
|T |  
k |T |
X X
|S|
(−1) = (−1) .
k
S⊆T k=0

Applying the Binomial Theorem (Theorem 2.33), we see that this is equal to
|T |   X |T |  
|T | |T |
= (1 + (−1))|T | = 0,
X
(−1)k = (1)|T |−k (−1)k
k k
k=0 k=0

which is what we needed to prove.

Exercise 3.20. Given a universe U and four sets A1 , A2 , A3 , A4 in U , write out the
complete formula for |(A1 ∪ A2 ∪ A3 ∪ A4 )c |.

Example 3.21. Count the number of arrangements of the letters in the word
EQUATION such that

• vowels are not in alphabetical order when read left-to-right; and

• consontants are not in alphabetical order when read left-to-right.

33 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 3.2 Principle of Inclusion-Exclusion

Solution: Let A1 be the set of arrangements where vowels are in alphabetical order,
and A2 the set of arrangements where consonants are in alphabetical order. Then the
desired number is |(A1 ∪ A2 )c | = |U | − |A1 | − |A2 | + |A1 ∩ A2 |, by Theorem 3.19.
We compute each quantity:

• |U | = 8!, the number of permutations of the letters.

• |A1 | = 3! · 83 (permute the consonants first, then insert among vowels using the


Balls in Bins Formula)

• |A2 | = 5! · 85 (permute the vowels first, then insert among consontants)




• |A1 ∩ A2 | = 85 (vowels and consonants are in a fixed order; just pick 5 slots for


vowels to be in and the rest follows)

8 8 8
Hence |(A1 ∪ A2 )c | = |U | − |A1 | − |A2 | + |A1 ∩ A2 | = 8! − 3!
  
3 − 5! 5 + 5 , or 33320.

Exercise 3.22. Use Theorem 3.19 to determine how many natural numbers less than
120 are relatively prime with 120.
(Hint: Consider prime factors of 120.)

Exercise 3.23. Given n ∈ N and {p1 , p2 , . . . , pk } its set of prime factors, we will prove
the following formula for the number of natural numbers less than n (denoted by φ(n))
that are also relatively prime with n:
X n
φ(n) = (−1)|S| Q .
S⊆{1,2,...,k} i∈S pi

(This is known as Euler’s totient function.)

(a) Define Ai to be the set of natural numbers less than n that are divisible by pi .
T
(b) For any set S ⊆ {1, 2, . . . , k}, compute the value of i∈S Ai .

(c) Apply Theorem 3.19.

Exercise 3.24. Use the formula in Exercise 3.23 to compute φ(100) and φ(135).

Exercise 3.25. Use Theorem 3.19 to determine how many five-card hands can be
drawn from a standard deck of cards such that there is at least one card of each suit.

Exercise 3.26. Use Theorem 3.19 to determine how many nonnegative integer solu-
tions there are to x1 + x2 + x3 = 10, x1 ≤ 3, x2 ≤ 4, x3 ≤ 8.
(Hint: Define A1 to be the set of solutions such that x1 > 3, etc.)

34 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 3.2 Principle of Inclusion-Exclusion

Recall that the permutations of a set S are the bijective functions from S to itself. We have a
special name for those permutations that leave no element fixed:

Definition 3.27 (Derangement)


A derangement is a permutation on {1, 2, . . . , n} such that no element is mapped to
itself.

Example 3.28. The permutation on {1, 2, 3} that takes 1 to 3, 2 to 1, and 3 to 2 is a


derangement; we can also denote it as the string 312.
There are only two derangements on {1, 2, 3}: 231 and 312.
The permutation 3241 on {1, 2, 3, 4} is not a derangement since 2 is sent to itself. We
call 2 a fixed point of the permutation.
(Try listing all derangements of {1, 2, 3, 4}.)

Exercise 3.29. Count the number of derangements Dn of the set {1, 2, . . . , n} using
Theorem 3.19, by following these steps:

(a) Define Ai to be the set of permutations of {1, 2, . . . , n} for which i is a fixed point.
(There are no restrictions on the other elements; there may be other fixed points)

(b) Express Dn as the cardinality of a set involving the Ai ’s.


T
(c) If S ⊆ {1, 2, . . . , n} with |S| = k, find a formula for i∈S Ai .

(d) Combine with Theorem 3.19 to derive a formula for Dn , then fill in the statement
of the result below.

Proposition 3.30
The number of derangements Dn of the set {1, 2, . . . , n} is

Note: For problems where it is relevant, you may leave your answers in terms of Dn . (You don’t
have to compute exact values.)

Exercise 3.31. Evaluate D4 and verify that it is the correct number by listing all
derangements of {1, 2, 3, 4}.

Dn
Exercise 3.32. Using a computer, evaluate the ratio n! of derangements to all per-
mutations of {1, 2, . . . , n} for n increasingly large.
Verify that the ratios approach the value of 1e .

35 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 3.3 Additional Exercises

3.3 Additional Exercises

Exercise 3.33. Prove that any (n+1)-subset of {1, 2, . . . , 2n} has a pair of consecutive numbers.
Why does this imply that any (n + 1)-subset must have a pair of relatively prime numbers?
Exercise 3.34. Prove that any (2n + 1)-subset of {1, 2, . . . , 3n} has three consecutive numbers.
Exercise 3.35. The numbers 1 to 10 are placed in some order around a circle. Prove that some
set of three consecutive numbers sums to at least 17.
Exercise 3.36. Jungkook has 6 friends; over several days he invites some of them over to his
home to eat lamb skewers for dinner, so that the company never repeats (i.e. a different set of
friends comes every night). If he has at least one friend over every day, how many days can he
follow this rule?

Exercise 3.37. Place 5 points inside (or on the boundary) of a square


√ with
side length 2 cm. Show that there is a pair of points no more than 2 cm
apart.

Exercise 3.38. Recall that the midpoint of the segment joining points (a, b) and (c, d) on the
plane has coordinates ( a+b c+d
2 , 2 ).
Show that given five integer points (i.e. points with integer coordinates) on the plane, the
midpoint of the segment joining some pair of them is also an integer point.
(Hint: Consider parity.)
Exercise 3.39. If we select 38 subsets of size at most three from the set S = {1, 2, . . . , 13},
show that two of these subsets must have the same sum.
Exercise 3.40. The UTM e-sports team Eagle Geniuses is training for an Ontario e-sports
tournament called The Provincial, which is 30 days away. They are scheduled to play at least
one scrim (practice game) with another university team every day for the next 30 days; their
coach tells them they will be playing a total of 42 games.
Prove that there was a period of consecutive days during which the team scrimmed exactly 17
times. (Hint: Similar to Exercise 3.14.)
Exercise 3.41. Fall 2019 course data about 1000 first-year students at a college reveal that:

• 800 are taking calculus • 500 are taking linear algebra and proofs

• 750 are taking linear algebra • 500 are taking calculus and proofs

• 550 are taking an intro to proofs course • 450 are taking all three

• 650 are taking calculus and linear algebra

(a) How many students are taking none of these courses?

(b) How many students are taking only linear algebra?

(c) Draw a venn diagram and indicate the number of students for each part of the diagram.

36 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 3.3 Additional Exercises

Exercise 3.42. How many ways are there to place 11 distinct people into 3 distinct rooms?
How many ways are there to place 11 distinct people into 3 distinct rooms such that each room
has at least one person?

Exercise 3.43. Twenty students in a class exchange quiz papers for peer evaluation. How many
ways can this be done so that no student gets their own paper?

Exercise 3.44. Count the number of 5-letter arrangements that can be formed from the letters
of the word EUPHORIA such that the string EAR does not appear, and there is at least one
vowel.

Exercise 3.45. Count the number of integer solutions to the system



 x1 + x2 + x3 + x4 = 25
2 ≤ x ≤ 9, 3 ≤ x ≤ 9, −1 ≤ x ≤ 11, 5 ≤ x
1 2 3 4

(6, 4)
Exercise 3.46. Count the number of lattice paths
from (0, 0) to (6, 4) that pass through at least one of
the points (2, 3), (3, 1), and (5, 4).

(Lattice paths are paths that only take unit steps to


the right or upwards. See Example 2.35.) (0, 0)

Exercise 3.47. Consider a set of n cats and n dogs; suppose we want to pair them up for an
afternoon playdate. Derive formulas for the number of ways this can be done, such that:
(a) For each i, the ith heaviest cat is not paired up with the ith heaviest dog (but pairs can
have two dogs or two cats).

(b) Same condition as (a), but also each pair has exactly one cat and one dog.

Exercise 3.48. Suppose that four friends have two pets each – a cat and a dog – and they all
meet up at the park. They decide to form four groups of 1 human, 1 cat, and 1 dog each. Count
the number of ways they can do this, such that:

(a) No human is with their dog.

(b) No human is with either of their pets.

(c) Each human is grouped with at most one of their pets.

37 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019)

4 Congruence Modulo n

Objectives:

• Define relations on a set; determine whether or not a relation is an equivalence relation;


determine the congruence classes of equivalence relations
• Apply the properties of congruence modulo n to prove congruence results; determine if a
number has a multiplicative inverse; solve linear congruences
• State and apply some basic number theoretic results (including Euler’s Theorem, Fermat’s
Little Theorem and properties of Euler’s totient function)
• State the Chinese Remainder Theorem and solve systems of congruences
• Encrypt and decrypt simple messages using the RSA cryptosystem

4.1 Equivalence Relations

You will have seen equivalence relations in MAT102. Recall that they allow us to talk about
the same-ness of objects in terms of some defining characteristic, even if those two objects are
not necessarily equal.
Relations generalize functions; equivalence relations are relations that satisfy a number of prop-
erties.

Definition 4.1 (Relation)


Given sets S and T , a relation between S and T is a subset of S × T ; that is, R is a
relation if R ⊆ S × T .

If S = T then we call R a relation on S.

Example 4.2. Let A = {0, 2, 4, 6} and B = {0, 1, 2, 3, 4}.


The set R = {(0, 0), (0, 2), (2, 2), (6, 3), (6, 4)} is a subset of A × B, so R is a relation
between A and B.

Exercise 4.3. How many relations are there between the sets A = {0, 2, 4, 6} and
B = {0, 1, 2, 3, 4}?

Exercise 4.4. Let A and B be finite sets.


(a) How many relations are there between A and B?

(b) How many functions are there from A to B?


Which of your answers from (a) and (b) should be larger? Why?

38 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 4.1 Equivalence Relations

Definition 4.5 (Equivalence relation)


An equivalence relation R on a set S is a relation such that

(a) For all x ∈ S, (x, x) ∈ R. [reflexive property]

(b) For all x, y ∈ S, (x, y) ∈ R implies (y, x) ∈ R. [symmetric property]

(c) For all x, y, z ∈ S, (x, y) ∈ R and (y, z) ∈ R imply (x, z) ∈ R. [transitive property]

Exercise 4.6. For each relation, determine whether or not it satisfies the reflexive,
symmetric, and transitive properties. Then conclude whether or not it is an equivalence
relation.

(a) The order relation < on R.

(b) The relation R = {(a, a), (b, b), (c, c), (a, b), (b, a), (a, c), (c, a)} on the set {a, b, c}.

(c) The relation D = {(m, n) : m + n is odd} on Z

(d) The relation ≡ on Z given by a ≡ b ⇔ n | (a − b), for a fixed n ∈ N.

(e) The relation ∼ on R given by x ∼ y ⇔ (x − y)(x2 + y 2 − 1) = 0.

(f) The relation ≈ on R2 given by (x, y) ≈ (w, z) ⇔ xy = wz.

Definition 4.7 (Equivalence class)


Let R be an equivalence relation on a set S, and x an element in S.
The equivalence class of x, denoted by [x], is the set of all elements in S related to x
under R; that is,
[x] = {y ∈ S : (x, y) ∈ R}.

Exercise 4.8. List all equivalence classes of the equivalence relation

R = {(v, v), (w, w), (x, x), (y, y), (z, z), (v, z), (z, v), (w, x), (x, w), (y, y)}

on the set S = {v, w, x, y, z}.

An equivalence relation on a set S induces a partition of S into its equivalence classes. This
is shown by proving that none of the equivalence classes overlap, and that their union is S.
First, we prove the following lemma that states that if two elements are equivalent, then their
equivalence classes are equal.

Lemma 4.9
Let R be an equivalence relation on S, and let a, b ∈ S. If (a, b) ∈ R, then [a] = [b].

39 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 4.1 Equivalence Relations

Proof. Let R be an equivalence relation on S, and let a, b ∈ S such that (a, b) ∈ R. We will
prove [a] ⊆ [b]. Let y ∈ [a]. Then:
(a, y) ∈ R (by definition of [a])
(y, a) ∈ R (since R is symmetric)
(a, b) ∈ R (given)
(y, b) ∈ R (since R is transitive)
(b, y) ∈ R (since R is symmetric)
y ∈ [b] (by definition of [b])
Hence [a] ⊆ [b]. The other inclusion is similarly proved, from which [a] = [b] follows.

Theorem 4.10
If R is an equivalence relation on a set S, then

(a) any x ∈ S belongs to some equivalence class; and

(b) any two different equivalence classes are disjoint.

In particular, the equivalence classes induced by R form a partitiona of the set S.


a
Recall Definition 2.4

Exercise 4.11. Write a one-line proof of part (a) of Theorem 4.10.

Exercise 4.12. Prove part (b) of Theorem 4.10 by showing that any two equivalence
classes that have a common element must be the same equivalence class. (You may
want to use Lemma 4.9.)

Exercise 4.13. Describe the equivalence classes of the equivalence relation ∼ on Z


defined by
m ∼ n ⇔ 3 | (m − n).

Exercise 4.14. Let A = {0, 1, 2}, and consider the relation ∼


= on P (A) defined by

X∼
= Y ⇔ the largest element in X equals the largest element in Y .

Prove ∼
= is an equivalence relation, and describe the equivalence classes.

Exercise 4.15. Give an example of an equivalence relation on Z:

(a) with exactly one equivalence class;

(b) with exactly two equivalence classes;

(c) with infinitely many equivalence classes.

40 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 4.2 Congruence

Note on equivalence classes and representatives. If x and y are in the same equivalence
class, then [x] = [y], and we can use either of them to refer to the same class. In fact, we can
use any member of the class to represent it!

Example 4.16. Consider the equivalence relation E = {(a, b) : a + b is even} on Z.


The equivalence class of 0 is

[0] = {a : a + 0 is even} = {a : a is even},

and hence [0] contains exactly all even integers.


This means we can also call [0] as [2] = [−2] = [4] = · · · (any of these names).
Similarly,
[1] = {a : a + 1 is even} = {a : a is odd}.
So, [1] = [−1] = [3] = [−3] = [5] = · · · .

Exercise 4.17. Given an equivalence relation R on a set S, and an equivalence class


[x], show that for all a, b ∈ S,

a ∈ [x] and b ∈ [x] ⇒ (a, b) ∈ R.

4.2 Congruence

In part (d) of Exercise 4.6 you would have proven that ≡ was an equivalence relation on the
integers. This is an important relation that has several applications, so it is given a name.

Definition 4.18 (Congruence)


Let n be a natural number. We say that two integers a and b are congruent modulo n
if n | (a − b). We denote this by writing

a ≡ b (mod n) .

The number n is called the modulus.

Example 4.19. Since 6 | (55 − 13), 55 and 13 are congruent modulo 6, and we write
55 ≡ 13 (mod 6). However 6 - (30 − 11) so 30 and 11 are not congruent modulo 6, or
30 6≡ 11 (mod 6).

Exercise 4.20. Show that two integers a and b are congruent modulo n if and only if
they have the same remainder when divided by n.
(Hint: Use the Division Algorithm (Theorem 1.18).)

41 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 4.2 Congruence

Definition 4.21 (Congruence classes)


The equivalence classes of congruence modulo n are called congruence classes or re-
mainder classes, and they are the sets

{[0], [1], [2], . . . , [n − 1]},

corresponding to the possible remainders when dividing by n.

Example 4.22. Modulo 5, the congruence classes are

[0] = {. . . , −10, −5, 0, 5, 10, . . .}


[1] = {. . . , −9, −4, 1, 6, 11, . . .}
[2] = {. . . , −8, −3, 2, 7, 12, . . .}
[3] = {. . . , −7, −2, 3, 8, 13, . . .}
[4] = {. . . , −6, −1, 4, 9, 14, . . .}.

Exercise 4.23. If today is Sunday, which day of the week is it 200 days from today?

Observe that if two numbers a and b are congruent modulo n, then their difference a − b
is congruent to 0 modulo n. This is because a and b are essentially ‘the same’ when working
modulo n (the remainder is all that matters), so subtracting them will give ‘0’ in that framework.
We can perform addition and multiplication modulo n as well.

Proposition 4.24 (Addition and multiplication with congruences)


Let n be a natural number, and a, b, r, s integers such that a ≡ r (mod n)
and b ≡ s (mod n). Then:

(a) a + b ≡ r + s (mod n)

(b) ab ≡ rs (mod n)

(c) ak ≡ rk (mod n) for any k ∈ N.

Exercise 4.25. Prove Proposition 4.24.

Importantly, Proposition 4.24 implies that in any congruence, we can replace any number with
another number it is congruent to, and obtain an equivalent statement.

Example 4.26. Suppose we wanted to compute the remainder when 4133 is divided
by 4. We first write 4123 = 4000 + 100 + 30 + 3, so that

4000 + 100 + 30 + 3 ≡ 0 + 0 + 2 + 3 (mod 4) .

Hence the remainder when 4123 is divided by 4 is 5.

42 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 4.2 Congruence

Exercise 4.27. Compute the remainder when:

(a) 2139138 is divided by 9. (b) 21000 is divided by 7. (c) 10! is divided by 17.

While Proposition 4.24 allows us to perform addition/subtraction and multiplication, when we


try dividing we find that we run into some issues.

Example 4.28. We know that 39 ≡ 123 (mod 12). If we divide both sides by 3, we
would get 13 ≡ 41 (mod 12), which is false.
However 13 ≡ 41 (mod 4) is true.

Proposition 4.29 (Dividing both sides of a congruence)  


n
Let n ∈ N and a, b, d ∈ Z. If ad ≡ bd (mod n), then a ≡ b mod .
gcd(d, n)

If d and n are relatively prime, then ad ≡ bd (mod n) implies a ≡ b (mod n).

Proof. Suppose that ad ≡ bd (mod n). This means ad = bd + kn for some k ∈ Z.


Since gcd(d, n) divides both d and n, we can divide through to get
d d n
a· =b· +k· .
gcd(d, n) gcd(d, n) gcd(d, n)

 
n d
This is equivalent to (a − b) .
gcd(d, n) gcd(d, n)
 
d n
Since gcd , = 1, we can apply the result of Exercise 1.282 to obtain
gcd(d, n) gcd(d, n)

n
(a − b),
gcd(d, n)
 
n
or that a ≡ b mod , as desired.
gcd(d, n)
If gcd(d, n) = 1, the statement reduces to a ≡ b (mod n).

 
d n
Exercise 4.30. Explain why gcd , = 1 in the proof above.
gcd(d, n) gcd(d, n)
(Hint: contradiction.)

The second statement of Proposition 4.29 is also called the cancellation law, since it gives a
condition under which one can divide both sides of a congruence by a number.
2
If m | ab and gcd(a, m) = 1, then m | b.

43 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 4.2 Congruence

4.2.1 Solving congruences

When we are asked to solve for x in an equation like 2x2 + 4 = 36, we know that we need to
look for all values of x that satisfy that equation (x = ±4). What if we are asked to solve for x
given a congruence?

Example 4.31. Solve for x in the congruence 2x ≡ 4 (mod 9).


Solution: We need to find values of x so that 9 | (2x − 4), or 9 | 2(x − 2).
Since gcd(2, 9) = 1, by Exercise 1.28 we have 9 | (x − 2), which means x ≡ 2 (mod 9).
Note that this is no different from applying Proposition 4.29 directly: since gcd(2, 9) =
1, we can safely divide both sides by 2 to obtain x ≡ 2 (mod 9).
This means that the congruence class [2] is the solution to 2x ≡ 4 (mod 9), or that all
integers in {. . . , −16, −7, 2, 11, . . .} satisfy the congruence.

The final answer in the above example is typical of solutions to congruences: since we are working
modulo n, answers will be congruence classes from {[0], [1], . . . , [n − 1]}. Hence when asked to
solve for x given a congruence, you should express your answer as a congruence class ([2]), or
as a statement of congruence like x ≡ 2 (mod 9).

Example 4.32. Solve the congruence 2x ≡ 6 (mod 10), and express your answer using
congruence classes of the original modulus.
Solution: We can apply Proposition 4.29 here to divide through by 2, and we get

x ≡ 3 (mod 5) .

In modulo 10, this is the same as

x ≡ 3 (mod 10) and x ≡ 8 (mod 10) .

So the original congruence has two solutions in {[0], [1], . . . , [9]}, namely [3] and [8].

Exercise 4.33. Solve each congruence for x, paying special attention to your usage of
Proposition 4.29.

(a) 3x ≡ 9 (mod 10) (b) 5x + 2 ≡ 27 (mod 15) (c) −11x − 3 ≡ 30 (mod 7)

Exercise 4.34. Proposition 4.29 cannot be used to solve the congruence

2x ≡ 3 (mod 7)

since we cannot divide both sides by 2.


Solve the congruence by trial-and-error (remember, there are only 7 congruence classes
to check, since we are working modulo 7).

44 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 4.3 Euler’s Theorem

Definition 4.35 (Multiplicative inverse)


Given natural numbers a, m such that gcd(a, m) = 1, the number b is called a multi-
plicative inverse of a modulo m if

ab ≡ 1 (mod m) .

In the above definition we are really saying that any number in [b] is a multiplicative inverse
of a modulo m, though we will usually be interested in finding that specific inverse that is also
in the set {0, 1, . . . , m − 1}. This is especially helpful when solving congruences of the form
ax ≡ b (mod n) where a - b. Instead of dividing both sides by a, we can multiply both sides by
the inverse of a (similar to multiplying both sides of ax = b by a1 to solve for x).

Exercise 4.36. Show that modulo 7, any number in [4] is a multiplicative inverse of
2. Then use this fact to solve the congruence 2x ≡ 3 (mod 7) from Exercise 4.34.

Exercise 4.37. Given a, m ∈ N such that gcd(a, m) = 1, prove that the multiplicative
inverse of a modulo m is unique (up to congruence class).

Exercise 4.38. Use the previous exercise to argue that ax ≡ b (mod m) has a unique
solution if gcd(a, m) = 1.
Does the converse hold? That is, if we know that ax ≡ b (mod m) has a unique
solution, can we conclude that gcd(a, m) = 1?

Exercise 4.39. Solve the congruences:

(a) 5x − 7 ≡ 9 (mod 11) (b) 3−2x ≡ 3−5x (mod 7) (c) 21x + 35 ≡ 9 (mod 19)

Exercise 4.40. Since gcd(6, 16) > 1, the number 6 has no multiplicative inverse mod-
ulo 16. Solve the congruences 6x ≡ 3 (mod 16) and 6x ≡ 4 (mod 16). How many
solutions do you get for each one (modulo 16)?

4.3 Euler’s Theorem

Before stating and proving Euler’s Theorem, we first restate the definition of Euler’s totient
function (introduced in Exercise 3.23), which counts the number of integers in {1, 2, . . . , m}
relatively prime with m.

Definition 4.41 (Euler’s totient function)


Euler’s totient function (or Euler’s phi-function) is the function φ : N → N defined
by
φ(m) = {k ∈ N : 1 ≤ k ≤ m, gcd(k, m) = 1} .

45 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 4.3 Euler’s Theorem

Example 4.42. We have φ(1) = 1 since 1 is the only integer in {1} relatively prime
with 1.
Also φ(8) = 4, since there are four numbers in the set {1, 2, . . . , 8} relatively prime
with 8: they are 1, 3, 5, and 7.

Exercise 4.43. The table below lists values of φ(m) for small values of m. Complete
the table for m = 11, 12, . . . , 20.

integers 1 ≤ k ≤ m integers 1 ≤ k ≤ m
m φ(m) m φ(m)
such that gcd(k, m) = 1 such that gcd(k, m) = 1
1 1 1 11
2 1 1 12
3 1, 2 2 13
4 1, 3 2 14
5 1, 2, 3, 4 4 15
6 1, 5 2 16
7 1, 2, 3, 4, 5, 6 6 17
8 1, 3, 5, 7 4 18
9 1, 2, 4, 5, 7, 8 6 19
10 1, 3, 7, 9 4 20
If p is prime, then all integers from 1 to p − 1 are relatively prime with p. This implies the
following result:

Proposition 4.44
If p is prime, then φ(p) = p − 1.

Exercise 4.45. Is the converse of the above statement true? That is, if m > 2 is an
integer such that φ(m) = m − 1, does it necessarily follow that m is prime?

Exercise 4.46. If p is prime and k ∈ N, prove that φ(pk ) = pk − pk−1 .

Exercise 4.47. If p and q are prime, prove that φ(pq) = (p − 1)(q − 1).
(Hint: Inclusion-Exclusion.)

Now we can state Euler’s Theorem and Fermat’s Little Theorem, which is a special case.

46 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 4.3 Euler’s Theorem

Theorem 4.48 (Euler’s Theorem)


If a, m ∈ N with gcd(a, m) = 1, then aφ(m) ≡ 1 (mod m).

Theorem 4.49 (Fermat’s Little Theorem/FLT)


If a ∈ N and p is prime such that p - a, then ap−1 ≡ 1 (mod p).

Proof. If p is prime with p - a, we have gcd(a, p) = 1. So we can use Theorem 4.48 on a and
m = p. Since φ(p) = p − 1 by Proposition 4.44, the result follows.

Although FLT is a special case of Euler’s Theorem, it was FLT that was actually proven first
– in 1736, also by Euler.3 Only in 1763 did Euler publish the generalization that is Euler’s
Theorem.4

Example 4.50. Take m = 8 and a = 7 so that gcd(a, m) = 1. By Euler’s Theorem,


we have
7φ(8) ≡ 1 (mod 8) ⇒ 74 ≡ 1 (mod 8) .

Example 4.51. What is the remainder when 32019 is divided by 113?


Solution: Since gcd(3, 113) = 1, we can apply Euler’s Theorem. In fact, 113 is prime,
so Fermat’s Little Theorem applies here, so we know that

3112 ≡ 1 (mod 13) .

Using the division algorithm on 2019 we get 2019 = 18 · 112 + 3. Hence

32019 ≡ (3112 )18 · 33 (mod 113) ≡ 27 (mod 113) .

So the remainder when 32019 is divided by 113 is 27.

Exercise 4.52. Compute the remainder when 66777 is divided by 667.


(Hint: 667 = 23 × 29.)

4.3.1 Proof of Euler’s Theorem

The idea behind the proof of Euler’s Theorem is that for a, m ∈ N relatively prime, multiplying
each element of the set S = {y ∈ {1, 2, . . . , m} : gcd(y, m) = 1} by a induces a permutation of
the set modulo m.

3
Euler, Theorematum quorundam ad numeros primos spectantium demonstratio,
http://eulerarchive.maa.org//pages/E054.html
4
Euler, Theoremata arithmetica nova methodo demonstrata, http://eulerarchive.maa.org//pages/E271.
html

47 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 4.3 Euler’s Theorem

Example 4.53. Let a = 4 and m = 9. Then φ(9) = 6, since the integers S =


{1, 2, 4, 5, 7, 8} are relatively prime with 9.
Multiplying each number in S by 4 and reducing modulo 9, we have

S= {1 2 4 5 7 8}
↓ ↓ ↓ ↓ ↓ ↓ (multiply by a = 4)

4 8 16 20 28 32
↓ ↓ ↓ ↓ ↓ ↓ (reduce modulo 9)

{4 8 7 2 1 5} → same as S!

What this means is that S and {4y : y ∈ S} contain the same numbers modulo 9; so
when we take the product of all elements in these sets, the results must be congruent
modulo 9:

(4 · 1)(4 · 2)(4 · 4)(4 · 5)(4 · 7)(4 · 8) ≡ (1)(2)(4)(5)(7)(8) (mod 9) .

Since each element of S is relatively prime with 9, we can apply Proposition 4.29 to
cancel each term, and we are left with

(4)(4)(4)(4)(4)(4) ≡ 1 (mod 9) ⇒ 4φ(9) ≡ 1 (mod 9)

since φ(9) = 6 = |S|.

Exercise 4.54. Replicate the idea in Example 4.53 to show that 7φ(15) ≡ 1 (mod 15).

Proof of Euler’s Theorem. Let a, m ∈ N such that gcd(a, m) = 1.


First define the set
S = {y : 1 ≤ y ≤ m, gcd(y, m) = 1}
to be the set of natural numbers smaller than m and relatively prime with m. We know that
there are exactly φ(m) elements in the set S, so we can label them as S = {b1 , b2 , . . . , bφ(m) },
where gcd(bi , m) = 1 for i = 1, 2, . . . , φ(m).
Since we have gcd(bi , m) = 1 and gcd(a, m) = 1, we must also have

gcd(abi , m) = 1 for any i = 1, 2, . . . , φ(m).

We invoke the Division Algorithm (Theorem 1.18) now to write abi as

abi = qm + r for some 0 ≤ r < m,

which implies that abi ≡ r (mod m). Combining with the fact that gcd(abi , m) = 1, this implies
that gcd(r, m) = 1, so r is a natural number smaller than m and relatively prime with m.

48 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 4.3 Euler’s Theorem

In other words, r is in the set S, and we can write r = bj for some 1 ≤ j ≤ φ(m). This means
for each 1 ≤ i ≤ φ(m), we have abi ≡ bj (mod m) for some 1 ≤ j ≤ φ(m).
Furthermore, none of the bj ’s are repeated, because no two abi terms are equivalent modulo
m. (Otherwise, abi1 ≡ abi2 (mod m) ⇒ bi1 ≡ bi2 (mod m) by Proposition 4.29, which is a
contradiction as the bi ’s are all distinct and smaller than m.)
Hence, each integer abi is congruent modulo m to distinct elements in S:

ab1 ≡ bj1 (mod m)


ab2 ≡ bj2 (mod m)
..
.
abφ(m) ≡ bjφ(m) (mod m)

Multiplying all the congruences together gives another congruence, where the right-hand-side is
φ(m) φ(m)
Y Y
just bjk = bi since each element of S appears exactly once. Hence,
k=1 i=1

φ(m) φ(m)
Y Y
abi ≡ bi (mod m) ⇒ aφ(m) ≡ 1 (mod m) .
i=1 i=1

by an application of Proposition 4.29.

Note on primality testing. Fermat’s Little Theorem asserts that

if p is prime and gcd(a, p) = 1, then ap−1 ≡ 1 (mod p).

Note that the converse of this statement is not true in general: Even if gcd(a, m) = 1 and
am−1 ≡ 1 (mod m), we would not be able to conclude that m is prime.

Exercise 4.55. Give examples of pairs a, m such that gcd(a, m) = 1 and


am−1 ≡ 1 (mod m) are both true, but m is not prime.

This means that we cannot use FLT/Theorem 4.49 to tell us when a number is prime.
However, we can use FLT to tell us that a number is not prime, using the contrapositive of the
theorem statement:

If a, m ∈ N, gcd(a, m) = 1, and am−1 6≡ 1 (mod m), then m is composite.

This is nice, because instead of trying to find factors of large numbers (which is difficult when
the numbers are very large!), we could just determine the congruence class of am−1 modulo m
through repeated exponentiation, and if it isn’t [1], then m can’t be prime.

Exercise 4.56. Show that 91 is composite using the contrapositive of Theorem 4.49
with a = 2.

49 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 4.4 The Chinese Remainder Theorem

4.4 The Chinese Remainder Theorem

The Chinese Remainder Theorem is a number theory result about solving systems of congru-
ences. It was stated as far back as the 3rd century AD by Chinese mathematician Sunzi.

Theorem 4.57 (Chinese Remainder Theorem (General case))


Let m1 , m2 , . . . , mn be pairwise relatively prime integers, that is, gcd(mi , mj ) = 1 when-
ever i 6= j. Then the system of n congruences

 x ≡ a1 (mod m1 )




 x ≡ a2 (mod m2 )

..



 .


x ≡ an (mod mn )

has a unique solution for x, modulo M = m1 m2 · · · mn .

Example 4.58. Consider the system of congruences



x ≡ 3 (mod 5)
x ≡ 1 (mod 7)

In English, this would be like asking the question

Find a natural number x that leaves


a remainder of 3 when divided by 5 and a remainder of 1 when divided by 7.

Clearly picking x = 8 will work, since 8 ≡ 3 (mod 5) and 8 ≡ 1 (mod 7). Another
solution is x = 78. (verify this yourself!)
The Chinese remainder theorem guarantees the existence of a solution as long as the
moduli (here, 5 and 7 are the moduli) are relatively prime, and also guarantees that in
the set of integers modulo 5 × 7 = 35, there is a unique solution.
So here x ≡ 8 (mod 35) is the solution. (Note that 78 and 8 belong to the same
congruence class modulo 35; any integer of the form 8 + 35k for k ∈ Z will work!)

Exercise 4.59. Sunzi’s classic example is the system





x ≡ 2 (mod 3)

x ≡ 3 (mod 5)



x ≡ 2 (mod 7)

Verify that x ≡ 23 (mod 105) is a solution to this system.

50 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 4.4 The Chinese Remainder Theorem

While Theorem 4.57 guarantees the existence of a unique solution to the system of congruences,
it is in its proof that we see how this solution is obtained. Here are methods for systems of two
congruences, and for systems of any number of congruences:
Solution to a system of two congruences
Let m1 , m2 ∈ N and gcd(m1 , m2 ) = 1, and consider the system

x ≡ a (mod m1 )
 x ≡ b (mod m )
2

Perform the following steps:

• Find the multiplicative inverse of m2 modulo m1 , call it t.

• Find the multiplicative inverse of m1 modulo m2 , call it s.

• Modulo M = m1 m2 , the solution is x ≡ atm2 + bsm1 (mod m1 m2 ).

Example 4.60. Once again consider the system



x ≡ 3 (mod 5)
x ≡ 1 (mod 7)

We have a = 3, b = 1, m1 = 5, m2 = 7, and inverses t = 3 and s = 3.


Hence the solution, modulo M = m1 m2 = 35, is x ≡ (3)(3)(7) + (1)(3)(5) (mod 35).
Simplifying gives 3 · 3 · 7 + 1 · 3 · 5 = 63 + 15 = 78, so the solution is x ≡ 78 (mod 35) ≡
8 (mod 35), which agrees with our initial answer.

Exercise 4.61. Prove that x ≡ atm2 + bsm1 (mod m1 m2 ) satisfies both congruences
in the given system.

Exercise 4.62. Prove that x ≡ atm2 + bsm1 (mod m1 m2 ) is the only solution to the
given system modulo m1 m2 .

Solution to a general system of congruences


Let m1 , m2 , . . . , mn ∈ N and gcd(mi , mj ) = 1 for i 6= j, and consider the system



 x ≡ a1 (mod m1 )


 x ≡ a2 (mod m2 )

..



 .


x ≡ an (mod mn )

51 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 4.5 The RSA Cryptosystem

Perform the following steps:

• Let M = m1 m2 · · · mn .

• For each i = 1, 2, . . . , n:

– Define bi = M/mi (the product of all moduli other than mi ).


– Find the multiplicative inverse of bi modulo mi , call it ti .

• Modulo M = m1 m2 · · · mn , the solution is


n
X
x ≡ a1 b1 t1 + a2 b2 t2 + · · · + an bn tn (mod M ) ≡ ai bi ti (mod M ) .
i=1

Example 4.63. Applying the above algorithm to Sunzi’s system, we have M = 3·5·7 =
105, and the quantities

a1 = 2 m1 = 3 b1 = 35 t1 = 2
a2 = 3 m2 = 5 b2 = 21 t2 = 1
a3 = 2 m3 = 7 b3 = 15 t3 = 1

3
X
Hence we calculate ai bi ti = 2 · 35 · 2 + 3 · 21 · 1 + 2 · 15 · 1 = 140 + 63 + 30 = 233,
i=1
and so the solution is

x ≡ 233 (mod 105) ≡ 23 (mod 105) .

4.5 Application: The RSA Cryptosystem

The RSA Algorithm (after Rivest, Shamir, Adleman) is an public-key cryptosystem that is
used for data transmission. A public key (based on two large primes p and q) is given out, and
anyone who would like to send a message to the receiver can use this public key to encrypt the
data. Any encrypted message can only be decrypted with the private key, that only the receiver
knows. This is based on the fact that factoring the number N = pq is very difficult.
To discuss the algorithm, we first define the mod operation to be:

a mod m = the remainder obtained from the Division Algorithm when a is divided by m.

This is another way of representing the congruence class of a modulo m.


Suppose Alice wants to send Bob a message. Bob picks

• two large primes p and q, and

• another number e such that gcd(e, (p − 1)(q − 1)) = 1.

52 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 4.5 The RSA Cryptosystem

Bob computes N = pq, M = (p − 1)(q − 1), and d, the multiplicative inverse of e modulo M .
Then, Bob publishes the public key (e, N ) and keeps the other quantities private.
Suppose Alice wants to send the message x to Bob. They can ensure privacy of the data
transmitted in this manner:

• Alice computes y = xe mod N and sends y to Bob.

• Anyone who sees the message y will not be able to decrypt it and retrieve x.

• Bob knows d, so he computes y d mod N . The result is x, the original message.

Why does this work?


First of all, since d and e are inverses modulo (p − 1)(q − 1), we have

ed ≡ 1 (mod M ) , or ed = 1 + kM for some k

so
y d ≡ (xe )d (mod N ) ≡ xed (mod N ) ≡ x1+kM (mod N ) .

By Exercise 4.47 and Fermat’s Little Theorem, we have

xφ(N ) ≡ 1 (mod N ) ⇒ x(p−1)(q−1) ≡ 1 (mod N ) ⇒ xM ≡ 1 (mod N ) .

Thus we have

y d ≡ x · (xM )k (mod N ) ≡ x · (1)k (mod N ) ≡ x (mod N ) .

This means Bob successfully recovers Alice’s original message x.

Example 4.64. Suppose Bob picks p = 7, q = 13 as two primes, so that N = 91 and


M = (6)(12) = 72. Also, Bob picks e = 5, which has multiplicative inverse d = 29
modulo M . (Check this!)
Bob’s public key is (N = 91, e = 5).
Alice wants to transmit the message ROFL. To do this she first represents it numerically:

R O F L → 18 15 6 12

Then she computes xe mod N for each number x in the message, and sends the results
to Bob.

• 185 mod 91 = 44 • 65 mod 91 = 41

• 155 mod 91 = 71 • 125 mod 91 = 38

So Alice sends the message 44 71 41 38 to Bob.

53 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 4.6 Additional Exercises

To decrypt, Bob just raises each block to d = 29 and computes the remainder modulo
91.

• 4429 mod 91 = 18 • 4129 mod 91 = 6

• 7129 mod 91 = 15 • 3829 mod 91 = 12

Bob obtains the message 18 15 6 12, and translates it back to ROFL.

Note that the two primes we used were small enough so that N = 91 = 7 · 13 is easily factorable,
and d obtainable. When p and q are very large, it becomes close to impossible to factor N ,
protecting the secrecy of the private key d used to decrypt any sent messages. (Also, the
operation is usually done on blocks of letters and not on single letters, to make the transmission
more difficult to attack.)

4.6 Additional Exercises

Exercise 4.65. Let

R = {(1, 1), (2, 2), (1, 2), (2, 1), (1, 3), (3, 3), (3, 1), (4, 4)}

be a relation on the set {1, 2, 3, 4}. Is R an equivalence relation? Which properties (reflexive,
symmetric, transitive) hold/fail?

Exercise 4.66. Let S be the set of differentiable functions from R to R, and let ? be the relation

f ? g ⇔ f 0 (x) = g 0 (x).

Is ? an equivalence relation? If it is, describe its equivalence classes.

Exercise 4.67. Let ∼ be the following relation on Z:

m ∼ n ⇔ 4 | (m2 − n2 ).

Is ∼ an equivalence relation? If it is, describe its equivalence classes.

Exercise 4.68. Let A1 , A2 , . . . , Ak form a partition of S. Show that the relation

R = {(x, y) : x and y are in the same Ai }

is an equivalence relation on S.
What are the equivalence classes of R?

Exercise 4.69. If R is an equivalence relation on S, and a, b ∈ S such that a ∈ [b], show that
[a] = [b]. Do not use Lemma 4.9 or Theorem 4.10.

Exercise 4.70. Compute the remainder when

(a) 3333 is divided by 100 (c) 2888 is divided by 8

(b) 5444 is divided by 11 (d) 9999 is divided by 99

54 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 4.6 Additional Exercises

Exercise 4.71 (December 2017 Final). Show that (3 + 33 + 35 + 37 + 39 + 311 ) mod 10 = 0

Exercise 4.72 (April 2018 Final). Without using induction, prove that 11n+2 + 122n+1 is
divisible by 133 for any n ∈ N.

Exercise 4.73. Let N be the product of any k consecutive natural numbers. Prove k! | N .

Exercise 4.74. Find the multiplicative inverse of each integer b modulo m:

(a) b = 4, m = 5 (d) b = 10, m = 9

(b) b = 13, m = 76 (e) b = 100, m = 999

(c) b = 33, m = 7

Exercise 4.75. Solve the following congruences. Express your answer as congruence classes of
the original modulus.

(a) 4x ≡ 8 (mod 5) (d) 33x + 4 ≡ 2 (mod 7)

(b) 4x ≡ 3 (mod 5) (e) 100x − 23 ≡ 11 (mod 99)

(c) 2x ≡ 10 (mod 8) (f) 31 − 11x ≡ 4x + 8 (mod 44)

Exercise 4.76. Prove that if gcd(a, n) - b, then ax ≡ b (mod n) has no solutions.

Exercise 4.77. Let a ∈ N and suppose p is prime. Prove that a2 ≡ 1 (mod p) if and only if
a ≡ 1 (mod p) or a ≡ −1 (mod p).

Exercise 4.78. If m = 2k is a power of 2, explain how you could use repeated squaring to
compute am mod n for any n. Then apply the method to compute 1032 mod 41.

Exercise 4.79. If m is not a power of 2, explain how you could use the results of Exercise 4.78
to compute am mod n for any n. Then apply the method to compute 1726 mod 44.
(Hint: Express m as a sum of powers of two.)

Exercise 4.80. Prove φ(pk q l ) = pk − pk−1 q l − q l−1 for primes p and q, and k, l ∈ N.
 

(Hint: Exercise 4.46 and Exercise 4.47.)

Exercise 4.81. Find the smallest positive integer y such that

• y divided by 9 leaves a remainder of 7, and

• y divided by 10 leaves a remainder of 9.

Exercise 4.82. Solve the system of congruences





 x ≡ 2 (mod 3)

x ≡ 2 (mod 7)



x ≡ 1 (mod 13)

using the method outlined in the discussion of the Chinese Remainder Theorem.

55 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 4.6 Additional Exercises

Exercise 4.83. Compute each quantity:

(a) 32019 mod 5 (d) 32019 mod 385


(Hint: 385 = 5 · 7 · 11;
(b) 32019 mod 7
use Chinese Remainder Theorem)
(c) 32019 mod 11

Exercise 4.84. Your friend has been boasting about getting an A in their cryptography course,
and now refuses to reply to any messages that are not encrypted using their RSA public key
(N = 77 and e = 19).
You want to send the message WEIRDFLEX to your friend.

(a) Encode the message as two-digit blocks, one block for each letter. (e.g. W is 23, etc.)

(b) Encrypt the message using your friend’s public key.

Your friend might not have deserved that A, since they picked N to be easily factorable.
(c) Determine your friend’s private key, then decrypt the message you sent them.

Exercise 4.85. You want to get back at your friend from Exercise 4.84 by using the RSA
system to receive messages as well. You pick p = 53 and q = 61, so that N = 3233, and you
pick e = 121.

(a) Determine your private key M and d.

(b) You receive the message 0685 1635 0365 from your friend, who grouped letters into blocks
of two letters each. Decrypt the message and translate back into letters.
(You may want to use a calculator for this one.)

In the next few exercises you will construct a proof of Wilson’s Theorem, which states that
if p is prime, then (p − 1)! ≡ −1 (mod p).

Exercise 4.86. Verify that Wilson’s Theorem holds for p = 5 and p = 7.

Exercise 4.87. For larger primes, instead of naively multiplying out (p − 1)!, we make use of
the fact that we are working modulo p. Verify Wilson’s theorem for p = 19 via the following
steps:

(a) Except for [1] and [18], list all congruence classes modulo 19.

(b) For each congruence class listed in (a), try to pair it up with its inverse. E.g. the inverse of
[2] is [10], since 2 · 10 ≡ 1 (mod 19). Are you able to completely pair all of them up?

(c) How would you use (b) to prove 18! ≡ −1 (mod 19)?

Exercise 4.88. (Difficult) Prove Wilson’s Theorem by repeating the process in the previous
exercise, but for a general prime p. A crucial step in the proof is to show that one can always
partition the set of congruence classes {[2], [3], . . . , [p − 2]} into pairs {[a], [b]} such that
ab ≡ 1 (mod p). Why does each [a] have an inverse modulo p?

56 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019)

5 Graph Theory

Objectives:

• Use graphs and their properties to model problems.


• Demonstrate understanding of graph-theoretic definitions and properties by formally ap-
plying them to solve problems and prove basic results.

5.1 Modeling using Graphs

A graph is, simply, an object with vertices (or nodes), and edges (each of which connects
two vertices). The power of graph theory lies in abstraction: given a problem with physical,
structural, or time-related elements, modeling them as graphs allows us to focus our efforts at
solving the problem on only the relevant details necessary. Consider the two examples below:

Example 5.1 (The 5-room problem). One day, you suddenly gain the power to walk
through walls. Is there a way for you to walk through each wall of the building below
(given its floor plan), such that you start and end in the same room (or the outside)?
Assume you can visit any room as many times as you want, but cannot walk through
each wall more than once.

For instance, the following path through the


building does not pass through all walls (the
walls in red are not used).

Example 5.2. In the graph below, can you trace a path starting and ending at the
same vertex that uses each edge exactly once? (Vertices can be repeated.)

You might be surprised to find out that answering Example 5.2 is equivalent to answering
Example 5.1, in that a positive or negative answer to one implies the same answer for the other.

57 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 5.1 Modeling using Graphs

Here is how we can model the physical constraints of Example 5.1 as the graph in Example 5.2.
Observe that to answer the question, we only need to determine which two rooms are incident
to (or beside) each wall; let’s assume the outside of the building is one big room as well. So we
have six rooms, and we label them using the set V = {u, v, w, x, y, z} as follows:

y z

v w x

Each wall can now be represented by a pair of rooms – for example, the thick blue wall in the
figure above can be represented as (w, z), while the north and west (red) walls of room y can
both be represented as (u, y).
We can visually encode this information about each wall as an edge connecting the two rooms:
we remove the floor plan, and draw all edges (the edges corresponding to the red and blue walls
are highlighted in the graph).

y z

v w x

Hence the question of whether or not it is possible to walk through all the walls of the building
exactly once, is the same as determining if there is a way to walk along each edge of the graph
obtained exactly once. For instance, here is the blue path shown in Example 5.1, as a trail along
the graph (where red walls/edges are not used).

We will prove in a later example that it is impossible to construct a path through the building
that satisfies the condition being asked. What is important now is that you understand how the
problem was transformed into a question about a graph.

58 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 5.1 Modeling using Graphs

Read the next three exercises and think about how you can represent the given scenarios as
graphs. We will come back to each of them in a later section.

Exercise 5.3. An about-to-be-married couple made the mistake of asking their 8 guests
to indicate on their RSVPs who they would not like to sit with at the dinner reception.
There will be two tables of four seats each (it is a really small venue).
Given the guestlist below, is there a way to seat the guests so that everyone is satisfied?

Does not want Does not want


Guest Guest
to sit beside to sit beside
Angela Donald Giuseppe Shinzo
Emmanuel
Boris Justin
Justin
Angela
Donald Emmanuel Shinzo Donald
Justin
Emmanuel Boris Vladimir Emmanuel

Exercise 5.4. You are working as a delivery person for a company selling medicinal
herbs online. On April 20th, a particularly busy day, you have to make deliveries
to Brampton, Burlington, Cambridge, and Guelph; the company has its distribution
center in Mississauga, which is where you live as well. Given the table of distances
below, can you determine the route that will take you from the distribution center
in Mississauga, to each city exactly once, then back home, such that total distance
traveled is minimized?

distance (km) Mississauga Brampton Burlington Cambridge Guelph


Mississauga 22 41 72 72
Brampton 22 60 75 65
Burlington 41 60 49 50
Cambridge 72 75 49 25
Guelph 72 65 50 25

Exercise 5.5. Six graph theorists are at a conference. During a coffee break, each
of them starts counting how many coauthors they have among the group (so 0 means
that person has not written a paper with anyone in the group; 5 means that person has
written a paper with everyone in the group). When they scribble the numbers down
on a napkin, they get:
3, 2, 2, 2, 1, 1.
Prove that this is impossible, so someone must have made a mistake counting.

59 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 5.2 Definitions and Eulerian Graphs

5.2 Basic Definitions and Eulerian Graphs

We now formally state the definition of a graph. Unless otherwise specified, the graphs you will
encounter in this text are simple graphs.

Definition 5.6 (Graph)


A graph G is defined as a pair G = (V, E) where V is a finite set consisting of elements
called vertices, and E is a collection of unordered pairs of elements in V called edges.

If e = (u, v) is an edge of the graph, then we say that the vertices u and v are the
endpoints of the edge e. The vertices u and v are called adjacent vertices; the edge e
is also said to be incident to the vertices u and v.

A graph is a simple graph if E has no repeated elements, i.e. between every pair of
vertices there is at most one edge. A graph that is permitted to have multiple edges
between a pair of vertices is called a multigraph.

Visually, a graph can be drawn by using points to represent its vertices, and lines connecting
pairs of vertices to represent the edges.

Example 5.7. Define the graph G to have vertices V = {v1 , v2 , v3 , v4 , v5 } and edges
E = {(v1 , v2 ), (v1 , v3 ), (v1 , v4 ), (v2 , v5 ), (v4 , v5 )}. We can represent this graph by label-
ing five nodes, and drawing each edge.
v3

v2 v4

v5
v1

Exercise 5.8. Draw each of the following graphs:

(a) G1 = (V1 , E1 ) where V1 = {p, q, r, s, t, u} and


E1 = {(p, q), (q, r), (q, s), (q, t), (q, u), (r, s), (r, t), (r, u), (s, u)}.

(b) G2 = (V2 , E2 ) where V2 = {1, 2, 3, 4} and E2 contains all pairs of elements from V .

Exercise 5.9. List all elements in the vertex and edge sets of each graph below.

3 v6

2 4 v4 v5
v1 v2 v3
5
1 G4
G3 v7

60 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 5.2 Definitions and Eulerian Graphs

Definition 5.10 (Degree of a vertex)


The degree d(v) of a vertex v is the number of edges incident to it.

The degree sequence of a graph is the nonincreasing sequence of numbers formed by


the degrees of its vertices.

Example 5.11. In the graph of Example 5.7, the degrees of each vertex are:

Vertex v1 v2 v3 v4 v5
Degree 3 2 1 2 2

We write this as d(v1 ) = 3, d(v2 ) = 2, and so on. Hence the degree sequence of the
graph is 3, 2, 2, 2, 1 (just rearrange the numbers in nonincreasing order).

Exercise 5.12. Determine the degrees of each vertex of the graphs G1 , G2 , G3 , and
G4 from Exercises 5.8 and 5.9, then write the degree sequence of each graph.

Exercise 5.13. What does it mean for a vertex v to have degree d(v) = 0? Can you
draw a graph with degree sequence 0, 0, 0, 0, 0?

While it is easy to write the degree sequence of a given graph, it is much harder to start with a
nonincreasing sequence and determine whether or not it is possible to draw a graph with that
particular sequence of vertex degrees.
From the next result we can derive one simple way to tell whether or not a given sequence can
be realized as a graph. This will be our first graph theory proof: that the sum of the degrees of
all vertices must be equal to twice the number of edges in the graph.

Theorem 5.14 (Degree-sum Formula)


Let G be a graph with m edges. Then
X
d(v) = 2m
v∈V (G)

Note: In the above statement we used the notation V (G) to refer to the vertex set of G; we
will also use the notation E(G) to refer to the collection of edges of G. This notation comes in
handy if we are talking about the vertex or edge sets of different graphs.

Proof. If (u, v) is an edge of G, then it contributes 2 to the sum of all vertex degrees (one to
the degrees of each of its endpoints: d(u) and d(v)). This is true for all edges of G, so twice the
number of edges must be exactly the sum of all degrees.

Example 5.15. Consider the graph of Example 5.7. The degrees sum to 10, which is
exactly twice the number of edges of G.

61 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 5.2 Definitions and Eulerian Graphs

Exercise 5.16. Use the degree-sum formula to prove that any graph must have an
even number of vertices with odd degree.

Exercise 5.17. Explain how Exercise 5.16 implies that in a party, the number of
people who shook hands with an odd number of other people’s hands must be even.

Because of Exercise 5.17, the result of Exercise 5.16 is sometimes called the Handshake Lemma.
This can be used to prove that certain sequences will never occur as the degree sequence of a
graph.

Example 5.18. Exercise 5.5 can be resolved by arguing that the coauthorship relations
among the six mathematicians can be represented using a graph: by taking the six
mathematicians as vertices and placing an edge between two mathematicians if they
have coauthored a paper together.
The sequence 3, 2, 2, 2, 1, 1 cannot be the degree sequence of this graph, since there is
an odd number of vertices of odd degree. (There are three: 3, 1, 1.) Therefore someone
must have made a mistake counting.

Try proving the following basic properties about degree sequences.5

Exercise 5.19. Can a graph on 4 vertices have degree sequence 3, 2, 1, 0?

Exercise 5.20. Is it possible for the numbers 0 and n − 1 to both occur in the degree
sequence of a graph with n vertices? Prove your answer.

Exercise 5.21. Show that the sum of the degrees of a graph cannot add up to more
than n(n − 1).

We can use vertex degrees to answer the five-room problem in Exercise 5.1 in the negative. First,
we need some definitions:

Definition 5.22 (trail)


A trail in a graph G = (v, E) is an alternating list of vertices and edges

u0 , e0 , u1 , e1 , u2 , . . . , ek−1 , uk

such that each edge ei has ui and ui+1 as its endpoints, and that these ei ’s are distinct
(for i = 0, 2, . . . , k − 1). A trail is said to be closed if its endpoints u0 and uk are the
same vertex.

Note that for simple graphs we can simply write a list of vertices to describe the trail since there
are no multiple edges between any two vertices.
5
There is a theorem that characterizes completely whether or not a degree sequence can be realized as a graph,
but is beyond the scope of this course: the Erdös-Gallai Theorem.

62 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 5.2 Definitions and Eulerian Graphs

Example 5.23.
The graph G contains the trail 1-2-6-7-3-2, denoted by 5 6 7 8
the thick red edges. It is not closed. Also, it cannot
be continued to make it closed because one of the edges G
(1, 2) or (2, 6) would have to be repeated for the trail to
make its way back to vertex 1. 1 2 3 4

Definition 5.24 (Eulerian)


A graph is said to be Eulerian if it has a closed trail containing all its edges. This trail
is called an Eulerian trail.

The condition of having a closed trail that uses all the edges of a graph is equivalent to saying
that the graph can be drawn on paper in one motion without lifting one’s pen.

Example 5.25. The graph H1 below is Eulerian since the closed trail 3-1-2-3-4-5-3
uses all its edges exactly once.
However the graph H2 is not Eulerian. Although it has a trail 4-3-2-5-4-2-1-3-5 that
uses all its edges exactly once, it is not a closed trail.

2 1
1

H1 3 2 3

5 H2
4 4 5

It turns out that there is an easy way to tell whether a graph is Eulerian or not.

Theorem 5.26
A (not necessarily simple) graph G is Eulerian if and only if all its vertex degrees are
even, and every edge is reachable from every other edge.

The second condition about ‘reachability’ of edges from all 1 6


other edges will be formalized in Section 5.4. For this result it
3 4
simply means that graphs like the one on the right which have
at least two separate ‘components’ can never have an Eulerian
trail. (Can you see why?) 2 5

Exercise 5.27. Verify Example 5.25 using Theorem 5.26.

Now we present the proof of Theorem 5.26; note that this theorem also holds for multigraphs.

63 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 5.2 Definitions and Eulerian Graphs

Proof of Theorem 5.26. We first show the only if implication. Suppose G is an Eulerian graph.
Then there is a closed trail in G, say

u0 , e0 , u1 , e1 , . . . , ek−1 , uk = u0

that traverses all the edges of G exactly once. (Some of the ui ’s may be repeated, but none of
the edges are repeated.)

ei−1
ei
ui−1 ui
ui+1

For each vertex in V (G), each time it appears in this list (say as ui ), the trail passes through it
and we add two to its degree (one from ei−1 = (ui−1 , ui ) and one from ei = (ui , ui+1 )). This is
true even for u0 since we also add two to its degree for the first and last edge of the trail, which
comes back to uk = u0 .
Hence all vertex degrees must be even. The ‘reachability’ condition must clearly also be true if
an Eulerian trail exists on the graph G.
The if implication is better explained by the following algorithm:
Suppose G is a graph whose vertices all have even degree, and also assume that every vertex is
reachable from every other vertex.
1
v
Step 1: Choose any vertex v of G, and create a trail 5
that starts and ends at v, never repeating 2 G
C
an edge. Call this trail C.
4
Step 2: If C is all of G, then we are done, and we 3
have found an Eulerian trail in G.
4 v0
Step 3: If not, then remove the edges of C from G
to form a new graph G0 . Since C is a closed 1
trail, removing it reduces each vertex degree C0
3 G0
of G by an even number – so G0 also has all 2
vertex degrees even.

Step 4: Choose a vertex v 0 common to C and G0 ,


and create a trail in G0 that starts and ends 5 1
at v 0 . Call this new trail C 0 . 2
9
6
Step 5: Combine C and C0
to get a new trail by C 00 4 G
inserting C 0 where the vertex v 0 occurs in 3
8
C. Now set C = C 00 and go back to Step 2.
7

64 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 5.2 Definitions and Eulerian Graphs

Example 5.28. Now we can finally resolve the 5-room problem in Exercise 5.1.
Whether or not one can walk through all the walls of the building exactly once and
return to the same room is equivalent to asking whether the graph of Exercise 5.2
contains an Eulerian trail or not. The answer here is no, since the graph has vertices
of odd degree.

Example 5.29.
7
4 3
The vertices of the graph on the right all have even
degree but H is not Eulerian. This is because the
graph has two separate ‘components,’ and the reach- 8 6
ability condition is not satisfied. 1 2
5

Exercise 5.30.
Verify that all vertex degrees of G1 , G2 , and G3 are even, then find an Eulerian trail
in each graph. (Note that G3 is a multigraph)
8 5 6
6 7 7 3 8 11

4 5 2 4 9 3 4
G1 1 6 5 G3
10
2 3 G2
1 1 2

We end this section by defining some special graphs.

Definition 5.31 (Cycle)


A cycle is a closed trail in which only the first and last vertices are repeated.
The cycle graph with n vertices is denoted by Cn , and is a graph that consists of a
single cycle.

Definition 5.32 (Complete Graph)


The complete graph on n vertices is denoted by Kn , and is the simple graph on n
vertices that consists of all possible edges between all vertex pairs.

Example 5.33. Here are the graphs of C4 , C5 , K4 , and K5 (from left to right).

65 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 5.3 Isomorphisms and Subgraphs

Exercise 5.34. Determine |E(Kn )|, the number of edges of the complete graph on n
vertices.

Exercise 5.35. Determine the degree sequences of Cn and Kn for any n ∈ N. Then
show that the graph Cn is Eulerian for all n ∈ N, while the complete graph Kn is
Eulerian only for odd n ∈ N.

Exercise 5.36. Find an Eulerian trail on K5 and on K7 .

5.3 Isomorphisms and Subgraphs

Given any graph G = (V, E), there is usually more than one way of representing G as a drawing.
In fact, the definition of a graph as a pair (V, E) of vertex and edge sets makes no reference to
how it is visualized as a drawing on a sheet of paper. So when we say ‘consider the following
graph’ when referring to a drawing, we technically mean: ‘consider the graph that is represented
by this drawing. . . ’
In the next example it is clear that G2 and G3 are exactly the same graph. But how about G1 ?

Example 5.37. Let G1 , G2 , and G3 be the following graphs:

b v5 v2 G3 v1
G1
G2 v4
a v2

e v3 v4
d
v1 v5 v3
c

Clearly G2 and G3 are equal as graphs – their vertex sets

V = {v1 , v2 , v3 , v4 , v5 }

and edge sets


E = {(v1 , v2 ), (v2 , v3 ), (v3 , v4 ), (v4 , v5 ), (v5 , v1 )}
are exactly the same, even if they are drawn differently on the plane.
As for G1 , it is apparent that it has the same structure as both G2 and G3 (they are
all the cycle graph on five vertices, or C5 ), even if they don’t share the same vertex set
(V (G1 ) = {a, b, c, d, e}). This motivates our next definitions.

Definition 5.38 (Graph equality)


Two graphs G1 = (V1 , E1 ) and G2 = (V2 , E2 ) are said to be equal if and only if both
V1 = V2 and E1 = E2 hold.

66 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 5.3 Isomorphisms and Subgraphs

Definition 5.39 (Graph isomorphism)


Two simple graphs G1 = (V1 , E1 ) and G2 = (V2 , E2 ) are said to be isomorphic if there
exists a function
f : V1 → V2
such that for all u, v ∈ V1 ,

(u, v) ∈ E(G1 ) ⇔ (f (u), f (v)) ∈ E(G2 ),

that is, f preserves adjacencies between vertices.


We call f an isomorphism from G1 to G2 ; we also say G1 is isomorphic to G2 .

When two graphs G1 and G2 are isomorphic, this means one can relabel the vertices of G2 to
match the vertex names of G1 such that both graphs become equal) (Note that we only define
isomorphisms for simple graphs at the moment.)

Exercise 5.40. Verify that in the graphs of Example 5.37, the function f : V (G1 ) →
V (G2 ) given by

f (a) = v1 , f (b) = v5 , f (c) = v4 , f (d) = v3 , f (e) = v2

is an isomorphism.
Then, construct two other isomorphisms from G1 to G2 . (Yes, there can be multiple!)

Exercise 5.41. Given the graphs H1 , H2 , H3 , and H4 , which pairs (if any) are iso-
morphic?
1 2

H2 = (V2 , E2 ), where
H1 3 V2 = {v1 , v2 , v3 , v4 , v5 } and
E2 = {(v1 , v2 ), (v3 , v4 ), (v4 , v5 ), (v5 , v3 )}.

4 5
e b

H3 = (V3 , E3 ), where H4
V3 = {p, q, r, s, t} and
c d
E3 = {(p, q), (p, r), (p, s), (p, t), (r, t), (s, q)}
a

It is typically easier to prove that two graphs are not isomorphic, than to prove that they are,
since two isomorphic graphs must agree on many of their structural properties. Most obviously,
two isomorphic graphs must have the same number of vertices – this is an immediate consequence
of the fact that the function f defining the isomorphism is a bijection.

67 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 5.3 Isomorphisms and Subgraphs

We now prove two isomorphic graphs must have the same number of edges as well.

Example 5.42. If G1 = (V1 , E1 ) and G2 = (V2 , E2 ) are isomorphic simple graphs,


prove that they must have the same number of edges, or |E1 | = |E2 |.
Proof: Let f : V1 → V2 be an isomorphism from G1 to G2 . To prove |E1 | = |E2 | we
construct a bijection between these two sets.
This is straightforward; we know from Definition 5.39 that for any pair of vertices
u, v ∈ V1 ,
(u, v) ∈ E1 ⇔ (f (u), f (v)) ∈ E2 .
So define a function g : E1 → E2 such that g ((u, v)) = (f (u), f (v)).
Since f is injective, g must also be injective. Also g must be surjective since any
edge (x, y) ∈ E2 has a preimage (f −1 (x), f −1 (y)) in E1 . Thus g is a bijection, and
|E1 | = |E2 |.

Exercise 5.43. Prove that two isomorphic simple graphs must have the same degree
sequence.

Exercise 5.44. Use Exercise 5.43 to determine which pairs in Exercise 5.41 are not
isomorphic.

Exercise 5.45. The converse of Exercise 5.43 is not true. Find a counterexample,
i.e. two non-isomorphic graphs with the same degree sequence. (Hint: 2, 2, 2, 1, 1.)

Another way we can prove two graphs are not isomorphic is by looking at their subgraphs, which
are graphs whose vertices and edges are subsets of that of the original graph.

Definition 5.46 (Subgraph)


Given a graph G = (V, E), a subgraph of G is another graph G0 = (V 0 , E 0 ) where

(i) V 0 ⊆ V ,

(ii) E 0 ⊆ E, and

(iii) (v1 , v2 ) ∈ E 0 ⇒ v1 , v2 ∈ V 0 .

Example 5.47. Suppose we label the vertices of K4 to be V = {1, 2, 3, 4}, so that its
edges are E = {(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)}.
4 3
The cycle graph C4 arises as a subgraph of the
complete graph K4 , by taking V 0 = {1, 2, 3, 4} and
E 0 = {(1, 2), (2, 3), (3, 4), (1, 4)}.
1 2

68 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 5.3 Isomorphisms and Subgraphs

Example 5.48.
The graphs H1 and H2 have the same degree sequence 4, 4, 4, 4, 4, 4, 4, 4 so we cannot
use this to rule out isomorphism. However, H2 has a K4 subgraph, while H1 does not,
which tells us that they are not isomorphic.

6 5 6 5 6 5
7 4 7 4 7 4

8 3 8 3 8 3
1 2 1 2 1 2
H1 H2 A K4 subgraph of H2

The reason why this is sufficient to conclude they are not isomorphic is that no matter
how we try to form the bijection f : V (H1 ) → V (H2 ), we will never be able to find four
vertices in V (H1 ) to map to {1, 2, 3, 4} in V (H2 ) that also preserve adjacency relations.
That is, no four vertices in H1 are all connected to one another by edges, as opposed
to {1, 2, 3, 4}, which are all adjacent to one another in H2 .

Example 5.49. The following graphs are isomorphic. To produce the bijection f
explicitly we examine the degrees and adjacencies of the vertices.

The degree sequence of both graphs is 4, 4, 4, 3, 3, 2. So the


5 4 vertex with degree 2 in G must be mapped to the vertex with
degree 2 in H; this means 3 ↔ t in any isomorphism.

6 3 There are two vertices of degree 3 in each: {2, 5} in G and {q, r}


in H. So we should map either

1 2 2 ↔ q and 5 ↔ r, or 2 ↔ r and 5 ↔ q.
G
Clearly it must be the first option, since 2 is adjacent to 3 (the
t s vertex with degree 2) in G, while q is adjacent to t in H.
Now we just need to determine how the four vertices of degree 4
u r {1, 4, 6} in G are mapped to those in H, {p, s, u}. Observe that
we must have 4 ↔ p, since they are both adjacent to the vertex
of degree 2 in their graphs.
p q
As for the others, you can check that both ways of assigning {s, u}
H to {1, 6} will produce an isomorphism. So we see there are two
isomorphisms between G and H:

G 3 2 5 4 1 6 G 3 2 5 4 1 6
l and l
H t q r p s u H t q r p u s

69 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 5.3 Isomorphisms and Subgraphs

Exercise 5.50. Prove the following graphs are isomorphic:

5 4 a b
f
6
g
c

7 3
1 2 e d
G H

Sometimes when graphs have many edges, it is easier to look at the edges they don’t have!

Definition 5.51 (Complement)


Let G = (V, E) be a simple graph. We define its complement G to be the graph on the
same vertex set V (G), and with edge set

E 0 = {(u, v) ∈ V × V : (u, v) 6∈ E},

that is, (u, v) is an edge in G if and only if it was not an edge in G.

Example 5.52. A graph G (red) and its complement G (blue) are shown below.

5 4 5 4
5 4
6 3 6 3
6 3
1 2 1 2
1 2
G G

Proposition 5.53
Graphs G and H are isomorphic if and only if their complements G and H are.

Exercise 5.54. Verify Proposition 5.53 on Example 5.49 and Exercise 5.50.

Exercise 5.55. Prove Proposition 5.53.

Note on Graph Isomorphism


In general it is a difficult problem to determine whether or not two graphs are isomorphic. While
algorithms exist that work well on random graphs, in the worst-case some of these still exhibit exponential-
time behaviour. For some special cases this problem has efficient solutions that run in polynomial time.
See this page and the references therein to read more about the problem.

70 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 5.4 Connectedness and Trees

5.4 Connectedness and Trees

In this section we introduce a few more graph-theoretic terminology, starting with paths and
connectedness.

Definition 5.56 (Path)


A path is a trail in which no vertices are repeated (so it is not closed). The endpoints
of a path are the first and last vertices.
If a path has endpoints u and v, it is called a u-v path.
Any graph isomorphic to a path on n vertices is denoted by Pn .

Example 5.57.

Two different drawings of the graph P6 , or


the path on six vertices.

Definition 5.58 (Connectedness)


A graph G = (V, E) is said to be connected if for all u, v ∈ V (G), there is a u-v path
joining them.
A connected component of G is a connected subgraph of G that is not contained in
any other connected subgraph (i.e. the maximal connected subgraphs of G).

If there exists a u-v path on a graph G, we say that u and v are connected on G. This
condition formalizes the notion of reachability used in the characterization of Eulerian graphs
in Theorem 5.26.

Exercise 5.59. Verify that the graph P6 is connected.

Example 5.60.
The graph G is not connected since not all pairs of vertices
2 4 are endpoints of some path. For example, there is no path
joining 1 and 6; nor is there one joining 3 and 4.
3
1 5 6 The graph G has two connected components: one is the C3
subgraph formed by the vertices {1, 2, 3}, and the other one
G is a path of length three (P3 ) formed by the vertices {4, 5, 6}.
These are the maximal connected subgraphs of G. (On the
other hand, the path 1-2-3 is not a maximal connected sub-
graph, since it is a subgraph of the cycle 1-2-3-1.)
4 6
1 3 The graph H is connected, since between any two of its ver-
tices one can find a path. For example, if we pick vertices
2 5
1 and 5, we can find a 1-5 path: 1-2-3-5. In fact there is
H another path (1-4-3-5) but we only need at least one for each
vertex pair to satisfy the condition of connectedness.

71 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 5.4 Connectedness and Trees

Exercise 5.61. Which of the following graphs are connected?

Exercise 5.62. Prove that if G1 = (V1 , E1 ) and G2 = (V2 , E2 ) are isomorphic, and G1
is connected, then G2 must be connected as well.

If a graph is connected, and contains no copies of Cn for any n (i.e. it does not have cycles) then
we call it a tree.

Definition 5.63 (Tree, Forest)


A tree is a simple connected graph that contains no cycles as a subgraph.
A forest is a simple graph that contains no cycles as a subgraph.

Example 5.64.

A tree on six vertices A forest on six vertices A connected graph A tree


(also a forest) (not a tree) (not a tree) (not a graph)

Exercise 5.65. Find all nonisomorphic trees on (a) four vertices; (b) five vertices.

In a sense, trees are the minimally connected graphs, since removing any edge from a tree results
in a disconnected graph.

Proposition 5.66
Let G = (V, E) be a tree, and (u, v) ∈ E an edge. Then the graph G0 = (V, E \ {(u, v)})
is disconnected.

Proof. We proceed by contradiction. Assume that the graph G0 remains


connected after removing the edge (u, v). Then by the definition of
connectnedness there is a u-v path in G0 .
But this means that there had to have been a cycle in the original graph
G, consisting of the u-v path in G0 and the edge (u, v). This contradicts u v
the assumption that G was a tree.
Therefore removing any edge from G results in a disconnected graph.

There is a simple relationship between the number of vertices and the number of edges in a tree.

72 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 5.4 Connectedness and Trees

Exercise 5.67. For each tree below, count the number of vertices and edges. What
relationship do you observe?

Formulate a general statement relating |V | and |E| based on this relationship and
complete the theorem below:

Theorem 5.68
A tree on |V | = n vertices has |E| = edges.

Before we prove this theorem we will need the following result:

Lemma 5.69
If G is a tree on at least two vertices, then it has at least two vertices of degree 1 (which
are called leaves).

Proof of Lemma 5.69. Let G = (V, E) be a tree on |V | ≥ 2 vertices, so that it is connected and
has no cycles.
Assume towards a contradiction that G has at most one vertex of degree one (so all except for
one vertex has degree at least 2). Choose a maximal path in the graph (a path in the graph
such that it cannot be extended any further by adding a vertex at either end), and suppose the
vertices in this path are labeled x1 to xk .

x2 ··· xk−1
xk
x1 x3 xk−2

By the definition of a path, none of the xi ’s are repeated. Also, since at most one vertex in
the tree has degree one, one of x1 or xk must have degree at least 2. Suppose (without loss of
generality) that it is xk . Now if d(xk ) ≥ 2, it must be adjacent to at least one other vertex v.

Note that if v were on the path as one of


..
the xi ’s, this will result in a cycle (xi , xi+1 , x2 . ···
. . ., xk−1 , xk , v = xi ), which contradicts x1 xi−1 xi = v xi+1 xk−1
xk
the assumption that G is a tree.

If v were not on the path, this means the


path from x1 to xk could be continued for x2 xk−1
one more edge (xk , v), which contradicts ··· xk v
x1 x3 xk−2
the fact that the path x1 to xk was a max-
imal path in G.
Hence there must be at least two vertices of degree one in the graph G.

73 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 5.4 Connectedness and Trees

Exercise 5.70. The previous proof uses the fact that we can always find a maximal
path in a graph. Find all maximal paths in each graph in Exercise 5.67. Do maximal
paths of a graph always have the same number of vertices?

Exercise 5.71. Verify Lemma 5.69 for each graph in Exercise 5.67.

Exercise 5.72. Lemma 5.69 gives the minimum number of leaves in any tree on at
least two vertices. What is the maximum number of leaves in a tree on n vertices?

Exercise 5.73. What is the minimum and maximum number of leaves in a forest that
has k connected components (assume the components have n1 , n2 , . . . , nk vertices)?

We can now prove Theorem 5.68.

Proof of Theorem 5.68. We proceed by induction on the number of vertices |V | in the tree. The
claim is:
P (n) : All trees with n vertices have n − 1 edges.

Base case: P (1) is clearly true, since a tree on one vertex has no edge.
Induction step: Assume that P (k − 1) holds; that is, any tree with k − 1 vertices has k − 2 edges.
To prove P (k) holds, let G be an arbitrary tree on k vertices. By Lemma 5.69, G must have a
leaf, or a vertex v with d(v) = 1.
Remove the vertex v from the tree and the one edge it is an endpoint of. The resulting graph
G0 is still a tree (it must still be connected and have no cycles, since we only removed a leaf),
but with k − 1 vertices. By the induction hypothesis, G0 has k − 2 edges.
Therefore the original graph G must have had k − 1 edges (adding back what was removed with
v). This completes the proof.

Interestingly, a ‘converse’ of this theorem is also true.

Theorem 5.74
If G is a connected simple graph on n vertices and n − 1 edges, then G must be a tree.

We will not prove it here, but we can now summarize Theorems 5.68 and 5.74 into a nice
characterization of trees.

Theorem 5.75
If G = (V, E) is a connected simple graph, then |E| = |V | − 1 if and only if G is a tree.

Exercise 5.76. Find an example of a simple graph on n vertices and n − 1 edges that
is not a tree.

74 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 5.5 Bipartite and Hamiltonian Graphs

5.5 Bipartite Graphs and Hamiltonian Cycles

Definition 5.77 (Bipartite graph)


A simple graph G = (V, E) is said to be bipartite if we can partition V into two disjoint
sets V1 and V2 such that any edge in E must have exactly one endpoint in each of V1 and
V2 .
That is, G does not have any edges whose endpoints are both in V1 , or both in V2 .

Example 5.78. Consider the path P6 on six vertices. It is bipartite, because we can
partition V into two sets V1 = {1, 3, 5} and V2 = {2, 4, 6}, such that any edge in the
graph has one endpoint in each of the partitions.

5 3 1 V1

1 2 3 4 5 6

2 4 6 V2

Exercise 5.79. Which of the following graphs are bipartite? For those that are, give
the bipartition, and redraw them to show the bipartition explicitly. For those that are
not, explain why a bipartition cannot exist.

Exercise 5.80. Explain how Exercise 5.3 relates to determining whether a certain
graph is bipartite. Then answer the exercise.

As with trees, there is a nice characterization of bipartite graphs.

Theorem 5.81
A simple graph is bipartite if and only if it does not contain any odd cycles as a subgraph
(i.e. it does not contain any Cn for n odd).

Exercise 5.82. Prove the ‘only if’ part of Theorem 5.81 by contradiction; that is,
assume that G has an odd cycle, then show that it cannot be bipartite. (We will not
prove the other direction.)

Exercise 5.83. Use Theorem 5.81 to prove that all trees are bipartite.

75 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 5.5 Bipartite and Hamiltonian Graphs

Definition 5.84
The complete bipartite graph on m and n vertices, denoted by Km,n , is the bipartite
graph G = (V1 ∪ V2 , E) where |V1 | = m, |V2 | = n, V1 ∩ V2 = ∅, and

E = {(u, v) : u ∈ V1 , v ∈ V2 },

that is, there is an edge in between any vertex in V1 to any vertex in V2 .

Example 5.85. The graph of K2,4 :

5 6

1 2 3 4

Exercise 5.86. Draw the graphs of K1,2 , K4,1 , K3,3 , and K5,5 .

Exercise 5.87. Find all pairs of natural numbers (m, n) for which Km,n is a tree.

Recall that a graph that contains a trail that traverses all its edges is called an Eulerian graph.
Sometimes we would like a graph to have a cycle that passes through all of its vertices in some
order, without repeating any vertex. These graphs are called Hamiltonian graphs.

Definition 5.88 (Hamiltonian cycle)


Let G = (V, E) be a simple graph. A Hamiltonian cycle on G is a cycle C that contains
all the vertices of G.
A graph that contains a Hamiltonian cycle is called a Hamiltonian graph.

Example 5.89. This graph from Exercise 5.49 is Hamiltonian, since it contains a
Hamiltonian cycle s-p-t-q-u-r-s.

t s

u r

p q

While it is very easy to determine whether a graph is Eulerian (just check that all its vertices have
even degree!), it is generally very difficult to determine whether or not a graph is Hamiltonian.

76 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 5.5 Bipartite and Hamiltonian Graphs

Exercise 5.90. The following graph is Hamiltonian. Find a Hamiltonian cycle in the
graph.

In order to prove a graph is not Hamiltonian, one has to argue that it does not contain a
Hamiltonian cycle as a subgraph (or, to assume that it does, and show it leads to a contradiction).

Example 5.91. Consider the following graph:

5 4

6 3 G

1 2

If G had a Hamiltonian cycle C, it must contain both edges (6, 3) and (6, 5), since these
are the only two edges passing through 6. Similarly, C must contain both (1, 5) and
(1, 2), and (2, 1) and (2, 3), and (4, 5) and (4, 3) (there are no other options for choosing
two edges incident to vertices 1, 2, and 4).
This is already a contradiction, since we have argued that C must contain seven edges,
while a Hamiltonian cycle in G will have only 6 edges. Hence G is not Hamiltonian.

The Traveling Salesman Problem generalizes the problem of finding a Hamiltonian cycle in
a graph – when numbers called costs are assigned to the edges of a graph, one can also ask the
question:
Find a Hamiltonian cycle of least cost on the graph G.

We also call these numbers distances or weights, and we want to minimize total distance or total
weight of the Hamiltonian cycle.

Exercise 5.92. In the following graph (numbers on edges are weights), find two dif-
ferent Hamiltonian cycles and compute their total costs. Can you find the least cost
Hamiltonian cycle on this graph?
3
e d

10 5
1
3 2 8
f 8 c
12
4 9

a b
10

77 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 5.5 Bipartite and Hamiltonian Graphs

Exercise 5.93. Explain how the problem in Exercise 5.4 relates to the Traveling Sales-
man Problem. Then solve it.

We end this section with a sufficient condition for a graph to be Hamiltonian.

Theorem 5.94 (Dirac)


If a graph G on n ≥ 3 vertices has minimum vertex degree n/2, then G is Hamiltonian

Exercise 5.95. Verify that the following graph satisfies the conditions of Theorem 5.94,
then find a Hamiltonian cycle on the graph.

Exercise 5.96. Theorem 5.94 is a sufficient condition for a graph to be Hamiltonian,


but it is not necesssary. Can you find an example of a Hamiltonian graph G that does
not satisfy the conditions of the theorem?

Proof of Theorem 5.94. Let G = (V, E) be a graph on n = |V | ≥ 3 vertices, such that minv deg(v) ≥
n/2. Then G must be connected (by Exercise 5.123).
Let P = x1 x2 · · · xk be a longest path in G (note it has k − 1 edges).
Then all vertices of G that are adjacent to x1 must already be on P , otherwise, P can be
extended to a longer path. Similarly, all vertices adjacent to xk must already be on P . Because
the minimum vertex degree is n/2, this means:

• x1 is adjacent to n/2 of the vertices {x2 , x3 , . . . , xk }


• xk is adjacent to n/2 of the vertices {x1 , x2 , . . . , xk−1 }

Since k ≤ n, there must be some pair of vertices xi+1 and xi such that (x1 , xi+1 ) ∈ E and
(xi , xk ) ∈ E. This is because there are n/2 neighbours of x1 in the set {x2 , . . . , xk }, and hence
only k −1−n/2 of the set {x1 , . . . , xk−1 } do not precede some neighbour of x1 . Since k ≤ n, then
k − 1 − n/2 ≤ n/2 − 1, which implies xk must have a neighbour xi that immediately precedes a
neighbour of x1 .

··· ···
x1 x2 xi−1 xi xi+1 xi+2 xk−1 xk

We claim that the cycle C = x1 xi+1 xi+2 · · · xk xi xi−1 · · · x2 x1 contains all vertices of G, and is
therefore a Hamiltonian cycle on G.
If not, since G is connected, there must be some vertex xj on this cycle that is adjacent to some
vertex y not on C. But now we can construct a path starting at y, moving to xj , then following
the cycle C for k − 1 more edges, creating a new path with k edges. This contradicts the fact
that x1 x2 · · · xk was the longest path on G.
Hence C must be a Hamiltonian cycle on G, and G is Hamiltonian.

78 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 5.6 Additional Exercises

5.6 Additional Exercises

Exercise 5.97. Write the definitions for each of the following terms: graph, simple graph,
vertex, edge, degree, degree sequence, trail, path, cycle, complete graph, Eulerian, subgraph,
graph isomorphism, complement, connectedness, tree, forest, leaf, bipartite graph, Hamiltonian
graph.
Exercise 5.98. List all vertices and edges of the graphs G1 , G2 , and G3 :

y2 y3 v2 v4 G3
v2 v6
G1
y1 y4
v1
v1 v5
v4 v5
v7 G2
v3 v6
y6 y5 v3

Exercise 5.99. Determine the degree sequences of the graphs G1 , G2 , and G3 .


Exercise 5.100. Determine which of the graphs G1 , G2 , G3 are Eulerian, and for each one that
is, find an Eulerian trail.
Exercise 5.101. For each nonincreasing sequence of numbers below, draw a simple graph with
that degree sequence, or explain why it is impossible to do so.

(a) 1, 1, 1, 1, 1 (c) 2, 2, 2, 2, 2, 2 (e) 4, 4, 2, 2, 2

(b) 1, 1, 1, 1, 1, 1 (d) 9, 3, 3, 2, 1 (f) 4, 4, 3, 2, 1

Exercise 5.102. You meet with six other friends for lunch, and because you had just learned
about Exercise 5.17 in class, you ask each of your friends how many in the group they shook
hands with before eating. You are surprised to hear each friend reply with a different number
from 1 to 6. How many hands did you shake at that lunch?
Exercise 5.103 (April 2016 Final). In a group of two or more people, must there always be at
least two people who are acquainted with the same number of people within the group? Explain
your answer.
Exercise 5.104. For which natural n ≥ 3 is Cn Eulerian? How about Kn ? Pn ?
Exercise 5.105. How many different Eulerian trails does Cn have for n ≥ 3?
Exercise 5.106. Find two nonisomorphic simple graphs w/ degree sequence 3,3,3,3,2,2,2,2.
Exercise 5.107 (April 2017 Final). Let G be a graph on n vertices. It is known that there are
6 vertices which have degree 3, and all of the remaining vertices are of degree 4. Show that G
cannot be disconnected with exactly two isomorphic connected components.
Exercise 5.108. Prove that the following graphs P and Q are isomorphic.

2
d 1 3
e c
4
P Q
a b 5

79 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 5.6 Additional Exercises

Exercise 5.109. Are there any isomorphic graphs among G4 , G5 , and G6 ?

2 3 5
G4 6 6
G5 4 G6
1 2 3 2
1 1
4 5
5 4
7
7 7 6 3

Exercise 5.110. Prove that graph isomorphism is an equivalence relation on the set of all
simple graphs.

Exercise 5.111. There are eleven simple graphs on four vertices (up to isomorphism). Find all
of them.

Exercise 5.112.
Show that the following graphs are not isomorphic:

Exercise 5.113. Are there any isomorphic graphs among the following graphs?

Exercise 5.114. Suppose that a graph G has degree sequence 3, 3, 2, 2, 2, 1, 1. What is the
degree sequence of G?

Exercise 5.115. Generalize the previous exercise. How are the degree sequences of a graph G
and its complement G related?

Exercise 5.116. Can a graph G be isomorphic to its complement G? Either find an example
(if yes) or prove it cannot happen (if no).

Exercise 5.117. Prove that Cn is connected for n ≥ 2.

Exercise 5.118. Prove that Kn is connected for n ≥ 2.

Exercise 5.119. In a graph G = (V, E), explain why a u-v path and a v-w path, when connected
at the point v, may not necessarily result in a path.
Prove that a u-v path and a v-w path together must contain a u-w path.

Exercise 5.120. Let G = (V, E) be a simple graph. Prove that the relation ∼ on V given by

u ∼ v ⇔ u and v are joined by a u-v path

is an equivalence relation. This is called the connectedness relation on the vertices of a graph.
(Hint: Use Exercise 5.119 to show transitivity.)

80 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 5.6 Additional Exercises

Exercise 5.121. 7
Describe the equivalence class [1] of the vertex 1 in the graph 2 4
on the right in the connectedness relation defined in Exer-
3
cise 5.120.
1 5 6

Exercise 5.122. Draw an example of each of the following graphs or explain why it is impossible:

(a) A bipartite Eulerian graph

(b) A forest on 7 vertices and 4 edges

(c) A tree on 6 vertices that has 5 leaves

(d) A connected graph whose complement is connected.

(e) A disconnected graph whose complement is disconnected.

Exercise 5.123 (December 2016 Final). Prove that any simple graph whose vertices all have
degree at least n−1
2 must be connected.

Exercise 5.124. Find an Eulerian trail in K2,4 .

Exercise 5.125. Prove that Km,n is connected for any m, n ∈ N.

Exercise 5.126. Find all pairs of natural numbers (m, n) for which Km,n is Eulerian.

Exercise 5.127. Find all pairs of natural numbers (m, n) for which Km,n is Hamiltonian.

Exercise 5.128. Find a Hamiltonian cycle in each of the graphs in Exercise 5.113.

Exercise 5.129. Find a Hamiltonian cycle of least cost in each of the following graphs:

v4 e
6
3 1
1 1
5 7 v3 1 2
12
a b c
9 2
1 0
v1 v2
10
d

Exercise 5.130. The graph Kn is Hamiltonian for any n ≥ 3. How many different Hamiltonian
cycles are contained in Kn for n ≥ 3?
Hint: K3 has only one, while K4 has three, shown below.

4 3 4 3 4 3

1 2 1 2 1 2

1-2-3-4-1 1-3-4-2-1 1-4-2-3-1

81 (c) TJ Yusun

You might also like