202 Notes
202 Notes
202 Notes
Discrete Mathematics
MAT202H5 Course Notes, Fall 2019
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
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
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
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:
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.
• 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
Theorem 1.6
The composition of two (injections, surjections, bijections) is an (injection, surjection,
bijection).
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
P (A) = {X : X ⊆ A},
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:
• 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.
(h) A three-digit natural number is divisible by 9 if and only if the sum of its digits is
divisible by 9.
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.
then P (n) is true for all n ∈ N. One can also replace (b) with the following:
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.
√ 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
For completeness we restate here the definition of divisibility and the Division Algorithm.
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:
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).
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.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.
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
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
m is even ⇐⇒ m3 is even.
m3 = (2k)3 = 8k 3 = 2(4k 3 ).
(⇐) Next, we prove that m3 even ⇒ m even. To do this we prove the contrapositive: If
m is odd, then m3 is odd.
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.
Explain steps
• By simplification/manipulation/rearranging, . . .
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.
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:
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.
(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.
• B1 ∪ B2 ∪ · · · ∪ Bm = A.
12 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 2.1 The Basic Counting Principles
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 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.
• 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.
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.
Tip: For problems where the answer involves a factorial, it is fine to leave the factorial in your
answer without computing the actual value.
14 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 2.2 Permutations and Combinations
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.
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,
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:
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:
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.)
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:
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,
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.
(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
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.
(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.
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.
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)
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:
Simplify your answers to arrive at a single number for each part. How are your answers
related?
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.)
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.
• 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.
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:
••• ••••• ••
• • • | • • • • • | •• ||
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.
(c) • • || • • • • • • || • • (d) || • • • • • | • | • • • •
22 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 2.4 The Balls in Bins Formula
• The order in which objects are picked does not matter (i.e. A-B-A is the same as B-A-A).
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:
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.
x1 + x2 + x3 + x4 + x5 = 10.
23 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 2.5 Summary
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:
Prop 2.22
24 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 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:
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:
Exercise 2.55. A new format for passenger vehicle licence plates issued in the province is being
proposed, that adheres to the following conditions:
(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!
(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)?
(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.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).
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
(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.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)
Objectives:
• State the Pigeonhole Principle and the Principle of Inclusion-Exclusion and apply them
to problems as appropriate.
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.
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.
Exercise 3.4. Prove Theorem 3.3 following the proof of Examples 3.1, 3.2.
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:
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:
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.
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?
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|.
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
• 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.
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 .
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
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
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
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:
• |A1 | = 3! · 83 (permute the consonants first, then insert among vowels using the
• |A1 ∩ A2 | = 85 (vowels and consonants are in a fixed order; just pick 5 slots for
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
(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 .
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:
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)
(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
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.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
(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.
(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).
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:
37 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019)
4 Congruence Modulo n
Objectives:
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.
Exercise 4.3. How many relations are there between the sets A = {0, 2, 4, 6} and
B = {0, 1, 2, 3, 4}?
38 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 4.1 Equivalence Relations
(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.
(b) The relation R = {(a, a), (b, b), (c, c), (a, b), (b, a), (a, c), (c, a)} on the set {a, b, c}.
R = {(v, v), (w, w), (x, x), (y, y), (z, z), (v, z), (z, v), (w, x), (x, w), (y, y)}
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
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.)
X∼
= Y ⇔ the largest element in X equals the largest element in Y .
Prove ∼
= is an equivalence relation, and describe the 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!
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.
a ≡ b (mod n) .
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
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.
(a) a + b ≡ r + s (mod n)
(b) ab ≡ rs (mod n)
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
42 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 4.2 Congruence
(a) 2139138 is divided by 9. (b) 21000 is divided by 7. (c) 10! is divided by 17.
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.
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
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?
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) .
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.
2x ≡ 3 (mod 7)
44 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 4.3 Euler’s Theorem
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?
(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)?
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.
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.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
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
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
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:
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
Exercise 4.54. Replicate the idea in Example 4.53 to show that 7φ(15) ≡ 1 (mod 15).
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:
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
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.
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:
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
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.
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!)
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
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 .
51 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 4.5 The RSA Cryptosystem
• Let M = m1 m2 · · · mn .
• For each i = 1, 2, . . . , n:
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
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.
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:
• Anyone who sees the message y will not be able to decrypt it and retrieve x.
so
y d ≡ (xe )d (mod N ) ≡ xed (mod N ) ≡ x1+kM (mod N ) .
Thus we have
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.
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.
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.)
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).
m ∼ n ⇔ 4 | (m2 − n2 ).
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.
54 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 4.6 Additional Exercises
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 .
(c) b = 33, m = 7
Exercise 4.75. Solve the following congruences. Express your answer as congruence classes of
the original modulus.
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.
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.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.)
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.
(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.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:
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.
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?
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?
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
We now formally state the definition of a graph. Unless otherwise specified, the graphs you will
encounter in this text are simple graphs.
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
(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
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.
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.
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:
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
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.
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.
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
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.
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 ?
b v5 v2 G3 v1
G1
G2 v4
a v2
e v3 v4
d
v1 v5 v3
c
V = {v1 , v2 , v3 , v4 , v5 }
66 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 5.3 Isomorphisms and Subgraphs
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
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.
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.
(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.
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
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!
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.
70 (c) TJ Yusun
MAT202H5F - Discrete Mathematics (Fall 2019) 5.4 Connectedness and Trees
In this section we introduce a few more graph-theoretic terminology, starting with paths and
connectedness.
Example 5.57.
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.
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.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.
Example 5.64.
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.
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.
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.
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)?
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.
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
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.
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 },
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.
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).
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.
Exercise 5.95. Verify that the following graph satisfies the conditions of Theorem 5.94,
then find a Hamiltonian cycle on the graph.
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:
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
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.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
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.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
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:
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.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
81 (c) TJ Yusun