All Notes

Download as pdf or txt
Download as pdf or txt
You are on page 1of 416

Random Variables

ELEE 2110U Discrete Mathematics 1


Random Variables
A random variable 𝑋 is a deterministic function that assigns a real number to each outcome in the sample space 𝑆.
The sample space 𝑆 is the domain of the random variable and the set of all values taken on by the random variable, denoted
by 𝑆 , is the range of the random variable. The range 𝑆 is a subset of all real numbers ∞, ∞ .

If the range of the random variable assumes values from a countable set, it is then a discrete random variable. The defining
characteristic of a discrete random variable is that the set of possible values in the range can all be listed, where it may be a
finite list or a countably infinite list.

ELEE 2110U Discrete Mathematics 2


Probability Mass Function
The probability mass function of a discrete random variable 𝑋 expresses the complete probability model of a random
experiment as the following mathematical function:

𝑝 𝑥 𝑃 𝑋 𝑥 𝑥∈𝑆

Note that 𝑝 𝑥 is a function ranging over real numbers 𝑥 and that 𝑝 𝑥 can be non-zero only at the values 𝑥 ∈ 𝑆 . For
any value of 𝑥, the function 𝑝 𝑥 is the probability of the event 𝑋 𝑥 . The pmf must satisfy the following important
properties:

𝑝 𝑥 0 ∀𝑥 & 𝑝 𝑥 1 & 𝑃 𝑋∈𝐵 𝑝 𝑥


∈ ∈ ⊆

Note that 𝐵 is an event and the above summations have a finite or an infinite number of terms, depending on whether the
range is finite or not. All three properties are consequences of the axioms of probability.
ELEE 2110U Discrete Mathematics 3
Example
Suppose we have a fair coin. Let 𝑋 be the number of heads in three coin tosses. Find the pmf of the random variable 𝑋.

Solution
In a coin toss, there are 2 possibilities, a head and a tail. In tossing a coin 3 times, there are a total of 8 2 different
possible outcomes, as reflected below:
𝑇𝑇𝑇, 𝑇𝑇𝐻, 𝑇𝐻𝑇, 𝑇𝐻𝐻, 𝐻𝑇𝑇, 𝐻𝑇𝐻, 𝐻𝐻𝑇, 𝐻𝐻𝐻
As the coin is fair, the likelihood of a tail is the same as the likelihood of a head. The coin tosses are independent. After
tossing a fair coin three times, the probability of each of the eight outcomes is .
In short, we have
1
𝑃 𝑋 0 𝑃 𝑇𝑇𝑇
8
3
𝑃 𝑋 1 𝑃 𝑇𝑇𝐻 𝑃 𝑇𝐻𝑇 𝑃 𝐻𝑇𝑇
8
3
𝑃 𝑋 2 𝑃 𝑇𝐻𝐻 𝑃 𝐻𝐻𝑇 𝑃 𝐻𝑇𝐻
8
1
𝑃 𝑋 3 𝑃 𝐻𝐻𝐻
8
ELEE 2110U Discrete Mathematics 4
Expected Value of a Random Variable
The expected value or the mean of a random variable 𝑋 represents a real number ∞, ∞ . The expected value of a random
variable 𝑋, denoted by 𝐸 𝑋 or 𝜇 , is defined as follows:

𝐸𝑋 𝜇 𝑥 𝑃 𝑋 𝑥 𝑥𝑝 𝑥 Discrete 𝑋

ELEE 2110U Discrete Mathematics 5


Variance of Random Variable
As the expected value of a random variable 𝜇 fails to show the spread of random values in its distribution, a measure to
highlight its dispersion is essential. The variance of the random variable 𝑋 is expressed as follows:

𝜎 𝐸𝑋 𝜇

The variance of a random variable, if it is defined, is always non-negative. The square root of the variance of 𝑋, denoted by
𝜎 , is called the standard deviation of the random variable 𝑋, and is a positive quantity with the same unit as 𝑋.

The variance of a random variable provides essentially a measure of the effective width of the pmf of the random variable.
The variance of a random variable in some sense is a measure of the variable’s randomness, as it indicates the variability of
the outcomes. For instance, a large variance indicates the random variable is quite spread out and it is thus more
unpredictable, whereas a small variance shows the random variable is concentrated around its mean and it is thus less
random.

ELEE 2110U Discrete Mathematics 6


Example
Let 𝑋 be the number of tails in four coin tosses with a fair coin, determine the variance of the random variable 𝑋.

Solution
The pmf of the discrete random variable 𝑋 is as follows:
1 4 6 4 1
𝑃 𝑋 0 𝑃 𝑋 1 𝑃 𝑋 2 𝑃 𝑋 3 𝑃 𝑋 4
16 16 16 16 16

The mean is thus as follows:


1 4 6 4 1
𝐸𝑋 𝜇 0 1 2 3 4 2
16 16 16 16 16

The mean square is obtained as follows:


1 4 6 4 1
𝐸𝑋 0 1 2 3 4 5
16 16 16 16 16

The variance is therefore as follows:


𝜎 𝐸𝑋 𝐸𝑋 5 2 1
ELEE 2110U Discrete Mathematics 7
Example
Consider a six-sided cube-shaped die, which is not fair. Let 𝑋 be the random variable which represents the outcome of a roll
of the die. The pmf of the random variable 𝑋 is as follows:

𝑃 𝑋 1 𝑃 𝑋 2 𝑃 𝑋 4 𝑃 𝑋 5 𝑃 𝑋 6 0.1 & 𝑃 𝑋 3 0.5

Determine the variance of the random variable 𝑋. Show your work. Do simplify your answer to 2 decimal places.

Solution
𝐸𝑋 1 0.1 2 0.1 3 0.5 4 0.1 5 0.1 6 0.1 3.3

𝐸𝑋 1 0.1 2 0.1 3 0.5 4 0.1 5 0.1 6 0.1 12.7

𝜎 𝐸𝑋 𝐸𝑋 12.7 3.3 1.81

ELEE 2110U Discrete Mathematics 8


Standard Deviation
• The square root of the variance of 𝑋, denoted by 𝜎 , is called the standard deviation of the random variable 𝑋, and is a
positive quantity with the same unit as 𝑋. For instance, the random variable 𝑋 and its standard deviation 𝜎 may be both
in meters, seconds, degrees Celsius, or kilograms.
• The great importance of the standard deviation of a random variable lies in the fact that it brings context to the mean
value. For instance, a student, who has a test mark of 10 points above the test mean, is likely to be in the middle of the
class, if the standard deviation of test marks is 20 points, however, she is likely to be near the top of the class, if the
standard deviation is 5 points.

ELEE 2110U Discrete Mathematics 9


Mode and Median
• There are two other simple measures that can provide further insights into the possible values of a discrete random
variable, they are namely the mode and median. The mode and median both make the most sense when a very large
discrete sample space must be described.
• The mode of a random variable is that value that occurs most often, i.e., it has the greatest probability of occurring.
Sometimes, a random variable has more than one mode, thus naming it a multi-modal random variable.
• The median of a random variable is that particular value for which the sum of the probabilities of all values greater than
the median and the sum of the probabilities of all values less than the median are equal, that is, each sum is equal to 0.5.
The median of a discrete random variable may not exist.
• Note that median is generally employed when there are outliers in the sample data, that is, when there are data values
that appear remote from all or most of the other data values.

ELEE 2110U Discrete Mathematics 10


Example
Determine the mode, median, and mean of the discrete
random variable 𝑋 whose pmf is presented in Table 𝒙 𝒑𝑿 𝒙
0 2%
1 3%
Solution
2 5%
The median is 6, as the sum of the probabilities of all values 3 10%
greater than 6 and the sum of the probabilities of all values 4 10%
5 20%
less than 6 each is equal to 50%. The mode is 8, as it is the
6 0%
most likely to occur. The mean is obtained as follows: 7 20%
8 25%
𝐸𝑋 9 3%
10 2%
0 2% 1 3% 2 5% 3 10% 4 10%
5 20% 6 0% 7 20% 8 25% 9 3%
10 2% 5.7.

ELEE 2110U Discrete Mathematics 11


Bernoulli Distribution
The Bernoulli random variable 𝑋 takes the value of 1 with probability 𝑝 (also known as the probability of success) and the
value of 0 with probability 1 𝑝 (also known as the probability of failure), where 0 𝑝 1. The pmf of a Bernoulli
random variable is defined as follows:

1 𝑝 𝑥 0
𝑝 𝑥 𝑝 𝑥 1 0 𝑝 1
0 𝑥 0, 1

The Bernoulli trial is equivalent to the tossing of a biased coin or examining if a component is defective in a system or
modelling any other process that has only two possible outcomes, such as taking a pass-fail exam.
The mean 𝜇 and variance 𝜎 of the Bernoulli random variable 𝑋, which cannot be independently set as they are both
functions of 𝑝 only, are respectively as follows:
𝜇 𝑝
𝜎 𝑝 1 𝑝

ELEE 2110U Discrete Mathematics 12


Example
Determine the maximum and minimum values of the variance of the Bernoulli random variable. Comment on the results.

Solution
The maximum value of the variance is obtained as follow:

𝑑𝜎
1 2𝑝 0
𝑑𝑝 1
𝜎 𝑝 𝑝 → → 𝑝
2
𝑑𝜎
2 0
𝑑𝑝

Therefore, the maximum value of the variance occurs when 𝑝 , which in turn corresponds to the highest level of

uncertainty, as there are two equally likely outcomes. The variance is minimum, i.e., its value is approaching zero, when
𝑝 0 or 𝑝 1, which in turn implies there is then no uncertainty, as there is always only one possible outcome.

ELEE 2110U Discrete Mathematics 13


Binomial Distribution
The binomial random variable 𝑋 is the number of times 1 (i.e., successes) occurs in 𝑛 independent Bernoulli trials, where 𝑛
is a positive integer, and each occurrence of 1 is assumed to have probability 𝑝, where 0 𝑝 1.

Applications of binomial distribution may include estimation of probabilities of the number of times hitting the target or the
number of erroneous bits when a packet of data (long sequence of bits) is transmitted over a noisy communication channel.

The pmf of a binomial random variable is defined as follows:

𝑛
𝑝 1 𝑝 𝑥 0, 1, … , 𝑛
𝑝 𝑥 𝑥 0 𝑝 1
0 otherwise
𝑛 !
where ≜ is known as the binomial coefficient. The binomial distribution is frequently used to model the number
𝑥 ! !
of successes when the sampling is performed with replacement, as the draws are independent.

The mean 𝜇 and variance 𝜎 of the binomial random variable 𝑋, which can be independently set by the appropriate
selection of 𝑝 and 𝑛, are respectively as follows:

𝜇 𝑛𝑝 & 𝜎 𝑛𝑝 1 𝑝

ELEE 2110U Discrete Mathematics 14


Example
In a digital communication system, bits are transmitted over a channel in which the average bit error rate is assumed to be
0.0001. The transmitter sends each bit 5 times, rather than once, and the receiver takes a majority vote of the received bits to
determine what the transmitted bit was. Determine the probability that the receiver will make an incorrect decision.
Comment on the results.

Solution
Noting that the bit transmission can be viewed as a Bernoulli trial, the probability of interest is as follows:

5
𝑃 𝑋 3 0.0001 0.9999 ≅ 10
𝑥

By sending the same bit five times, the bit error rate can be reduced from 10 to about 10 , a very significant reduction
in bit error rate, but of course at the heavy price of repeating a bit five times.

ELEE 2110U Discrete Mathematics 15


Discrete Uniform Distribution
The discrete uniform random variable occurs when outcomes are equally likely, such as rolling a fair die. It takes on values
in a set of 𝐿 positive integers with equal probability. This distribution is generally employed when there are no information
at all regarding the possible outcomes, as such they are all assumed to have the same probability. The pmf of a discrete
uniform random variable is defined as follows:

𝑃 𝑋 𝑘 𝑝 𝑘 𝑘 𝑚 1, … , 𝑚 𝐿 ∞ 𝑚 ∞ 𝐿 ∈ 1, 2, …

The mean 𝜇 and variance 𝜎 of the discrete uniform distribution 𝑋 are respectively as follows:

𝐿 1 𝐿 1
𝜇 𝑚 & 𝜎
2 12

The discrete random variable is used to generate random numbers in computer simulation models. Note that events that have
an equiprobable finite number of outcomes form the basis upon which counting formulas are developed.
ELEE 2110U Discrete Mathematics 16
Example
Suppose the mean and variance of a discrete uniform random variable 𝑋 are both 10. Determine the set of consecutive
integers that this discrete uniform random variable can take on.

Solution
We have:

𝐿 1
𝜎 10 → 𝐿 11
12
We can therefore have:

𝐿 1 11 1
𝜇 𝑚 10 → 𝑚 10 → 𝑚 4
2 2

Hence, 𝑋 takes on values in the set of consecutive integers 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 , each with probability .

ELEE 2110U Discrete Mathematics 17


Geometric Distribution
In a sequence of independent Bernoulli trials with a success probability 𝑝, where 0 𝑝 1, the random variable 𝑋 that
denotes the number of trials performed until the first success occurs is said to have the geometric distribution with
probability 𝑝.
For instance, the geometric distribution could be used to describe the number of candidates to be interviewed until a
candidate is accepted or the number of cars to be test driven until a car is bought.
The pmf of a geometric random variable is defined as follows:

𝑝 𝑥 1 𝑝 𝑝 𝑥 1, 2, … 0 𝑝 1.

ELEE 2110U Discrete Mathematics 18


Example
Tickets for the final of 2026 World Cup are sold exclusively online on a single website. Suppose that the chance of
successfully accessing the website by a fan to buy a ticket is 0.01. Determine the probability that a fan has to attempt one
hundred or more times to get through.

Solution
The probability that a fan has to attempt one hundred or more times to get through is as follows:

𝑃 𝑋 100 1 𝑃 𝑋 99 1 1 0.99 0.99 ≅ 0.36973.

This is simply the probability that the first ninety-nine attempts are unsuccessful.

ELEE 2110U Discrete Mathematics 19


Poisson Distribution
• The Poisson distribution represents the number of occurrences of events occurring within certain specified boundaries,
such as the number of text messages received by a mobile user during an hour, the number of potholes in a road, the
number of goals scored in a soccer or hockey game, and the number of defective units in a sample taken from a
production line.
• The Poisson random variable arises in situations where the events occur completely at random in time or space. These
events occur with a constant average rate and independently of the time or space associated with the last event.

• The pmf of a Poisson random variable is defined as follows:

𝑒 𝜆
𝑝 𝑥 𝑥 0, 1, 2, … 𝜆 0.
𝑥!

where 𝜆 is the parameter of the distribution reflecting the average rate of occurrence.

ELEE 2110U Discrete Mathematics 20


Example
Suppose that the number of errors in a book has a Poisson distribution with parameter 𝜆 7. Determine the probability that
a book has no errors, and the probability that the number of errors are three or more.

Solution
The probability that a computer program has no bugs is as follows:

𝑒 7
𝑃 𝑋 0 ≅ 0.0009.
0!

The probability that the number of bugs is three or more is as follows:

𝑒 7
𝑃 𝑋 3 1 𝑃 𝑋 𝑖 1 ≅ 0.0296.
𝑖!

ELEE 2110U Discrete Mathematics 21


Counting

ELEE 2110U Discrete Mathematics 1


Basic Rules of Counting: Fundamental Principle of Counting
• Suppose a task can be broken down into a sequence of 𝑘 independent subtasks, where 𝑘 is a positive integer. Any one
subtask is thus done regardless of how the other 𝑘 1 subtasks are done.
• Assuming 𝑛 , 𝑛 , …, and 𝑛 are all positive integers, the first subtask can be accomplished in 𝑛 ways, the second
subtask in 𝑛 ways, …, and the 𝑘 subtask in 𝑛 ways.
• The fundamental principle of counting, also known as the product rule of counting or the multiplication rule of
counting, states that there are a total of 𝑛 𝑛 ⋯ 𝑛 distinct ways to accomplish the task.
Example
How many four-digit integers are there that are multiples of twenty?

Solution
In a four-digit integer, the first (the most significant) digit cannot be zero. There are therefore nine possible ways for the first
digit, from 1 to 9 inclusive.
The second most significant digit can be any one of the ten possible digits, from 0 to 9 inclusive.
The third digit cannot be an odd integer, that is, it must be one of the five digits 0, 2, 4, 6, and 8.
The fourth (the least significant) digit must be 0.
Using the product rule, there is then a total of 9 10 5 1 450 four-digit integers that are multiples of twenty.

ELEE 2110U Discrete Mathematics 3


Basic Rules of Counting: Sum Rule of Counting
• Suppose a task can be done in 𝑘 mutually exclusive sets of ways, where 𝑘 is a positive integer. The ways in any one set
thus excludes the ways in the other 𝑘 1 sets.
• Assuming 𝑛 , 𝑛 , …, and 𝑛 are all positive integers, the task can be accomplished in one of 𝑛 ways in set 1, in one of
𝑛 ways in set 2, …, and in one of 𝑛 ways in set 𝑘, where the set of 𝑛 ways, the set of 𝑛 ways, …, and the set of 𝑛
ways are all pairwise disjoint finite sets.
• The sum rule of counting, also known as the addition rule of counting, states that there are a total of 𝑛 𝑛 ⋯ 𝑛
distinct ways to accomplish the task.
Example
How many two-digit integers are there that are divisible by 11 or 13?

Solution
There is a set of 9 two-digit integers that are divisible by 11, and there is a set of 7 two-digit integers that are divisible by 13.
These two sets are mutually exclusive, as there is no two-digit integer that is divisible by both 11 and 13.
Using the sum rule, there are therefore 9 7 16 two-digit integers that are divisible by 11 or 13.

ELEE 2110U Discrete Mathematics 5


Example
How many four-digit integers are there using the digits 0, 1, 2, 3, 4, and 5, where no digit is repeated and the integer is a multiple of 3.

Solution
For an integer to be a multiple of 3, the sum of its digits must be a multiple of 3.
A digit can be used only once, therefore the smallest sum of all digits in a four-digit integer can be 0 1 2 3 6, and the largest sum
of all digits can be 2 3 4 5 14. The sum that must be divisible by three can then be 6, 9, or 12.
Note that the first digit cannot be 0 as it is a four-digit integer.
We therefore have the following mutually exclusive cases:
• The sum of the integers is 6. The four integers are 0, 1, 2, and 3. Using the product rule, there are 3 3 2 1 18 integers.
• The sum of the integers is 9. The four integers are 0, 1, 3, and 5. Using the product rule, there are 3 3 2 1 18 integers.
• The sum of the integers is 9. The four integers are 0, 2, 3, and 4. Using the product rule, there are 3 3 2 1 18 integers.
• The sum of the integers is 12. The four integers are 0, 3, 4, and 5. Using the product rule, there are 3 3 2 1 18 integers.
• The sum of the integers is 12. The four integers are 1, 2, 4, and 5. Using the product rule, there are 4 3 2 1 24 integers.
By the sum rule, the total number of integers is thus 18 18 18 18 24 96.

ELEE 2110U Discrete Mathematics 6


Basic Rules of Counting: Principle of Inclusion-Exclusion
• Suppose a task can be accomplished in 𝑘 sets of ways, where 𝑘 is a positive integer.
• Assuming 𝑛 , 𝑛 , …, and 𝑛 are all positive integers, the task can be accomplished in one of 𝑛 ways in set 1, in one of
𝑛 ways in set 2, …, and in one of 𝑛 ways in set 𝑘, where the set of 𝑛 ways, the set of 𝑛 ways, …, and the set of 𝑛
ways are not pairwise disjoint finite sets. In other words, some of the ways to do the task are thus common, and must not
be counted more than once.
• The subtraction rule of counting, also widely known as the principle of inclusion-exclusion, states that the number of
distinct ways to accomplish the task is 𝑛 𝑛 ⋯ 𝑛 minus the number of common ways that have been
overcounted, so no common way is counted more than once.
Example
How many two-digit integers are there that are multiples of at least one of these three integers 3, 4, and 5?

Solution
The set of two-digit integers that are multiples of 3, the set of integers that are multiples of 4, and the set of integers that are
multiples of 5 are not mutually exclusive.
There are 30 two-digit integers that are divisible by 3, there are 22 two-digit integers that are divisible by 4, and there are 18
two-digit integers that are divisible by 5.
There are 8 two-digit integers that are divisible by both 3 and 4, there are 6 two-digit integers that are divisible by both 3 and
5, and there are 4 two-digit integers that are divisible by both 4 and 5. Also, there is one two-digit integer that is divisible by
all 3, 4, and 5.
Using the subtraction rule, there are therefore 30 22 18 8 6 4 1 53 two-digit integers that are multiples of
3, 4, or 5.

ELEE 2110U Discrete Mathematics 8


Example
In a survey of 1200 people, it was found that 650 have shares of AA stock, 450 have shares of GG stock, and 420 have
shares of ZZ stock. It was also found that 200 have shares in both AA and GG stocks, 250 have shares in both AA and ZZ
shares, 150 have shares in both GG and ZZ stocks, and 80 have shares in all three AA, GG and ZZ stocks. Determine:
(a) The number of people who have shares at least in one of the three stocks.
(b) The number of people who have shares exactly in one stock.

Solution
Using the inclusion-exclusion principle, we have:

a 650 450 420 200 250 150 80 1000


b 650 200 250 80 450 200 150 80 420 250 150 80 560

ELEE 2110U Discrete Mathematics 9


Example
A computer access password consists of four to seven digits chosen from 0 to 9 inclusive, where no digit in a password can
be repeated. How many different passwords are possible?

Solution
Using the product rule and noting that a digit in a password cannot be repeated,
o the number of passwords consisting of four different digits is 10 9 8 7 5,040,
o the number of passwords consisting of five different digits is 10 9 8 7 6 30,240,
o the number of passwords consisting of six different digits is 10 9 8 7 6 5 151,200, and
o the number of passwords consisting of seven different digits is 10 9 8 7 6 5 4 604,800.
By the sum rule, the total number of all passwords is thus 5040 30240 151200 604800 791,280.

ELEE 2110U Discrete Mathematics 10


The Pigeonhole Principle
The pigeonhole principle, also known as the Dirichlet drawer principle, states that if 𝑘 0 is an integer and 𝑘 pigeonholes
are occupied by 𝑘 1 or more pigeons, then at least one pigeonhole is occupied by more than one pigeon.

The pigeonhole principle can be proven using a proof by contraposition.

ELEE 2110U Discrete Mathematics 11


Example
Determine the minimum number of digits in an integer to guarantee that at least two of the digits are the same digits.

Solution
Using the pigeonhole principle, we have 𝑘 10, as there are ten distinct digits in the Hindu-Arabic numeral system. In
order to have at least two of the digits the same, the minimum number of the digits in the integer must then be 𝑘 1 11.

ELEE 2110U Discrete Mathematics 12


Generalized Pigeonhole Principle
The generalized pigeonhole principle states that if 𝑘 and 𝑛 are positive integers and 𝑘 pigeonholes are occupied by 𝑚
𝑘𝑛 1 or more pigeons, then at least one pigeonhole is occupied by 𝑛 1 or more pigeons.

The generalized pigeonhole principle can be proven using a proof by contraposition.

ELEE 2110U Discrete Mathematics 13


Example
A bag contains eighteen red balls and eighteen blue balls. A woman selects balls at random one at a time without looking at
them. Determine the minimum number of balls that she must select from the bag to be sure of having at least nine balls of
the same colour.

Solution
Using the generalized pigeonhole principle, we have 𝑘 2, as there are two different colors and we have 𝑛 8, as 𝑛 1
9. The minimum number of balls that she must select to be sure of having at least nine balls of the same color is thus 𝑚
𝑘𝑛 1 2 8 1 17.

ELEE 2110U Discrete Mathematics 14


Permutations
An ordered arrangement of 𝑘 distinguishable objects from a set of 𝑛 𝑘 objects is called a 𝒌-permutation.
In a 𝑘-permutation, different outcomes are distinguished by the order in which objects are selected in a sequence. Therefore,
in a 𝑘-permutation, both the identity of the objects and their order matter.
For instance, if a fair coin is tossed twice, the outcome that consists of getting a tail on the first flip and a head on the second
(TH) is different from the outcome that consists of getting a head on the first flip and a tail on the second (HT). As order
matters, TH and HT are not the same outcome.
Some real-life examples of permutations include
o order of letters in an English word,
o sequence of digits in a telephone number,
o Olympic winners in races and matches,
o order of alphanumeric characters in passwords,
o sequence of numbers in combination locks, and
o positions in hierarchical systems.
Combinations
An unordered selection of 𝑘 distinguishable objects from a set of 𝑛 𝑘 objects is called a 𝒌-combination. In a 𝑘-
combination, the identity of objects in a sequence matters, not their order. For instance, in tossing a fair coin twice, all that
matters is one flip is a tail (T) and the other is a head (H). As order is immaterial, TH and HT are the same outcome.
Some real-life examples of combinations include:
o selections of members of committees and teams (without counting positions),
o multiplication of numbers,
o buying groceries,
o handshakes among a group of people,
o voting in an election,
o answering questions on exams,
o games in a round-robin tournament,
o dice rolled in a dice game, and
o cards dealt to form a hand in a card game.
Selection with/without Replacement
In a selection with replacement (repetition, substitution), after an object out of 𝑛 objects is selected, it is returned to the set
and it is thus possible that it will be selected again. In sampling with replacement, the sample space remains the same after
each selection.

In a selection without replacement, an object, once selected, is not available for future selections. In sampling without
replacement, the sample space of each selection depends on the outcomes of previous selections.

Selection with or without replacement can be both applied to both 𝑘-permutations and 𝑘-combinations, thus giving rise to
four distinct counting methods.
Permutations & Combinations, with & without Replacement

Permutations Combinations
(ordered arrangements) (unordered selections)

Without 𝒏! 𝒏!
replacement 𝒏 𝒌 ! 𝒌! 𝒏 𝒌 !

With 𝒏𝒌 𝒏 𝒌 𝟏 !
replacement
𝒌! 𝒏 𝟏 !
Example
How many different ways are there to select a gold medalist, a silver medalist, and a bronze medalist from 195 athletes with
different nationalities who have entered a world sports competition?

Solution
Since it matters which athlete wins which medal and no athlete can win more than one medal, it is a selection with ordering
!
and without replacement. Noting that 𝑛 195 and 𝑘 3, the number of ways is thus 195 194 193
!

7,301,190.

ELEE 2110U Discrete Mathematics 19


Example
How many different ways are there to have a gold medalist, a silver medalist, and a bronze medalist from 32 national teams
that have entered a sports competition?

Solution
Since it matters which team wins which medal and no team can win more than one medal, it is a permutation without
!
replacement. Noting that 𝑛 32 and 𝑘 3, the number of ways is thus 32 31 30 29,760.
!

ELEE 2110U Discrete Mathematics 20


Example
There are 22 players on a soccer team. The starting lineup consists of only eleven players. How many possible starting
lineups are there, assuming what positions they play is of no concern?

Solution
Since the order of the selection of the players is immaterial and no player can be selected more than once, it is a combination
!
without replacement. Noting that 𝑛 22 and 𝑘 11, the number of ways is thus 705,432.
! !

ELEE 2110U Discrete Mathematics 21


Example
How many four-letter passwords from the capital letters 𝐴 to 𝑍 inclusive can be made, noting that a letter can be repeated in
a password?

Solution
This is a permutation with replacement, as the order of capital letters in a password matters and a capital letter can be used in
a password more than once. Noting that 𝑛 26 and 𝑘 4, the number of words is thus 26 456,976.

ELEE 2110U Discrete Mathematics 22


Example
There is a list of 25 different exotic foods on the menu of a special restaurant. For a flat price, a customer can select 4 foods.
In how many ways can a selection of four foods be chosen?

Solution
This is a combination but with replacement, as the order of the selection does not matter and a food can be selected more
!
than once. With 𝑛 25 and 𝑘 4, the number of ways is thus 20,475.
! !

ELEE 2110U Discrete Mathematics 23


Example
There are six balls in a bag, numbered 1, 2, 3, 4, 5, and 6. We randomly pick two balls from it, one by one. Find the number
of permutations and combinations, with and without replacement, i.e., consider all four possible cases.

Solution (1, 1) (1, 2) (1, 3) (1, 4) (1, 5) (1, 6)


Noting that 𝑛 6 and 𝑘 2, the outcomes can be divided into
three mutually exclusive sets: the set 𝐴 that includes 15 pairs, in (2, 1) (2, 2) (2, 3) (2, 4) (2, 5) (2, 6)
each of which the first number is larger than the second number,
the set 𝐵 that includes 15 pairs, in each of which the first (3, 1) (3, 2) (3, 3) (3, 4) (3, 5) (3, 6)

number is smaller than the second number, and the set 𝐶 that B
(4, 1) (4, 2) (4, 3) (4, 4) (4, 5) (4, 6)
includes 6 pairs, in each of which the first and the second
numbers are the same. We have the following four cases:
C
(5, 1) (5, 2) (5, 3) (5, 4) (5, 5) (5, 6)

A B
! !
!
15 pairs A
(6, 1) (6, 2) (6, 3) (6, 4) (6, 5) (6, 6)
!
A C B C 21 pairs
! !
!
A B 30 pairs No. of perms. with replacement 𝐴 𝐵 𝐶 36
!
𝐴 𝐵 𝐶 6 36 15 15 6 pairs No. of perms. without replacement 𝐴 𝐵 30
No. of combs. with replacement 𝐴 𝐶 𝐵 𝐶 21
No. of combs. without replacement 𝐴 𝐵 15
Example
In a bag, there are three black balls, four white balls, and five red balls. Two balls are picked from the bag. How many ways
(permutations) are there if the two balls are not of the same color?

Solution
To choose two balls of different colors, we consider three mutually exclusive cases, where each is based on the product rule:
3 4 3 5 5 4 47 ways.

ELEE 2110U Discrete Mathematics 25


Multinomial Counting
Suppose 𝑛 𝑘 ,𝑛 𝑘 , …, and 𝑛 𝑘 are all positive integers, and 𝑘 items from a group of 𝑛 items, 𝑘 items from
a group of 𝑛 items,…, and 𝑘 items from a group of 𝑛 items are selected in an unordered fashion without replacement,
while noting that 𝑛 𝑛 𝑛 ⋯ 𝑛 is the total number of items available and 𝑘 𝑘 𝑘 ⋯ 𝑘 is the total
number of items selected. The number of ways to make such a particular selection is the product of 𝑚 binomial terms, and it
is as follows:

𝑛 𝑛 𝑛 ! 𝑛 !
⋯ ⋯
𝑘 𝑘 𝑘 ! 𝑛 𝑘 ! 𝑘 ! 𝑛 𝑘 !

ELEE 2110U Discrete Mathematics 26


Example
Suppose we have ten black balls, twenty white balls, and eighteen yellow balls in a bag. Determine the number of ways to
make a combination without replacement of five black balls, four white balls, and six yellow balls.

Solution
! ! !
As we have 𝑛 10, 𝑛 20, 𝑛 18, 𝑘 5, 𝑘 4, and 𝑘 6, the number of ways is thus
! ! ! ! ! !

22,665,530,160.

ELEE 2110U Discrete Mathematics 27


Example
Bridge is a popular card game in which 52 cards are dealt to four players, each having 13 cards. The order in which the cards
are dealt is not important, just the final 13 cards each player ends up with are of importance. How many different ways are
there to deal hands of 13 cards to each of 4 players?

Solution

Note that there are ways to choose the 13 cards of the first player, ways to choose the 13 cards of the

second player, ways to choose the 13 cards of the third player, and way to choose the 13
cards of the fourth player. Using multinomial counting, the total number of possible ways is as follows:

52 39 26 13 52!
≅ 5.364 10 .
13 13 13 13 13! 13! 13! 13!

ELEE 2110U Discrete Mathematics 28


Lottery (for info only)
In a typical lottery game, a player chooses 𝑛 distinct numbers from 1 to 𝑁
inclusive, where clearly 𝑛 and 𝑁 are both positive integers. At the lottery 𝑘 𝑝 𝑁 49, 𝑛 6
drawing, identical balls numbered from 1 to 𝑁 are mixed, and 𝑛 𝑁 balls are
randomly picked from a device, one by one. 0 , ,
≅ 𝟒𝟑. 𝟓𝟗𝟔𝟓%
, ,

1 , ,
Assuming that once a ball is drawn, it is not put back in the device, we need to ≅ 𝟒𝟏. 𝟑𝟎𝟏𝟗%
, ,

determine the probability that 0 𝑘 𝑛 of the 𝑛 balls picked match the 2 , ,


≅ 𝟏𝟑. 𝟐𝟑𝟕𝟖%
, ,
player’s choices. This is a combination without replacement, in which 𝑘 3 ,
≅ 𝟏. 𝟕𝟔𝟓𝟎%
, ,
numbers are drawn from 𝑛 numbers and 𝑛 𝑘 numbers are drawn from 𝑁 𝑛
4 ,
numbers. Using hypergeometric probability, we can have the following ≅ 𝟎. 𝟎𝟗𝟔𝟗%
, ,

probability 5 ≅ 𝟎. 𝟎𝟎𝟏𝟖%
, ,
6 ≅ 𝟎. 𝟎𝟎𝟎𝟎𝟎𝟕%
, ,
𝑝

ELEE 2110U Discrete Mathematics 29


Poker (for info only)
Since the order of cards dealt does Category Description Probability
not matter, we have Royal It contains Ace, King, Queen, Jack, and a 10, all of the same 4
≅ 𝟎. 𝟎𝟎𝟎𝟏𝟓%
Flush suit, the highest possible hand. 2598960

! Straight It contains five cards of sequential rank, all of the same suit, but 36
2,598,960 Flush not Royal Flush. 2598960
≅ 𝟎. 𝟎𝟎𝟏𝟒%
! !
Four of It contains four cards of one rank and one other card. 624
≅ 𝟎. 𝟎𝟐𝟒%
a Kind 2598960
possible combinations in five-card
Full It contains three matching cards of one rank and two matching 3744
poker. Probability analysis can House cards of another rank. ≅ 𝟎. 𝟏𝟒𝟒%
2598960
provide the valuable knowledge Flush It contains five cards of the same suit, but not in sequence. 5108
about the probabilities of an array 2598960
≅ 𝟎. 𝟏𝟗𝟕%

of hands, a necessary but not a Straight It contains five cards of sequential rank, but in more than one
10200
suit. ≅ 𝟎. 𝟑𝟗𝟐%
sufficient requirement to win in 2598960

poker. Three of It contains three cards of the same rank, plus two unmatched
54912
a Kind (not of this rank nor the same as each other) cards. ≅ 𝟐. 𝟏𝟏%
2598960
Two It contains two cards of the same rank, plus two cards of
In poker, there are also other 123552
≅ 𝟒. 𝟕𝟓%
Pair another rank (that match each other, but not the first pair) and 2598960
important factors involved, such one unmatched (not of either rank) card.
as the betting sequence, other One It contains two cards of the same rank, plus three other
1098240
Pair unmatched (not of this rank nor the same as each other) cards. ≅ 𝟒𝟐. 𝟐𝟔%
players’ hands, and above of all 2598960
High It contains no two cards of the same rank, the five cards are not
the playing decisions made by the ≅ 𝟓𝟎. 𝟏𝟐%
Card in sequence, and the five cards are not all the same suit.
other players.

ELEE 2110U Discrete Mathematics 30


Discrete Probability

ELEE 2110U Discrete Mathematics 31


Statistical Regularity and Relative Frequency
• Experiment: A measurement procedure or observation process.
• Deterministic experiment: If the outcome of an experiment is always the same.
• Random experiment: The outcome may unpredictably vary when the experiment is repeated.
• Trial: Each repetition of the experiment.
• Independent trials: The outcome of one trial has no bearing on the other.
• Statistical regularity: Averages in long sequences of independent trials almost always give rise to the same value.
• Probability model: An approximation that details enough to include all major aspects of the random phenomenon.
• Relative frequency: The ratio of the number of times an event occurs to the number of times the trial has been repeated.
• Relative-frequency definition of probability: It is the relative frequency when the number of times the experiment being
repeated approaches infinity.
• Classical definition of probability: If outcomes are equally likely, then the probability of an event is equal to the number
of outcomes that the event can have divided by the total number of possible outcomes in a random experiment.

ELEE 2110U Discrete Mathematics 32


Relative Frequency: Tossing a Fair Coin
𝑁
𝑁

0.5

0 𝑁
1 10 50 100

ELEE 2110U Discrete Mathematics 33


Basic Definitions in Probability
• Outcome: The end result of an experiment.
• Equally-likely outcomes: When no single outcome is any more likely than any other.
• Sample space: All possible outcomes of an experiment.
• Sample points: The outcomes that cannot occur simultaneously.
• Event: A subset of the sample space of an experiment.
• Certain (sure) event: An event with all outcomes, and thus always occurs.
• Null (impossible) event: An event contains no outcomes, and thus never occurs.
• Mutually exclusive events (disjoint events): They have no common outcomes.
• Discrete sample space: When the sample space is countable.
• Continuous sample space: When the sample space is uncountably infinite.

ELEE 2110U Discrete Mathematics 34


Example
Consider a random experiment that constitutes rolling a fair six-sided cube-shaped die and coming to rest on a flat surface, where the face of
the die that is uppermost yields the outcome. Provide specific examples to highlight the above definitions associated with the sample space
and events in a die-rolling experiment.

Solution
• The sample space 𝑆 includes six sample points 1, 2, 3, 4, 5, and 6. Since the die is fair (unbiased), all six outcomes are equally likely.
• Some different events can be defined as follows: one with even outcomes (i.e., 2, 4, and 6), one with odd outcomes (i.e., 1, 3, and 5), and
one whose outcomes are divisible by 3 (i.e., 3 and 6).
• Two mutually exclusive events may be an event with even outcomes and an event with odd outcomes.
• The union of two events, where one is with odd outcomes and the other is with outcomes that are divisible by 3, consists of 1, 3, 5, and
6, and their intersection consists of only 3.
• A certain (sure) event consists of outcomes that are integers between 1 and 6 inclusive. A null (impossible) event consists of outcomes
that are less than 1 or greater than 6.
• The complement of the event whose outcomes are divisible by 3 is an event that contains 1, 2, 4, and 5.

ELEE 2110U Discrete Mathematics 35


Example
Suppose a pair of fair (ideal) dice is rolled. Determine the probability when the sum of the outcomes is three.

Solution
For mere clarity, it is assumed that one of the two dice is red and the other is green. There are 6 possible outcomes for the red
die and 6 possible outcomes for the green die. The outcome of one die is independent of the outcome of the other die. In
other words, for a specific outcome for the red die, there can be 6 different outcomes for the green die, and for a specific
outcome for the green die, there can be 6 different outcomes for the red die. We therefore have 36 6 6 possible
outcomes in rolling a pair of dice, and as the dice are fair, we have a total of 36 equally-likely outcomes. It is thus a discrete
sample space. To have a sum of three, the outcomes must then be a 1 and a 2. But to get a sum of 3, there are two different
possible scenarios that include the red die is a 1 and the green die is a 2 or the red die is a 2 and the green die is a 1. Hence,

the probability that a sum of three comes up is .

ELEE 2110U Discrete Mathematics 36


Axiomatic Definition of Probability
In the axiomatic definition of probability, the probability of the event 𝐴, denoted by 𝑃 𝐴 , in the sample space 𝑆 of a random
experiment is a real number assigned to 𝐴 that satisfies the following axioms of probability:

Axiom I: 𝑃 𝐴 0

Axiom II: 𝑃 𝑆 1

Axiom III: If 𝐴 , 𝐴 , … is a countable sequence of events such that 𝐴 ∩ 𝐴 ∅ for all 𝑖 𝑗, where ∅ is the null event,
that is they are pairwise disjoint (mutually exclusive) events, then 𝑃 𝐴 ∪ 𝐴 ∪ ⋯ 𝑃 𝐴 𝑃 𝐴 ⋯

ELEE 2110U Discrete Mathematics 37


Example
A box contains 20 balls, numbered from 1 to 20 inclusive. Determine the probability that the number on a ball chosen at
random is either a prime number or a multiple of 4.

Solution
Let 𝐴 be the event that includes prime numbers, and 𝐴 be the event that includes numbers that are multiples of 4, that is
we have:
8 2
𝐴 2, 3, 5, 7, 11, 13, 17, 19 → 𝑃 𝐴
20 5
5 1
𝐴 4, 8, 12, 16, 20 → 𝑃 𝐴
20 4
We also have:
𝐴 ∩𝐴 ∅ → 𝑃 𝐴 ∩𝐴 0

As the events 𝐴 and 𝐴 are mutually exclusive, we can use Axiom III to determine the probability that the number on a ball
chosen at random is either a prime number or a multiple of 4. We thus have:
2 1 13
𝑃 𝐴 ∪𝐴 𝑃 𝐴 𝑃 𝐴
5 4 20

ELEE 2110U Discrete Mathematics 38


Corollaries of Probability
I. 𝑃 ∅ 0, where ∅ is a null event

II. 𝑃 𝐴 𝑃 𝐴 1, where event 𝐴 is the complement of event 𝐴

III. 𝑃 𝐴 1

IV. 𝑃 𝐴 𝑃 𝐴∩𝐵 𝑃 𝐴∩𝐵

V. 𝐴⊂𝐵 → 𝑃 𝐴 𝑃 𝐵

VI. 𝑃 𝐴∪𝐵 𝑃 𝐴 𝑃 𝐵 𝑃 𝐴∩𝐵

VII. 𝑃 𝐴∪𝐵 𝑃 𝐴 𝑃 𝐵

ELEE 2110U Discrete Mathematics 39


Example
A sequence of twenty bits is randomly generated. Noting that the probability of a bit being 0 is equal to that being 1,
determine the probability that at least one of these bits is 0.

Solution
There are many possibilities where at least one of the twenty bits is a zero. For instance, there may only be one zero in the
sequence, and this constitutes twenty different possibilities, such as the first one is a 0 or the second one is a 0, so on and so
forth. There may be only two zeros or three zeros or four zeros in the sequence or even more, where the locations of the
zeros could be anywhere in the sequence of twenty bits. In fact, there are quite many possibilities, in each of which there is
at least one zero in the sequence of twenty bits, and the sum of the probabilities of all these possibilities would then
determine the probability that at least one of these bits is 0.

There is an alternative strategy for finding the probability of an event when a direct approach is long and difficult. Instead of
determining the probability of an event 𝐴, the probability of its complement 𝐴 can be first found. The complement of the
event that has at least one bit being 0 is the event that all bits are 1’s. There are 2 1048576 different sequences of 20
bits, i.e., there are 1048576 sample points in the sample space. The probability of a sequence with all 1’s is thus .
Using 𝑃 𝐴 1 𝑃 𝐴 , the probability that at least one of these bits is 0 is then as follows: 1 .

ELEE 2110U Discrete Mathematics 40


Example
There are 7 identical bags. In each bag, there are 9 balls, numbered from 1 to 9, inclusive. We randomly pick a ball from
each bag. Determine the probability that the product of the 7 numbers on the 7 balls is a multiple of 3. You do not need to
simplify your answer.

Solution
The product of 7 numbers is not a multiple of 3 if none of them is a multiple of 3. The probability that a number from a bag

is not a multiple of 3 is . Therefore, the probability that the product of 7 numbers is not a multiple of 3 is . We can

then conclude that the probability that the product is a multiple of 3, using the complement law, is 1 .

ELEE 2110U Discrete Mathematics 41


Example
A box contains ten balls, numbered from 2 to 11 inclusive. A ball is drawn at random. Determine the probability that the
drawn ball has an odd number, a prime number, both a prime number and an odd number, a prime number or an odd number
or both, and neither an odd number nor a prime number.

Solution
Let 𝐴 be the event with balls having odd numbers and 𝐵 be the event with balls having prime numbers, we thus have:

5 1
𝐴 3, 5, 7, 9, 11 → 𝑃 𝐴
10 2
5 1
𝐵 2, 3, 5, 7, 11 → 𝑃 𝐵
10 2
4 2
𝐴∩𝐵 3, 5, 7, 11 → 𝑃 𝐴∩𝐵
10 5
6 3
𝐴∪𝐵 2, 3, 5, 7, 9, 11 → 𝑃 𝐴∪𝐵
10 5
4 2
𝐴 ∩𝐵 𝐴∪𝐵 4, 6, 8, 10 → 𝑃 𝐴 ∩𝐵
10 5
ELEE 2110U Discrete Mathematics 42
Example
Suppose for the events 𝐴 and 𝐵, we have 𝑃 𝐴 0.8 and 𝑃 𝐵 0.6. Show that 𝑃 𝐴 ∩ 𝐵 0.4.

Solution
We have:

𝑃 𝐴∪𝐵 𝑃 𝐴 𝑃 𝐵 𝑃 𝐴∩𝐵 1 → 0.8 0.6 𝑃 𝐴∩𝐵 1 → 𝑃 𝐴∩𝐵 0.4

ELEE 2110U Discrete Mathematics 43


Marginal Probability, Joint Probability and Conditional Probability
The probability of the occurrence of a single event, such as 𝑃 𝐴 or 𝑃 𝐵 , which takes a specific value irrespective of the
values of other events, i.e., unconditioned on any other events, is called a marginal probability.

The probability that both events 𝐴 and 𝐵 simultaneously occur is known as the joint probability of events 𝐴 and 𝐵, and is
denoted by 𝑃 𝐴 ∩ 𝐵 or 𝑃 𝐴, 𝐵 , and read as probability of 𝐴 and 𝐵.

If we assume the probability of event 𝐵 is influenced by the outcome of event 𝐴 and we also know that event 𝐴 has
occurred, then the probability that event 𝐵 will occur may be different from 𝑃 𝐵 . The probability of event 𝐵 when it is
known that event 𝐴 has occurred is defined as the conditional probability, denoted by 𝑃 𝐵|𝐴 and read as probability of 𝐵
given 𝐴. The conditional probability 𝑃 𝐵|𝐴 captures the information that the occurrence of event 𝐴 provides about event 𝐵.
The conditional probability 𝑃 𝐵|𝐴 and the conditional probability 𝑃 𝐴|𝐵 are, respectively, defined as follows:

𝑃 𝐴∩𝐵
𝑃 𝐵|𝐴 𝑃 𝐴 0
𝑃 𝐴
𝑃 𝐴∩𝐵
𝑃 𝐴|𝐵 𝑃 𝐵 0
𝑃 𝐵

ELEE 2110U Discrete Mathematics 44


Statistically Independent Events and Mutually Exclusive Events
If the occurrence of event 𝐴 has no statistical impact on the occurrence of event 𝐵, we then say events 𝐴 and 𝐵 are
statistically independent. If the knowledge of event 𝐴 does not change the probability of the occurrence of event 𝐵, then we
have 𝑃 𝐵|𝐴 𝑃 𝐵 . If the knowledge of event 𝐵 does not change the probability of the occurrence of event 𝐴, then we
have 𝑃 𝐴|𝐵 𝑃 𝐴 . These events are then said to be statistically independent.

If the joint probability of events 𝐴 and 𝐵 is zero, i.e., 𝑃 𝐴 ∩ 𝐵 0, these two events are then said to be mutually exclusive
or disjoint.

𝐒𝐭𝐚𝐭𝐢𝐬𝐭𝐢𝐜𝐚𝐥𝐥𝐲 𝐢𝐧𝐝𝐞𝐩𝐞𝐧𝐝𝐞𝐧𝐭 𝐞𝐯𝐞𝐧𝐭𝐬 ⟺ 𝑷 𝑨 ∩ 𝑩 𝑷 𝑨 𝑷 𝑩 ⟺ 𝑷 𝑨∪𝑩 𝑷 𝑨 𝑷 𝑩 𝑷 𝑨 𝑷 𝑩


𝐌𝐮𝐭𝐮𝐚𝐥𝐥𝐲 𝐞𝐱𝐜𝐥𝐮𝐬𝐢𝐯𝐞 𝐞𝐯𝐞𝐧𝐭𝐬 ⟺ 𝑷 𝑨∩𝑩 𝟎 ⟺ 𝑷 𝑨∪𝑩 𝑷 𝑨 𝑷 𝑩

ELEE 2110U Discrete Mathematics 45


Example
Determine the conditional probability that a family with two children has two girls, given they have at least one girl. Assume
the probability of having a girl is the same as the probability of having a boy.

Solution
The four possibilities 𝐺𝐺, 𝐺𝐵, 𝐵𝐺, and 𝐵𝐵, each reflecting the order of birth, are equally likely, where 𝐺 represents a girl
and 𝐵 represents a boy. Let 𝐴 be the event that a family with two children has two girls, and let 𝐶 be the event that a family
with two children has at least one girl. We therefore have the following events and probabilities:
1
𝐴 𝐺𝐺 → 𝑃 𝐴
4
3
𝐶 𝐺𝐺, 𝐺𝐵, 𝐵𝐺 → 𝑃 𝐶
4
1
𝐴∩𝐶 𝐺𝐺 → 𝑃 𝐴∩𝐶
4
We can thus conclude:
1
𝑃 𝐴∩𝐶 4 1
𝑃 𝐴|𝐶
𝑃 𝐶 3 3
4

ELEE 2110U Discrete Mathematics 46


Example
There are 10,000 smart phones in a warehouse, out of which 10 are defective. Two phones are selected at random and tested
one by one. Determine the probability that both phones are defective.

Solution
Let 𝐴 denote the event that the first phone tested is defective, we therefore have:

10 1
𝑃 𝐴
10000 1000

Let 𝐵 denote the event that the second phone tested is defective. Therefore, the event 𝐵|𝐴 represents that the second phone
tested is also defective, and we have:
9 1
𝑃 𝐵|𝐴
9999 1111
We can thus obtain:

1 1
𝑃 𝐴∩𝐵 𝑃 𝐵|𝐴 𝑃 𝐴 ≅ 0.9 10
1111 1000

ELEE 2110U Discrete Mathematics 47


Example (1)
A box contains ten balls, numbered from 11 to 20 inclusive. A ball is drawn from the box at random. We define the
following five distinct events:
𝐴: Number on ball drawn is an odd number
𝐵: Number on ball drawn is a prime number
𝐶: Number on ball drawn is an even number
𝐷: Number on ball drawn is a multiple of 5
𝐸: Number on ball drawn is a multiple of 25

For each of the following four cases, determine if the two events are mutually exclusive and also if they are statistically
independent: the events 𝐴 and 𝐵, the events 𝐴 and 𝐶, the events 𝐴 and 𝐷, and the events 𝐴 and 𝐸. Comment on the results.

Solution
5
𝐴 11, 13, 15, 17, 19 → 𝑃 𝐴
10
4
𝐵 11, 13, 17, 19 → 𝑃 𝐵
10
5
𝐶 12, 14, 16, 18, 20 → 𝑃 𝐶
10
2
𝐷 15, 20 → 𝑃 𝐷
10
𝐸 ∅ → 𝑃 𝐸 0
ELEE 2110U Discrete Mathematics 48
Example (2)
We then identify the four joint events of interest and their corresponding probabilities:

4
𝐴∩𝐵 11, 13, 17, 19 → 𝑃 𝐴∩𝐵
10
𝐴∩𝐶 ∅ → 𝑃 𝐴∩𝐶 0
1
𝐴∩𝐷 15 → 𝑃 𝐴∩𝐷
10
𝐴∩𝐸 ∅ → 𝑃 𝐴∩𝐸 0

The results can then be summarized as follows:

Events Statistically Independent? Mutually Exclusive?


𝐴&𝐵 𝑃 𝐴∩𝐵 𝑃 𝐴 𝑃 𝐵 → No 𝑃 𝐴∩𝐵 0 → No
𝐴&𝐶 𝑃 𝐴∩𝐶 𝑃 𝐴 𝑃 𝐶 → No 𝑃 𝐴∩𝐶 0 → Yes
𝐴&𝐷 𝑃 𝐴∩𝐷 𝑃 𝐴 𝑃 𝐷 → Yes 𝑃 𝐴∩𝐷 0 → No
𝐴&𝐸 𝑃 𝐴∩𝐸 𝑃 𝐴 𝑃 𝐸 → Yes 𝑃 𝐴∩𝐸 0 → Yes

We can thus conclude that any two events, no matter how they are defined, always fall into one of these four distinct cases,
i.e., whether being statistically independent or not as well as whether being mutually exclusive or not.

ELEE 2110U Discrete Mathematics 49


Partition of Sample Space into Disjoint Sets
𝑆 𝐴

𝐵 … …

𝐵A 𝐵

𝐵
𝐵
𝐵
𝐵
𝐵 𝐵

In order to determine the probability of event 𝐴, it is sometimes best to separate all possible causes leading to event 𝐴. If the
events 𝐵 , 𝐵 , … , 𝐵 are all mutually exclusive events whose union forms the entire sample space 𝑆, that is we have 𝑆
𝐵 ∪ 𝐵 ∪ ⋯ ∪ 𝐵 , we then refer to these sets as a partition of 𝑆.

ELEE 2110U Discrete Mathematics 50


Law of Total Probability
If the events 𝐵 , 𝐵 , … , 𝐵 are all mutually exclusive events, we then have:

𝑷 𝑨 𝑷 𝑨 ∩ 𝑩𝟏 𝑷 𝑨 ∩ 𝑩𝟐 ⋯ 𝑷 𝑨 ∩ 𝑩𝒏 𝑷 𝑨|𝑩𝟏 𝑷 𝑩𝟏 𝑷 𝑨|𝑩𝟐 𝑷 𝑩𝟐 ⋯ 𝑷 𝑨|𝑩𝒏 𝑷 𝑩𝒏

This divide-and-conquer approach is a practical tool used to determine the probability of event 𝐴. This is simply due to the
fact that the probability of event 𝐴 can be expressed as a combination of the probabilities of the mutually exclusive events
𝐵 , 𝐵 , … , 𝐵 that form the partition of the sample space 𝑆. The law of total probability thus highlights the probabilities of
effects given causes when causes do not deterministically select effects.

ELEE 2110U Discrete Mathematics 51


Example
Assuming the following information regarding the incidence of rabies in an ecosystem is available, determine the probability that rabies will
appear within the population of animals.
Animals Percent of population Probability of infection
Rabbits 30 0.1
Foxes 10 0.4
Wolves 20 0.2
Raccoons 20 0.6
Skunks 10 0.5
Coyotes 10 0.3
Solution
Let event 𝐴 denote the population of animals with rabies, event 𝐵 denote the population of rabbits, event 𝐵 denote the population of foxes,
event 𝐵 denote the population of wolves, event 𝐵 denote the population of raccoons, event 𝐵 denote the population of skunks, and event
𝐵 denote the population of coyotes. Noting that we have the following probabilities:

𝑃 𝐵 0.3, 𝑃 𝐵 0.1, 𝑃 𝐵 0.2, 𝑃 𝐵 0.2, 𝑃 𝐵 0.1, 𝑃 𝐵 0.1

𝑃 𝐴|𝐵 0.1, 𝑃 𝐴|𝐵 0.4, 𝑃 𝐴|𝐵 0.2, 𝑃 𝐴|𝐵 0.6, 𝑃 𝐴|𝐵 0.5, 𝑃 𝐴|𝐵 0.3
the probability of interest is then as follows:

𝑃 𝐴 0.3 0.1 0.1 0.4 0.2 0.2 0.2 0.6 0.1 0.5 0.1 0.3 0.31
ELEE 2110U Discrete Mathematics 52
Bayes’ Theorem
When one conditional probability is given, but the reversed conditional probability is required, the following relation, known
as Bayes’ theorem or Bayes’ rule, which is based on the law of total probability, can be used:

𝑷 𝑨 ∩ 𝑩𝟏 𝑷 𝑨|𝑩𝟏 𝑷 𝑩𝟏
𝑷 𝑩𝟏 |𝑨
𝑷 𝑨 𝑷 𝑨|𝑩𝟏 𝑷 𝑩𝟏 𝑷 𝑨|𝑩𝟐 𝑷 𝑩𝟐 ⋯ 𝑷 𝑨|𝑩𝒏 𝑷 𝑩𝒏

where the events 𝐵 , 𝐵 , … , 𝐵 are all mutually exclusive events whose union makes the entire sample space 𝑆. Bayes’
theorem highlights inference from an observed effect, and is used to estimate probabilities based on partial evidence. It can
be used to synthesize decision rules that attempt to determine the most probable cause in light of an observation. In short, the
law of total probability is about effects from causes and Bayes’ theorem is about causes from effects.

ELEE 2110U Discrete Mathematics 53


Example
There are three boxes. The first box contains four brown balls and two white balls, the second box contains eleven brown
balls and eleven white balls, and the third box contains five brown balls and fifteen white balls. The probability of selecting
any one box is one third. If a ball selected at random from one of the boxes is white, determine the probability that it was
drawn from the first box. Do simplify your answer and round it to two decimal places.

There are three boxes 𝐴 , 𝐴 , and 𝐴 , and the probabilities of selecting them are as follows: 𝑃 𝐴 𝑃 𝐴 𝑃 𝐴 .

Let 𝑊 represent the event that the ball is white. We thus have:

1 1 3
𝑃 𝑊|𝐴 , 𝑃 𝑊𝐴 , 𝑃 𝑊|𝐴
3 2 4

Using Bayes’ rule, the probability of interest is then as follows:

1 1
𝑃 𝑊|𝐴 𝑃 𝐴 𝑃 𝑊|𝐴 𝑃 𝐴 3 3 4
𝑃 𝐴 |𝑊 ≅ 21%
𝑃 𝑊 𝑃 𝑊|𝐴 𝑃 𝐴 𝑃 𝑊|𝐴 𝑃 𝐴 𝑃 𝑊|𝐴 𝑃 𝐴 1 1 1 1 3 1 19
3 3 2 3 4 3
ELEE 2110U Discrete Mathematics 54
Bayesian Spam Filtering
• Spam e-mails, also known as junk e-mails, are unwanted, irrelevant e-mails sent on the Internet to a large number of recipients, and
may contain disguised links, malware, and fraudulent messages. Bayesian spam filtering a popular spam-filtering technique that relies
on word probabilities and can tailor itself to the e-mail needs of individual users.
• Let 𝑆 be the event that the e-mail is spam and 𝑆 be the event that the e-mail is not spam. If we use 𝑘 words, say 𝑋 , 𝑋 , … , 𝑋 , we can
then increase significantly the probability of detecting spam correctly. Assuming that 𝑊 , 𝑊 , … , 𝑊 are the events that the e-mail
contains the words 𝑋 , 𝑋 , … , 𝑋 , the number of incoming spam e-mails is about the same as the number of incoming e-mails that are
not spam, and the events 𝑊 |𝑆, 𝑊 |𝑆, … , 𝑊 |𝑆 are independent, by using Bayes’ theorem, 𝑝 the probability that an e-mail containing
all the words 𝑋 , 𝑋 , … , 𝑋 is spam is thus as follows:

𝑃 𝑊 |𝑆 ⋯ 𝑃 𝑊 |𝑆
𝑝 𝑃 𝑆 𝑊 ∩ 𝑊 ∩ ⋯∩ 𝑊
𝑃 𝑊 |𝑆 ⋯ 𝑃 𝑊 |𝑆 𝑃 𝑊 |𝑆 ⋯ 𝑃 𝑊 |𝑆

𝑎 𝑋 ⋯ 𝑎 𝑋
𝑎 𝑋 ⋯ 𝑎 𝑋 𝑏 𝑋 ⋯ 𝑏 𝑋

ELEE 2110U Discrete Mathematics 55


Example
Suppose a Bayesian spam filter is trained on a set of 10,000 spam e-mails and 5,000 e-mails that are not spam. The word
“information” appears in 1,500 spam e-mails and 20 e-mails that are not spam, the word “account” appears in 800 spam e-
mails and 200 e-mails that are not spam, and the word “time” appears in 200 spam e-mails and 500 e-mails that are not
spam. Estimate the probability that a received e-mail containing all three words of “information”, “account”, and “time” is
spam. Will the e-mail be rejected as spam if the threshold for rejecting spam is set at 0.9?

Solution
Assuming 𝑋 , 𝑋 , and 𝑋 refer to the words “information”, “account, and “time”, respectively, we have the following
probabilities:
1500 20
𝑎 𝑋 0.15 & 𝑏 𝑋 0.004
10000 5000
800 200
𝑎 𝑋 0.08 & 𝑏 𝑋 0.04
10000 5000
200 500
𝑎 𝑋 0.02 & 𝑏 𝑋 0.1
10000 5000
We can thus obtain:
0.15 0.08 0.02
𝑝 0.9375
0.15 0.08 0.02 0.004 0.04 0.1

As 𝑝 0.9, an incoming e-mail containing all these three words will be rejected.

ELEE 2110U Discrete Mathematics 56


Monte Carlo Algorithm
• Algorithms that make random choices at one or more steps are called probabilistic algorithms. A particular class of probabilistic
algorithms is Monte Carlo algorithms. Monte Carlo algorithms always produce answers to decision problems, but a small probability
remains that these answers may be incorrect. A Monte Carlo algorithm uses a sequence of tests and the probability that the algorithm
answers the decision problem correctly increases as more tests are carried out.
• Suppose there are 𝑛 ≫ 0 items in a batch and the probability that an item is defective is 𝑝 when random testing is done. To decide all
items are good, 𝑛 tests are required to guarantee that none of the items are defective. However, a Monte Carlo algorithm can determine
whether all items are good as long as some probability of error is acceptable.
• A Monte Carlo algorithm proceeds by successively selecting items at random and testing them one by one, where the maximum number
of items being tested is a pre-determined 𝑘 ≪ 𝑛. When a defective item is encountered, the algorithm stops to indicate that out of the 𝑛
items in a batch, there is at least one defective. If a tested item is good, the algorithm goes on to the next item. If after testing 𝑘 items, no
defective item is found, the algorithm concludes all 𝑛 items are good, but with a modest probability of error that is independent of 𝑛.
• Assuming the events of testing different items are independent, the probability of finding not even a defective one, which does not
depend on 𝑛, is as follows:
𝒌
𝟏 𝒑

ELEE 2110U Discrete Mathematics 57


Example
Suppose there are 1,000,000 cell-phones in a factory, where the probability that a cell-phone is in a perfect condition is
0.99. Based on the Monte Carlo algorithm, determine the minimum number of cell-phones which needs to be tested so the
probability of finding not even a defective cell-phone among those tested is less than one in a million.

Solution
Probability of finding not even a defective one is 1 𝑝 , which does not depend on 𝑛. We need to find 𝑘, which is the
number of cell-phones tested, where every one of the 𝑘 cell-phones tested is good, we thus need to have

1 𝑝 0.99 10 → log 0.99 log 10 → 𝑘 log 0.99 6 → 𝑘 1375

This probability is independent of 1,000,000, the total number of cell-phones in the factory. The MC algorithm saves a lot of
testing 1,000,000 1,375 998,625 . We can thus conclude that when more than 1375 tested cell-phones are all good,
where the probability of such an occurrence is less than one in a million, we could say the entire batch of 1,000,000 cell-
phones, even those not tested, is good, of course with some probability of error.

ELEE 2110U Discrete Mathematics 58


ELEE 2110U Discrete Mathematics 1
Trees

ELEE 2110U Discrete Mathematics 2


Basic Definitions (1)
A tree is defined as a connected undirected graph with no simple circuits.
As a tree does not contain multiple loops or edges, any tree is a simple graph. A tree has a simple path between any two of
its vertices.
A trivial tree is a graph consisting of a single vertex.
A graph is called a forest if and only if it is circuit free and not connected. All trees are assumed to be finite, i.e., they have a
finite number of vertices. A tree with 𝑛 vertices has exactly 𝑛 1 edges and a connected graph with 𝑛 vertices and 𝑛 1
edges is a tree.

ELEE 2110U Discrete Mathematics 3


Example
Determine if the graphs shown below are trees.
𝑎 𝑎

Solution
Graph 𝑎 is connected with no simple circuits, 𝑏 𝑐 𝑏 𝑐

it is thus is a tree.
𝑑 𝑒 𝑓 𝑔 𝑑 𝑒 𝑓 𝑔
Graph 𝑏 is circuit free, but is not connected,
ℎ ℎ
𝑎 𝑏
it is thus not a tree.
𝑎 𝑎
Graph 𝑐 is connected, but has a simple circuit,
it is thus not a tree.
𝑏 𝑐 𝑏 𝑐
Graph 𝑑 is not connected, and has a simple circuit,
it is thus not a tree. 𝑑 𝑒 𝑓 𝑔 𝑑 𝑒 𝑓 𝑔

ℎ ℎ
𝑐 𝑑

ELEE 2110U Discrete Mathematics 4


Basic Definitions (2)
A rooted tree is a tree in which one vertex has been designated as the root and every edge is implicitly directed away from
the root. The level or depth of a vertex in a rooted tree is the number of edges in the unique path, i.e. the length of the path,
from the root to the vertex. The height of a rooted tree is the maximum level or depth of its vertices. A tree with exactly one
vertex (the root) has height zero. In summary, height is a feature of a tree and level is a feature of an individual vertex.

A child of a vertex 𝑣 in a rooted tree is a vertex that is the immediate successor of 𝑣 on a path away from the root. The
parent of a vertex 𝑣 in a rooted tree is a vertex that is the immediate predecessor of 𝑣 on the path to 𝑣 away from the root.
Two distinct vertices that are both children of the same parent are called siblings. Given two distinct vertices 𝑣 and 𝑤, if 𝑣
lies on the unique path between 𝑤 and the root, then 𝑣 is an ancestor of 𝑤 and 𝑤 is a descendant of 𝑣. A vertex of a rooted
tree is called a leaf if it has no children. Vertices that have children are called internal vertices.

ELEE 2110U Discrete Mathematics 5


Basic Definitions (3)
A subtree is a subgraph of the tree consisting of a vertex and its descendants and all edges incident to these descendants, i.e.,
a subtree is a subgraph of a tree that is also a tree. A rooted tree in which the vertices at each level are ordered as the first,
second, third, and so on is called an ordered rooted tree, that is. The term rooted tree generally implies ordered rooted tree.
A rooted tree in which every node has at most 𝑚 children is called an 𝒎-ary tree. An 𝑚-ary tree of height ℎ is balanced if
its leaves lie at level ℎ 1 or ℎ, that is, if its leaves lie on adjacent levels. There are at most 𝑚 leaves in an 𝑚-ary tree of
height h.
An 𝑚-ary tree with 𝑚 2 is called a binary tree. Binary trees are often used to store information in a computer. The height
of the tree determines how quickly information can be retrieved.
A tree is called a full 𝒎-ary tree if every internal vertex has exactly 𝑚 children. A full 𝑚-ary tree with 𝑖 internal vertices
contains 𝑣 𝑚𝑖 1 vertices, 𝑒 𝑣 1 edges, and 𝑙 𝑚 1 𝑣 1 /𝑚 leaves.
In an ordered binary tree, the children are denoted as the left child and the right child. The convention is to regard the left
child as the first child (the elder child) and the right child as the second child (the younger child). The subtree at a left child
𝑢 is the left subtree rooted at 𝑢, and the subtree rooted at a right child 𝑣 is the right subtree rooted at 𝑣.

ELEE 2110U Discrete Mathematics 6


Example
Identify, through some examples, the relevant tree terminology for the tree shown below.
𝑎

Solution
𝑏 𝑐
The vertex 𝑎 is the root of the tree and the height of the tree is 4. The vertices 𝑏, 𝑐 each
has a level or depth of 1, the vertices ℎ, 𝑖, 𝑗 each has a level or depth of 3. The vertex 𝑑 𝑑 𝑒 𝑓 𝑔

is a child to the vertex 𝑏, is a sibling to the vertex 𝑒, and is a parent to the left child ℎ and ℎ 𝑖 𝑗

the right child 𝑖. The vertex 𝑏 is an ancestor of the vertex ℎ and the vertex ℎ is a
𝑘 𝑙 𝑚 𝑛
descendant of the vertex 𝑏. The vertices 𝑏, 𝑑, ℎ, 𝑔, 𝑗 are called internal vertices.
The vertices 𝑒, 𝑖, 𝑘, 𝑙, 𝑓, 𝑚, 𝑛 are called leaves. The tree is a binary tree, but not a full one. The
vertices 𝑎, 𝑏, 𝑑, ℎ, 𝑐, 𝑗 each has two children, but the vertex 𝑔 has only one child. The left
subtree rooted at the vertex 𝑎 consists of the vertices 𝑏, 𝑑, 𝑒, ℎ, 𝑖, 𝑘, 𝑙 and the right subtree
rooted at the vertex 𝑐 consists of the vertices 𝑐, 𝑔, 𝑗, 𝑚, 𝑛 . The subtree at the vertex 𝑑 is a
balanced subtree, but the subtree at the vertex 𝑐 is not a balanced subtree.

ELEE 2110U Discrete Mathematics 7


Spanning Trees
• A spanning tree of a graph 𝐺 is a subgraph of 𝐺 that is a tree and contains every vertex of 𝐺. Any two spanning trees for a
graph have the same number of edges. Spanning trees are useful in visiting the vertices of a graph. Every connected
simple graph has a spanning tree with a path between any two vertices.

ELEE 2110U Discrete Mathematics 8


Example
Shows all spanning trees for a graph with four
vertices that are all connected to one another
(a graph of a square with its two diagonals drawn).

Solution

ELEE 2110U Discrete Mathematics 9


Depth-First Search (DFS) Algorithm
An outline of the recursive depth-first search (DFS) algorithm, also known as the backtracking algorithm, consists of the
following steps:
1) Choose a vertex of the graph as the root.
2) Form a path starting at this vertex by successively adding vertices and edges, where each new edge is incident with the
last vertex in the path and a vertex not already visited.
3) Continue the process by adding vertices and edges to the path.
4) Check if the path goes through all vertices:
 If it does, then the tree consisting of this path is a spanning tree.
 If it does not, then more vertices and edges must be added by moving back to the next to last vertex in the path to
form a new path starting at this vertex passing through vertices not already visited, if not, move back another vertex
in the path, and try again. Repeat this procedure until all vertices have been visited.
In summary, each stage of the DFS traversal seeks to move to an unvisited neighbor of the most recently visited vertex, and
backtracks only if there is none available.

ELEE 2110U Discrete Mathematics 10


Breadth-First Search (BFS) Algorithm
An outline of the breadth-first search (BFS) algorithm consists of the following steps:
1) Choose a vertex of the graph as the root, and mark it as visited.
2) Visit all unvisited vertices adjacent to this vertex, the new vertices added at this stage become the vertices at level 1.
3) Visit all unvisited vertices adjacent to each of them, this in turn produces the vertices at level 2.
4) Follow the same procedure until all the vertices in the tree have been visited.

In summary, after the BFS traversal visits a vertex, all of the previously unvisited neighbors of that vertex go to the queue,
and then the transversal removes from the queue whatever vertex is at the front of the queue, and visits that vertex.

ELEE 2110U Discrete Mathematics 11


Example (1)
Find a spanning tree for the graph shown in Fig. a, using the following algorithms:
(a) DFS algorithm.
(b) BFS algorithm.
𝑏
𝑎 𝑐

𝑒
𝑑 𝑓

𝑔 𝑖

(a)

ELEE 2110U Discrete Mathematics 12


Example (2)
(a) The steps of the DFS algorithm, as shown in Fig. 19.5b, are as (b) The steps of the BFS algorithm, as shown in Fig. 19.5c, are as
follows: follows:
1) Out of all vertices, we choose 𝑎 to start the process. 1) Out of all vertices, we choose 𝑎 to start the process.
2) Out of the vertices adjacent to 𝑎 (i.e., 𝑏 and 𝑑), neither has 2) Out of the vertices adjacent to 𝑎 (i.e., 𝑏 and 𝑑), we must
been visited yet, we choose 𝑏. visit them both, we first choose 𝑏.
3) Out of the vertices adjacent to 𝑏 (i.e., 𝑎, 𝑐 and 𝑓), 𝑎 has 3) Out of the vertices adjacent to 𝑎 (i.e., 𝑏 and 𝑑), 𝑏 has
been visited, we choose 𝑐. been visited, we must then choose 𝑑.
4) Out of the vertices adjacent to 𝑐 (i.e., 𝑏 and 𝑓), 𝑏 has been 4) Out of the vertices adjacent to 𝑏 (i.e., 𝑎, 𝑐, and 𝑓), 𝑎 has
visited, we must then choose 𝑓. been visited, we must visit 𝑐 and 𝑓, we choose 𝑐.
5) Out of the vertices adjacent to 𝑓 (i.e., 𝑏, 𝑐, 𝑒, and 𝑖), 𝑏 and 𝑐 5) Out of the vertices adjacent to 𝑏 (i.e., 𝑎, 𝑐, and 𝑓), 𝑎 and
have been visited, we choose 𝑒. 𝑐 have been visited, we must then choose 𝑓.
6) Out of the vertices adjacent to 𝑒 (i.e., 𝑑, 𝑓, and ℎ), 𝑓 has 6) Out of the vertices adjacent to 𝑑 (i.e., 𝑎, 𝑒, 𝑔, and ℎ), 𝑎
been visited, we choose 𝑑. has been visited, we must visit 𝑒, 𝑔 and ℎ, we choose 𝑒.
7) Out of the vertices adjacent to 𝑑 (i.e., 𝑎, 𝑒, 𝑔, and ℎ), 𝑎 and 7) Out of the vertices adjacent to 𝑑 (i.e., 𝑎, 𝑒, 𝑔, and ℎ), 𝑎
𝑒 have been visited, we choose 𝑔. and 𝑒 have been visited, we must visit 𝑔 and ℎ, we
8) Out of the vertices adjacent to 𝑔 (i.e., 𝑑 and ℎ), 𝑑 has been choose 𝑔.
visited, we must then choose ℎ. 8) Out of the vertices adjacent to 𝑑 (i.e., 𝑎, 𝑒, 𝑔, and ℎ), 𝑎,
9) We then back track to 𝑓, out of the vertices adjacent to 𝑓 𝑒 and, 𝑔 have been visited, we must then choose ℎ.
(i.e., 𝑏, 𝑐, 𝑒, and 𝑖), 𝑖 has not been visited, we must then 9) Out of the vertices adjacent to 𝑓 (i.e., 𝑏, 𝑐, 𝑒, and 𝑖), 𝑖
choose 𝑖. has not been visited, we must then choose 𝑖.
ELEE 2110U Discrete Mathematics 13
Example (3)
𝑎 𝑎 𝑎 𝑐
𝑏 𝑏

1 2 3

𝑎 𝑐 𝑎 𝑐 𝑎 𝑐
𝑏 𝑏 𝑏

𝑒
𝑓 𝑒 𝑓 𝑑 𝑓

4 5 6

𝑎 𝑐 𝑎 𝑐 𝑎 𝑐
𝑏 𝑏 𝑏

𝑒 𝑒 𝑒
𝑑 𝑓 𝑑 𝑓 𝑑 𝑓

𝑔 𝑔 ℎ 𝑔 ℎ 𝑖
7 8 9
(b)
ELEE 2110U Discrete Mathematics 14
Example (4)
𝑎 𝑎 𝑎
𝑏 𝑏

1 2 3

𝑎 𝑐 𝑎 𝑐 𝑎 𝑐
𝑏 𝑏 𝑏

𝑑 𝑑 𝑓 𝑑 𝑒 𝑓

4 5 6

𝑎 𝑐 𝑎 𝑐 𝑎 𝑐
𝑏 𝑏 𝑏

𝑑 𝑒 𝑓 𝑑 𝑒 𝑓 𝑑 𝑒 𝑓

𝑔 𝑔 ℎ 𝑔 ℎ 𝑖
7 8 9

ELEE 2110U Discrete Mathematics


(c) 15
Minimum Spanning Trees
A minimum spanning tree in a connected weighted graph is a spanning tree for which the sum of weights of its edges is the
least compared to all other spanning trees for the graph. This problem arises in a wide range of important applications, such
as designing physical systems where the system components are geographically dispersed or distanced. Some specific
applications may include i) construction of a wired/pipeline/road network connecting a significant number of places to
reduce the total cost, ii) construction of a digital computer system composing of high-frequency circuitry to reduce delay
effects, and iii) design of a backbone network of high-capacity links to support high-throughput low-delay Internet traffic.

We now discuss two algorithms, Prim’s algorithm and Kruskal’s algorithm, to construct a minimum spanning tree in a
connected graph, where each adds an edge with the smallest weight to the current configuration based on only local
information, nonetheless they both guarantee to produce a minimum spanning tree. These two algorithms employ a greedy
algorithm to make an optimal choice at each step, nevertheless, they produce optimal solutions. Note that a connected
weighted graph may have more than one minimal spanning tree. Nonetheless they all weigh the same.

ELEE 2110U Discrete Mathematics 16


Prim’s Algorithm & Kruskal’s Algorithm
An outline of Prim’s algorithm consists of the following steps:
1) Pick a vertex.
2) Choose an edge with the least weight connected to the selected vertex.
3) Add successively to the tree edges of minimum weight that are incident to a vertex already in the tree, while avoiding to
make a simple circuit with the edges already in the tree.
4) Repeat step (iii) until 𝑛 1 edges have been added, where 𝑛 is the number of vertices in the graph.
An outline of Kruskal’s algorithm consists of the following steps:
1) Arrange the edges in nondecreasing order of weights.
2) Choose an edge with the least weight.
3) Add an edge of the least weight, while avoiding to make a simple circuit with the edges already in the tree.
4) Repeat step (iii) until 𝑛 1 edges have been added, where 𝑛 is the number of vertices in the graph.
Note that in Prim’s algorithm, edges become eligible for inclusion in the tree gradually, whereas in Kruskal’s algorithm, the
eligible edges are known from the start.

ELEE 2110U Discrete Mathematics 17


Example
𝑐 8 𝑑
Find a minimum spanning tree for the graph shown in Fig. a, 4 4
using the following algorithms:
𝑎 6 10 𝑓
12
(a) Prim’s algorithm.
6 12
(b) Kruskal’s algorithm.
𝑏 a 𝑒
𝑐 8 𝑑

Solution 4 4

There are two minimum spanning trees as shown in Fig. b and Fig. c. 𝑎 10 𝑓

(a) Starting at vertex 𝑎, edges are added in one of the following two orders: 6

i. 𝑎, 𝑐 , 𝑎, 𝑏 , 𝑐, 𝑑 , 𝑑, 𝑓 , 𝑑, 𝑒 . 𝑏 (b) 𝑒
𝑐 8 𝑑
ii. 𝑎, 𝑐 , 𝑏, 𝑐 , 𝑐, 𝑑 , 𝑑, 𝑓 , 𝑑, 𝑒 .
4 4
(b) Edges are added in one of the following two orders:
𝑎 6 10 𝑓
i. 𝑑, 𝑓 , 𝑎, 𝑐 , 𝑎, 𝑏 , 𝑐, 𝑑 , 𝑑, 𝑒 .
ii. 𝑑, 𝑓 , 𝑎, 𝑐 , 𝑏, 𝑐 , 𝑐, 𝑑 , 𝑑, 𝑒 .
𝑏 (c) 𝑒

ELEE 2110U Discrete Mathematics 18


W
Best of Seven Series E

W E
W
E
Championship W
E

W E W E
W E W E
E W E W
W E
W E
W E W E
W E W E
E E W W
W W E E
W E W E
E E W W
E W E W
W E W E
E W E W
There are 35 different There are 35 different
W E
W ways in the ways in the E
W left branch to win the right branch to win the E
E W
W E championship championship W E
E W when the Western team when the Eastern team E W
W W wins the first game wins the first game E E
W E W E
E E W W
W W E E
E W
E W
E E W W
W W E E
W E W E
E W E W
W W E E
E E W W
E E W W
W W E E
E W E W
E E W W

E W
Magic Square Example

𝟗 𝟗

8 𝟗

𝟗 𝟗 8

8 7 𝟗

𝟗 𝟗 8

𝟕 8 7

𝟔 𝟖 1 3 𝟖 4 𝟑 𝟕 𝟓 𝟔 𝟕 𝟐

2 4 𝟗 5 1 𝟗 𝟒 𝟐 𝟗 𝟏 𝟓 𝟗

𝟕 3 5 𝟕 6 2 𝟖 𝟔 𝟏 𝟖 𝟑 𝟒
Huffman Coding: Background
In order to reduce the storage requirements in digital systems as well as the transmission time requirements in digital
networks, data must be coded so fewer bits are used to represent a data symbol. For efficient coding, i.e., effective data
compression, data symbols that occur more frequently should be encoded using shorter bit sequences and longer bit
sequences should be used to encode rarely occurring data symbols. Therefore, data symbols are encoded using varying
number of bits. When the statistics regarding data symbols are available, the Huffman code is the optimum algorithm. The
Huffman code is a prefix-free (instantaneous) code, where no codeword is a prefix of another codeword, as such a Huffman
code can be represented using a rooted binary tree. It is important to note that Huffman code is widely used in compression
of image files.

ELEE 2110U Discrete Mathematics 21


Huffman Coding: Algorithm
The Huffman coding algorithm begins with a forest of trees each consisting of a single vertex, where each vertex shows a
data symbol and its probability of occurrence. It is very important to put the vertices in the order of increasing probabilities,
that is, the first vertex indicates the least likely symbol and the last vertex reflects the most likely symbol. At each step, we
combine two trees with the least total probability into a single tree by introducing a new root and placing the tree with larger
weight as one of its subtrees and the tree with smaller weight as the other subtree. Moreover, the sum of the two probabilities
associated with the two subtrees is assigned as the total probability of the tree. If necessary, reorder the probabilities of trees,
including the newly formed one, so they are still in increasing order. There are many ways to come up with a Huffman code
for a given set of data symbols and their probabilities of occurrences. However, they will all have the same average number
of bits per symbol for a given set of data symbols.

ELEE 2110U Discrete Mathematics 22


𝟏. 𝟎𝟎

Example
𝟎. 𝟎𝟐 𝟎. 𝟎𝟑 𝟎. 𝟎𝟓 𝟎. 𝟏𝟎 𝟎. 𝟏𝟓 𝟎. 𝟐𝟓 𝟎. 𝟒𝟎
𝟏
𝑨 𝑩 𝑪 𝑫 𝑬 𝑭 𝑮 𝟎 𝟏

𝟎. 𝟎𝟓 𝟎. 𝟎𝟓 𝟎. 𝟏𝟎 𝟎. 𝟏𝟓 𝟎. 𝟐𝟓 𝟎. 𝟒𝟎 𝑮
𝟎. 𝟒𝟎 𝟎. 𝟔𝟎 𝟎 𝟏
𝑪 𝑫 𝑬 𝑭 𝑮
𝟐 𝟎 𝟏 𝑮
𝟎 𝟏 𝑭
𝟎 𝟏
𝑨 𝑩
𝑭 𝟕
𝟎 𝟏 𝑬
𝟎 𝟏
𝟎. 𝟏𝟎 𝟎. 𝟏𝟎 𝟎. 𝟏𝟓 𝟎. 𝟐𝟓 𝟎. 𝟒𝟎
𝑪
𝑫 𝑬 𝑭 𝑮 𝑬
𝟎 𝟏 𝟔 𝟎 𝟏
𝟎 𝟏
𝑫

𝟑 𝟎. 𝟐𝟓 𝟎. 𝟑𝟓 𝟎. 𝟒𝟎
𝑪 𝑫
𝟎 𝟏 𝟎 𝟏 𝑪
𝑭 𝑮 𝟎 𝟏
𝟎 𝟏
𝑨 𝑩 𝑪
𝟎 𝟏 𝑨 𝑩
𝑬
𝟎. 𝟏𝟓 𝟎. 𝟐𝟎 𝟎. 𝟐𝟓 𝟎. 𝟒𝟎 𝟎 𝟏
𝑨 𝑩
𝑬 𝑭 𝑮 𝟓
𝟎 𝟏 𝑫
𝟎 𝟏
𝟎. 𝟎𝟐 𝟎. 𝟎𝟑 𝟎. 𝟎𝟓 𝟎. 𝟏𝟎 𝟎. 𝟏𝟓 𝟎. 𝟐𝟓 𝟎. 𝟒𝟎
𝑫 𝟖
𝟎 𝟏
𝟒 𝟎 𝟏
𝑪 𝑨 𝑩 𝑪 𝑫 𝑬 𝑭 𝑮
𝟎𝟎𝟎𝟎𝟎𝟎 𝟎𝟎𝟎𝟎𝟎𝟏 𝟎𝟎𝟎𝟎𝟏 𝟎𝟎𝟎𝟏 𝟎𝟎𝟏 𝟎𝟏 𝟏

𝟎 𝟏 𝑪
𝑨 𝑩
0.02 6 0.03 6 0.05 5 0.1 4 0.15 3 0.25
𝑨 𝑩 2 0.40 1 2.3 bits/symbol
ELEE 2110U Discrete Mathematics 1
Induction

ELEE 2110U Discrete Mathematics 2


Deductive Reasoning
• Deductive reasoning refers to the process of concluding that something must be true because it is a specific case of a
general principle that is already known to be true.
• Deductive reasoning is the process of reasoning from premises to reach a logically certain conclusion, it is logically valid
and it is the fundamental method in which mathematical facts are shown to be true.
• In a deductive argument, the premises are intended to provide such a strong support for the conclusion that, if the
premises are true, then it would be impossible for the conclusion to be false.
• Example: A general principle in plane geometry states that the sum of the angles in any triangle is 180 degrees, then one
can conclude that the sum of the angles in an isosceles right triangle is also 180 degrees.
• Example: The colonial powers over a couple of centuries systematically colonized countries and oppressed their people,
then one can conclude that the British government, as it was a major colonial power, also colonized countries and
oppressed people in a systematic manner.
• In summary, deductive reasoning requires one to start with a few general ideas, called premises, and apply them to a
specific situation.

ELEE 2110U Discrete Mathematics 3


Inductive Reasoning
• Inductive reasoning is the process of reasoning that a general principle is true because the special cases are true.
Inductive reasoning makes broad generalizations from specific observations. Inductive reasoning is a process of
reasoning in which the premises are viewed as supplying some evidence for the truth of the conclusion.
• Example: If all the people one has ever met from a particular country have been racist, one might then conclude all the
citizens of that country are racist. Inductive reasoning is not logically valid. Just because all the people one happens to
have met from a country were racist is no guarantee at all that all the people from that country are racist. Therefore, this
form of reasoning has no part in a mathematical proof.
• Even if all of the premises are true in a statement, inductive reasoning allows for the conclusion to be false.
• Example: My neighbor is a grandfather. My neighbor is bald. Therefore, all grandfathers are bald. The conclusion does
not follow logically from the statements.
• In summary, inductive reasoning uses a set of specific observations to reach an overarching conclusion. Therefore, a few
particular premises create a pattern that gives way to a broad idea that is possibly true.

ELEE 2110U Discrete Mathematics 4


Deductive Reasoning vs Deductive Reasoning
• Deductive reasoning, which is top-down logic, contrasts with inductive reasoning, which is bottom-up logic. While the
conclusion of a deductive argument is certain, based on the facts provided, the truth of the conclusion of an inductive
argument may be probable, based upon the evidence given.
• Inductive reasoning is part of the discovery process whereby the observation of special cases leads one to suspect very
strongly (though not know with absolute logical certainty) that some general principle is true.
• Deductive reasoning, on the other hand, is the method you would use to demonstrate with logical certainty that the
principle is true.
• Inductive reasoning is used to formulate hypothesis and theories, and deductive reasoning is employed when applying
them to specific situations.
• The difference between the two kinds of reasoning lies in the relationship between the premises and the conclusion. If the
truth of the premises definitely establishes the truth of the conclusion (due to definition, logical structure, or mathematical
necessity), then it is deductive reasoning. If the truth of the premises does not definitely establish the truth of the
conclusion, but nonetheless provides a reason to believe the conclusion may be true, then the argument is inductive.

ELEE 2110U Discrete Mathematics 5


Idea behind Mathematical Induction
• The idea behind mathematical induction is in showing how each statement follows from the previous one – all that
remains is to kick off this logical chain reaction from some starting point.
• Informal metaphors of mathematical induction may include:
 Step-by-step climbing an infinite ladder that is every rung of the ladder could be reached after reaching the first rung
 The sequential falling of an infinite row of dominoes meaning every single domino could knock over after the first
domino falls backward

ELEE 2110U Discrete Mathematics 6


Mathematica Induction
• Induction is a very powerful method of proof.
• A multitude of mathematical claims can be validated using this technique.
• Induction is not a tool for discovering true claims or deriving correct formulas.
• Induction can be effectively used to prove a conjecture once it has been made (and is true), while not providing insights
as to why it is true.
• Induction deals with families of statements that are generally indexed by the natural numbers (positive integers).
• Mathematical induction is a technique for proving statements of the form ∀𝑛𝑃 𝑛 , where 𝑃 𝑛 is a propositional function
and the domain is generally the set of positive integers.
• There exists a very wide set of applications of the mathematical induction, such as summation and product formulas,
inequalities, divisibility, regions in plane geometry, set identities, complexity of algorithms, theorems about graphs and
trees, and correctness of computer programs and algorithms.

ELEE 2110U Discrete Mathematics 7


Mathematical Induction Statement
• Let 𝑃 𝑛 be a propositional function, where 𝑛 is a positive integer, that is, 𝑛 ∈ 𝑵. A proof by mathematical induction
consists of two steps.
• First, the basis step, where we show 𝑃 1 , called basis premise, is true.
• Second, the inductive step, where we show that if 𝑃 𝑘 , called the inductive hypothesis, is true for an arbitrary integer
𝑘 1, then 𝑃 𝑘 1 is also true.
• The principle of mathematical induction states that by proving these two key steps we can conclude that the predicate
𝑃 𝑛 is true for every positive integer 𝑛 ∈ 𝑵.
• Expressing as a rule of inference, while assuming the domain is the set of positive integers 𝑵, the principle of
mathematical induction can be stated as follows:

𝑃 1 ∧ ∀𝑘 𝑃 𝑘 → 𝑃 𝑘 1 → ∀𝑛𝑃 𝑛 .

ELEE 2110U Discrete Mathematics 8


Why Mathematical Induction Works
• In mathematical induction, we first show that 𝑃 1 is true, and then show that if 𝑃 𝑘 is true, then 𝑃 𝑘 1 is true,
where 𝑘 1. Therefore, we know that 𝑃 2 is true, because 𝑃 1 is true. Moreover, we know 𝑃 3 is true, because 𝑃 2
is true. Continuing along these lines, we see that 𝑃 𝑛 is true for every integer 𝑛 1.
• In a way, the principle of mathematical induction contains a technique based on a chain of deductive reasoning that
infinitely many steps 𝑛 → ∞ are true in just two steps.
• Some mistakenly believe that a proof by mathematical induction is a fallacy known as a case of circular reasoning, in that
what is assumed is what needs to be proven!
• The confusion stems from misinterpreting the inductive step for the conclusion. The inductive step involves showing that
the implication 𝑃 𝑘 → 𝑃 𝑘 1 is a tautology.
• In other words, “if it is assumed” that 𝑃 𝑘 is true for a particular but arbitrarily chosen 𝑘 1, then 𝑃 𝑘 1 is also
true, whereas the conclusion is that 𝑃 𝑛 is true for every integer 𝑛 1.

ELEE 2110U Discrete Mathematics 9


There Is No Substitute for Mathematical Induction
• It is important to note that in order to prove a mathematical statement, verifying it for a number of different values of
positive integer 𝑛 does not form a formal proof, because there may exist a particular value of 𝑛, for which the statement
may not be true. In short, a proof for some values of 𝑛 is not a proof for all values of 𝑛.
• To prove formally that a mathematical statement is true, we must show that it is true for all values of 𝑛 greater than the
initial value. However, it is impossible to verify it for every single value of 𝑛, as there are infinitely many values.
• Example: In order to prove the function 𝑛 𝑛 41, introduced by Euler, produces only prime numbers, it is not good
enough to verify it for a few values of 𝑛. Simply because for any positive integer 𝑛 41, the function does produce a
prime number, but for 𝑛 41, it does not produce a prime number.

ELEE 2110U Discrete Mathematics 10


Basis and Inductive Steps: Essential
• The basis and inductive steps are both essential in the principle of mathematical induction as the validity of each step is
necessary, but not sufficient, to guarantee the proposition is true.
• Example: Consider the summation formula 2 2𝑛, for every positive integer 𝑛. We can easily verify the basis step, as
2 2 1 is true. However, we cannot show the inductive step to be true, because if we have 2 2𝑘 for an integer
𝑘 1, we then have 2 2 𝑘 1 .
• Example: Consider the summation formula 1 3 5 ... 2𝑛 1 𝑛 1, for every positive integer 𝑛. The
inductive step is true, simply because if we assume we have 1 3 5 ... 2𝑘 1 𝑘 1 for an integer 𝑘 1,
we can then have 1 3 5 ... 2𝑘 1 2𝑘 1 𝑘 1 2𝑘 1 𝑘 1 1 for an integer 𝑘 1.
However, the summation formula does not hold for any positive integer, as we cannot show the basis step to be true,
simply because for 𝑘 1, we have 1 1 1.

ELEE 2110U Discrete Mathematics 11


Example
Prove the following summation formula, known as arithmetic progression, for every integer 𝑛 1:

𝑛 𝑛 1
1 2 3 ⋯ 𝑛
2
Solution
Let 𝑃 𝑛 be the propositional function of interest that must be proven to be true for every integer 𝑛 1.
Basis step: When 𝑛 1, we have 1 , therefore 𝑃 1 is true.
Inductive step: Assuming the inductive hypothesis
𝑘 𝑘 1
𝑃 𝑘 1 2 ⋯ 𝑘
2
is true, for an arbitrary integer 𝑘 1, we must show
𝑘 1 𝑘 2
𝑃 𝑘 1 1 2 ⋯ 𝑘 𝑘 1
2
is true. If we add 𝑘 1 to both sides of the equation representing 𝑃 𝑘 , then we have

𝑘 𝑘 1 𝑘 1 𝑘 2
1 2 ⋯ 𝑘 𝑘 1 𝑘 1 .
2 2

This thus means that the statement 𝑃 𝑘 1 also holds true, as was to be shown.

ELEE 2110U Discrete Mathematics 12


Example
Prove the following summation formula, known as geometric progression, for every integer 𝑛 1:

𝑟 1
1 𝑟 𝑟 ⋯ 𝑟 , 𝑟 1
𝑟 1
Solution
Let 𝑃 𝑛 be the propositional function of interest that must be proven to be true for every integer 𝑛 1.
Basis step: When 𝑛 1, we have 1 , therefore 𝑃 1 is true.
Inductive step: Assuming the inductive hypothesis
𝑟 1
𝑃 𝑘 1 𝑟 𝑟 ... 𝑟
𝑟 1
is true, for an arbitrary integer 𝑘 1, we must show
𝑟 1
𝑃 𝑘 1 1 𝑟 𝑟 ... 𝑟 𝑟
𝑟 1
is true. If we add 𝑟 to both sides of the equation representing 𝑃 𝑘 , then we have

𝑟 1 𝑟 1
1 𝑟 𝑟 … 𝑟 𝑟 𝑟 .
𝑟 1 𝑟 1

This thus means that the statement 𝑃 𝑘 1 also holds true, as was to be shown.
ELEE 2110U Discrete Mathematics 13
Example
Using mathematical induction, prove the following inequality for every integer 𝑛 1:

1 𝑥 1 𝑛𝑥, for every real number 𝑥 1.

Solution
Let 𝑃 𝑛 be the propositional function of interest that must be proven to be true for every integer 𝑛 1.
Basis step: When 𝑛 1, we have 1 𝑥 1 𝑥, therefore 𝑃 1 is true.
Inductive step: Assuming the inductive hypothesis
1 𝑥 1 𝑘𝑥

is true, that is 𝑃 𝑘 is true, for an arbitrary integer 𝑘 1, we must show

1 𝑥 1 𝑘 1 𝑥

is true, that is, 𝑃 𝑘 1 is true. Using the assumption that 𝑃 𝑘 is true, we multiply both sides of the inequality in 𝑃 𝑘 by
1 𝑥 , we thus obtain

1 𝑥 1 𝑥 1 𝑘𝑥 1 𝑘 1 𝑥 𝑘𝑥 1 𝑘 1 𝑥

as 𝑘𝑥 0. This thus means that the statement 𝑃 𝑘 1 also holds true, as was to be shown.
ELEE 2110U Discrete Mathematics 14
Example
Using mathematical induction, prove the following inequality for every integer 𝑛 1:

2 𝑛.

Solution
Let 𝑃 𝑛 be the propositional function of interest that must be proven to be true for every integer 𝑛 1.
Basis step: When 𝑛 1, we have 2 1, therefore 𝑃 1 is true.
Inductive step: Assuming the inductive hypothesis
2 𝑘

is true, that is 𝑃 𝑘 is true, for an arbitrary integer 𝑘 1, we must show

2 𝑘 1

is true, that is, 𝑃 𝑘 1 is true. Using the assumption that 𝑃 𝑘 is true, we multiply both sides of the inequality in 𝑃 𝑘 by
2, we thus obtain

2 2 2 𝑘 → 2 2𝑘 𝑘 1

as 𝑘 1. This thus means that the statement 𝑃 𝑘 1 also holds true, as was to be shown.
ELEE 2110U Discrete Mathematics 15
Example
Using mathematical induction, prove the following divisibility case for every integer 𝑛 0:

𝑛 2𝑛 𝑛 2𝑛 is divisible by 12
Solution
Let 𝑃 𝑛 be the propositional function of interest that must be proven to be true for every integer 𝑛 0.
Basis step: When 𝑛 0, the value of the function is 0 which is divisible by 12, therefore 𝑃 0 is true.
Inductive step: Assuming the inductive hypothesis
𝑘 2𝑘 𝑘 2𝑘 12𝑚
is true for a nonnegative integer 𝑚, that is, 𝑃 𝑘 is true for an arbitrary integer 𝑘 0, we must then show
𝑘 1 2 𝑘 1 𝑘 1 2 𝑘 1 12𝑡
is true for a nonnegative integer 𝑡, that is, 𝑃 𝑘 1 is true. Using the assumption that 𝑃 𝑘 is true, we have
𝑘 1 2 𝑘 1 𝑘 1 2 𝑘 1 𝑘 6𝑘 11𝑘 6𝑘 𝑘 2𝑘 𝑘 2𝑘 12𝑘 4𝑘 4𝑘
12𝑚 12𝑘 4 𝑘 1 𝑘 𝑘 1 12𝑡,
as 𝑘 1, 𝑘, and 𝑘 1 are three consecutive integers, their product is thus a multiple of 3, and as a result, 4 𝑘 1 𝑘 𝑘 1 is also a
multiple of 12. This thus means that the statement 𝑃 𝑘 1 also holds true, as was to be shown.

ELEE 2110U Discrete Mathematics 16


Example
Using mathematical induction, prove the following divisibility case for every integer 𝑛 0:

7 2 is divisible by 5.
Solution
Basis step: When 𝑛 0, the value of the function is 0, which is divisible by 5, therefore 𝑃 0 is true.
Inductive step: Assuming the inductive hypothesis
7 2 5𝑚
is true for a nonnegative integer 𝑚, that is, 𝑃 𝑘 is true for an arbitrary integer 𝑘 0, we must show
7 2 5𝑡
is true for a nonnegative integer 𝑡, that is, 𝑃 𝑘 1 is true. Using the assumption that 𝑃 𝑘 is true, we have

7 2 7 7 2 7 5𝑚 2 2 2 35𝑚 5 2 5 7𝑚 2 5𝑡.
This thus means that the statement 𝑃 𝑘 1 also holds true, as was to be shown.

ELEE 2110U Discrete Mathematics 17


Example
Using mathematical induction, prove the following product formula for every integer 𝑛 2:
1 1 1 𝑛 1
1 1 ⋯ 1 .
𝑚 2 𝑛 2𝑛
Solution
Let 𝑃 𝑛 be the propositional function of interest that must be proven to be true for every integer 𝑛 2.
Basis step: When 𝑛 2, we have 1 , therefore, 𝑃 2 is true.
Inductive step: Assuming the inductive hypothesis
1 𝑘 1
1
𝑚 2𝑘
is true, that is 𝑃 𝑘 is true, for an arbitrary integer 𝑘 2, we must show
1 𝑘 1 1
1
𝑚 2 𝑘 1
is true, that is, 𝑃 𝑘 1 is true. Using the assumption that 𝑃 𝑘 is true, we multiply both sides of the equality in 𝑃 𝑘 by 1 , we
thus obtain
1 1 1 𝑘 1 1 𝑘 1 1
1 1 1 → 1 .
𝑘 1 𝑚 𝑘 1 2𝑘 𝑚 2 𝑘 1

This thus means that the statement 𝑃 𝑘 1 also holds true, as was to be shown.

ELEE 2110U Discrete Mathematics 18


Example (1)
Using mathematical induction, prove the binomial theorem, for every integer 𝑛 0, where 𝑥 and 𝑦 are variables and is 𝑛 choose 𝑖:

𝑛
𝑥 𝑦 𝑥𝑦 .
𝑖
Solution
Let 𝑃 𝑛 be the propositional function of interest that must be proven to be true for every integer 𝑛 0.
Basis step: When 𝑛 0, both sides of the formula are equal to 1, therefore 𝑃 0 is true.
Inductive step: If we assume the inductive hypothesis

𝑘
𝑥 𝑦 𝑥𝑦
𝑖
is true, we must then show

𝑘 1
𝑥 𝑦 𝑥𝑦
𝑖
is true.
ELEE 2110U Discrete Mathematics 19
Example (2)
We have

𝑘 𝑘 𝑘
𝑥 𝑦 𝑥 𝑦 𝑥 𝑦 𝑥 𝑦 𝑥𝑦 𝑥 𝑦 𝑥𝑦
𝑖 𝑖 𝑖
As we take out the last term, i.e., 𝑥 , from the first sum and the first term, i.e., 𝑦 , from the second sum, we obtain

𝑘 𝑘
𝑥 𝑦 𝑥 𝑥 𝑦 𝑥𝑦 𝑦
𝑖 𝑖
We now make a change of variable in the first sum, as we set 𝑖 𝑖 1, we therefore have

𝑘 𝑘 𝑘 𝑘
𝑥 𝑦 𝑥 𝑥𝑦 𝑥𝑦 𝑦 𝑥 𝑥𝑦 𝑦
𝑖 1 𝑖 𝑖 1 𝑖

𝑘 1 𝑘 1
𝑥 𝑥𝑦 𝑦 𝑥𝑦
𝑖 𝑖
This thus means that the statement 𝑃 𝑘 1 also holds true, as it was to be shown.
ELEE 2110U Discrete Mathematics 20
Strong Induction
When the truth of 𝑃 𝑘 might not be enough to establish the truth of 𝑃 𝑘 1 , we need to use strong induction. Let 𝑃 𝑛 be
a propositional function, where 𝑛 is a positive integer. A proof by strong induction consists of two steps.
First, the basis step, where we show 𝑃 1 , called basis premise, is true.
Second, the inductive step, where we show that for all positive integers 𝑘 1, if 𝑃 1 , 𝑃 2 , …, 𝑃 𝑘 1 , 𝑃 𝑘 , called the
inductive hypothesis, are all true, then 𝑃 𝑘 1 is also true. The principle of strong induction states that by proving these
two key steps we can conclude that 𝑃 𝑛 is true for every positive integer 𝑛 1.
Expressing as a rule of inference, while assuming the domain is the set of positive integers 𝑵, the second principle of
mathematical induction can be stated as follows:

𝑃 1 ∧ ∀𝑘 𝑃 1 ∧𝑃 2 ∧... ∧𝑃 𝑘 1 ∧𝑃 𝑘 →𝑃 𝑘 1 → ∀𝑛𝑃 𝑛

ELEE 2110U Discrete Mathematics 21


Example
Using strong induction, show that for every integer 𝑛 2, then either 𝑛 is a prime or 𝑛 can be written as the product of
prime numbers, in other words, 𝑛 is divisible by a prime number.

Solution
Let 𝑃 𝑛 be the proposition that 𝑛 can be written as the product of primes or 𝑛 is divisible by a prime number, for every
integer 𝑛 2.
Basis step: 𝑃 2 is true, as 2 is a prime number.
Inductive step: Assuming 𝑃 𝑗 is true for all integers 𝑗 with 2 𝑗 𝑘, we need to prove 𝑃 𝑘 1 is true. There are
two mutually exclusive cases, namely when 𝑘 1 is prime and when 𝑘 1 is composite (not prime):
i) If 𝑘 1 is prime, then 𝑃 𝑘 1 is true.
ii) If 𝑘 1) is composite, then 𝑘 1 𝑎 𝑏, where 𝑎 and 𝑏 are integers with 2 𝑎 𝑏 𝑘 1. Using the
inductive hypothesis, both 𝑎 and 𝑏 can be written as product of primes. Thus, 𝑘 1 can be written as the product of those
primes in factorization of 𝑎 and those in the factorization of 𝑏.

ELEE 2110U Discrete Mathematics 22


Example
Suppose 𝑆 0 0, 𝑆 1 4, and 𝑆 𝑛 6𝑆 𝑛 1 5𝑆 𝑛 2 . Using strong induction, show that for every integer 𝑛
0, 𝑆 𝑛 5 1.

Solution
Let 𝑆 𝑛 be the propositional function of interest that must be proven to be true for every integer 𝑛 0.
Basis step: 𝑆 0 and 𝑆 1 are both true, as we have 5 1 0 and 5 1 4.
Inductive step: Assuming 𝑆 𝑗 is true for all integers 𝑗 with 0 𝑗 𝑘, thus implying 𝑆 𝑘 and 𝑆 𝑘 1 are true, we then
need to prove
𝑆 𝑘 1 5 1
is true. We have
𝑆 𝑘 1 6𝑆 𝑘 5𝑆 𝑘 1 6 5 1 5 5 1 5 1.

This thus means that the statement 𝑆 𝑘 1 also holds true, as was to be shown.

ELEE 2110U Discrete Mathematics 23


Recursion

ELEE 2110U Discrete Mathematics 24


Recursion: Definition, Solutions & Applications
• Recursion is the process of defining a problem or the solution to a problem in terms of a simpler version of itself.
• Recursion is a powerful problem-solving technique extensively used in computer science as such many programming
languages support it. The application of recursion is where an entity being defined is applied within its own definition.
• Examples may include a function (e.g. a factorial function), a set (e.g., the power set of a set), a tree, (e.g., a full binary
tree), a sequence, (e.g., a geometric progression), and an algorithm, (e.g., a sorting algorithm).
• There exist various methods for solving recurrence relations, namely, by iteration, characteristic equations, and
generating functions.

ELEE 2110U Discrete Mathematics 25


Sequences
A sequence with its discrete structure presents an ordered list of terms, where repetitions are allowed.
A function 𝑓 whose domain is a subset of the set of consecutive positive or nonnegative integers is called a sequence. A
sequence is a function whose domain is either all the integers between two given integers or all the integers greater than or
equal to a given integer.
The function 𝑓 𝑛 , denoted by 𝑎 and called a term of the sequence, is the image of the integer 𝑛 0. The integer 𝑛 of the
term 𝑎 is called an index. The 𝑛 term is the general term of a sequence and it is often used to define a sequence. Note
that the notation 𝑎 describes the sequence. For instance, the list of terms of the sequence 𝑎 , where 𝑎 𝑛 , namely
𝑎 , 𝑎 , 𝑎 , 𝑎 , …, starts with 1, 4, 9, 16, … corresponding to 𝑛 1, 2, 3, 4, …. Hence, the sequence is 1, 4, 9, 16, … .
The first term of the sequence is called the initial term. A sequence is finite if its domain is finite; otherwise, it is infinite.
Note that a finite sequence of 𝑛 terms is also called a string or an n-tuple, and its last term is known as the final term and the
length of a string is the number of terms in the string. For instance, the set of two-digit integers that are positive represents a
finite sequence of 90 terms, where 10 is its initial term and 99 is its final term, and the set of prime numbers represents an
infinite sequence, where the initial term is 2 and there is no final term as there are infinitely many prime numbers.

ELEE 2110U Discrete Mathematics 26


Recursively Defined Functions
• A recursively defined function 𝑓 𝑛 refers to itself and its domain is a subset of the set of positive or nonnegative
integers. In order for the definition not to be circular, the function definition must have the following two properties:
 Basis clause: A finite number of initial values of the function 𝑓 𝑛 , known as the initial conditions, are specified,
for which the function does not refer to itself. Thus, 𝑓 𝑏 , 𝑓 𝑏 1 ,…,𝑓 𝑏 𝑘 1 , where integers 𝑘 1 and 𝑏
0, are given.
 Recursive clause: The function 𝑓 𝑛 is defined in terms of the 𝑘 preceding functional values 𝑓 𝑛 1 ,𝑓 𝑛
2 ,…,𝑓 𝑛 𝑘 , with 𝑘 𝑛, as the function refers to itself. An equation expressing a term of a sequence as a
function of prior terms in the sequence is known as a recurrence relation.
• Recursively defined functions are well defined, as the value of the function at every integer in the domain is determined
in an unambiguous way. A solution of a recurrence relation is called a sequence and a given recurrence relation may be
satisfied by many different sequences. Once the initial conditions are included, there is then only one sequence satisfying
the recurrence relation of interest.
• Any recurrence relation for a sequence can be written in terms of their differences and the resulting equation involving its
differences is called a difference equation.
ELEE 2110U Discrete Mathematics 27
Examples
Define recursively the following functions, and then for each function find 𝑓 4 :
(a) The compound amount with annually compounded interest.
(b) The number of fist bumps in a group when each person fist bumps with everyone else only once.

Solution
(a) The compound amount 𝑓 is defined by 𝑓 𝑛 compound amount at the end of the 𝑛 1 year interest earned
during the 𝑛 year with an annual interest rate of 𝑖 , where 𝑓 0 𝑝, known as the principal. Therefore, 𝑓 can be defined
respectively as follows:
𝑓 0 𝑝 (initial condition)
𝑓 𝑛 𝑓 𝑛 1 𝑖 𝑓 𝑛 1 1 𝑖 𝑓 𝑛 1 , 𝑛 1 (recurrence relation)
𝑓 4 1 𝑖 𝑓 3 1 𝑖 1 𝑖 𝑓 2 1 𝑖 𝑓 2 1 𝑖 1 𝑖 𝑓 1
1 𝑖 𝑓 1 1 𝑖 1 𝑖 𝑓 0 𝑝 1 𝑖 .

(b) With one person in the group, the number of fist bumps is obviously zero. With 𝑛 persons in the group, one of them fist
bumps with each of the remaining 𝑛 1 persons resulting in 𝑛 1 fist bumps and the number of fist bumps made by the
other 𝑛 1 persons among themselves is 𝑓 𝑛 1 . Therefore, 𝑓 can be defined respectively as follows:

𝑓 1 0 (initial condition)
𝑓 𝑛 𝑓 𝑛 1 𝑛 1 , 𝑛 2 (recurrence relation)
𝑓 4 𝑓 3 3 𝑓 2 2 3 𝑓 1 1 2 3 6.
ELEE 2110U Discrete Mathematics 28
Recursive Algorithm vs Iterative Algorithm
• A recursive algorithm is an algorithm that invokes itself during execution with a reduced version of itself, as it proceeds
by reducing a problem to the same problem with smaller input.
• An iterative algorithm is developed to evaluate the value of a function at the base cases, and successively apply the
recursive definition to find values of the function at larger integers.
• Oftentimes, an iterative approach requires less computation than a recursive approach, but writing a software program for
the nonrecursive version of a recursive algorithm is often a difficult and time-consuming task.

ELEE 2110U Discrete Mathematics 29


Example (1)
Consider the Fibonacci sequence as recursively defined by 𝑓 𝑛 𝑓 𝑛 1 𝑓 𝑛 2 , where 𝑓 0 0 and 𝑓 1 1.
Find the number of additions required for 𝑓 6 for each of the following two cases, and comment on the results:
(a) Using a recursive algorithm. (b) Using an iterative algorithm.

Solution
(a) A recursive algorithm is based on a top-down approach. We evaluate the value of 𝑓 6 in terms of the values of the
function at smaller integers, namely 𝑓 5 and 𝑓 4 , and successively apply the recursive definition to find values of the
function at smaller integers. Therefore, we have the following:
𝑓 6 𝑓 5 𝑓 4 𝑓 4 𝑓 3 𝑓 3 𝑓 2 𝑓 3 𝑓 2 𝑓 2 𝑓 1 𝑓 2 𝑓 1 𝑓 1 𝑓 0
𝑓 2 𝑓 1 𝑓 1 𝑓 0 𝑓 1 𝑓 0 𝑓 1 𝑓 1 𝑓 0 𝑓 1 𝑓 1 𝑓 0
𝑓 1 𝑓 0 𝑓 1 𝑓 1 𝑓 0 𝑓 1 𝑓 0 𝑓 1 𝑓 1 𝑓 0 𝑓 1 𝑓 1 𝑓 0 .

We thus need to carry out 12 additions for a recursive algorithm.

ELEE 2110U Discrete Mathematics 30


Examples
Consider the Fibonacci sequence as recursively defined by 𝑓 𝑛 𝑓 𝑛 1 𝑓 𝑛 2 , where 𝑓 0 0 and 𝑓 1 1.
Find the number of additions required for 𝑓 6 for each of the following two cases, and comment on the results:
(a) Using a recursive algorithm. (b) Using an iterative algorithm.

Solution
(b) An iterative algorithm is based on a bottom-up approach. We use the given value of the function at the base cases,
namely 𝑓 0 and 𝑓 1 , and successively apply the recursive definition to find values of the function at larger integers until
𝑓 6 is obtained. Therefore, we have the following relations:
𝑓 2 𝑓 1 𝑓 0 .
𝑓 3 𝑓 2 𝑓 1 .
𝑓 4 𝑓 3 𝑓 2 .
𝑓 5 𝑓 4 𝑓 3 .
𝑓 6 𝑓 5 𝑓 4 .
We thus need to carry out 5 additions for an iterative algorithm.
ELEE 2110U Discrete Mathematics 31
Solving Recurrence Relations by Iteration
A sequence is called a solution of a recursive relation if its terms satisfy the recurrence relation. We often want to know an
explicit formula for a recurrence relation 𝑓 𝑛 or equivalently a sequence 𝑎 , especially when we need to compute terms
with very large 𝑛 or assess general properties of a relation.

The most basic method for finding a closed-form formula for a recursively defined function is iteration. In the iterative
method, we take the approach based on back substitution in order to see a pattern developing, and then guess or discover an
explicit formula. We can then use induction to verify the closed-form formula. Although it is a straightforward method, it can
become algebraically unwieldy if the recurrence relation is too complex.

It is important to highlight that when the iteration is used and substitution followed by simplification are performed
repeatedly, full simplification after a substitution should be in general avoided, so the terms left in expanded form can help
recognize the pattern that develops.

ELEE 2110U Discrete Mathematics 32


Example
Solve the following recurrence relation by iteration:

𝑛 𝑛 1
𝑎 𝑎 , 𝑛 1, 𝑎 0.
2

Solution
Using iteration, we have
𝑛 𝑛 1 𝑛 1 𝑛 𝑛 𝑛 1
𝑎 𝑎 𝑎 ⋯
2 2 2

1 2 𝑛 1 𝑛 𝑛 𝑛 1
𝑎 ⋯
2 2 2

𝑖 𝑖 1 𝑖 𝑖 1 1
𝑎 𝑖 𝑖
2 2 2

1 𝑛 𝑛 1 2𝑛 1 𝑛 𝑛 1 𝑛 𝑛 1 𝑛 2
,𝑛 0.
2 6 2 6

ELEE 2110U Discrete Mathematics 33


Example
In a sports tournament, there are 𝑛 1 teams. Suppose each team plays all other teams (i.e., it is a round-robin tournament
in which each team plays in turn against every other only once). Using iteration, determine the total number of games 𝑎 to
be played in the tournament.
Solution
We have the following specific cases:
𝑘 2 → 𝑎 1.
𝑘 3 → 𝑎 2 1.
𝑘 4 → 𝑎 3 2 1.
𝑘 5 → 𝑎 4 3 2 1.
We can thus conclude
𝑘 𝑛 → 𝑎 𝑛 1 𝑛 2 ⋯ 2 1.
Using the arithmetic progression, we have

𝑛 𝑛 1
𝑎 .
2
ELEE 2110U Discrete Mathematics 34
Solving Recurrence Relations Using Generating Functions
Generating functions are a powerful and efficient tool to solve many types of problems, such as advanced counting,
calculating the probability of discrete random variables, and solving recurrence relations. The solution to a recurrence
relation with its initial conditions can be found when an explicit formula for the associated generating function is determined.
Generating functions can translate the terms of a sequence as coefficients of powers of a variable 𝑧 in a formal power series.
The generating function for the sequence 𝑎 , 𝑎 , 𝑎 . . . of real numbers is the following infinite series:

𝐺 𝑧 ≜𝑎 𝑎 𝑧 𝑎 𝑧 ... 𝑎 𝑧 .

Note that two generating functions can be added and multiplied as follows:

𝐺 𝑧 𝑎 𝑎 𝑧 𝑎 𝑧 ... 𝑎 𝑧 𝐺 𝑧 𝐹 𝑧 𝑎 𝑏 𝑧

𝐹 𝑧 𝑏 𝑏 𝑧 𝑏 𝑧 ... 𝑏 𝑧 𝐹 𝑧 𝐺 𝑧 𝑏𝑎 𝑧

ELEE 2110U Discrete Mathematics 35


Useful Generating Functions

𝑮 𝒛 𝒂𝒏

𝟏 𝟏 if m divides n
𝒛𝒎𝒏
𝟏 𝒛𝒎
𝒏 𝟎 𝟎 otherwise

𝟏 𝒎 𝒏 𝟏 𝒎 𝒏 𝟏
𝒄𝒏 𝒛𝒏 𝒄𝒏
𝟏 𝒄𝒛 𝒎 𝒏 𝒏
𝒏 𝟎

𝒛
𝟐
𝒏𝒛𝒏 n
𝟏 𝒛
𝒏 𝟎

𝒛𝟐 𝒛
𝒏𝟐 𝒛𝒏 𝒏𝟐
𝟏 𝒛 𝟑
𝒏 𝟎

ELEE 2110U Discrete Mathematics 36


Generating Functions
The following highlights shifting a generating function and differentiating a generating function as two important
mathematical operations that can help solve recurrence relations:

𝑧 𝐺 𝑧 𝑎 𝑧 𝑎 𝑧

𝐺 𝑧 𝑛𝑎 𝑧 .

It is imperative to highlight that the goal is to use the generating function and its properties to a recurrence relation in order
to find 𝐺 𝑧 in the form of a single summation, of course after some mathematical manipulation, and then to determine the
sequence 𝑎 by using the definition of the generating function.
It is of utmost importance that after a recurrence relation of any type is solved by using any method, the solution is checked
not only to make sure that it satisfies the recurrence relation, but also it fully meets the given initial conditions.
ELEE 2110U Discrete Mathematics 37
Example (1)
Solve the following recurrence relation using generating functions:

𝑎 𝑎 𝑛, 𝑛 1, 𝑎 1

Solution
We first multiply both sides of the recurrence relation by 𝑧 to obtain

𝑎 𝑧 𝑎 𝑧 𝑛𝑧 .

We then sum both sides of the equation starting with 𝑛 1 to have the following equation:

𝑎 𝑧 𝑎 𝑧 𝑛𝑧 .

We now change the indices and simplify the equation, we thus have

𝑎 𝑧 𝑎 𝑧 𝑎 𝑧 𝑛𝑧

ELEE 2110U Discrete Mathematics 38


Example (2)
Using the definition of 𝐺 𝑧 and its properties highlighted in the table, we then have:

𝑧
𝐺 𝑧 𝑎 𝑧𝐺 𝑧 .
1 𝑧

Noting 𝑎 1, 𝐺 𝑧 can be obtained as follows:

1 𝑧
𝐺 𝑧 .
1 𝑧 1 𝑧

Using the properties highlighted in the table, we write each term in the equation in terms of a summation

𝑛 2
𝐺 𝑧 𝑧 𝑧 𝑧 .
𝑛

We now perform the following mathematical manipulation to obtain 𝐺 𝑧 in terms of a single summation:

ELEE 2110U Discrete Mathematics 39


Example (3)

𝑛 2 𝑛 1 𝑛 2 𝑛 1
𝐺 𝑧 𝑧 𝑧 𝑧 𝑧 𝑧
2 2
𝑛 1 𝑛 𝑛 1 𝑛 𝑛 1 𝑛
1 𝑧 𝑧 1 1 𝑧 1 𝑧
2 2 2
𝑛 2 𝑛 1
𝑧 .
2

Using the definition of the generating function, we thus have

𝑛 2 𝑛 1 𝑛 2 𝑛 1
𝐺 𝑧 𝑎 𝑧 𝑧 → 𝑎 , 𝑛 0.
2 2

ELEE 2110U Discrete Mathematics 40


Graphs

ELEE 2110U Discrete Mathematics 41


Definitions and Terminology (1)
• In fact, graph theory, which was invented by Leonard Euler, is a branch of mathematics concerned with networks of
points connected by lines.
• A graph 𝐺 𝑉, 𝐸 consists of 𝑉, a nonempty finite set of vertices (points or nodes), and 𝐸, a finite set of edges (lines,
links, or arcs), where an edge either joins one vertex to another or joins a vertex to itself. Note that the number of distinct
vertices in the set 𝑉 and the number of distinct edges in the set 𝐸 are represented by |𝑉| and |𝐸|, respectively.
• Geometrically, vertices are shown by small solid circles and edges are represented by curves or straight-line segments.
The number of vertices of a graph is called its order and the number of edges of a graph is called its size.
• Each edge of a graph has one or two vertices associated with it, called its endpoints. An undirected edge is said to
connect its endpoints 𝑢 and 𝑣, and is denoted by 𝑢, 𝑣 . An undirected graph consists of a set of vertices and a set of
undirected edges each of which is associated with a set of one or two vertices. Two vertices 𝑢 and 𝑣 in an undirected
graph are called adjacent (or neighbors) in the graph 𝐺 if 𝑢 and 𝑣 are endpoints of an edge 𝑒 of the graph 𝐺, and an edge
𝑒 is then called incident with the vertices 𝑢 and 𝑣. The set of all neighbors of a vertex is called the neighborhood of the
vertex.

ELEE 2110U Discrete Mathematics 42


Definitions and Terminology (2)
• An edge emanating from and terminating at the same vertex 𝑢 is called a loop, and denoted by 𝑢, 𝑢 . A loop thus has
only one endpoint. It is possible to have more than one loop at a vertex.
• Adjacent edges have a common vertex. Parallel edges (or multiple edges) have the same two vertices.
• A simple graph contains no loops or parallel edges. In a simple graph, each edge is associated to an unordered pair of
vertices. Graphs that may have multiple edges connecting the same vertices are called multigraphs.
• Graphs with loops and multiple edges may be called pseudographs (or general graphs). A simple graph in which each
edge is assigned a positive number, called the weight, is a weighted graph.
• A directed edge (or arc) is associated with an ordered pair of vertices 𝑢, 𝑣 , where it starts at 𝑢 and ends at 𝑣. A directed
edge is depicted by an arc with an arrow from 𝑢, the initial vertex, to 𝑣, the terminal vertex, to indicate the direction of
an edge. The initial vertex and the terminal vertex of a loop are the same.
• A directed graph (or digraph) consists of a nonempty, finite set of vertices and a set of finite directed edges. When a
directed graph has no loops and no multiple directed edges, it is called a simple directed graph. Directed graphs with
multiple directed edges are called directed multigraphs.

ELEE 2110U Discrete Mathematics 43


Degree of a Vertex
• The degree of a vertex 𝑢 in an undirected graph 𝐺, denoted by deg 𝑢 , is the number of edges incident with (meeting at
or ending at) 𝑢.
• The total degree of the graph 𝐺 is the sum of the degrees of all the vertices of 𝐺. Note that for an isolated vertex 𝑢,
deg 𝑢 0, and with a loop at a vertex 𝑢, deg 𝑢 2. A vertex 𝑢 with deg 𝑢 1 is called a pendant vertex (or leaf
vertex).
• The handshaking theorem states that the sum of the degrees of all vertices in an undirected graph is twice the total
number of edges, i.e., 2 𝐸 , which also includes multiple edges and loops.
• In a graph with directed edges, the in-degree of a vertex 𝑣, denoted by deg 𝑣 , is the number of edges with 𝑣 as their
terminal vertex (the number of arcs having 𝑣 as head).
• The out-degree of a vertex 𝑢, denoted by deg 𝑢 , is the number of edges with 𝑢 as their initial vertex (the number of
arcs having 𝑣 as tail).
• Note that the sum of the in-degrees of all vertices and the sum of the out-degrees of all vertices in a graph with directed
edges are equal, and in turn is the same as the number of edges 𝐸 in the graph.

ELEE 2110U Discrete Mathematics 44


Example
Determine the number of vertices, the number of edges, and
the degree of each vertex in the undirected graph shown
below
𝑎 𝑐

𝑏
Solution
There are 5 vertices and 11 edges. The degrees are as
follows: deg 𝑎 4, deg 𝑏 6, deg 𝑐 1, deg 𝑑 5,
𝑒 𝑑
and deg 𝑒 6. Note that according to the handshaking
theorem, the sum of the degrees of all vertices is twice the
number of edges, i.e., 4 6 1 5 6 2 11 22.

ELEE 2110U Discrete Mathematics 45


Example
Determine the number of vertices, the number of
edges, and the in-degree and out-degree of each vertex
in the directed graph shown below.
𝑎
𝑏
Solution
There are 4 vertices and 8 edges. The degrees are as
follows: deg 𝑎 2, deg 𝑎 2, deg 𝑏 3,
𝑑
deg 𝑏 4, deg 𝑐 2, deg 𝑐 1, 𝑐

deg 𝑑 1, and deg 𝑑 1. Note that the sum of


the in-degrees of all vertices and the sum of the out-
degrees of all vertices are equal, and in turn is the
same as the number of edges in the graph, i.e., 2
3 2 1 2 4 1 1 8.

ELEE 2110U Discrete Mathematics 46


Some Real-Life Examples of Graph Models
Graph Model Vertices Edges
1) Telecommunications networks Transceivers Wired/wireless links
2) Drug interactions Medications Interactions
3) Electric circuits Circuit components Wires
4) Family trees in genealogy Family members Parenthood
5) Flowcharts in computer programming Steps to do Flow
6) Food webs in ecology Species Who eats whom
7) Information management Data records Decisions
8) Module dependency in software design Modules Dependency
9) Personnel assignment People/tasks Job capabilities
10) Physical chemistry Atoms Molecular bonds
11) Protein interaction in biology Proteins Interactions
12) Scheduling in operations research Activities Activity conflicts
13) Semantic in linguistics Words Connections among words
14) Set theory Elements Relatedness
15) Shortest path in network optimization Locations Distances
16) Social networks Individuals/organizations Relationships
17) Sport tournaments Teams Who beats whom
18) Supply chain management Supply and demand Supply lines
19) The worldwide web Computers/cellphones Wired/wireless links
20) Transportation networks Intersections Roads
ELEE 2110U Discrete Mathematics 47
Operations on Graphs
• A subgraph of a simple graph 𝐺 𝑉, 𝐸 is a graph 𝐺 𝑉 ,𝐸 where 𝑉 ⊆ 𝑉 and 𝐸 ⊆ 𝐸. In other words, a graph 𝐺
is a subgraph of 𝐺 if and only if every vertex in 𝐺 is also a vertex in 𝐺, every edge in 𝐺 is also in 𝐺, and every edge in
𝐺 has the same endpoints as it has in 𝐺.
• A spanning subgraph of a graph 𝐺 is a subgraph that contains all the vertices of 𝐺.
• The complement or inverse of a simple graph 𝐺 𝑉, 𝐸 is the complementary graph 𝐺 𝑉 ,𝐸 which has the same
vertices as 𝐺 and has edges joining every pair of vertices that are not joined in 𝐺, and vice versa, that is, two distinct
vertices in 𝐺 are adjacent if and only if they are not adjacent in 𝐺.
• The converse of a directed graph 𝐺 𝑉 ,𝐸 is the directed graph 𝐺 𝑉 , 𝐸 , where the set 𝐸 of edges of 𝐺 is
obtained by reversing the direction of each edge in the set 𝐸 of edges of 𝐺 .
• The graph union of two simple graphs 𝐺 𝑉 ,𝐸 and 𝐺 𝑉 , 𝐸 , denoted by 𝐺 ∪ 𝐺 , is the simple graph with the
vertex set 𝑉 ∪ 𝑉 and the edge set 𝐸 ∪ 𝐸 .
• The graph intersection of two simple graphs 𝐺 𝑉 ,𝐸 and 𝐺 𝑉 , 𝐸 , denoted by 𝐺 ∩ 𝐺 , is the simple graph
with the vertex set 𝑉 ∩ 𝑉 and the edge set 𝐸 ∩ 𝐸 .

ELEE 2110U Discrete Mathematics 48


Example
Consider the simple graphs 𝐺 and 𝐻. 𝑎 𝑏 𝑎 𝑏

List all the subgraphs of the graph 𝐺 with two edges and three vertices.
Determine the complement of the graph 𝐺.
Find the graph union of the graphs 𝐺 and 𝐻.
Find the graph intersection of the graphs 𝐺 and 𝐻. 𝑐 𝑑 𝑐 𝑑

G H

Solution

𝑎 𝑎 𝑏 𝑎 𝑏 𝑎 𝑏 𝑎 𝑏 𝑎 𝑏

𝑐 𝑑 𝑐 𝑑 𝑐 𝑑 𝑐
𝑐 𝑑

ELEE 2110U Discrete Mathematics


Types of Graphs (1)
• A complete graph (or mesh topology) is a simple graph with an edge between every two distinct vertices. A complete

graph with 𝑛 vertices, denoted by 𝐾 , has edges and each vertex has degree 𝑛 1.

• A simple graph with at least one pair of distinct vertices not connected by an edge is called a noncomplete graph.
• The cycle graph (or ring topology), denoted by 𝐶 , with 𝑛 3, consists of 𝑛 vertices 𝑣 , 𝑣 , . . . , 𝑣 as well as 𝑛 edges
𝑣 ,𝑣 , 𝑣 ,𝑣 ,..., 𝑣 , 𝑣 , 𝑣 , 𝑣 , while noting that each vertex has degree 2.
• The star graph, denoted by 𝑆 , with 𝑛 3, has 𝑛 1 vertices 𝑣 , 𝑣 , . . . , 𝑣 as well as 𝑛 edges
𝑣 ,𝑣 , 𝑣 ,𝑣 ,..., 𝑣 ,𝑣 , that is, the vertices 𝑣 , 𝑣 , . . . , 𝑣 are all connected to a central vertex 𝑣 with
degree 𝑛, but each of the other 𝑛 vertices has degree 1.
• The wheel graph (or hybrid topology), denoted by 𝑊 , with 𝑛 3, is the union of 𝐶 and 𝑆 graphs, it thus has 𝑛
1 vertices as well as 2𝑛 edges, where each vertex around the perimeter has degree 3, but the central vertex has degree 𝑛.
• The linear graph (or bus topology), denoted by 𝐿 , has 𝑛 vertices 𝑣 , 𝑣 , . . . , 𝑣 and with 𝑛 1 edges
𝑣 ,𝑣 , 𝑣 ,𝑣 ,..., 𝑣 , 𝑣 , while noting that the last two vertices at the two ends of the bus each has degree 1, but
each of the other vertices has degree 2.
ELEE 2110U Discrete Mathematics 50
Types of Graphs (2)
Complete Graphs Cycle Graphs Star Graphs Wheel Graphs Linear Graphs
(Mesh Topology) (Ring Topology) (Star Topology) (Hybrid Topology) (Bus Topology)

ELEE 2110U Discrete Mathematics 51


Bipartite
• If the vertex set 𝑉 of a simple graph 𝐺 𝑉, 𝐸 can be partitioned into two disjoint (mutually exclusive), nonempty subsets
𝑉 and 𝑉 , known as bipartite sets, such that every edge in the graph connects a vertex in 𝑉 and a vertex in 𝑉 , that is, no
edge in the graph 𝐺 connects either two vertices in 𝑉 or two vertices in 𝑉 , then we call the graph 𝐺 the bipartite graph,
and the pair 𝑉 , 𝑉 a bipartition of the vertex set 𝑉 of the graph 𝐺.
• Let 𝐺 be a bipartite graph with 𝑚 vertices in 𝑉 and 𝑛 vertices in 𝑉 . If an edge exists between every vertex in 𝑉 and
every vertex in 𝑉 , the graph 𝐺 is then called a complete bipartite graph, and has 𝑚 𝑛 edges.

ELEE 2110U Discrete Mathematics 52


Example
Determine which of the simple graphs shown in below are bipartite.

Solution
Fig. a is a bipartite graph, as the vertex set 𝑉 𝑎, 𝑏, 𝑐, 𝑑, 𝑒, 𝑓 consists of the two disjoint sets
𝑉 𝑎, 𝑏, 𝑐 and 𝑉 𝑑, 𝑒, 𝑓 , and every edge has one vertex in 𝑉 and the other in 𝑉 . Note
that since there is no edge connecting vertices 𝑎 and 𝑓, Fig. a is not a complete bipartite.
Fig. b is not a bipartite graph, and Fig. c is a complete bipartite graph.

𝑎 𝑏
𝑎 𝑏 𝑐 𝑎 𝑏

𝑑 𝑒 𝑓 𝑐 𝑑 𝑐 𝑑 𝑒

(a) (b) (c)

ELEE 2110U Discrete Mathematics 53


Shortest-Path Problem
• Many problems can be modeled using graphs with weights associated to their edges. In this context, weights may mean
distances, time periods, levels of risk, costs, or any other criterion of interest.
• Noting the weight of a path in a weighted graph is the sum of the weights of the edges along the path, the shortest-path
problem is then about finding the path of minimum weight from one specified vertex to another vertex of interest.
• The minimum weight of interest in a graph may thus be the shortest distance, the most quickly, the least risk, or the
lowest cost.
• The applications of such problems are numerous, such as routing of phone calls and the Internet packets in
telecommunication networks, transport and storage of raw materials and distribution of finished goods across a country,
and air travel in the national/global aviation transportation system.
• There are several algorithms that find a shortest path between any two vertices in a weighted graph. One such algorithm
is known as a brute-force approach by which every path between the two vertices of interest is examined. However,
when there exists a large number of edges in the graph, such an approach is extremely impractical and seemingly
impossible.

ELEE 2110U Discrete Mathematics 54


Dijkstra’s Algorithm (1)
• Our focus here is on Dijkstra’s algorithm, which solves the shortest-path problem in undirected weighted graphs with
positive weights along the edges. However, it is easy to adapt it to solve the shortest-path problem in directed weighted
graphs.
• Note that the correctness of Dijkstra’s algorithm can be shown by mathematical induction. This algorithm allows to find
the length of the shortest path from the starting vertex to all other vertices, and not just to the ending vertex.
• Dijkstra’s algorithm is a greedy algorithm, it thus seeks to find the global optimum (i.e., the shortest path) by making
locally optimal choices (edges with minimum weights) at each stage of the algorithm. Dijkstra’s algorithm uses 𝑂 𝑛
operations (additions and comparisons) to find the length of a shortest path between two vertices in a connected, simple,
undirected, weighted graph with 𝑛 vertices.

ELEE 2110U Discrete Mathematics 55


Dijkstra’s Algorithm (2)
• We assume the starting vertex is 𝑎 and the ending vertex is 𝑧, and the goal is to find the shortest path between 𝑎 and 𝑧 in
the graph 𝐺.
• The algorithm works outward from the vertex 𝑎, adding vertices and edges one by one to construct a tree 𝑇.
• The algorithm is based on an iterative procedure and a labeling is carried out at each iteration. At each iteration, the only
vertices in 𝐺 that are candidates to join 𝑇 are those that are adjacent to at least one vertex of 𝑇.
• Each vertex 𝑢 of 𝐺 is given a label 𝐿 𝑢 , which indicates the best estimate of the length of the shortest path from 𝑎 to 𝑢.
Initially, we label 𝑎 with zero, denoted by 𝐿 𝑎 0, and all other vertices, such as 𝑢, with ∞, denoted by 𝐿 𝑢 ∞, a
number greater than the sum of the weights of all the edges of 𝐺.
• After each iteration, the values of 𝐿 𝑢 are changed and eventually becoming the actual lengths of the shortest paths from
𝑎 to 𝑢. Therefore, when the iteration procedure terminates, 𝐿 𝑧 is the length of the shortest path from 𝑎 to 𝑧.

ELEE 2110U Discrete Mathematics 56


Dijkstra’s Algorithm (3)
• We maintain two sets of vertices, one set, denoted by 𝑉, contains vertices already visited and included in the tree 𝑇, the other set,
denoted by 𝑋, contains vertices either not yet visited or already visited, in either case, they are not included in the tree 𝑇.
• Initially, 𝑉 includes the vertex 𝑎 and 𝑋 includes all other vertices in the graph. Note that the only vertices from 𝑋 that are candidates to
join 𝑉, the so-called candidate vertices, are those that are adjacent to at least one vertex in 𝑉.
• Of the candidate vertices, the one that is chosen to be added to 𝑉 is the one for which the length of the shortest path to it from 𝑎 is a
minimum among all the candidate vertices.
• Each time a vertex is added to 𝑉, it is removed from the set of candidate vertices and the vertices adjacent to it are added to the set of
candidate vertices if they are not already in the set of candidate vertices or in the set 𝑉.

ELEE 2110U Discrete Mathematics 57


Dijkstra’s Algorithm (4)
• Assuming the vertex 𝑣 is the most recently vertex added to 𝑉, the only candidate vertices for which a shorter path from 𝑎 might be
found are those that are adjacent to 𝑣.
• The reason lies in the fact that the length of the path from 𝑎 to 𝑣 was a minimum among all the paths from 𝑎 to vertices in what was then
the candidate vertices. To this effect, after each addition of a vertex 𝑣 to 𝑉, each candidate vertex 𝑢 adjacent to 𝑣 is examined.
• Noting that 𝑤 𝑢, 𝑣 is the weight of the edge connecting 𝑢 and 𝑣, the current value of 𝐿 𝑢 and the value of 𝐿 𝑣 𝑤 𝑢, 𝑣 are
compared. If 𝐿 𝑣 𝑤 𝑢, 𝑣 𝐿 𝑢 , then 𝐿 𝑢 is changed to 𝐿 𝑣 𝑤 𝑢, 𝑣 .
• After finding a vertex among the candidate vertices, which has the smallest label, the vertex is added to the set 𝑉.
• This procedure is iterated by successively adding vertices to the set 𝑉 until 𝑧 is added. When 𝑧 is added, its label, 𝐿 𝑧 , is then the length
of the shortest path.

ELEE 2110U Discrete Mathematics 58


Example (1)
Use Dijkstra’s algorithm to find the length of the shortest path between the vertices 𝑎 and ℎ in the weighted graph shown in
below.

𝑏 10 𝑑 10 𝑓

8 14

𝑎 4 6 2 4 𝑧

6 8

𝑐 12 𝑒 10 𝑔

Solution
We find the shortest path from 𝑎 to 𝑧 is 𝑎, 𝑐, 𝑑, 𝑒, 𝑔, ℎ, with length 32.

ELEE 2110U Discrete Mathematics 59


Example (2)
𝑏 10 𝑑 10 𝑓 𝑏 𝑏 𝑑

8 14
0 0
𝑎 4 6 2 4 𝑧 𝑎 𝑎

6 8 6

𝑐 12 𝑒 10 𝑔 𝑐 𝟔 𝑐 𝑒
Step 0 Step 1 Step 2
𝟖 𝑏 𝑑 𝟖 𝑏 𝟏𝟐 𝑑 𝑓 𝟖 𝑏 𝟏𝟐 𝑑 𝑓

8 8 8
0 0 0
𝑎 𝑎 6 𝑎 6 2

6 6 6

𝟔 𝑐 𝑒 𝟔 𝑐 𝑒 𝟔 𝑐 𝟏𝟒 𝑒 𝑔
Step 3 Step 4 Step 5
𝟖 𝑏 𝟏𝟐 𝑑 𝑓 𝟐𝟐 𝟖 𝑏 𝟏𝟐 𝑑 𝑓 𝟐𝟐 𝟖 𝑏 𝟏𝟐 𝑑 𝑓 𝟐𝟐
10 10 10

8 8 8
0 0 0
𝑎 6 2 𝑧 𝑎 6 2 𝑧 𝑎 6 2 𝑧
𝟑𝟐
6 6 6 8

𝟔 𝑐 𝟏𝟒 𝑒 𝑔 𝟔 𝑐 𝟏𝟒 𝑒 10 𝑔 𝟐𝟒 𝟔 𝑐 𝟏𝟒 𝑒 10 𝑔 𝟐𝟒
Step 6 Step 7 Step 8

ELEE 2110U Discrete Mathematics 60


Example (3)

Step Vertices of Edges of Candidate 𝑳 𝒂 𝑳 𝒃 𝑳 𝒄 𝑳 𝒅 𝑳 𝒆 𝑳 𝒇 𝑳 𝒈 𝑳 𝒛


Path 𝑻 Path 𝑻 Vertices

0 𝟎 ∞ ∞ ∞ ∞ ∞ ∞ ∞
1 𝑎 ∅ 𝑏, 𝑐 8 6
2 𝑎, 𝑐 𝑎, 𝑐 𝑏, 𝑑, 𝑒 8 12 18

3 𝑎, 𝑐, 𝑏 𝑎, 𝑐 , 𝑎, 𝑏 𝑑, 𝑒 12 18

4 𝑎, 𝑐, 𝑏, 𝑑 𝑎, 𝑐 , 𝑎, 𝑏 , 𝑐, 𝑑 𝑒, 𝑓 14 22

5 𝑎, 𝑐, 𝑏, 𝑑, 𝑒 𝑎, 𝑐 , 𝑎, 𝑏 , 𝑐, 𝑑 , 𝑑, 𝑒 𝑓, 𝑔 22 24

6 𝑎, 𝑐, 𝑏, 𝑑, 𝑒, 𝑓 𝑎, 𝑐 , 𝑎, 𝑏 , 𝑐, 𝑑 , 𝑑, 𝑒 , 𝑑, 𝑓 𝑔, 𝑧 24 36

7 𝑎, 𝑐, 𝑏, 𝑑, 𝑒, 𝑓, 𝑔 𝑎, 𝑐 , 𝑎, 𝑏 , 𝑐, 𝑑 , 𝑑, 𝑒 , 𝑑, 𝑓 , 𝑒, 𝑔 𝑧 32

8 𝑎, 𝑐, 𝑏, 𝑑, 𝑒, 𝑓, 𝑔, 𝑧 𝑎, 𝑐 , 𝑎, 𝑏 , 𝑐, 𝑑 , 𝑑, 𝑒 , 𝑑, 𝑓 , 𝑒, 𝑔 , 𝑔, 𝑧

ELEE 2110U Discrete Mathematics 61


ELEE 2110U Discrete Mathematics 1
Number Theory

ELEE 2110U Discrete Mathematics 2


Numeral Systems
• A numeral is any symbol used to represent a number.
• In the Roman numeral system, numerals are represented by seven distinct letters. The basic numerals used by the
Romans are as follows: I 1, V 5, X 10, L 50, C 100, D 500, and M 1000. These seven numerals can be
combined together to represent larger integers.
• Although the Roman numeral system allowed easy addition and subtraction, multiplication and division proved to be
much more difficult. Combined with the lack of an effective system for utilizing fractions and irrational numbers, and the
imperative absence of the important concept of zero hindered mathematical advances.
• The Hindu-Arabic numeral system, which is based on ten distinct symbols, reflects human anatomy with its ten fingers.
The most powerful aspect of the Hindu-Arabic system is the existence of a separate numeral for zero that can serve both
as a placeholder and as a symbol for “none.”
• The modern system of notation, using ten different numerals including a zero, was invented in India and reached its
present form by the seventh century. This system was then spread to Europe by the Arabs, hence the name the Hindu-
Arabic numeral system.

ELEE 2110U Discrete Mathematics 3


Divisibility
• Let 𝑎 and 𝑏 be integers with 𝑎 0. If there is an integer 𝑐 such that 𝑏 𝑎𝑐, then we say 𝑎 divides 𝑏, 𝑎 is a factor of 𝑏, 𝑎
is a divisor of 𝑏, 𝑏 is divisible by 𝑎, or 𝑏 is a multiple of 𝑎.

• The notation 𝑎|𝑏 denotes 𝑎 divides 𝑏, that is, is an integer. For instance, 16|48 implies 16 divides 48, as 3 is an

integer. In contrast, the notation 𝑎 ∤ 𝑏 denotes 𝑎 does not divide 𝑏, which in turn means is not an integer. For instance,

20 ∤ 48 implies 20 does not divide 48, as 2.4 is not an integer. Note that if 𝑎 is a nonzero integer, then 𝑎|0, as 0

0 𝑎.

• With 𝑏 𝑎𝑐, every integer 𝑏 is divisible by 𝑎 1 (i.e., 𝑐 𝑏) and by 𝑎 𝑏 (i.e., 𝑐 1), where they are called
the trivial divisors of 𝑏.

ELEE 2110U Discrete Mathematics 4


Quotient-Remainder Theorem
• The process of long division is known as the division algorithm or the quotient-remainder theorem.
• Assuming 𝑎 is an integer and 𝑑 is a positive integer, then there exist unique integers 𝑞 and 𝑟 with 0 𝑟 𝑑, such that
𝑎 𝑑𝑞 𝑟.
• Note that 𝑑 is called the divisor, 𝑎 is called the dividend, 𝑞 is called the quotient, and 𝑟 is called the remainder.
• It is important to highlight that the notations 𝑞 𝑎 div 𝑑 and 𝑟 𝑎 mod 𝑑 are often used to express the quotient and
remainder, respectively. For 0 𝑟 𝑑, we thus have the following:

𝑞 𝑎 div 𝑑.
𝑎 𝑑𝑞 𝑟 ↔
𝑟 𝑎 mod 𝑑.

ELEE 2110U Discrete Mathematics 5


Examples
For each of the following values of 𝑎 and 𝑑, determine integers 𝑞 and 𝑟 such that 𝑎 𝑑𝑞 𝑟 and 0 𝑟 𝑑.
(a) 𝑎 54 and 𝑑 4.
(b) 𝑎 51 and 𝑑 5.
(c) Assuming 𝑎 is an integer, determine 4𝑎 mod 11 if we have 𝑎 mod 11 6.

Solution
(a) 54 4 13 2 → 𝑞 13 and 𝑟 2. We thus have 2 54 mod 4 and 13 54 div 4.
(b) 51 5 11 4 → 𝑞 11 and 𝑟 4 (as the remainder must be positive).
We thus have 4 51 mod 5 and 11 51 div 5.
(c) 𝑎 mod 11 6 →𝑎 11𝑞 6 → 4𝑎 4 11𝑞 6 44𝑞 24 → 4𝑎 11 4𝑞 2 2 → 4𝑎 mod 11 2.

ELEE 2110U Discrete Mathematics 6


Prime Numbers
• Euclid’s Theorem states that there are infinitely many primes.
• Prime numbers are important in many applications, especially in the field of cryptography.
• All integers greater than 1 are grouped into two mutually exclusive sets of integers, one set consists of prime numbers (or
simply primes) and the other consists of composite integers.
• An integer 𝑝 2 is prime if it is divisible only by 1 and itself (i.e., 𝑝). If an integer greater than 1 is not prime, it is then
composite.

• An integer 𝑛 2 is composite if and only if there exists an integer 𝑎 such that 𝑎|𝑛 with 1 𝑎 𝑛, that is, is an

integer. Note that 1 is neither prime nor composite.


• The fundamental theorem of arithmetic states that every integer greater than 1 is either prime or the product of two or
more primes.
• If the integer 𝑛 is greater than 1, then there is prime 𝑝 𝑛 such that 𝑝|𝑛.
• For instance, 101 is a prime integer as there are no positive integers but 1 and 101 that divide 101, and 102 is a composite
integer that can be expressed as the product of the prime numbers 2, 3, and 17.

ELEE 2110U Discrete Mathematics 7


Unique Prime-Power Factorization (1)
• Every integer 𝑛 1 can be expressed uniquely as 𝑛 𝑝 𝑝 . . . 𝑝 , with 𝑝 𝑝 ⋯ 𝑝 as primes, where 𝑘 is a
positive integer. For instance, we have 10,800 2 2 2 2 3 3 3 5 5.
• The unique factorization of an integer 𝑛 1 formed by grouping together equal prime factors produces the unique

prime-power factorization 𝑛 𝑝 𝑝 ...𝑝 , where 𝑝 𝑝 ⋯ 𝑝 are distinct primes, and 𝑚 , 𝑚 , . . . , 𝑚 are

positive integers. For instance, with 𝑛 10,800, we have 𝑝 2, 𝑝 3, 𝑝 5 and 𝑚 4, 𝑚 3, 𝑚 2, as


10,800 2 3 5 .

ELEE 2110U Discrete Mathematics 8


Unique Prime-Power Factorization (2)
• If 𝑛 is composite, then 𝑛 has a prime factor less than or equal to 𝑛, i.e., 𝑛 is composite if and only if 𝑛 has a divisor 𝑑
satisfying 2 𝑑 𝑛.
• If 𝑛 is not divisible by any prime, from 2, which is the smallest prime, up to the largest prime that is not exceeding 𝑛,
then 𝑛 is prime. However, if 𝑛 is divisible by a prime factor 𝑝, then the procedure is continued by prime factorization of

, while noting that has no prime factors less than 𝑝. Again, if is not divisible by any prime, from 𝑝 up to the largest

prime that is not exceeding , then is prime. If has a prime factor 𝑞, then continue by factoring . This process

continues until the factorization has been reduced to a prime.

ELEE 2110U Discrete Mathematics 9


Examples
Determine the prime factorization of each of the following numbers:
(a) 1547
(b) 1601

Solution
(a) To find the prime factorization of 1547, first perform divisions of 1547 by successive primes, beginning with 2 and no

greater than 1547. None of the primes 2, 3, and 5 divides 1547. However, 7 divides 1547, with 221. We then

divide 221 by successive primes, beginning with 7 itself. None of the primes 7 and 11 divide 221. However, 13 divides 221,

with 17. As 17 is prime, the procedure is completed. We thus have 1547 7 13 17.

(b) We first list all primes less than or equal to 1601, namely 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, and 37. None of them is
a factor of 1601, so 1601 is prime.

ELEE 2110U Discrete Mathematics 10


Euler’s Totient Function
• There is an important quantity in number theory, referred to as Euler’s totient function and denoted by 𝜑 𝑛 , defined as
the number of positive integers less than 𝑛 and relatively prime to 𝑛. By convention 𝜑 1 1.
• For instance, if 𝑛 9, then 𝜑 9 6, namely the set of relatively primes is 1, 2, 4, 5, 7, 8 . It should be noted that for
prime 𝑝, we have 𝜑 𝑝 𝑝 1.
• For instance, if 𝑝 11, then 𝜑 11 10, namely the set of relatively primes is 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 .
• If 𝑝 and 𝑞 are two prime numbers, with 𝑝 𝑞, we then have

𝜑 𝑛 𝜑 𝑝𝑞 𝜑 𝑝 𝜑 𝑞 𝑝 1 𝑞 1 .

• For instance, if 𝑝 7 and 𝑞 3, we then have 𝜑 21 𝜑 7 3 𝜑 21 𝜑 7 𝜑 3 7 1 3 1 12,


namely the set of primes is 1, 2, 4, 5, 8, 10, 11, 13, 16, 17, 19, 20 .

ELEE 2110U Discrete Mathematics 11


Greatest Common Divisor
• The greatest common divisor (gcd) of two nonzero integers 𝑎 and 𝑏, denoted by gcd 𝑎, 𝑏 , is the largest integer 𝑑 such
that 𝑑|𝑎 and 𝑑|𝑏, except that gcd 0,0 0.
• The greatest common divisor of two nonzero integers exists if the set of their common divisors is nonempty and finite.
• The integers 𝑎 and 𝑏 are relatively prime if their greatest common divisor is 1. For instance, neither 15 nor 16 is prime,
however, 15 and 16 are relatively prime, as their greatest common divisor is 1.
• If 𝑎 and 𝑏 are relatively prime, then there exist some integers 𝑠 and 𝑡 such that 𝑎𝑠 𝑏𝑡 1, and conversely, if 𝑎𝑠 𝑏𝑡

1, then 𝑎 and 𝑏 are relatively prime. Note that if 𝑑 gcd 𝑎, 𝑏 , then gcd , 1.

• In addition, integers are called pairwise relatively prime if the greatest common divisor of any two integers is 1. For
instance, none of the integers 25, 26, and 27 are prime, yet they are pairwise relatively prime.

ELEE 2110U Discrete Mathematics 12


Determining GCD: Brute-Force & Prime Factorization
Brute-force method: First find all the positive divisors of each integer, then determine all the positive common divisors of
both integers, and lastly select the largest common divisor.

Prime factorization: The prime factorizations of integers 𝑎, 𝑏, and gcd 𝑎, 𝑏 are as follows:

𝑎 𝑝 𝑝 ...𝑝
, , ,
→ gcd 𝑎, 𝑏 𝑝 𝑝 ...𝑝 .
𝑏 𝑝 𝑝 ...𝑝

where 𝑝 𝑝 ⋯ 𝑝 are distinct primes, each exponent is a nonnegative integer with min 𝑥, 𝑦 representing the
minimum of the two nonnegative integers 𝑥 and 𝑦, all primes occurring in the prime factorization of either 𝑎 or 𝑏, that is, 𝑝 ,
𝑝 , …, 𝑝 are included in both factorizations, and an exponent may be zero if necessary.

ELEE 2110U Discrete Mathematics 13


Determining GCD: The Euclidean Algorithm
Assuming 𝑎 𝑏, 𝑟 𝑎, and 𝑟 𝑏, successive application of the division algorithm yields the following sequence of
equations:
𝑟 𝑟𝑞 𝑟 0 𝑟 𝑟
𝑟 𝑟𝑞 𝑟 0 𝑟 𝑟
⋮ ⋮
𝑟 𝑟 𝑞 𝑟 0 𝑟 𝑟
𝑟 𝑟𝑞 𝑟 𝑟 0.

where 𝑛 1 is an integer. Since the remainders are nonnegative and getting smaller, the sequence of remainders 𝑟 𝑟
... 0 must eventually terminate with a remainder of zero. Using mathematical induction, we can show

gcd 𝑟 , 𝑟 gcd 𝑟 , 𝑟 ... gcd 𝑟 ,𝑟 gcd 𝑟 , 𝑟 gcd 𝑟 , 0 𝑟.

In summary, by applying the division algorithm successively, the greatest common divisor is the last (i.e., the smallest)
nonzero remainder in the sequence of divisions.

ELEE 2110U Discrete Mathematics 14


Example
Determine the greatest common divisor of 72 and 108 using the three above-mentioned methods.

Solution
The divisors of 72 include 2, 3, 4, 6, 8, 9, 12, 18, 24, 36, and 72, whereas the divisors of 108 include 2, 3, 4, 6, 9, 12, 18, 27,
36, 54, and 108. The common divisors are then 2, 3, 4, 6, 9, 12, 18, 36. The greatest common divisor is thus 36.

The prime factorizations of 72 and 108 are 2 3 and 2 3 , respectively. The greatest common divisor is thus
, ,
2 3 2 3 36.

Using the Euclidean algorithm, we have 108 72 1 36. As we have 72 36 2 0, 36, which is the last nonzero
remainder in the sequence of divisions, is the greatest common divisor.

ELEE 2110U Discrete Mathematics 15


Example
Determine the greatest common divisor of 2766 and 9960.

Solution
Successive application of the division algorithm yields the following sequence of equations:

9960 2766 3 1662


2766 1662 1 1104
1662 1104 1 558
1104 558 1 546
558 546 1 12
546 12 45 𝟔
12 6 2 0.

The greatest common divisor is 6, as it is the last (i.e., the smallest) nonzero remainder in the sequence of divisions.

ELEE 2110U Discrete Mathematics 16


Bezout Identity and Coefficients
• If 𝑎 and 𝑏 are positive integers, then there exist some integers 𝑠 and 𝑡 such that gcd 𝑎, 𝑏 𝑠𝑎 𝑡𝑏. This equation is
called Bezout’s identity, and 𝑠 and 𝑡 are referred to as Bezout coefficients of 𝑎 and 𝑏. Note that if 𝑎 and 𝑏 are relatively
prime, i.e., gcd 𝑎, 𝑏 1, we then have 𝑠𝑎 𝑡𝑏 1.
• In order to express gcd 𝑎, 𝑏 as a linear combination of integers 𝑎 and 𝑏, i.e., to determine the integers 𝑠 and 𝑡, a method
based on working backward through the divisions of the Euclidean algorithm, known as the extended Euclidean
algorithm, can be employed.

ELEE 2110U Discrete Mathematics 17


Example
Express the greatest common divisor of 210 and 54 as a linear combination of 210 and 54, i.e., determine the integers 𝑠 and
𝑡 in gcd 210, 54 210𝑠 54𝑡.

Solution
Using the Euclidean algorithm, we first find gcd 210, 54 . Successive application of the division algorithm yields the
following sequence of equations:
210 54 3 48
54 48 1 𝟔
48 6 9 0

Note that gcd 210, 54 6, as 6 is the last nonzero remainder in the sequence of divisions. We now employ the Euclidean
algorithm in the reverse order as follows:
gcd 210, 54 6 54 1 48 54 1 210 54 3 1 210 4 54 210𝑠 54𝑡 → 𝑠 1 & 𝑡 4

ELEE 2110U Discrete Mathematics 18


Least Common Multiple
• The least common multiple (lcm) of the positive integers 𝑎 and 𝑏, denoted by lcm 𝑎, 𝑏 , is the smallest positive integer
that is divisible by both 𝑎 and 𝑏. The prime factorizations of integers 𝑎, 𝑏, and lcm 𝑎, 𝑏 are as follows:

𝑎 𝑝 𝑝 ...𝑝
, , ,
→ lcm 𝑎, 𝑏 𝑝 𝑝 ...𝑝
𝑏 𝑝 𝑝 ...𝑝

where 𝑝 𝑝 ⋯ 𝑝 are distinct primes, each exponent is a nonnegative integer with max 𝑥, 𝑦 representing the
maximum of the two numbers 𝑥 and 𝑦, and all primes occurring in the prime factorization of either 𝑎 or 𝑏, that is, 𝑝 ,
𝑝 , …, 𝑝 are included in both factorizations.
• It is important to note that with positive integers 𝑎 and 𝑏, we have the following identity:

𝑎 𝑏 ≡ gcd 𝑎, 𝑏 lcm 𝑎, 𝑏 .

ELEE 2110U Discrete Mathematics 19


Example
Determine the least common multiple of 72 and 108 using the prime factorization. Using lcm 72,108 , determine
gcd 72,108 .

Solution
The prime factorizations of 72 and 108 are 2 3 and 2 3 , respectively.
, ,
Their least common multiple is thus 2 3 2 3 216.
As we have 𝑎 𝑏 gcd 𝑎, 𝑏 lcm 𝑎, 𝑏 , we have 72 108 gcd 72,108 216. We therefore have gcd 72,108
36.

ELEE 2110U Discrete Mathematics 20


Divisibility Test
A divisibility test is a quick way to determine whether an integer, called dividend, is divisible by a smaller integer, called
divisor, without performing the division.
The test is usually based on the examination of the digits of the dividend in a way that solely depends on what the divisor is.
Consider an integer 𝑎 with 𝑛 digits 𝑎 ,𝑎 ,...,𝑎 ,𝑎 whose decimal representation is then as follows:

𝑎 𝑎 10 𝑎 10 ... 𝑎 10 𝑎 10 .

Note that 𝑎 is the least significant digit and 𝑎 is the most significant digit. As an example, we have the following:

71524 70000 1000 500 20 4 7 10000 1 1000 5 100 2 10 4 1


7 10 1 10 5 10 2 10 4 10 .

ELEE 2110U Discrete Mathematics 21


Divisibility Rules
• Divisibility by 1: 1|𝑎 → No special condition on the coefficients 𝑎 ,𝑎 , . . . , 𝑎 , i.e., every integer is divisible by 1.
• Divisibility by 2: 2|𝑎 → 𝑎 mod 2 𝑎 mod 2 0 → 𝑎 ∈ 0, 2, 4, 6, 8 , i.e., the least significant digit must be even.
• Divisibility by 3: 3|𝑎 → 𝑎 mod 3 𝑎 𝑎 ,... 𝑎 mod 3 0, i.e., the sum of all digits must be divisible by 3.
• Divisibility by 4: 4|𝑎 → 𝑎 mod 4 𝑎 10 𝑎 10 mod 4 0, i.e., the number representing the last two digits
must be divisible by 4.
• Divisibility by 5: 5|𝑎 → 𝑎 mod 5 𝑎 mod 5 0, i.e., the last digit must be a 0 or a 5.
• Divisibility by 6: 6|𝑎 → 𝑎 mod 6 0 → 𝑎 mod 2 0 and 𝑎 mod 3 0, i.e., the integer must be divisible by both 2 and 3.

• Divisibility by 7: 7|𝑎 → 𝑎 mod 7 𝑎 10 𝑎 10 ... 𝑎 10 2 𝑎 mod 7 0. Note that

the process may need to be repeated.


• Divisibility by 8: 8|𝑎 → 𝑎 mod 8 𝑎 10 𝑎 10 𝑎 10 mod 8 0, i.e., the number representing the last
three digits must be divisible by 8.
• Divisibility by 9: 9|𝑎 → 𝑎 mod 9 𝑎 𝑎 ,... 𝑎 mod 9 0, i.e., the sum of all digits must be divisible by 9.
• Divisibility by 10: 10|𝑎 → 𝑎 mod 10 𝑎 mod 10 0, i.e., the last digit must be a 0.
ELEE 2110U Discrete Mathematics 22
Example
Determine which one of the integers from 1 to 10 inclusive divides 2520.
Solution
As any integer is divisible by 1, 2520 is divisible by 1.
As its last digit (i.e., 0) is even, 2520 is divisible by 2.
As the sum of all its digits (i.e., 9) is divisible by 3, 2520 is divisible by 3.
As its last two digits (i.e., 20) is divisible by 4, 2520 is divisible by 4.
As its last digit is a 0, 2520 is divisible by 5.
As it is divisible by 2 and 3 both, 2520 is divisible by 6.
As it is not clear if 252 2 0 252 is divisible by 7, we need to continue the process. As 25 2 2 21 is divisible by
7, 2520 is divisible by 7.
As its last three digits (i.e., 520) is divisible by 8, 2520 is divisible by 8.
As the sum of all its digits (i.e., 9) is divisible by 9, 2520 is divisible by 9.
As its last digit is a 0, 2520 is divisible by 10.

ELEE 2110U Discrete Mathematics 23


Congruences
• Modular arithmetic is an aspect of divisibility with some interesting applications. Simple examples may include two
hours and twenty minutes after 7:45 is 10:05 and 17 days after a Tuesday is a Friday.
• Congruences have many applications, such as generating pseudorandom numbers for computer simulations, generating
parity check bits to detect errors in digital transmission and storage, storing huge records in a rather small table and
retrieving them quickly, and above all modern cryptography.
• Assuming 𝑎 and 𝑏 are integers and 𝑚 is a positive integer, 𝒂 is congruent to 𝒃 modulo 𝒎, denoted by 𝑎 ≡ 𝑏 mod 𝑚 , if
𝑚 divides 𝑎 𝑏, that is, 𝑚| 𝑎 𝑏 or equivalently 𝑎 𝑏 𝑘𝑚 for some integer 𝑘. We say that 𝑎 ≡ 𝑏 mod 𝑚 is a
congruence and that 𝑚 is its modulus.

ELEE 2110U Discrete Mathematics 24


Modular Arithmetic
While noting that the notation 𝑎 ≡ 𝑏 mod 𝑚 represents a relation on the set of integers and
the notation 𝑎 mod 𝑚 𝑏 represents a function, we have 𝑎 ≡ 𝑏 mod 𝑚 if and only if 𝑎 mod 𝑚 𝑏 mod 𝑚
where 𝑎, 𝑏, and 𝑚 0 are all integers.
In addition, for integers 𝑎, 𝑏, 𝑐, 𝑑, 𝑛, and 𝑚 0, we have

𝑎 𝑐≡𝑏 𝑑 mod 𝑚

𝑎 ≡ 𝑏 mod 𝑚 𝑎 𝑐≡𝑏 𝑑 mod 𝑚



𝑐 ≡ 𝑑 mod 𝑚 𝑎𝑐 ≡ 𝑏𝑑 mod 𝑚

𝑎 ≡ 𝑏 mod 𝑚

Note that 𝑎𝑐 ≡ 𝑏𝑐 mod 𝑚 does not imply 𝑎 ≡ 𝑏 mod 𝑚 , unless gcd 𝑐, 𝑚 1. For instance, 85 ≡ 55 mod 10 does
not yield 17 ≡ 11 mod 10 as gcd 5, 10 1, but 85 ≡ 55 mod 6 does yield 17 ≡ 11 mod 6 as gcd 5, 6 1.

ELEE 2110U Discrete Mathematics 25


Fermat's Little Theorem
Fermat’s little theorem, which is extremely useful in computing the remainder modulo prime of large powers of integers, can
be expressed in terms of congruences. Fermat’s little theorem states that if 𝑝 is prime and 𝑎 is an integer not divisible by 𝑝,
then
𝑎 ≡ 1 mod 𝑝 ↔ 𝑎 mod 𝑝 1
or equivalently
𝑎 ≡ 𝑎 mod 𝑝 ↔ 𝑎 mod 𝑝 𝑎.

ELEE 2110U Discrete Mathematics 26


Example
Find 3 mod 11, using Fermat’s little theorem.

Solution
Note that 11 is prime and 3 is not divisible by 11, we can thus employ Fermat’s little theorem as follows:

3 ≡ 1 mod 11 → 3 11𝑘 1 → 3 11𝑘 1 11𝑘 1

While noting 201 1 20 10, we then have

3 3 3 3 11𝑘 1 11 3𝑘 3 11𝑘 3 → 3 ≡ 3 mod 11

where 𝑘 , 𝑘 , and 𝑘 are integers. We thus have 3 mod 11 3.

ELEE 2110U Discrete Mathematics 27


Euler’s theorem
Euler’s theorem states that for every 𝑎 and 𝑛 that are relatively prime, we have

𝑎 ≡ 1 mod 𝑛

where 𝜑 𝑛 is Euler’s totient function. As an example, 𝑎 3 and 𝑛 10 are relatively prime and 𝜑 10 4. We thus
have 3 3 81 ≡ 1 mod 10 . As another example, for 𝑎 2, if we have 𝑛 11 and consequently 𝜑 11
10, we then have 2 2 1024 ≡ 1 mod 11 .

ELEE 2110U Discrete Mathematics 28


An Inverse of Modulo
A congruence of the form 𝑎𝑥 ≡ 𝑏 mod 𝑚 is known as a linear congruence in one variable, where 𝑚 0, 𝑎, and 𝑏 are all
integers and 𝑥 is an unknown variable. A major application of linear congruences lies in cryptography.

For all integers 𝑎 and 𝑚 1, if gcd 𝑎, 𝑚 1, that is, 𝑎 and 𝑚 are relatively prime, then there exists a unique integer 𝑎,
such that 𝑎𝑎 ≡ 1 mod 𝑚 , where the integer 𝑎 is called an inverse of 𝒂 modulo 𝒎 and 0 𝑎 𝑚.

ELEE 2110U Discrete Mathematics 29


Example
Noting 43 and 660 are relatively prime integers, find an inverse of 43 modulo 660 using the extended Euclidean algorithm.

Solution
We use the Euclidean algorithm not to find gcd 43, 660 as we already know gcd 43, 660 1, but to employ the
extended Euclidean algorithm in order to find an inverse of 43 modulo 660. The steps are as follows:

660 43 15 15
43 15 2 13
15 13 1 2
13 2 6 1.

We now use the above results in the reverse order to find 1 in terms of 43 and 660:
1 13 2 6 13 15 13 6 7 13 6 15 7 43 15 2 6 15 7 43 20 15 7
43 20 660 43 15 307 43 20 660. Therefore, 307 is an inverse modulo 660, as 43 307 ≡
1 mod 660 .

ELEE 2110U Discrete Mathematics 30


Chinese Remainder Theorem
There are applications that require solutions to systems of linear congruences. The Chinese Remainder Theorem provides a
unique solution when the modulo of a system of linear congruences are pairwise relatively prime.
The Chinese Remainder Theorem states that if 𝑚 , 𝑚 , …, 𝑚 are pairwise relatively prime positive integers and 𝑎 , 𝑎 ,
…, 𝑎 are arbitrary integers, then the following system of linear congruences has a unique solution 𝑥 modulo
𝑚 𝑚 𝑚 . . . 𝑚 , with 0 𝑥 𝑚:
𝑥≡𝑎 mod 𝑚
𝑥≡𝑎 mod 𝑚

𝑥≡𝑎 mod 𝑚

where the simultaneous solution is as follows:

𝑥≡ 𝑎 𝛽 𝑦 mod 𝑚

with 𝛽 and an integer 𝑦 is an inverse of 𝛽 modulo 𝑚 , i.e., 𝛽 𝑦 ≡ 1 mod 𝑚 ).

ELEE 2110U Discrete Mathematics 31


Example
Determine the number when it is divided by 3, the remainder is 2, when it is divided by 5, the remainder is 4, and when it is
divided by 7, the remainder is 6.

Solution
𝑥 ≡ 2 mod 3
We must find a unique solution 𝑥 for the following system of linear congruences: 𝑥 ≡ 4 mod 5
𝑥 ≡ 6 mod 7 .
As 3, 5, and 7 are pairwise relatively prime, we can use the Chinese remainder theorem. Noting 𝑦 , 𝑦 , and 𝑦 can be found
by using the extended Euclidean algorithm or the method of inspection, we can then have
𝑚
𝛽 35
𝑚
𝑚 3 𝑚 𝑦 2
𝑚 5 → 𝑚 𝑚 𝑚 𝑚 105 → 𝛽 21 → 𝑦 1
𝑚
𝑚 7 𝑚 𝑦 1
𝛽 15
𝑚
with 𝑎 2, 𝑎 4, 𝑎 6, the solution to the simultaneous congruences is as follows: 𝑥 ≡ 𝑎 𝛽 𝑦 𝑎 𝛽𝑦
𝑎 𝛽𝑦 mod 𝑚 ≡ 2 35 2 4 21 1 6 15 1 mod 105 ≡ 314 mod 105 ≡ 104

ELEE 2110U Discrete Mathematics 32


Sum and Product of Integers in Modular Arithmetic
It is important to note that the sum and product of two integers in the modular arithmetic using the same divisor are as
follows:
𝑎 𝑏 mod 𝑚 𝑎 mod 𝑚 𝑏 mod 𝑚 mod 𝑚
and
𝑎 𝑏 mod 𝑚 𝑎 mod 𝑚 𝑏 mod 𝑚 mod 𝑚 → 𝑎 mod 𝑚 𝑎 mod 𝑚 mod 𝑚.

ELEE 2110U Discrete Mathematics 33


Modular Exponentiation
In modern cryptography, exponentiation in modular arithmetic is often much needed.
It is important to calculate 𝑐 mod 𝑚, where 𝑐, 𝑑, and 𝑚 are very large integers. Computing 𝑐 and then dividing it by 𝑚 to
determine its remainder is totally impractical.
To this effect, a two-step approach is generally taken. As the first step, the exponent 𝑑 can be written in the binary form, that
is, 𝑑 is written as the sum of terms, each in the form of 2 , where 𝑘 is a nonnegative integer.
As the second step, the product property of modular arithmetic is used to reduce the number of calculations.
To this end, the algorithm successively determines 𝑐 mod 𝑚, 𝑐 mod 𝑚, 𝑐 mod 𝑚, 𝑐 mod 𝑚, and so on, multiplies
together only those terms of interest as defined by 𝑑, and then finds the remainder of the product when it is divided by 𝑚.

ELEE 2110U Discrete Mathematics 34


Example
Find 3 mod 645.

Solution
The exponent in the binary form is as follows: 644 2 2 2 512 128 4 → 3 mod 645 3 3 3 mod 645.
We now successively determine 3 mod 𝑚, 3 mod 𝑚, 3 mod 𝑚 as well as similar terms up to 3 mod 𝑚.
3 mod 645 3 mod 645 3.
3 mod 645 3 mod 645 3 mod 645 mod 645 3 3 mod 645 9.
3 mod 645 3 mod 645 3 mod 645 mod 645 9 9 mod 645 𝟖𝟏.
3 mod 645 3 mod 645 3 mod 645 mod 645 81 81 mod 645 111.
3 mod 645 3 mod 645 3 mod 645 mod 645 111 111 mod 645 66.
3 mod 645 3 mod 645 3 mod 645 mod 645 66 66 mod 645 486.
3 mod 645 3 mod 645 3 mod 645 mod 645 486 486 mod 645 126.
3 mod 645 3 mod 645 3 mod 645 mod 645 126 126 mod 645 𝟑𝟗𝟔.
3 mod 645 3 mod 645 3 mod 645 mod 645 396 396 mod 645 81.
3 mod 645 3 mod 645 3 mod 645 mod 645 81 81 mod 645 𝟏𝟏𝟏.
Based on the product of two integers in the modular arithmetic and the modular exponentiation, we have
3 mod 645 3 3 3 mod 645 3 mod 645 3 mod 645 3 mod 645 mod 645 𝟏𝟏𝟏 𝟑𝟗𝟔
𝟖𝟏 mod 645 36.

ELEE 2110U Discrete Mathematics 35


Hashing Function (1)
• Data (record) that is stored in a computer memory (table) typically has two parts, a key that uniquely identifies that piece
of data and a value that is the information of interest. Often, a key is a large number 𝑘 consisting of many digits, say
ISBN 13-digit code to identify books. One way to store the records is to place the record with key 𝑘 into location 𝑘 of the
table, thus theoretically requiring a huge table, e.g., 10 locations in the case of ISBN 13-digit code. This is a very
wasteful of computer memory space, as the number of records to be stored is relatively small.

• In order to map data of arbitrarily large size to small fixed size, a hashing function ℎ is used to assign memory location
ℎ 𝑘 to the record that has 𝑘 as its key, i.e., a hashing function converts keys into lists positions. The location numbers
are formally called indices. The index produced by ℎ determines the spot in the list, i.e., the memory location, to store the
value of the record.

ELEE 2110U Discrete Mathematics 36


Hashing Function (2)
• The most common hashing function is ℎ 𝑘 𝑘 mod 𝑚, where 𝑚 is the number of available memory locations.
Therefore, to find ℎ 𝑘 , we need only to find the remainder when 𝑘 is divided by 𝑚. For instance, the memory location
assigned by the hashing function ℎ 𝑘 𝑘 mod 65536 to the records of a book with ISBN 9780124076822 is 19,222.

• Since a hashing function is not one-to-one, simply because there are much more possible keys than memory locations,
more than one record may be assigned to a memory location. In such a case, we say a collision has occurred. In other
words, ℎ 𝑘 ℎ 𝑘 , but 𝑘 𝑘 . To handle collisions, a collision resolution policy is required. One simple way to
resolve a collision is to find the next unoccupied memory location following the occupied memory location assigned by
the hashing function. If we come to the end of the list without finding a memory location, then we would continue the
search back at the beginning of the list, as if the array were circular. This method of collision resolution is called linear
probing.

ELEE 2110U Discrete Mathematics 37


Representation of Integers
Any positive integer 𝑎 can be uniquely represented in the following form:

𝑎 𝑎 𝑏 𝑎 𝑏 ... 𝑎 𝑏 𝑎 .

where 𝑏, known as the base, is an integer greater than 1, 𝑘 is a nonnegative integer, 𝑎 , 𝑎 , …, 𝑎 are nonnegative integers
less than 𝑏, and 𝑎 0. This representation of 𝑎 is called the base 𝒃 expansion of 𝑎, which can be denoted by
𝑎 𝑎 ... 𝑎 𝑎 . Note that 𝑏 represents the number of different symbols that can be used in a numeral system. There are
various representations of integers, including the following expansions:
Decimal expansions: 𝑏 10 → 10 symbols 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 .
Binary expansions: 𝑏 2 → 2 symbols 0, 1 .
Octal expansions: 𝑏 8 → 8 symbols 0, 1, 2, 3, 4, 5, 6, 7 .
Hexadecimal expansions: 𝑏 16 → 16 symbols 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F .

Base conversion of an integer 𝑎 in the decimal expansion into any nondecimal base 𝑏 is as follows: divide 𝑎 and its
successive quotients by 𝑏 until a zero quotient is reached, then pick the remainders in the reverse order.
ELEE 2110U Discrete Mathematics 38
Example
Express the following expansions in base 10:
(a) 11001101 .
(b) CD .

Solution
(a) 11001101 1 2 1 2 0 2 0 2 1 2 1 2 0 2 1 2 205
(b) CD 12 16 13 16 205.

ELEE 2110U Discrete Mathematics 39


Example
Express 3489, which is in the decimal expansion, in the following representations:
(a) The binary expansion, that is, the base is 2.
(b) The hexadecimal expansion, that is, the base 16.
Solution
(a) 3489 2 1744 𝟏 → 1744 2 872 𝟎 → 872 2 436 𝟎 → 436 2 218 𝟎 → 218
2 109 𝟎 → 109 2 54 𝟏 → 54 2 27 𝟎 → 27 2 13 𝟏 → 13 2 6 𝟏 → 6 2
3 𝟎 →3 2 1 𝟏 → 1 2 0 𝟏.
The successive remainders that we have found, i.e., 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, are digits from the right to the left of 3489
in base 2. Hence 3489 𝟏𝟏𝟎𝟏𝟏𝟎𝟏𝟎𝟎𝟎𝟎𝟏 .
(b) 3489 16 218 𝟏 → 218 16 13 𝟏𝟎 → 13 16 0 𝟏𝟑.
The successive remainders that we have found, 1, 10 A , and 13 D , are digits from the right to the left of 3489 in
base 16. Hence 3489 𝐃𝐀𝟏 . Note that for the conversion of a hexadecimal expansion to a binary expansion, each
hexadecimal digit corresponds to a block of four binary digits.

ELEE 2110U Discrete Mathematics 40


Binary Addition, Multiplication & Division
The computational methods of binary arithmetic are analogous to those of decimal arithmetic. In binary arithmetic, the
number 2 10 in binary notation plays a role similar to that of the number 10 in decimal arithmetic.

• In binary addition, carry-overs of binary addition are performed in the same manner as in decimal addition. We thus have
0 0 0, 0 1 1, 1 0 1, and 1 1 10, all in base 2.

• The binary multiplication is carried out by multiplying the multiplicand by one bit of the multiplier at a time and the
result of the partial product for each bit is placed in such a manner that the least significant bit is under the corresponding
multiplier bit. Finally, the partial products are added to get the complete product.

• The binary division is similar to that employed in the decimal system. However, in the case of binary numbers, the
operation is simpler because the quotient can have either 1 or 0 depending upon the divisor.

ELEE 2110U Discrete Mathematics 41


Binary Subtraction
• In binary subtraction, like decimal subtraction, it may be necessary to borrow. However, the method introduced here is
based on not using borrow, as one’s complement and two’s complement of binary numbers are used to perform
subtraction.

• The one’s complement of a binary number can be obtained by inverting each bit from 1 to 0 or from 0 to 1. For example,
one’s complement of the binary number 110010 is 001101. To get two’s complement of a binary number is to first obtain
the one’s complement of the number and then add 1 to the least significant bit. For example, two’s complement of the
binary number 10010 is 01101 00001 01110.

• The binary subtraction can be carried out using the following steps:
 Find the two’s complement of the subtrahend, and then add it to the minuend.
 If the final carry over of the sum is 1, it is dropped and the result is positive, and if there is no carry over, the two’s
complement of the sum will be the result and it is negative.

ELEE 2110U Discrete Mathematics 42


Example
Consider the two binary numbers 𝑚 1111 and 𝑛 11 . Perform the following binary operations:
(a) 𝑚 𝑛, (b) 𝑚 𝑛, (c) 𝑚 𝑛, and d) 𝑚 𝑛.

Solution

ELEE 2110U Discrete Mathematics 43


Cryptography

ELEE 2110U Discrete Mathematics 44


Cryptography
• Cryptography is about making secret communication to make messages secure in the presence of adversaries.
• By encryption, an original message, called plaintext, is transformed into a coded message, called ciphertext. This
transformation is performed before the plaintext is transmitted or stored.
• The reverse process is called decryption, and is performed after the ciphertext is received or retrieved.
• The algorithm used for encryption and decryption is often called a cipher and the process of encryption and decryption
requires a secret key. A key is a number (value) that the cipher operates on, without which the unauthorized parties must
not be able to recover the original message.
• In classical cryptography, symbols, characters, letters, and digits were directly manipulated with the sole goal to provide
secrecy through obscurity.

ELEE 2110U Discrete Mathematics 45


Caesar Cipher
• A well-known classical cryptography technique, which was developed by Romans, was the Caesar cipher, a simple
encryption method based on substitution.
• The Caesar cipher shifts each letter in the alphabet by three letters forward, for instance, the letter G becomes J. It thus
requires a letter three places further along, while wrapping the letters at the end of the alphabet around to the letters at the
beginning of the alphabet, for instance, X wraps around to A, Y to B, and Z to C.
• Mathematically described, in the Caesar cipher, each letter is coded by its position relative to others. To this effect, an
integer 𝑖 ∈ 1, 2, . . . , 25, 26 replaces a letter whose position in the alphabet A, B, … , Y, Z is the 𝑖 , for instance, D is the
fourth letter in the alphabet, i.e., 𝑖 4, D is thus replaced by 4.
• Assuming the positive integer 𝑝 26, the functions providing the encrypted message and the decrypted message are
𝑓 𝑝 𝑝 3 mod 26 and 𝑓 𝑝 𝑝 3 mod 26, respectively.

ELEE 2110U Discrete Mathematics 46


Shift Cipher
• A slight generalization of the Caesar cipher, called the shift cipher or the additive cipher, is when 3 is replaced by the
integer 𝑏, called a key.
• In other words, the numerical equivalent of each letter is shifted by 𝑏, thus yielding the following functions:

Encryption → 𝑓 𝑝 𝑝 𝑏 mod 26

Decryption → 𝑓 𝑝 𝑝 𝑏 mod 26

ELEE 2110U Discrete Mathematics 47


Example
Using the shift cipher with key 𝑏 7, encrypt the message DESTROY ALL THE EVIDENCE.

Solution
The following steps, shown below, must be taken to encrypt the message:
i) Break the message “DESTROY ALL THE EVIDENCE” into a set of individual letters.
ii) Translate each letter to the corresponding number.
iii) Apply 𝑓 𝑝 𝑝 7 mod 26 to each number in part (ii).
iv) Translate the new set of numbers to get a set of encrypted letters.
The encrypted text is thus KLZAYVFHSSAOLLCPKLUJL

ELEE 2110U Discrete Mathematics 48


Example
Using the shift cipher with key 𝑏 11, decrypt the message LEELNVHTESHSLEJZFSLGP.

Solution
The following steps, shown below, must be taken to decrypt the message:
(i) Break the message “LEELNVHTESHSLEJZFSLGP” into a set of individual letters.
(ii) Translate each letter to the corresponding number.
(iii) Apply 𝑓 𝑝 𝑝 11 mod 26 to each number in part (ii).
(iv) Translate the new set of numbers to get a set of decrypted letters.
The decrypted text is thus ATTACK WITH WHAT YOU HAVE.

ELEE 2110U Discrete Mathematics 49


Affine Cipher
• A generalization of the shift cipher, called the affine cipher, is when for the given alphabet size 𝑛, the encryption
function is 𝑓 𝑝 𝑚𝑝 𝑏 mod 𝑛, where 1 𝑝 𝑛, 𝑏, 𝑚, and 𝑛 are all integers, and gcd 𝑚, 𝑛 1 to ensure 𝑓 𝑝
is a one-to-one correspondence.
• To decrypt a message using an affine cipher, we need to find 𝑝 using 𝑝 ≡ 𝑚 𝑓 𝑝 𝑏 mod 𝑛 , where 𝑚 is an inverse
of 𝑚 modulo 𝑛, i.e., 𝑚𝑚 ≡ 1 mod 𝑛 .

ELEE 2110U Discrete Mathematics 50


Example
Consider the affine cipher 𝑓 𝑝 11𝑝 4 mod 26.
a. Encrypt the letter M.
b. Decrypt the letter R.

Solution
a. We first translate the letter M to the corresponding number, we therefore have p=13. We then apply 𝑓 𝑝 11𝑝
4 mod 26 for 𝑝 13 to obtain 𝑓 13 11 13 4 mod 26 17. We then translate 17 to get the letter P, the
encrypted letter of M.
b. We first translate the letter R to the corresponding number, and therefore obtain 𝑓 𝑝 18. With 𝑚 11, we find 𝑚
19 as 𝑚𝑚 ≡ 1 mod 26 . We thus have
𝑝 ≡ 19 18 4 mod 26 ≡ 19 14 mod 26 ≡ 266 mod 26 ≡ 6.
Having 𝑝 6, we translate 6 to get back the letter F, the decrypted letter of R.

ELEE 2110U Discrete Mathematics 51


Modern Cryptography (1)
Number theory uniquely plays a pivotal role in modern cryptography. Cryptography has become increasingly complex and
its applications more varied. The major requirements for a system employing cryptography are as follows:
1) To provide an easy and inexpensive means of encryption and decryption to all authorized users in possession of the
appropriate key.
2) To ensure that the task of producing the plaintext without the key is made extremely difficult and time-consuming.
• Modern cryptography operates on binary bit sequences and relies on publicly known algorithms for encoding the
message. Secrecy is obtained through a secrete key which is used as the seed for the algorithms. In modern cryptography,
encryption and decryption can be carried out rapidly using complicated functions that are designed to be resistant to
attack. The computational difficulty of algorithms in conjunction with the fact that only the parties interested in secure
communication possess the secret key make it extremely difficult for anyone else to obtain the original information.
• Some of the widely-popular applications requiring cryptography are electronic and mobile commerce transactions, email
privacy, secure remote surveillance, file transfers of confidential data, secure e-voting, banking data, secure cloud
computing, medical records, and secure remote access.

ELEE 2110U Discrete Mathematics 52


Modern Cryptography (2)
The primary reasons to make messages secure through cryptographic mechanisms are as follows:
 Confidentiality, that is ensuring the transmitted message containing confidential data is hidden from unauthorized parties.
 Authentication, that is verifying the communicating parties are those they claim to be.
 Integrity, that is confirming that the message content has not been tampered with.
 Nonrepudiation, that is not being able to deny the transmission between the two parties has taken place.

There are fundamentally two types of adversaries.


 Passive adversaries who are a threat to confidentiality, as they do not interrupt, alter, or insert any data.
 Active adversaries who additionally threaten integrity and authentication.
In any event, potential adversaries may have powers and resources ranging from minimal to unlimited.

There are two broad categories of cryptography:


 Private-key cryptography, also known as secret-key cryptography and symmetric-key cryptography,
 Public-key cryptography, also referred to as asymmetric-key cryptography.
The public-key cryptography is growing, but the private-key cryptography is more common. They often complement
each other, as there are applications that both public-key cryptography and private-key cryptography are used.

ELEE 2110U Discrete Mathematics 53


Private-Key Cryptography
• Private-key cryptography is based on sharing secrecy by permuting or substituting characters in the plaintext. All classical ciphers with
no exception fall into private-key cryptography. In the private-key cryptography, once the key is known, both encryption and decryption
can be carried out. The private-key cryptography is often used for long messages, for they require less time to encrypt.
• In private-key cryptography, an 𝑛-bit block of plaintext is encrypted and an 𝑛-bit block of ciphertext is decrypted. If a message block
has fewer than 𝑛 bits, padding must be added to make it an 𝑛-bit block. The common values of 𝑛 are 64, 128, 256, and 512 bits. The
private-key cryptography uses the same 𝑘-bit key for both the encryption at the transmitter and the decryption at the receiver, as shown
below.

• In private-key cryptography, decryption algorithm is the inverse of encryption algorithm, and the number of private keys for 𝑁 users to

communicate is , as each pair must have a unique private key.

ELEE 2110U Discrete Mathematics 54


Public-Key Cryptography
• Public-key cryptography is based on personal secrecy rather than sharing secrecy. In public-key cryptography, the
plaintext and ciphertext are numbers that are manipulated by mathematical functions.
• In public-key cryptography, as shown below, two different keys, a public key and a private key are used. It is a salient
requirement that it must not be possible to determine the private key from the public key. In general, the public key is
small and the private key is large. A pair of keys can be used many times.

• The number of keys for 𝑁 users to communicate is 2𝑁. The algorithm is complex and more efficient for short messages.

ELEE 2110U Discrete Mathematics 55


RSA Cryptosystem (1)
• The RSA, named after the initials of its inventors, is the most widely-used public-key cryptography for secure data transmission. Its
effectiveness is based on the fact that very large prime numbers are fairly easy to produce on a computer, but it is enormously difficult
(i.e., extremely time-consuming) to factor a product of two large unknown prime numbers. The following steps show how the RSA keys
can be generated:
1) Choose two very large distinct prime numbers 𝑝 and 𝑞 at random, on the order of a couple of hundred digits each, often using
probabilistic computer algorithms, and calculate 𝑛 𝑝𝑞. As the number of digits in 𝑛 is approximately equal to the sum of digits in 𝑝
and 𝑞, no computer currently can factor it in a reasonable length of time. Note that due to the nature of factoring algorithms, 𝑝 and 𝑞
need to be of similar size to keep the RSA system secure. In addition, the large numbers are stored in binary form and generally 2048 to
4096 bits are needed for 𝑛 to ensure a reasonably high degree of security.
2) Compute 𝜑 𝑛 𝑝 1 𝑞 1 , and choose an arbitrary integer 𝑒 satisfying 1 𝑒 𝜑 𝑛 which is relatively prime to 𝜑 𝑛 . In
other words, gcd 𝑒, 𝜑 𝑛 1. Although for some applications, such as making encryption faster on small devices like smart cards, it
is desirable to have small values of 𝑒, it is best not to choose a small value for 𝑒, as the secrecy of the cipher may then be compromised.
3) Find the positive integer 𝑑, an inverse of 𝑒 modulo 𝜑 𝑛 , that is, find an integer 𝑑 such that 𝑒𝑑 ≡ 1 mod 𝜑 𝑛 . Note that as
gcd 𝑒, 𝜑 𝑛 1, we have 𝑑𝑒 𝑐𝜑 𝑛 1, where the integers 𝑐 and 𝑑 be found using the extended Euclidean algorithm, with the
condition that 0 𝑑 𝜑 𝑛 .

ELEE 2110U Discrete Mathematics 56


RSA Cryptosystem (2)
• The public key is 𝑛, 𝑒 , which is widely distributed, and thus anyone with the public key can encrypt a message to send.
• The private key is 𝑛, 𝑑 , where the security of the system depends on 𝑑 being difficult to calculate if only 𝑛 and 𝑒 are known.
• Since 𝑑 is not publicly available, only someone in possession of that value can correctly decrypt the message.
• The RSA is a block cipher and the following steps reflect how to encrypt using the public key and decrypt using the private key:
1) Translate each letter in the plaintext message 𝑀 into a two-digit number, because the RSA cipher works only on numbers, while noting
that A is translated into 01, B is translated into 02, …, and Z is translated into 26.
2) Concatenate the two-digit numbers into a sequence of digits representing the plaintext message, and then divide the sequence of digits
into the largest possible equally-sized blocks of even number of digits. Note that a block of digits is represented by 𝑚, where 0 𝑚
𝑛, and gcd 𝑚, 𝑛 1.
3) Pad the plaintext message with a number of random characters at the beginning and the end of the message to foil some potential code
breaking attacks (if needed) or if a block is not full, additional characters need to be filled in to make the last block the same size as all
other blocks or to ensure gcd 𝑚, 𝑛 1.
4) Determine the cyphertext 𝐶 block by block using 𝑐 𝑚 mod 𝑛.
5) Determine the plaintext 𝑀 block by block using 𝑚 𝑐 mod 𝑛.

ELEE 2110U Discrete Mathematics 57


Example
Show how the message 19 can be encrypted using the RSA cryptography by the sender and how accordingly the encrypted
message can be decrypted by the receiver.

Solution
Suppose the sender arbitrarily chooses the two prime numbers 𝑝 83 and 𝑞 53, and thus has 𝑛 𝑝𝑞 83 53
4,399 and 𝜑 𝑛 𝑝 1 𝑞 1 82 52 4,264. The sender then chooses an arbitrary 𝑒 23, which is relatively
prime to 4,624, because we have gcd 4624, 23 1. Therefore, 4399, 23 is a valid public key. The encrypted message
using fast modular multiplication is then as follows: 𝑐 𝑚 mod 𝑛 19 mod 4399 2556.

The valid private key is thus 4399, 927 , which the receiver possesses. Note that 𝑑 927, as it is an inverse of
𝑒 modulo 𝜑 𝑛 23 modulo 4264, while noting that 𝑑𝑒 𝑐𝜑 𝑛 23𝑑 4264𝑐 1. The decrypted message using fast
modular multiplication is then as follows: 𝑚 𝑐 mod 𝑛 2556 mod 4399 19.

ELEE 2110U Discrete Mathematics 58


Example
Suppose in an RSA cryptosystem, we have 𝑝 23 and 𝑞 31. Encrypt 𝑀 572 to get 𝐶 and then decrypt 𝐶 to get 𝑀 back.

Solution
𝑝 23
Given → 𝑛 𝑝𝑞 713 → 𝜑 𝑛 𝑝 1 𝑞 1 660.
𝑞 31

𝑒 𝜑 𝑛 Choosing 𝑒 29
Having → as an arbitrary choice,
gcd 𝑒, 𝜑 𝑛 1 while meeting both requirements.

𝑑 𝜑 𝑛
Having → Using the Euclidean algorithm → 𝑑 569.
𝑑𝑒 ≡ 1 mod 𝜑 𝑛

Public key: 713, 29 𝐶 572 mod 713 113


Having → Obtaining
Private key: 713, 569 𝑀 113 mod 713 572

Note that by replacing each exponent by its binary expansion and then using the modular exponentiation algorithm, 𝐶 and 𝑀 were calculated.

ELEE 2110U Discrete Mathematics 59


Example
Suppose in an RSA cryptosystem, we have 𝑝 53 and 𝑞 61. Encrypt 𝑀 1717 to get 𝐶 and then decrypt 𝐶 to get 𝑀 back.

Solution
𝑝 53
Given → 𝑛 𝑝𝑞 3233 → 𝜑 𝑛 𝑝 1 𝑞 1 3120.
𝑞 61

𝑒 𝜑 𝑛 Choosing 𝑒 17
Having → as an arbitrary choice,
gcd 𝑒, 𝜑 𝑛 1 while meeting both requirements.

𝑑 𝜑 𝑛
Having → Using the Euclidean algorithm → 𝑑 2753.
𝑑𝑒 ≡ 1 mod 𝜑 𝑛

Public key: 3233, 17 𝐶 1717 mod 3233 2460


Having → Obtaining
Private key: 3233, 2753 𝑀 2460 mod 3233 1717

Note that by replacing each exponent by its binary expansion and then using the modular exponentiation algorithm, 𝐶 and 𝑀 were calculated.

ELEE 2110U Discrete Mathematics 60


Algorithms

ELEE 2110U Discrete Mathematics 61


Algorithm Requirements
• An algorithm is a finite unambiguous sequence of instructions, set of rules, or number of steps that involves repetition of an operation
or reiteration of a procedure for performing a computation, solving a mathematical problem, or accomplishing some end in a finite
amount of time.
• An algorithm is called optimal for the solution of a problem with respect to a specific operation (e.g., the number of comparisons), if
there is no algorithm for solving this problem using fewer number of operations.
Some of the important requirements for an algorithm are as follows:
• An algorithm has input values from a specified set.
• An algorithm produces the output values from the input values, which are the solution to a problem.
• An algorithm possesses finiteness, that is, it produces the output after a finite number of steps.
• An algorithm possesses definiteness, that is, all steps of the algorithm are precisely defined using unambiguous, well-defined operations.
• An algorithm possesses correctness, that is, it produces correct output values for any set of input values.
• An algorithm possesses effectiveness, that is, it performs each step precisely and in a finite amount of time, and no step can be
impossible to do, such as division by zero.
• An algorithm is well-ordered, as a computer can only execute an algorithm if it knows the exact order of steps to perform.
• An algorithm possesses generality, that is, it should accept any general set of input values.

ELEE 2110U Discrete Mathematics 62


Example
Noting a chessboard (a square board divided into sixty-four alternating dark and light squares) is referred to an 8 8 board,
the total number of squares of all sizes (from the largest square to the smallest squares) in an 𝑛 𝑛 chessboard is as follows:

𝑆 𝑖

Describe the steps of an algorithm that finds the sum 𝑆 for an integer 𝑛 1.

Solution
Noting that this algorithm meets all requirements, the following sequence of steps are required:
1) Input 𝑛.
2) Set 𝑆 0.
3) Set 𝑖 1.
4) Compute 𝑖 𝑖 𝑖.
5) Add 𝑖 to 𝑆.
6) Add 1 to 𝑖.
7) Compare 𝑖 to 𝑛, if 𝑖 𝑛, then output 𝑆 and stop.
8) Go back to step (4).

ELEE 2110U Discrete Mathematics 63


Algorithmic Paradigms (1)
An algorithmic paradigm is an abstraction higher than the notion of an algorithm. An algorithmic paradigm is a generic model, based on a
particular approach, which underlies the design of a class of algorithms for solving a multitude of problems.

Brute-force algorithms: The brute-force algorithm is a simple algorithm in concept that blindly iterates all possible solutions to search for
one or more than one solution that may solve a problem without any regard to the heavy computational requirements. It takes an inefficient
approach for solving problems as it does not take advantage of the special structure of the problem. Examples include using all possible
permutations of numbers to open a safe, finding the largest number in a list of numbers, sorting problems, such as the bubble, insertion, and
selection sorts, and polling a multitude of communication devices to determine those having messages to transmit.

Divide-and-conquer algorithms: The divide-and-conquer algorithm is an effective algorithm that works by recursively breaking down a
problem into two or more subproblems of the same or related type, until these become simple enough to be solved directly and rather easily.
The solutions to the subproblems are then combined to give a solution to the original problem. Examples include sorting problems, such as
quicksort and merge sort, binary search, solving the closest pair problem, routing mail by sorting letters into separate bags for different
geographical areas, and applying the law of total probability.

ELEE 2110U Discrete Mathematics 64


Algorithmic Paradigms (2)
Backtracking algorithms: The backtracking algorithm incrementally builds candidates to the solutions, and abandons a candidate, i.e.,
backtracks, as soon as it determines that the candidate cannot possibly be a part of a valid solution. It is generally applied to find solutions
to some constrained optimization problems. Examples include the eight queens puzzle that asks for all arrangements of eight chess queens
so that no queen attacks any other, crosswords, Sudoku, knapsack problem, and finding spanning trees.

Dynamic programming: It is an algorithm that can be effectively used for solving a complex problem by recursively breaking down the
problem. It requires that overlapping subproblems exist and the optimal solution of the problem can be obtained using optimal solutions of
its subproblems stored in memory with the help of a recurrence relation. Examples include scheduling problem, Fibonacci numbers, matrix
chain multiplication, and travelling salesman problem.

Probabilistic algorithms: The probabilistic algorithm can solve problems that cannot be easily solved by deterministic algorithms. In
contrast to a deterministic algorithm, which always follows the same steps for a given input and has to go through a very large number of
possible cases, the probabilistic algorithm makes some random choices at some steps, which may lead to different output in much fewer
steps, but with a tiny probability that the final answer may not be correct. Examples may include Monte Carlo algorithm in quality control,
collisions in hashing functions, and Bayesian spam filters.

ELEE 2110U Discrete Mathematics 65


Greedy Algorithm
• The greedy algorithm is one of the simplest and most intuitive algorithms that is used in optimization problems, and often
leads to an optimal solution.
• The algorithm makes the optimal choice at each step as it attempts to find the minimum or maximum value of some
parameter.
• Greedy algorithms sometimes fail to produce optimal solutions because they do not consider all the data, as the choice
made by a greedy algorithm may depend on choices it has made so far, but it is not aware of future choices it could make.
• A greedy algorithm in a shortsighted manner identifies an optimal subproblem in the problem.
• With the goal of minimizing or maximizing the parameter of interest, create an iterative way to go through all of the
subproblems so as to build a solution.
• Examples may include finding the shortest path through a graph and a Huffman code used in lossless digital compression
of data.

ELEE 2110U Discrete Mathematics 66


Example
Use the greedy algorithm to find an optimal solution in the following case
Use the least number of coins to make 92 cents change with quarters, dimes, nickels, and pennies.

Solution
In this case, the greedy algorithm produces an optimal solution. To make change for 92 cents for the least number of coins,
the focus at any step is on the largest possible coin, that is, on quarters, dimes, nickels, and pennies, respectively.
First, three quarters are selected, leaving 17 cents, next, one dime is selected, leaving 7 cents, followed by a nickel, leaving 2
cents, and finally by 2 pennies.
The total number of coins is thus 7 3 1 1 2 , as 92 3 25 1 10 1 5 2 1 .

ELEE 2110U Discrete Mathematics 67


Example
Use the greedy algorithm to find an optimal solution in the following case: Determine the path with the largest sum in the
following figure:

Solution
In this case, the greedy algorithm does not produce an optimal solution. The greedy algorithm fails to find the largest sum,
simply because it makes decisions based only on the information it has at any one step, without regard to the overall
problem. In order to reach the largest sum, at each step, the greedy algorithm chooses what appears to be the optimal
immediate choice.
It therefore chooses 30 instead of 20 at the second step, and thus does not reach the best solution, which is 100 10
20 70 , and it mistakenly finds 90 10 30 50 as the largest sum.
ELEE 2110U Discrete Mathematics 68
Complexity of Algorithms
The two main measures for the computational complexity of an algorithm are as follows:
 Space complexity: It is measured by the maximum amount of computer memory needed in the execution of the algorithm and the
requirement is frequently a multiple of the data size.
 Time complexity: It is measured by counting the number of key operations using the size of the input as its argument.
The term complexity generally refers to the running time of the algorithm. The function 𝑓 𝑛 representing the time complexity of an
algorithm is measured by the following two factors:
 The size 𝑛 of the input data and the characteristics of the particular input data.
 The number of basic key operations that must be performed when the algorithm is executed, while noting they generally include
addition, subtraction, multiplication, division, and comparison.
There are typically two types of time complexity to analyze:
 The average-case time complexity, i.e., the expected value of 𝑓 𝑛 , is usually difficult to analyze, and it is generally assumed that the
distribution of the possible inputs is uniform, when the actual distribution is unknown and the uniform distribution may not actually
apply to real situations.
 The worst-case time complexity, i.e., the maximum value of 𝑓 𝑛 , is easier than the average-case complexity to analyze, as this
complexity is based on the largest number of operations required, as a solution for any possible input is guaranteed.

ELEE 2110U Discrete Mathematics 69


Measuring Algorithm Efficiency
Algorithmic efficiency is a property of an algorithm which relates to the amount of computational resources used by the
algorithm. An algorithm must be analyzed to determine its resource usage, and the efficiency of an algorithm can be
measured based on the usage of different resources.
The asymptotic growth of functions is commonly used in the analysis of algorithms to estimate the run time and the amount
of memory they require. It is very important to provide approximations that make it easy to estimate the large-scale
differences in algorithmic efficiency, while ignoring differences of a constant factor and differences that occur only for small
sets of input data.
The estimates of resources required by an algorithm are represented by the big-Oh (𝑂), big-Omega (Ω), and big-Theta (Θ)
notations without being concerned about constant multipliers or smaller order terms. Note that the notations 𝑓 𝑥
𝑂 𝑔 𝑥 ,𝑓 𝑥 Ω 𝑔 𝑥 , and 𝑓 𝑥 Θ 𝑔 𝑥 all stand for collections of functions. Hence, the equality sign does not
mean equality of functions.
Moreover, as we are dealing with functions representing complexity, these functions take on only positive values. Therefore,
all references to absolute values can be dropped for such functions.

ELEE 2110U Discrete Mathematics 70


Big- notation
The growth of a function representing the complexity of an algorithm can be estimated using the big-𝑂 notation, as its input grows.
Let 𝑓 𝑥 and 𝑔 𝑥 be real-valued functions defined on the same set of nonnegative real numbers. Then 𝑓 𝑥 is 𝑂 𝑔 𝑥 , read as 𝑓 𝑥 is
big-Oh of 𝑔 𝑥 , if there are real constants 𝐶 and 𝑘 such that |𝑓 𝑥 | 𝐶|𝑔 𝑥 |, whenever 𝑥 𝑘.
This definition indicates that 𝑓 𝑥) grows slower than some fixed multiple of 𝑔 𝑥 as 𝑥 grows slowly without bound. However, the rate of
growth of multiple of 𝑔 𝑥 should be preferably close to the rate of growth of 𝑓 𝑥 , where 𝑔 𝑥 provides an upper bound for the size of
𝑓 𝑥 for large values of 𝑥.
The constants 𝐶 and 𝑘 are called witnesses to the relationship 𝑓 𝑥 is 𝑂 𝑔 𝑥 , and are not unique. Although there are infinitely many pairs
of witnesses, we need only one pair of witnesses. The approach to find a pair of witnesses is to first find a value of 𝑘 for which the size of
|𝑓 𝑥 | can be easily estimated when 𝑥 𝑘, and then find a value of 𝐶 for which |𝑓 𝑥 | 𝐶|𝑔 𝑥 | when 𝑥 𝑘. In short, if, for a
sufficiently large value of 𝑥, the values of 𝑓 𝑥 are less than those of a multiple of 𝑔 𝑥 , then 𝑓 𝑥 is 𝑂 𝑔 𝑥 .
When 𝑥 is a very large positive integer, the order functions satisfy the following relationships:

𝑂 1 𝑂 log 𝑥 𝑂 𝑥 𝑂 𝑥 log 𝑥 𝑂 𝑥 𝑂 2 𝑂 𝑥! 𝑂 𝑥 .

ELEE 2110U Discrete Mathematics 71


Example (1)
Show that 𝑓 𝑥 𝑥 3𝑥 3𝑥 1 is 𝑂 𝑥 for three pairs of witnesses.

Solution
If we choose 𝑘 1, i.e., 𝑥 1, we then have 3𝑥 3𝑥 3𝑥 and 𝑥 1, where these inequalities are obtained by
multiplying both sides of 𝑥 1 by appropriate terms. An upper bound on 𝑓 𝑥 is thus as follows:

0 𝑥 3𝑥 3𝑥 1 𝑥 3𝑥 3𝑥 𝑥 8𝑥 → 𝐶 8.

If we choose 𝑘 2, i.e., 𝑥 2, we have 𝑥 3𝑥 , 𝑥 𝑥 3𝑥, and 1, where these inequalities are obtained by
multiplying both sides of 𝑥 2 by appropriate terms. An upper bound on 𝑓 𝑥 is thus as follows:

3 3 1 27 27
0 𝑥 3𝑥 3𝑥 1 𝑥 𝑥 𝑥 𝑥 𝑥 → 𝐶 .
2 4 8 8 8

If we choose 𝑘 3, i.e., 𝑥 3, we have 𝑥 3𝑥 , 𝑥 3𝑥, and 1, where these inequalities are obtained by
multiplying both sides of 𝑥 3 by appropriate terms. An upper bound on 𝑓 𝑥 is thus as follows:

1 1 64 64
0 𝑥 3𝑥 3𝑥 1 𝑥 𝑥 𝑥 𝑥 𝑥 → 𝐶 .
3 27 27 27
ELEE 2110U Discrete Mathematics 72
Example (2)
Show that 𝑓 𝑥 𝑥 3𝑥 3𝑥 1 is 𝑂 𝑥 for three pairs of witnesses.

Solution
𝑓 𝑥 𝑂 𝑥 for all these three pairs of witnesses.

ELEE 2110U Discrete Mathematics 73


Example
Give a big-𝑂 estimate for 𝑓 𝑛 𝑎𝑛 log 𝑛! 𝑛 𝑎 log 𝑛 𝑎 , where 𝑎 1 is a real number and 𝑛 1 is an integer.

Solution
We have
𝑎𝑛 log 𝑛! 𝑎𝑛 log 1 2 ... 𝑛 𝑎𝑛 log 𝑛 𝑛 ... 𝑛 𝑎𝑛 log 𝑛 𝑎𝑛 log 𝑛 .

If we choose 𝑛 𝑎 1, i.e., 𝑘 𝑎 1, we then have

𝑛 𝑎 log 𝑛 𝑎 𝑛 𝑎 log 𝑛 𝑎𝑛 𝑛 𝑎 log 1 𝑎 𝑛 𝑛 𝑎 log 1 𝑎 log 𝑛


𝑛 𝑎 log 1 𝑎 2 log 𝑛 𝑛 𝑎 log 𝑛 2 log 𝑛 𝑛 𝑎 3 log 𝑛 2𝑛 3 log 𝑛 6𝑛 log 𝑛 .

We therefore have
𝑓 𝑛 𝑎𝑛 log 𝑛! 𝑛 𝑎 log 𝑛 𝑎 𝑎𝑛 log 𝑛 6𝑛 log 𝑛 𝑎𝑛 6𝑛 log 𝑛 𝑎 6 𝑛 log 𝑛
𝑂 𝑛 log 𝑛 → 𝐶 𝑎 6.

ELEE 2110U Discrete Mathematics 74


Big- Notation
Let 𝑓 𝑥 and 𝑔 𝑥 be real-valued functions defined on the same set of nonnegative real numbers.
Then 𝑓 𝑥 is Ω 𝑔 𝑥 , read as 𝑓 𝑥 is big-Omega of 𝑔 𝑥 , if there are real constants 𝐶 and 𝑘 such that |𝑓 𝑥 | 𝐶|𝑔 𝑥 |,
whenever 𝑥 𝑘.
This definition indicates 𝑔 𝑥 provides a lower bound for the size of 𝑓 𝑥 for large values of 𝑥. Note that 𝑓 𝑥 is Ω 𝑔 𝑥 if

and only if 𝑔 𝑥 is 𝑂 𝑓 𝑥 .
In short, if, for sufficiently large value of 𝑥, the values of 𝑓 𝑥 are greater than those of a multiple of 𝑔 𝑥 , then 𝑓 𝑥 is
Ω 𝑔 𝑥 .

ELEE 2110U Discrete Mathematics 75


Example
Give a big-Ω estimate for 𝑓 𝑥 , if 𝑥 0.

Solution
For 𝑥 1, we have

15 𝑥 2𝑥 9 15 𝑥 2𝑥 2 30 𝑥 𝑥 1
30 𝑥.
𝑥 1 𝑥 1 𝑥 1

The function 𝑓 𝑥 is Ω 𝑥 with 𝑥 1 and 𝐶 30.

ELEE 2110U Discrete Mathematics 76


Big- Notation
Let 𝑓 𝑥 and 𝑔 𝑥 be real-valued functions defined on the same set of nonnegative real numbers. Then 𝑓 𝑥 is Θ 𝑔 𝑥 ,

read as 𝑓 𝑥 is big-Theta of 𝑔 𝑥 , if 𝑓 𝑥 is 𝑂 𝑔 𝑥 and 𝑓 𝑥 is Ω 𝑔 𝑥 .


This definition indicates 𝑔 𝑥 provides a lower bound as well as an upper bound for the size of 𝑓 𝑥 for large values of 𝑥.
Note that 𝑓 𝑥 is Θ 𝑔 𝑥 if and only if there are real numbers 𝐶 and 𝐶 and a positive real number 𝑘 such that 𝐶 |𝑔 𝑥 |
|𝑓 𝑥 | 𝐶 |𝑔 𝑥 |, wherever 𝑥 𝑘.
In short, if, for sufficiently large value of 𝑥, the values of 𝑓 𝑥 are bounded both above and below by those of a multiple of
𝑔 𝑥 , then 𝑓 𝑥 is Θ 𝑔 𝑥 .

ELEE 2110U Discrete Mathematics 77


Example
Give a big-Θ estimate for 𝑓 𝑥 5𝑥 10𝑥 log 𝑥, if 𝑥 0.

Solution
Assuming 𝑥 1, we have the following:

𝑥 log 𝑥 0 → 10𝑥 10𝑥 . log 𝑥 0 → 5𝑥 10𝑥 5𝑥 10𝑥 log 𝑥 5𝑥 → 15𝑥 𝑓 𝑥 5𝑥 .

Consequently, 5𝑥 10𝑥 log 𝑥 is Θ 𝑥 , where 𝐶 5 and 𝐶 15, for 𝑘 1.

ELEE 2110U Discrete Mathematics 78


Sorting Algorithms (1)
The process of arranging a collection of database entries into a sequence that conforms to the order of their keys is called sorting.
• The bubble sort is a simple, but not a very efficient, sorting algorithm. In the bubble sort, smaller elements bubble to the top and larger
elements sink to the bottom. It successively compares adjacent elements in the list and swaps them if they are not in the right order. The
first element is compared with the second element, interchange them if the second element is smaller than the first one, otherwise no
swapping is done. Then the current second element is compared with the third element, interchange them if the third element is smaller
than the second one. This process of interchanging a larger element with a smaller one following it starts with the first element and
continues to the last element, for a full pass. This procedure is repeated through several passes until the sort is complete.
• The insertion sort is a simple sorting algorithm that builds the final sorted list one element at a time. It is less efficient than most sorting
algorithms, unless the number of elements in the list is modest, say about 50 or less. The insertion sort begins with the second element
and compares it with the first element and inserts it before the first element if it does not exceed the first element and after the first
element otherwise. Then the third element is compared with the first element and if it is larger than the first element, it is compared with
the second element, and it is inserted in the correct position among the first three elements. The insertion sort iterates through the list
and removes one element per iteration, finds the place for which the element belongs to, and then places it there. The resulting list
after 𝑘 iterations has the property where the first 𝑘 1 elements are sorted.

ELEE 2110U Discrete Mathematics 79


Sorting Algorithms
• The merge sort, a recursive sorting algorithm, focuses on how to merge together two presorted lists such that the resulting list is also
sorted. A merge sort proceeds by iteratively splitting lists into two sublists of equal or almost equal number of elements until each sublist
contains one element, a list of one element is considered sorted. Then successively merges pairs of sublists, where both sublists are in
increasing order to produce a new larger sublist with elements in increasing order. This continues until the original list is put into
increasing order.
• The quicksort is an efficient sorting algorithm employing a divide-and-conquer strategy. It begins by selecting a pivot element, usually
the first element from the list, and partitioning the other elements into two sublists. One sublist consists of all elements in the list less
than the pivot and the other consists of all elements greater than the pivot. Then the pivot is put at the end of the first list as its final
resting place. The two sublists are then recursively sorted until all sublists contain only one element. The sorted list can then be obtained
by combining the sublists of one item in the order they occur.
• The selection sort is a very simple, but inefficient, sorting algorithm. The algorithm proceeds by finding the smallest element in the
unsorted list, and moves it to the top of the sorted list. Then the least element among the remaining elements of the unsorted list is found
and moves to the second position of the ordered list. This procedure is repeated until the entire list has been sorted. The selection sort
requires at 𝑛 1 comparisons to select the smallest element and swap it to make it into the first position, and 𝑛 2 comparisons to
select the second smallest element and swap it, and so on.

ELEE 2110U Discrete Mathematics 80


Example (1)
Sort the list 7, 6, 1, 9, 5 using the following sorting algorithms:
(a) Bubble sort. (b) Insertion sort. (c) Merge sort. (d) Quicksort. (e) Selection sort.

Solution
(a) In each step of a pass, elements in boldface are being compared.
𝟕, 𝟔, 1, 9, 5 𝟔, 𝟏, 7, 5, 9 𝟏, 𝟔, 5, 7, 9 𝟏, 𝟓, 6, 7, 9
6, 𝟕, 𝟏, 9, 5 1, 𝟔, 𝟕, 5, 9 1, 𝟔, 𝟓, 7, 9 1, 𝟓, 𝟔, 7, 9
1 pass  6, 1, 𝟕, 𝟗, 5, 2 pass  1, 6, 𝟕, 𝟓, 9, 3rd pass 
st nd 1, 5, 𝟔, 𝟕, 9, 4th pass  1, 5, 𝟔, 𝟕, 9
6, 1, 7, 𝟗, 𝟓 1, 6, 5, 𝟕, 𝟗 1, 5, 6, 𝟕, 𝟗 1, 5, 6, 𝟕, 𝟗
6, 1, 7, 5, 9 1, 6, 5, 7, 9 1, 5, 6, 7, 9 1, 5, 6, 7, 9
Note that the bubble sort needs one whole pass, i.e., the fourth pass, without any swap to know it is sorted.
(b) The insertion sort begins with 6 and compares it with 7. It inserts it before 7 as it does not exceed 7. Then, 1 is compared with 6 as it is
smaller than 6, it is inserted before 6. Next, 9 is compared with 1, as it is larger than 1, it is compared with 6, as it is larger than 6, it is
compared with 7, as it is larger than 7, it is inserted after 7. Lastly, 5 is compared with 1, as it is larger than 1, it is compared with 6, as it is
smaller than 6, it is inserted after 1 and before 6. Note that the following shows the required steps, where the element under consideration in
each step is in boldface:
7, 𝟔, 1, 9, 5  6, 7, 𝟏, 9, 5  1, 6, 7, 𝟗, 5  1, 6, 7, 9, 𝟓  1, 5, 6, 7, 9.
ELEE 2110U Discrete Mathematics 81
Example (2)
(c) As shown, the merge sort, where the top part is the split and the bottom part is the merge
(d) Employing the quicksort, the first element, i.e., 7, is selected, and we partition the other
elements into two sublists. The first sublist consists of all elements in the list less than 7, that
is, 6, 1, 5, and the other consists of all elements greater than 7, that is, 9. Then 7 is put at the
end of the first sublist as its final resting place. The two sublists are then recursively sorted
the same way, that is, 6 is selected in the first sublist and the other elements in that sublist are
compared with 6, i.e., 1, 5, and 9 is selected in the second sublist. Note that the following
shows the required steps, where the element under consideration in each step is in boldface:
𝟕, 6, 1, 9, 5  𝟔, 1, 5, 7, 9  𝟏, 5, 6, 7, 9  1, 5, 6, 7, 9.
(e) The selection sort finds 1 as it is the smallest element in the unsorted list, and moves it
to the top of the sorted list. Then, the least element among the remaining elements of
the unsorted list, that is, 5, is found and moves to the second position of the ordered list. This
procedure is repeated until the entire list has been sorted. Note that the following shows the
required steps, where the element under consideration in each step is in boldface:
7, 6, 1, 9, 5  𝟏  1, 𝟓  1, 5, 𝟔  1, 5, 6, 𝟕  1, 5, 6, 7, 𝟗  1, 5, 6, 7, 9.

ELEE 2110U Discrete Mathematics 82


Search Algorithms
A search algorithm is an algorithm that involves a search problem. Searching a database employs a systematic procedure to find an entry with a key
designated as the objective of the search. A search algorithm locates an element 𝑥 in a list of distinct elements or determines that it is not in the list.
The solution to the search is either the location of the element 𝑥 in the list or 0 if 𝑥 is not on the list.
The linear search, also known as the sequential search, is the simplest search algorithm. It is an algorithm, based on the brute-force algorithmic
paradigm, that scans the elements of a list in sequence in search of 𝑥, the element that needs to be located. A comparison is made between 𝑥 and the
first element in the list, if they are the same, then the solution is 1. Otherwise, a comparison is made between 𝑥 and the second element in the list, if
they are the same, then the solution is 2. This process continues until a match is found and the solution is the location of the element sought. If no
match is found, then the solution is 0. Linear search is applied on unsorted or unordered lists consisting of small number of elements.
The list of data in a binary search must be in a sorted order for it to work. This search algorithm, which is quite effective in large sorted array, is based
on the divide-and-conquer algorithmic paradigm. A binary search works by comparing the element to be searched with the element in the middle of
the array of elements. If we get a match, the position of the middle element is returned. If the target element is less than the middle element, the search
continues in the upper half of the array, that is, the target element is compared to the element in the middle of the upper subarray, and the process
repeats itself. If the target element is greater than the middle element, the search continues in the lower half of the array, that is, the target element is
compared to the element in the middle of the lower subarray, and the process repeats itself. By doing this, the algorithm eliminates the half in which
the target element cannot lie in each iteration.

ELEE 2110U Discrete Mathematics 83


Example
Consider an array consisting of these integers: 2, 3, 5, 7, 23, 19, 17, 13, 11, 29, 31, 37. (a) Use the linear search to find 17. (b) Use the
binary search to find 17.

Solution
(a) The first element of the array, that is, 2 is compared with 17, as they are not the same, 3 is compared with 17, as they are not the same, 5
is compared with 17, this process continues until 17 which is in the list is found. Then, the solution is 7, as 7 is the location of 17 in the list.
(b) In order to apply the binary search, we first need to sort the list. The sorted list, in an ascending order, is then as follows: 2, 3, 5, 7, 11,
13, 17, 19, 23, 29, 31, 37. As the number of integers in the list is twelve, there is no middle integer. Therefore, the sorted list is split into two
sublists each consisting of 6 integers, namely, 2, 3, 5, 7, 11, 13 and 17, 19, 23, 29, 31, 37. Then, compare 17 and the largest integer in the
first list. Because 17 13, the search for 17 must be restricted to the second sublist, namely 17, 19, 23, 29, 31, 37. Next, we split this
sublist into two smaller sublists, each with three integers, namely, 17, 19, 23 and 29, 31, 37. Then, compare 17 and the largest integer in the
first sublist. Because 23 17, the search for 17 can be restricted to the first sublist. Next, we compare 17 to the middle integer in this
sublist, namely 19, as 19 17, we split this sublist into two integers, one smaller than 19, i.e., 17, and the other larger than 19, i.e., 23. The
search has been narrowed down to one term, we thus compare 17 and 17, and 17 is thus located in the sorted list.

ELEE 2110U Discrete Mathematics 84


Sets, Functions & Relations

ELEE 2110U Discrete Mathematics 1


Sets

ELEE 2110U Discrete Mathematics 2


Set Theory
• The concept of set is basic to all of mathematics and mathematical applications, as almost all mathematical objects are
first of all sets, regardless of any additional properties they may possess.
• According to Greg Cantor, the founder of set theory, a set is a many that allows itself to be thought of as a one.
• Our focus is on naïve set theory, which is based on Cantor’s intuitive notion of an object and a set as defined informally
in natural language, rather than on axiomatic set theory, which is based on the rules of inference provided by formal
logic.

ELEE 2110U Discrete Mathematics 3


Set Definition
• A set is an unordered collection of distinct objects that are called elements or members of the set.
• It is essential to have a clear and rigorous definition of a set.
• Examples: “smart children in a town” does not form a set as the word “smart” does not have a universally agreeable
definition and its membership is debatable, whereas “pregnant women in a town” does form a well-defined set.
• It is common to use capital letters, such as 𝐴, to denote sets, and lowercase letters, such as 𝑥, to refer to set elements.
• If 𝑥 is an element of the set 𝐴, or equivalently 𝑥 belongs to 𝐴 or 𝐴 contains 𝑥, we use the notation 𝑥 ∈ 𝐴, and if 𝑥 does
not belong to the set 𝐴 or 𝑥 is not an element of 𝐴, we write 𝑥 ∉ 𝐴.
• Examples: If 𝐴 is the set of all capital cities, then Tokyo, denoted by 𝑥, is an element of 𝐴, i.e., 𝑥 ∈ 𝐴, and if 𝐵 is the set
of all European cities, then Tokyo, denoted by 𝑥, is not a member of 𝐵, as Tokyo is an Asian city, we thus have 𝑥 ∉ 𝐵.

ELEE 2110U Discrete Mathematics 4


Set Representation
• A set is generally represented by braces (curly brackets), that is by .
• One way to specify a set is to use the set roaster method by which all the elements of the set are listed between curly
brackets, such as 3, 6, 9 .
• The order of elements presented in a set is immaterial and a set remains the same if its elements are repeated or
rearranged.
• Another way to specify a set is the set builder notation through which some property held only by all members of the set
is clearly described, such as 𝑥 ∈ 𝑷 𝑥 a multiple of 3, 0 𝑥 10 , where the vertical line "|" is read as “such that” and
the comma “,” as “and”, and 𝑷 represents the set of all positive integers.

ELEE 2110U Discrete Mathematics 5


Universal Set
• The universal set, also known as the universe of
discourse, denoted by 𝑈, is defined to include all possible
elements in a given setting and every set under the
𝑼
discussion, the universal set thus varies depending on
which objects are of interest.
• The universal set 𝑈 is usually represented pictorially as the
set of all points within a rectangle, as shown here.

ELEE 2110U Discrete Mathematics 6


Equality of Sets
• Two sets 𝐴 and 𝐵 are equal if and only if they have exactly
the same elements, as shown here.
• We write 𝐴 𝐵 if 𝐴 and 𝐵 are equal sets.
𝑼
• Example: the sets 𝐴 𝑎, 𝑒, 𝑖, 𝑜, 𝑢 and
𝐵 𝑥 ∈ 𝑈 𝑥 is a vowel of the English alphabet
are equal, where 𝑈 is the set of all letters in the English 𝑩 𝑨

alphabet, i.e., 𝐴 𝐵.
• If the sets 𝐴 and 𝐵 are not equal, we then write 𝐴 𝐵.
• Example: the sets 𝐴 𝑥 ∈ 𝑷 | 𝑥 is an odd integer and
𝐵 𝑥 ∈ 𝑷 | 𝑥 is a prime number are not equal, where the
set 𝑷 represents all positive integers, i.e., 𝐴 𝐵.

ELEE 2110U Discrete Mathematics 7


Subset
• The set 𝐵 is a subset of the set 𝐴, and the set 𝐴 is a superset of the set 𝐵, if and only if
every member of 𝐵 is also a member of 𝐴. We use the symbol ⊆ to denote subset,
𝐵 ⊆ 𝐴 thus implies 𝐵 is a subset of 𝐴 or alternatively 𝐵 is contained in 𝐴 or 𝐴 𝑼

contains 𝐵.
• In order to show that 𝐵 is not a subset of 𝐴, that is 𝐵 ⊈ 𝐴, it is only needed to find 𝑨
𝑩
one element 𝑥 ∈ 𝐵 with 𝑥 ∉ 𝐴.
• Every set is a subset of itself as well as a subset of the universal set.
• If 𝐵 ⊆ 𝐴 and 𝐴 ⊆ 𝐶, then 𝐵 ⊆ 𝐶. 
• The set 𝐵 is a proper subset of the set 𝐴 if every member of 𝐵 is also a member of 𝐴,
but there is at least one element of 𝐴 that is not an element of 𝐵. We use the symbol ⊂
to denote proper subset, 𝐵 ⊂ 𝐴 thus implies 𝐵 is a proper subset of 𝐴, as shown here.
• Oftentimes, the terms “subset” and “proper subset” are interchangeable, as it is not
important to differentiate them.

ELEE 2110U Discrete Mathematics 8


Empty Set & Singleton Set
• The empty set or null set, denoted by ∅, is defined as the set with no elements. For instance, the set of human beings who
are older than 200 years is the empty set.
• The empty set is thus a subset of every set. The empty set is unique that is there is exactly one empty set. Therefore, if 𝐴
and 𝐵 are both empty sets, then 𝐴 𝐵, since they have exactly the same elements, namely, none.
• To prove a set 𝐴 is the empty set, first suppose 𝐴 has an element 𝑥 and then derive a contradiction.

• A set with one element is called a singleton set. An example of a singleton set is the set of positive integers that are both
prime and even, i.e., 2 .

ELEE 2110U Discrete Mathematics 9


Disjoint Sets
• The sets 𝐴 and 𝐵 are known as disjoint, if and only if the
sets 𝐴 and 𝐵 have no common elements.
• For instance, the set of odd numbers and the set of even
𝑨
numbers are disjoint. If two sets are disjoint, then neither
is a subset of the other, unless one is the empty set.
• The sets 𝐴 , 𝐴 , … , 𝐴 are mutually disjoint, also known
as pairwise disjoint, if and only if no two sets have any
element in common. For instance, the sets of birds, cars,
𝑩
books, and trees are mutually disjoint.

ELEE 2110U Discrete Mathematics 10


Set Partition
• A partition of a nonempty set 𝐴 is a finite collection of 𝑛 nonempty
subsets, 𝐴 , 𝐴 , … , 𝐴 , that are all pairwise disjoint and every element of
the set 𝐴 belongs to only one of these 𝑛 mutually-exclusive subsets.
𝑼 𝑨
• The nonoverlapping subsets in a partition are called cells or blocks.
• Example: The set of letters in an English word can be partitioned into two 𝑨𝟏 𝑨𝒏
𝑨𝟐
nonempty mutually exclusive subsets of vowels and consonants. 𝑨𝟑 𝑨𝒏 𝟏

• Example: The population of a country can be partitioned into three 𝑨𝟕



𝑨𝟒 𝑨𝒏 𝟐
nonempty mutually exclusive subsets, children who are younger than 18 𝑨𝟔 𝑨𝟓

years of age, senior citizens who are at least 65 years old, and those adults
who are at leats18 years old but younger than 65 years of age.

ELEE 2110U Discrete Mathematics 11


Set Operation: Union
The union of two sets 𝐴 and 𝐵, denoted by 𝐴 ∪ 𝐵, is the set of all elements that are in 𝐴 or in 𝐵 or in both.

𝐴 ∪ 𝐵 ≜ 𝑥 ∈ 𝑈 | 𝑥 ∈ 𝐴 or 𝑥 ∈ 𝐵

Note “or” is used in the sense of “and” and “or.”

ELEE 2110U Discrete Mathematics 12


Set Operation: Intersection
The intersection of two sets 𝐴 and 𝐵, denoted by 𝐴 ∩ 𝐵, is the set of all elements that contain in both 𝐴 and 𝐵.

𝐴 ∩ 𝐵 ≜ 𝑥 ∈ 𝑈 | 𝑥 ∈ 𝐴 and 𝑥 ∈ 𝐵

The intersection of two disjoint sets 𝐴 and 𝐵 is thus the empty set, i.e., 𝐴 ∩ 𝐵 ∅.

ELEE 2110U Discrete Mathematics 13


Set Operation: Difference
The difference of sets 𝐴 and 𝐵 (or the relative complement of 𝐵 with respect to 𝐴), denoted by 𝐴 𝐵 or 𝐴\𝐵, is the set of
elements in 𝐴 that are not in 𝐵.

𝐴 𝐵 ≜ 𝑥 ∈ 𝑈 | 𝑥 ∈ 𝐴 and 𝑥 ∉ 𝐵

The set 𝐴 𝐵, read as “𝐴 minus 𝐵, is different from the set 𝐵 𝐴.

ELEE 2110U Discrete Mathematics 14


Set Operation: Complement
The absolute complement or, simply, complement of a set 𝐴, with respect to the universal set 𝑈, denoted by 𝐴 or 𝐴̅, is the
set of all elements that are not in 𝐴.
𝐴 𝐴̅ ≜ 𝑥 ∈ 𝑈 | 𝑥 ∉ 𝐴

The complement of the universal set is the empty set, and vice versa.

𝑨𝒄

ELEE 2110U Discrete Mathematics 15


Set Operation: Symmetric Difference
The symmetric difference of sets 𝐴 and 𝐵, denoted by 𝐴⨁𝐵 or 𝐴∆𝐵, consists of those elements which belong to 𝐴 or 𝐵 but
not to both.

𝐴⨁𝐵 𝐴∆𝐵 ≜ 𝑥 ∈ 𝑈 | 𝑥 ∈ 𝐴, 𝑥 ∉ 𝐵 or 𝑥 ∉ 𝐴, 𝑥 ∈ 𝐵

ELEE 2110U Discrete Mathematics 16


Example
Suppose the universal set 𝑈 represents all possible outcomes when a typical six-sided cube-shape die is rolled, i.e.,
𝑈 1, 2, 3, 4, 5, 6 . We also define the set 𝐴 representing the odd outcomes and the set 𝐵 representing the outcomes that
are prime. Determine the following sets: 𝐴 ∪ 𝐵, 𝐴 ∩ 𝐵, 𝐴 𝐵, 𝐴 , and 𝐴⨁𝐵.

Solution
We first identify the elements of the sets 𝐴 and 𝐵 from the universal set 𝑈, and then perform the required set operations:

𝐴∪𝐵 1, 2, 3, 5
𝐴∩𝐵 3, 5
𝐴 1, 3, 5
𝑈 1, 2, 3, 4, 5, 6 → → 𝐴 𝐵 1
𝐵 2, 3,5
𝐴 2, 4, 6
𝐴⨁𝐵 1, 2

ELEE 2110U Discrete Mathematics 17


Example
Suppose the universal set 𝑈 represents all positive integers less than or equal to 20, i.e., we have 𝑈 1, 2, … , 20 . We also
define the set 𝐴 representing the positive integers that are divisible by 3, the set 𝐵 representing the positive integers that are
divisible by 4, and the set 𝐶 representing the positive integers that are divisible by 6. Determine the following sets: 𝐴 ∪ 𝐵 ∪
𝐶, 𝐴 ∩ 𝐵 ∩ 𝐶, 𝐴 ∪ 𝐵 ∩ 𝐶, and 𝐴 ∪ 𝐵 ∩ 𝐶 . Comment on the results.

Solution
We first identify the elements of the sets 𝐴, 𝐵, and 𝐶, and then perform the required set operations:

𝐴∪𝐵∪𝐶 3, 4, 6, 8, 9, 12, 15, 16, 18, 20


𝐴 3, 6, 9, 12, 15, 18
𝐴∩𝐵∩𝐶 12
𝑈 1, 2, … , 20 → 𝐵 4, 8, 12, 16, 20 →
𝐴∪𝐵 ∩𝐶 6, 12, 18
𝐶 6, 12, 18
𝐴∪ 𝐵∩𝐶 3, 6, 9, 12, 15, 18

When the set operations are all unions or all intersections, associative law holds. However, when they are a mix of unions
and intersections, associative law does not hold, we therefore have 𝐴 ∪ 𝐵 ∩ 𝐶 𝐴 ∪ 𝐵 ∩ 𝐶 .

ELEE 2110U Discrete Mathematics 18


Special Set of Numbers

ELEE 2110U Discrete Mathematics 19


Set Identities

ELEE 2110U Discrete Mathematics 20


Membership Table
• In set identities, membership tables are used.
• A table that displays the membership of elements in sets is called a membership table, also known as truth table.
• The columns of a membership table must represent the original sets as well as the two sets on both sides of the set
identity, where a 1 is used to indicate an element that is in the set and a 0 is used to indicate an element that is not in the
set.
• There is a great similarity between membership tables in set theory and truth tables in logic.

ELEE 2110U Discrete Mathematics 21


Principle of Duality
• It is a fact of set algebra, called the principle of duality, that the dual of an identity is also an identity, where the dual of
an identity can be obtained by replacing each occurrence of ∪, ∩, 𝑈, and ∅ in the identity by ∩, ∪, ∅, and 𝑈, respectively.
Many of the identities arranged in pairs reflect the principle of duality.

• De Morgan’s laws are prominent set identities that provide a pair of transformation rules. The laws can be expressed as
the complement of the union of two sets is the same as the intersection of their complements and the complement of the
intersection of two sets is the same as the union of their complements. De Morgan’s laws are used when the complements
of sets are easier to define than the sets themselves.

ELEE 2110U Discrete Mathematics 22


Methods to Prove a Set Identity
1) Show each side of the identity is a subset of the other side. This method of proof is known as the element argument. In
other words, to prove 𝑀 𝐾, we need to prove 𝑀 ⊆ 𝐾 and 𝐾 ⊆ 𝑀. This powerful method brings insight into the proof,
but in some cases, this proof method may prove to be rather complex.

2) Transform one side into the other side step by step by employing the other known set identities. This method of proof is
known as the algebraic proof. This is usually the shortest method, provided that there are relevant set identities that can
be applied to simplify the set expressions.

3) Build a membership table step by step for each side of the set identity, and show the columns corresponding to the both
sides of the identity match. This method does not provide any insight into the proof; however, it is a straightforward
method if the number of the original sets in the identity is half a dozen or less, otherwise a computer should be used to
build the membership table of interest.

ELEE 2110U Discrete Mathematics 23


Example
Prove that 𝐴 𝐶 ∩ 𝐵 𝐶 𝐴 ∩ 𝐵 ∩ 𝐶̅ , using the element argument proof.

Solution
The first method is to show that each side of the identity is a subset of the other side.
The first step is to show 𝐴 𝐶 ∩ 𝐵 𝐶 ⊆ 𝐴 ∩ 𝐵 ∩ 𝐶̅ . When 𝑥 ∈ 𝐴 𝐶 ∩ 𝐵 𝐶 , then by definition of
intersection, 𝑥 ∈ 𝐴 𝐶 and 𝑥 ∈ 𝐵 𝐶 . When 𝑥 ∈ 𝐴 𝐶 , then by definition of difference, 𝑥 ∈ 𝐴 and 𝑥 ∉ 𝐶, and when
𝑥∈ 𝐵 𝐶 , then by definition of difference, 𝑥 ∈ 𝐵 and 𝑥 ∉ 𝐶. When 𝑥 ∈ 𝐴 and 𝑥 ∈ 𝐵 and 𝑥 ∉ 𝐶, then by definition of
complement, 𝑥 ∈ 𝐴 and 𝑥 ∈ 𝐵 and 𝑥 ∈ 𝐶̅ . Hence 𝑥 ∈ 𝐴 ∩ 𝐵 ∩ 𝐶̅ by definition of intersection.
The second step is to show 𝐴 ∩ 𝐵 ∩ 𝐶̅ ⊆ 𝐴 𝐶 ∩ 𝐵 𝐶 . When 𝑥 ∈ 𝐴 ∩ 𝐵 ∩ 𝐶̅ , then 𝑥 ∈ 𝐴 ∩ 𝐵 and 𝑥 ∈ 𝐶̅ by
definition of intersection. When 𝑥 ∈ 𝐴 ∩ 𝐵 , then 𝑥 ∈ 𝐴 and 𝑥 ∈ 𝐵 by definition of intersection, and when 𝑥 ∈ 𝐶̅ then 𝑥 ∉
𝐶 by definition of complement. When 𝑥 ∈ 𝐴 and 𝑥 ∈ 𝐵 and 𝑥 ∉ 𝐶, then 𝑥 ∈ 𝐴 𝐶 and 𝑥 ∈ 𝐵 𝐶 by definition of
difference. Hence 𝐴 𝐶 ∩ 𝐵 𝐶 by definition of intersection.

ELEE 2110U Discrete Mathematics 24


Example
Prove that 𝐴 𝐶 ∩ 𝐵 𝐶 𝐴 ∩ 𝐵 ∩ 𝐶̅ , using the algebraic proof.

Solution
The second method is to apply the relevant set identities step by step to make one side equal to the other side, as follows:

𝐴 𝐶 ∩ 𝐵 𝐶 𝐴⋂𝐶̅ ⋂ 𝐵⋂𝐶̅ by the difference equivalence


𝐴 ∩ 𝐵 ∩ 𝐶̅ ⋂𝐶̅ by the associative law
𝐴 ∩ 𝐵 ∩ 𝐶̅ by the idempotent

ELEE 2110U Discrete Mathematics 25


Example
Prove that 𝐴 𝐶 ∩ 𝐵 𝐶 𝐴 ∩ 𝐵 ∩ 𝐶̅ , using membership table.

Solution
The third method is to build a membership table. There are three basic sets 𝐴, 𝐵, and 𝐶 that have been combined to create the
set identity of interest. The presence of an element to any one of these three sets is denoted by 1 and its absence by 0. We
thus have a membership table consisting of 8 2 rows, as shown below. After forming the three columns associated with
the three sets 𝐴, 𝐵, and 𝐶, which are the building sets of the identity, we first form the columns corresponding to the sets
𝐴 𝐶 and 𝐵 𝐶 to construct the column associated
with the set 𝐴 𝐶 ∩ 𝐵 𝐶 , which is the left-hand side
of the identity. We then form the columns corresponding to
the sets 𝐴 𝐵 and 𝐶̅ to construct the column associated
with the set 𝐴 ∩ 𝐵 ∩ 𝐶̅ , which is the right-hand side of the
identity. We notice that because the columns for the sets
𝐴 𝐶 ∩ 𝐵 𝐶 and 𝐴 ∩ 𝐵 ∩ 𝐶̅ are the same, the identity is valid.

ELEE 2110U Discrete Mathematics 26


Cardinality of a Set
• The number of distinct elements in a set 𝐴 is called the cardinality of 𝐴, written as 𝐴 .
• The cardinality of a set, i.e., the size of a set, may be finite or infinite. For instance, we have ∅ 0, as the empty set has
no elements.
• A set with a definite number of elements is defined as a finite set, and it is thus countable. The exact number of elements
in a finite set can be known, such as the set of cards in a deck of playing cards, or unknown, such as the set of lions in the
world.
• A set that is not finite is infinite, an infinite set is either countable or uncountable.
• In a countably infinite set, it is possible to list the elements of the set in a sequence, index by positive integers, such as
the set of all odd numbers.
• In an uncountably infinite set, it is not possible to list the elements of the set in a sequence, index by positive integers,
such as the set of all real numbers between 0 and 1.

ELEE 2110U Discrete Mathematics 27


Power Set
• The set of all subsets of a set 𝐴, which also includes the empty set ∅ and the set 𝐴 itself, is called the power set of 𝐴, and
denoted by 𝑃 𝐴 . If 𝐴 is a finite set, then we have

𝑃 𝐴 2 → 𝐴 |𝑃 𝐴 |.

ELEE 2110U Discrete Mathematics 28


Cartesian Product of Sets
• Given two sets of 𝐴 and 𝐵, the Cartesian product of 𝐴 and 𝐵, denoted by 𝐴 𝐵 and read as 𝐴 cross 𝐵, is the set of all
ordered pairs 𝑎, 𝑏 , where 𝑎 ∈ 𝐴 and 𝑏 ∈ 𝐵.
• The number of ordered pairs in the Cartesian product of 𝐴 and 𝐵 is equal to the product of the number of elements in the
set 𝐴 and the number of elements in the set 𝐵, i.e., 𝐴 𝐵 𝐴 𝐵.
• The Cartesian product of more than two sets can also be defined. The Cartesian product of 𝑛 sets 𝐴 , 𝐴 , …, 𝐴 is the set
of all ordered n-tuples, and symbolically is shown as follows:

𝐴 𝐴 ⋯ 𝐴 𝑎 ,𝑎 ,…,𝑎 | 𝑎 ∈ 𝐴 ,𝑎 ∈ 𝐴 ,…,𝑎 ∈ 𝐴
• The notation for an ordered 𝑛-tuple is a generalization of the notation for an ordered pair, and it takes both order and
multiplicity into account.
• A subset 𝑅 of the Cartesian product 𝐴 𝐵 is called a relation from the set 𝐴 to the set 𝐵. The elements of 𝑅 are ordered
pairs, where the first element belongs to 𝐴 and the second to 𝐵. As relations are important, a later chapter will be
exclusively devoted to the topic of relations. In general, we have 𝐴 𝐵 𝐵 𝐴, unless 𝐴 ∅ or 𝐵 ∅ or 𝐴 𝐵.

ELEE 2110U Discrete Mathematics 29


Example
(a) Suppose 𝑋 3, 6, 9 , determine the power set of set 𝑋.
(b) Suppose 𝐴 1, 2, 3 , 𝐵 𝑎, 𝑏 , and 𝐶 1, # , determine the Cartesian products 𝐴 𝐵 𝐶 and 𝐴 𝐶 𝐵.
Comments on the results.

Solution
(a) Since we have 𝑋 3, we have 𝑃 𝑋 2 8. 𝑃 𝑋 is thus a set with the following eight subsets:
𝑃 𝑋 ∅, 3 , 6 , 9 , 3, 6 , 3, 9 , 6, 9 , 3, 6, 9
(b) We thus have
𝐴 𝐵 𝐶 1, 𝑎, 1 , 1, 𝑎, # , 1, 𝑏, 1 , 1, 𝑏, # ,
2, 𝑎, 1 , 2, 𝑎, # , 2, 𝑏, 1 , 2, 𝑏, # ,
3, 𝑎, 1 , 3, 𝑎, # , 3, 𝑏, 1 , 3, 𝑏, #
and
𝐴 𝐶 𝐵 1,1, 𝑎 , 1,1, 𝑏 , 1, #, 𝑎 , 1, #, 𝑏 ,
2,1, 𝑎 , 2,1, 𝑏 , 2, #, 𝑎 , 2, #, 𝑏 ,
1,1, 𝑎 , 1,1, 𝑏 , 1, #, 𝑎 , 1, #, 𝑏

Each of these two Cartesian products is a set consisting of 12 3 2 2 ordered triples. However, the resulting two sets
are different, i.e., 𝐴 𝐵 𝐶 𝐴 𝐶 𝐵, as both order and multiplicity matter.
ELEE 2110U Discrete Mathematics 30
Principle of Inclusion-Exclusion
• The cardinality of the union of two finite sets 𝐴 and 𝐵 can be found using the principle of inclusion-exclusion, as
reflected below:

𝐴∪𝐵 𝐴 𝐵 |𝐴 ∩ 𝐵|

• 𝐴 |𝐵| counts each element that is in set 𝐴 but not in set 𝐵 once and in set 𝐵 but not in set 𝐴 once, and each element
that is in both sets 𝐴 and 𝐵 exactly twice. The number of elements that are in both 𝐴 and 𝐵, i.e., |𝐴 ∩ 𝐵|, is subtracted
from 𝐴 |𝐵| so as to count the elements in the intersection only once. If the sets 𝐴 and 𝐵 are disjoint, then we have
𝐴∪𝐵 ≜ 𝐴 𝐵.
• The principle of inclusion-exclusion can be extended to 𝑛 sets 𝐴 , 𝐴 , … , 𝐴 , as reflected below:

𝐴 ∪ 𝐴 ∪ ⋯∪ 𝐴 𝐴 𝐴 ∩𝐴 𝐴 ∩𝐴 ∩𝐴 ⋯ 1 𝐴 ∩ 𝐴 ∩ ⋯∩ 𝐴

• In general, for 𝑛 sets, where 𝑛 is a positive integer, the principle of inclusion-exclusion has a maximum of 2 1 terms.
However, some of these terms may be zero, as it is possible that some of the 𝑛 sets are mutually exclusive.

ELEE 2110U Discrete Mathematics 31


Example
Give formulas for the number of elements in the union of three sets as well as in the union of four sets.

Solution
As highlighted below, the formula for three sets contains 7 2 1 different terms and that for four sets contains
15 2 1 different terms:

𝐴 ∪𝐴 ∪𝐴 𝐴 𝐴 𝐴 𝐴 ∩𝐴 𝐴 ∩𝐴 𝐴 ∩𝐴 𝐴 ∩𝐴 ∩𝐴
and
𝐴 ∪𝐴 ∪𝐴 ∪𝐴
𝐴 𝐴 𝐴 𝐴 𝐴 ∩𝐴 𝐴 ∩𝐴 𝐴 ∩𝐴 𝐴 ∩𝐴 𝐴 ∩𝐴 𝐴 ∩𝐴
𝐴 ∩𝐴 ∩𝐴 𝐴 ∩𝐴 ∩𝐴 𝐴 ∩𝐴 ∩𝐴 𝐴 ∩𝐴 ∩𝐴 𝐴 ∩𝐴 ∩𝐴 ∩𝐴

ELEE 2110U Discrete Mathematics 32


Computer Representation of Sets
• Various set operations can be implemented using a computer. Although the members of a set have inherently no order, an
order is imposed to make computing combinations of sets easy. Suppose that the universal set 𝑈 is finite whose number
of elements 𝑛 is not larger than the memory size of the computer being used.
• In computer representation of sets, the elements are represented by the bits 0 and 1, where the universal set 𝑈 is an array
with 𝑛 bits, i.e., 𝑎 , 𝑎 , … , 𝑎 , each containing a 1, and a subset 𝐴 of 𝑈 is an array with 𝑛 bits, where the 𝑖 bit in this
string is 1 if 𝑎 belongs to 𝐴 and is 0 if 𝑎 does not belong to 𝐴.
• The sets are represented by an array of bits, and there is a one-to-one correspondence between set operations and parallel
logic operations on their representation.

ELEE 2110U Discrete Mathematics 33


Representation of Subsets by Bit Strings

ELEE 2110U Discrete Mathematics 34


Example
With the universal set 𝑈 consisting of the first eight positive integers, consider the set 𝐴 consisting of even integers less than
9 and the set 𝐵 consisting of integers less than 9 that are divisible by 3. Determine the bit sequences representing the union,
intersection, difference, and symmetric difference of sets 𝐴 and 𝐵.

Solution
We first determine the sets 𝑈, 𝐴, and 𝐵, and then obtain their computer representations, as follows:

𝑈 1, 2, 3, 4, 5, 6, 7, 8 → 𝑈 1, 1, 1, 1, 1, 1, 1, 1
𝐴 2, 4, 6, 8 → 𝐴 0, 1, 0, 1, 0, 1, 0, 1
𝐵 3, 6 → 𝐵 0, 0, 1, 0, 0, 1, 0, 0

The bit sequences representing the union, intersection, difference, and symmetric difference of sets 𝐴 and 𝐵 are thus as
follows:
𝐴∪𝐵 2, 3, 4, 6, 8 → 𝐴 ∪ 𝐵 0, 1, 1, 1, 0, 1, 0, 1
𝐴∩𝐵 6 →𝐴∩𝐵 0, 0, 0, 0, 0, 1, 0, 0
𝐴 𝐵 2, 4, 8 → 𝐴 𝐵 0, 1, 0, 1, 0, 0, 0, 1
𝐴⨁𝐵 2, 3, 4, 8 → 𝐴⨁𝐵 0, 1, 1, 1, 0, 0, 0, 1

ELEE 2110U Discrete Mathematics 35


Multiset
• A set is an unordered collection of objects, where multiplicity of objects is ignored and the membership of an object has a
binary status, that is either an element belongs to the set or it does not.
• A multiset (short form for multiple-membership set), also known as bag, is an unordered collection of objects where an
object can occur as a member of the set more than once, i.e., repeated occurrences of objects are allowed. For instance,
multisets 7, 8, 9 and 9, 8, 7 are the same, but multisets 7, 8, 9 and 7, 8, 7, 9 are different.
• The number of occurrences, given for each element, is called the multiplicity of the element in the multiset. A multiset
corresponds to an ordinary set if the multiplicity of every element is one.
• Example of multisets may include multiset of prime factors of an integer, such as the integer 360 that has the prime
factorization 360 2 3 5 , which gives the multiset {2, 2, 2, 3, 3, 5}. The sets of letters forming the words “are,”
“era,” “ear,” and “rear” are the same, which is 𝑟, 𝑎, 𝑒 , however, their multisets of letters forming these words are
different, as the multiset of the words “are,” “era,” and “ear” is 𝑟, 𝑎, 𝑒 , whereas that for the word “rear” is 𝑟, 𝑟, 𝑎, 𝑒 .

ELEE 2110U Discrete Mathematics 36


Basic Operations on Multiset
• The notation 𝑚 . 𝑎 , 𝑚 . 𝑎 , … , 𝑚 . 𝑎 denotes the multiset with the element 𝑎 occurring 𝑚 times, the element 𝑎
occurring 𝑚 times, and so on. The numbers 𝑚 , 𝑖 1, … , 𝑛, are called the multiplicities of the elements 𝑎 , 𝑖 1, … , 𝑛,
where elements not in a multiset are assigned 0 as their multiplicity.
• The cardinality of a multiset is determined by summing up the multiplicities of all its elements, i.e., 𝑚 𝑚 ⋯ 𝑚 .
For example, in the multiset 𝑐, 𝑎, 𝑛, 𝑎, 𝑑, 𝑖, 𝑎, 𝑛 , the multiplicities of the distinct members c, a, n, d, and i are respectively
1, 3, 2, 1, and 1, and therefore the cardinality of this multiset is 8 1 3 2 1 1 .
• The union or intersection of two multisets is the multiset in which the multiplicity of an element is the maximum or the
minimum of its multiplicities in those two multisets.
• The difference of two multisets is the multiset in which the multiplicity of an element is the difference between the
multiplicities of the element in these two multisets, unless the difference is negative in which case the multiplicity is 0.
• The sum of two multisets is the multiset in which the multiplicity of an element is the sum of multiplicities in those two
multisets.

ELEE 2110U Discrete Mathematics 37


Example
Suppose that 𝐻 and 𝐾 are the multisets 4. 𝑎, 3. 𝑏, 2. 𝑐, 1. 𝑑 and 2. 𝑎, 3. 𝑏, 4. 𝑐, 1. 𝑒 , respectively. Determine their union
(𝐻 ∪ 𝐾 , intersection (𝐻 ∩ 𝐾 , difference (𝐻 𝐾 , and sum (𝐻 𝐾 .

Solution
We thus have the following multisets sets:
𝐻∪𝐾 max 4, 2 . 𝑎, max 3, 3 . 𝑏, max 2, 4 . 𝑐, max 1, 0 . 𝑑, max 0, 1 . 𝑒
4. 𝑎, 3. 𝑏, 4. 𝑐, 1. 𝑑, 1. 𝑒 .
𝐻∩𝐾 min 4, 2 . 𝑎, min 3, 3 . 𝑏, min 2, 4 . 𝑐, min 1, 0 . 𝑑, min 0, 1 . 𝑒
2. 𝑎, 3. 𝑏, 2. 𝑐 .
𝐻 𝐾 max 4 2, 0 . 𝑎, max 3 3, 0 . 𝑏, max 2 4, 0 . 𝑐, max 1 0, 0 . 𝑑, max 0 1, 0 . 𝑎
2. 𝑎, 1. 𝑑 .
𝐻 𝐾 4 2 . 𝑎, 3 3 . 𝑏, 2 4 . 𝑐, 1 0 . 𝑑, 0 1 .𝑒
6. 𝑎, 6. 𝑏, 6. 𝑐, 1. 𝑑, 1. 𝑒 .

ELEE 2110U Discrete Mathematics 38


Fuzzy Sets
• In a world of many shades of gray, a black-white dichotomy is an unnecessary artificial imposition. The concept of fuzzy
sets is an important and practical generalization of the notion of classical sets. For instance, if the universe of discourse
consists of knowledgeable people, then in fuzzy set theory, members of a set can have varying degrees of knowledge.
• Fuzzy sets, where each member of the set is defined by the degree of fuzziness, have an array of applications in
modelling, control systems, linguistics, information retrieval, decision making, and of course artificial intelligence, where
information is incomplete or imprecise.
• In classical set theory, a set 𝐴 is defined in terms of its characteristic function 𝜇 𝑥 , a mapping from the universal set
𝑈 to the binary set 0, 1 , where 𝑥 belongs to 𝐴 if and only if 𝜇 𝑥 1 and 𝑥 does not belong to 𝐴 if and only if
𝜇 𝑥 0.
• In fuzzy set theory, a set 𝐴 is defined in terms of its membership function 𝜇 𝑥 , a mapping from the universal set 𝑈 to
the unit interval 0, 1 , where 𝑥 in the fuzzy set 𝐴 has certain degree of membership. Therefore, the fuzzy set 𝐴 is
denoted by listing the elements with their degrees of membership.

ELEE 2110U Discrete Mathematics 39


Insights into Fuzzy Set
• Classical sets are special cases of fuzzy sets, and that is when the
membership functions of fuzzy sets only take values 0 or 1. In the
context of fuzzy sets, classical sets are usually called crisp sets.
• As an example, the membership functions for fuzzy and crisp sets 𝜇 𝑥

of tall people reflecting their degrees of tallness can be shown.


1
• The crisp set assigns a number from the binary set 0, 1 to Crisp set

indicate whether a person is considered tall or not (i.e., whether


the person’s height is greater than or less than 180 cm), whereas Fuzzy set

the fuzzy set assigns a real number in the interval 0, 1 to 0 𝑥 cm


170 180 190
indicate the extent to which a person is a member of the set of tall Figure 5.5 Membership functions of sets.

people (i.e., the person’s height ranges between 170 cm and 190
cm).

ELEE 2110U Discrete Mathematics 40


Degrees of Fuzziness
• The degree of fuzziness for each member of the fuzzy set needs to be always specifically stated, while noting that
elements with 0 degree of membership are not listed.
• As an example, the fuzzy set 𝐴 of healthy people consists of 𝑎, 𝑏, 𝑐, 𝑑, and 𝑒, whose degrees of membership, i.e., degrees
of healthiness, are as follows: 𝜇 𝑎 0.99, 𝜇 𝑏 0.9, 𝜇 𝑐 0.5, 𝜇 𝑑 0.05, and 𝜇 𝑒 0.001. This in turn
points to 𝑎 being the healthiest and 𝑒 having the poorest health in the fuzzy set 𝐴.
• As another example, the fuzzy set B of wealthy people consists of 𝑎, 𝑏, 𝑐, and 𝑑, whose degrees of membership, i.e.,
degrees of wealthiness, are as follows: 𝜇 𝑎 0.999, 𝜇 𝑏 0.95, 𝜇 𝑐 0.2, and 𝜇 𝑑 0.001. This in turn
indicates that 𝑎 is the wealthiest and 𝑑 is the poorest in the fuzzy set 𝐵.

ELEE 2110U Discrete Mathematics 41


Operations on Fuzzy Sets
• The concepts of set inclusion and equality can also be extended to fuzzy sets. Assuming 𝐴 and 𝐵 are fuzzy sets, we have
𝐴 ⊂ 𝐵, i.e., 𝐴 is a proper subset of 𝐵, if and only if for every element 𝑥, we have 𝜇 𝑥 𝜇 𝑥 , and we have 𝐴 𝐵 if
and only if for every element 𝑥, we have 𝜇 𝑥 𝜇 𝑥 .

• Set operations in classical sets can be extended to fuzzy sets in terms of membership function, namely we have
• The complement of fuzzy set 𝐴 is 𝐴 , where 𝜇 𝑥 1 𝜇 𝑥 .
• The union of fuzzy sets 𝐴 and 𝐵 is 𝐴 ∪ 𝐵, where 𝜇 ∪ 𝑥 max 𝜇 𝑥 , 𝜇 𝑥 .
• The intersection of fuzzy sets 𝐴 and 𝐵 is 𝐴 ∩ 𝐵, where 𝜇 ∩ 𝑥 min 𝜇 𝑥 , 𝜇 𝑥 .

ELEE 2110U Discrete Mathematics 42


Example
Suppose the fuzzy set 𝐼 of three intelligent students 𝑎, 𝑏, and 𝑐 has the degrees of membership 𝜇 𝑎 0.9, 𝜇 𝑏 0.7,
and 𝜇 𝑐 0.3, respectively, and the fuzzy set 𝐷 of three diligent students 𝑎, 𝑏, and 𝑐 has the degrees of membership
𝜇 𝑎 0.5, 𝜇 𝑏 0.6, and 𝜇 𝑐 0.8, respectively. Determine the fuzzy sets 𝐼 ∪ 𝐷 and 𝐼 ∩ 𝐷.

Solution
We thus have the following fuzzy sets:

𝐼∪𝐷 𝑎𝜇 ∪ 𝑎 0.9, 𝑏 𝜇 ∪ 𝑏 0.7, 𝑐 | 𝜇 ∪ 𝑐 0.8


and
𝐼∩𝐷 𝑎𝜇 ∩ 𝑎 0.5, 𝑏 𝜇 ∩ 𝑏 0.6, 𝑐 | 𝜇 ∩ 𝑐 0.3 .

ELEE 2110U Discrete Mathematics 43


Functions

ELEE 2110U Discrete Mathematics 44


Basic Definition
• A function from 𝑋 to 𝑌 is an assignment of exactly one element of 𝑌 to each element of 𝑋, where 𝑋 and 𝑌 are two
nonempty sets of real numbers.
• Every element in 𝑋 is related to some element in 𝑌 and no element in 𝑋 is related to more than one element in 𝑌.
• If 𝑓 is a function from 𝑋 to 𝑌, we then write 𝑓: 𝑋 → 𝑌. Functions may also be called maps, mappings or transformations.
𝑓
• As a function is a correspondence that associates with each member in 𝑋 exactly one member in 𝑌.
• A relation from 𝑋 to 𝑌 that contains only one ordered pair 𝑥, 𝑦 for every
element 𝑥 ∈ 𝑋 defines a function 𝑓 from 𝑋 to 𝑌 where 𝑦 ∈ 𝑌, as shown below.
• With 𝑓 as a function from 𝑋 to 𝑌, the set 𝑋 is the domain of the function 𝑓
𝑥 𝑦 𝑓 𝑥
and 𝑌 is the codomain of 𝑓.
• 𝑦 is the image of 𝑥 and 𝑥 is a pre-image or an inverse image of 𝑦.
• The range of 𝑓 is the set of all images of elements of 𝑋.
• The codomain of a function is the set of all possible values, i.e.,
𝑋 𝑌
all elements of 𝑌, and the range is the set of all values of 𝑓 𝑥 for 𝑥 ∈ 𝑋, the range is therefore a subset of the codomain.

ELEE 2110U Discrete Mathematics 45


Example
Determine whether or not the correspondences in this Figure are functions.
If an assignment is a function, determine its domain, codomain, and range.

Solution
(a) The correspondence in Figure-a is not a function, because it maps an element in 𝑋 to
two distinct elements in 𝑌.
(b) The correspondence in Figure-b is a function, as each member in 𝑋 is associated with
exactly one member in 𝑌. Its domain is the set 𝑎, 𝑏, 𝑐, 𝑑 , codomain is the set
1, 2, 3, 4 , and range is the set 1, 3, 4 .
(c) The correspondence in Figure-c is not a function, because there is an element of 𝑋,
namely 𝑏 that is not mapped to any element of 𝑌.

ELEE 2110U Discrete Mathematics 46


Variables
• For a function of 𝑦 𝑓 𝑥 , the variable 𝑥 is called the independent variable, as it can have any permissible number
from the domain, and the variable 𝑦 is called the dependent variable, because its value depends on the value of 𝑥.
• Assuming 𝑓 represents a system, then 𝑦 is the output or value corresponding to the input or argument 𝑥.
• As a function is defined by its domain, codomain, and the mapping of elements of the domain to elements in the
codomain, two functions are equal when they have the same domain, the same codomain, and the same mapping of
elements in the domain.
• A function is called real-valued if its codomain is the set of real numbers 𝑹, and it is called integer-valued if its
codomain is the set of integers Z.

ELEE 2110U Discrete Mathematics 47


Sum and Product of Functions
• A function is uniquely represented by the set of all pairs 𝑥, 𝑓 𝑥 . When the domain 𝑋 and codomain 𝑌 of a function are
sets of real numbers, each such pair may be considered as the Cartesian coordinates of a point in the plane.
• The graph of the function 𝑓 is the set of ordered pairs 𝑥, 𝑦 |𝑥 ∈ 𝑋, 𝑓 𝑥 𝑦∈𝑌 .
• Let 𝑓: 𝑋 → 𝑹 and 𝑔: 𝑋 → 𝑹. The sum and product of 𝑓 and 𝑔, denoted by 𝑓 𝑔 and 𝑓𝑔 respectively, are also functions
from 𝑋 to 𝑹 defined for all 𝑥 ∈ 𝑋 by
𝑓 𝑔 𝑥 𝑓 𝑥 𝑔 𝑥

𝑓𝑔 𝑥 𝑓 𝑥 𝑔 𝑥

• The functions 𝑓 𝑔 and 𝑓𝑔 are defined only wherever both 𝑓 and 𝑔 are defined.
• The domain of the function 𝑓 𝑔 or the domain of the function 𝑓𝑔 is the intersection of the domain of 𝑓 and the domain
of 𝑔.

ELEE 2110U Discrete Mathematics 48


Example
Let 𝑓 𝑥 4 𝑥 and 𝑔 𝑥 𝑥 1. Determine the functions 𝑓 𝑔 𝑥 and 𝑓𝑔 𝑥 as well as their domains.

Solution
We first find the domains of 𝑓 𝑥 and 𝑔 𝑥 .
The domain of 𝑓 𝑥 is 2 𝑥 2 and the domain of 𝑔 𝑥 is 𝑥 1.
Therefore, both 𝑓 𝑔 𝑥 and 𝑓𝑔 𝑥 are defined only when 1 𝑥 2.
We can now have the sum and product of the two functions as follows:

𝑓 𝑔 𝑥 4 𝑥 𝑥 1

𝑓𝑔 𝑥 4 𝑥 𝑥 1

ELEE 2110U Discrete Mathematics 49


Increasing and Decreasing Functions
• Let the domain and codomain of the function 𝑓 be subsets of the set of real numbers.
 𝑓 is called a non-decreasing function if 𝑓 𝑥 𝑓 𝑥 and an increasing function if 𝑓 𝑥 𝑓 𝑥 , whenever
𝑥 𝑥 and both 𝑥 and 𝑥 are in the domain of 𝑓.
 𝑓 is called a non-increasing function if 𝑓 𝑥 𝑓 𝑥 and a decreasing function if 𝑓 𝑥 𝑓 𝑥 , whenever
𝑥 𝑥 and both 𝑥 and 𝑥 are in the domain of 𝑓.
• Using quantifiers and assuming the universe of discourse is the domain of 𝑓, we thus have the following:
 Non-decreasing function 𝑓 → ∀𝑥 ∀𝑥 𝑥 𝑥 →𝑓 𝑥 𝑓 𝑥

 Increasing function 𝑓 → ∀𝑥 ∀𝑥 𝑥 𝑥 →𝑓 𝑥 𝑓 𝑥

 Non-increasing function 𝑓 → ∀𝑥 ∀𝑥 𝑥 𝑥 →𝑓 𝑥 𝑓 𝑥

 Decreasing function 𝑓 → ∀𝑥 ∀𝑥 𝑥 𝑥 →𝑓 𝑥 𝑓 𝑥

ELEE 2110U Discrete Mathematics 50


Piece-Wise Defined Functions
• The definition of a function in mathematics generally consists of just one formula. However, many practical functions
reflecting real-world applications may consist of more than one formula, depending on the values of 𝑥. Such a function is
called a piece-wise defined function.
• Functions defined piece-wise are written as if-then-else statements in most programming languages.
• Example:
 Unit step function used often in modelling physical systems is piece-wise defined as follows: 𝑓 𝑥 0, if 𝑥 0,
and 𝑓 𝑥 1, if 𝑥 0.
 Absolute-value function defined by 𝑓 𝑥 |𝑥|.

ELEE 2110U Discrete Mathematics 51


Floor and Ceiling Functions
• The floor function, also known as the greatest integer function, assigns to the real number 𝑥 the largest integer that is
less than or equal to 𝑥. The floor of 𝑥 rounds down 𝑥 and is denoted by 𝑥 .
• The ceiling function, also known as the least integer function, assigns to the real number 𝑥 the smallest integer that is
greater than or equal to 𝑥. The ceiling of 𝑥 rounds up 𝑥 and is denoted by 𝑥 .
• Examples: if 𝑥 6.4, then 𝑥 6 and 𝑥 7, and if 𝑥 6.4, then x 7 and x 6.
• These functions are often used in the analysis of the number of steps required by algorithms, and help provide measures
of complexities of algorithms. All programming languages provide these functions as built-in functions.

ELEE 2110U Discrete Mathematics 52


One-to-One Function
• A function 𝑓: 𝑋 → 𝑌 is said to be one-to-one or injection if and only if 𝑓 𝑥 𝑓 𝑥 implies that 𝑥 𝑥 for all
elements in 𝑋.
• If at least different two elements in the domain of a function can be found that have the same element in the codomain,
then the function is not one-to-one.
• Using quantifiers, a function 𝑓 is one-to-one if ∀𝑥 ∀𝑥 𝑓 𝑥 𝑓 𝑥 →𝑥 𝑥 or equivalently, ∀𝑥 ∀𝑥 𝑓 𝑥
𝑓 𝑥 →𝑥 𝑥 , where the universe of discourse is the domain of the function.

• Geometrical characterization using graphs:


• If 𝑓: 𝑅 → 𝑅 is one-to-one, then each horizontal line intersects the graph of the function 𝑓 in at most one point, i.e., the
number of intersection points 1.

ELEE 2110U Discrete Mathematics 53


Onto Functions
• A function 𝑓: 𝑋 → 𝑌 is said to be onto or surjection if and only if for every element 𝑦 ∈ 𝑌 there is at least one element
𝑥 ∈ 𝑋 with 𝑓 𝑥 𝑦.
• If the range and codomain are not the same, then the function is not onto. Using quantifiers, a function 𝑓 is onto if
∀𝑦∃𝑥 𝑓 𝑥 𝑦 , where 𝑥 and 𝑦 are in the domain and codomain of the function, respectively.

• Geometrical characterization using graphs:


• If 𝑓: 𝑅 → 𝑅 is onto, then each horizontal line intersects the graph of the function 𝑓 in at one or more points, i.e., the
number of intersection points 1.

ELEE 2110U Discrete Mathematics 54


One-to-One Correspondence
• A function 𝑓: 𝑋 → 𝑌 is said to be one-to-one correspondence or bijection if and only if it is both one-to-one and onto.
• When a function is a one-to-one correspondence, the elements of its domain and codomain match up perfectly.
• A function 𝑓: 𝑋 → 𝑌 is both one-to-one and onto if and only if it is invertible, as it will be discussed later.

• Geometrical characterization using graphs:


• If 𝑓: 𝑅 → 𝑅 is one-to-one correspondence, then each horizontal line intersects the graph of the function 𝑓 in at exactly
one point, i.e., the number of intersection points 1.

ELEE 2110U Discrete Mathematics 55


Example
Consider the four arrow diagrams in Fig. 7.3, where each represents a
𝑎 1 𝑎 1
function. Identify the functions that are one-to-one and those that are onto.
𝑏 2 𝑏 2

Solution 𝑐 3 𝑐 3

Only the arrow diagrams in (a) and (c) are one-to-one functions, because in
4 𝑑
each of them, different elements of domain have distinct images, i.e., no two
𝑋 𝑌 𝑋 (b) 𝑌
values in the domain are assigned to the same function value. (a)

Only the arrow diagrams in (b) and (c) are onto functions, because in each of
𝑎 1 𝑎 1
them, all elements in the codomain are images of elements in the domain.
𝑏 2 𝑏 2
In summary, the function in (a) is one-to-one, but not onto, the function in (b)
is onto, but not one-to-one, the function in (c) is both one-to-one and onto, 𝑐 3 𝑐 3

i.e., one-to-one correspondence, and the function in (d) is neither one-to-one 𝑑 4 𝑑 4

nor onto.
𝑋 𝑌 𝑋 𝑌
(c) (d)

ELEE 2110U Discrete Mathematics 56


Example
Consider the following four functions of the form 𝑓: 𝑅 → 𝑅 and identify the one-to-one and onto functions using their
geometric characterizations:
(a) 𝑓 𝑥 𝑥
(b) 𝑔 𝑥 𝑒
(c) ℎ 𝑥 𝑥 𝑥
(d) 𝑘 𝑥 𝑥

Solution
The functions 𝑔 𝑥 and 𝑘 𝑥 are both one-to-one, as in the graph of 𝑔 𝑥 or the graph of 𝑘 𝑥 , no horizontal line intersects
the graph in more than one point.
The functions ℎ 𝑥 and 𝑘 𝑥 are both onto, as in the graph of ℎ 𝑥 or the graph of 𝑘 𝑥 , each horizontal line intersects the
graph at one or more points.
In summary, the function 𝑔 𝑥 is one-to-one, but not onto, the function ℎ 𝑥 is onto, but not one-to-one, the function
𝑘 𝑥 is both one-to-one and onto, i.e., one-to-one correspondence, and the function 𝑓 𝑥 is neither one-to-one nor onto.

ELEE 2110U Discrete Mathematics 57


Compositions of Functions
• Consider the function 𝑓: 𝑋 → 𝑌 and the function 𝑔: 𝑌 → 𝑍. The composition of the functions 𝑓 and 𝑔, denoted by 𝑔 ∘ 𝑓
and read as 𝑔 circle 𝑓, is a function from 𝑋 to 𝑍, defined as follows:
𝑔∘𝑓 𝑥 𝑔 𝑓 𝑥

• In order to find 𝑔 ∘ 𝑓 𝑥 , we first apply the function 𝑓 to 𝑥 to obtain 𝑓 𝑥 and then


we apply the function 𝑔 to the result of 𝑓 𝑥 to obtain 𝑔 ∘ 𝑓 𝑥 𝑔 𝑓 𝑥 .
• In general, the domain of the function 𝑔 need not be the same as the codomain of the
function 𝑓. The composition of 𝑔 ∘ 𝑓 cannot be defined unless the range of the
function 𝑓 is a subset of the domain of the function 𝑔.
• At a system level, the composite function can be also viewed as two subsystems in
series, where the output of the first subsystem forms the input of the second
subsystem, and the composite function represents the system output 𝑔 ∘ 𝑓 𝑥 for the system input 𝑥.
• The order of the functions matters. Even if both 𝑔 ∘ 𝑓 and 𝑓 ∘ 𝑔 are defined, in general, we have 𝑔 ∘ 𝑓 𝑓 ∘ 𝑔.

ELEE 2110U Discrete Mathematics 58


Example
Consider the functions 𝑓: 𝑹 → 𝑹 and 𝑔: 𝑹 → 𝑹, where 𝑹 represents the set of real numbers. Assuming 𝑓 𝑥 𝑥 1 and
𝑔 𝑥 𝑥 𝑥, determine 𝑔 ∘ 𝑓 𝑥 and 𝑓 ∘ 𝑔 𝑥 . Comment on the results.

Solution
𝑔∘𝑓 𝑥 𝑔 𝑓 𝑥 𝑔 𝑥 1 𝑥 1 𝑥 1 𝑥 3𝑥 4𝑥 2
and
𝑓∘𝑔 𝑥 𝑓 𝑔 𝑥 𝑓 𝑥 𝑥 𝑥 𝑥 1 𝑥 𝑥 1

Since we have 𝑥 3𝑥 4𝑥 2 𝑥 𝑥 1, we can conclude 𝑔 ∘ 𝑓 𝑓 ∘ 𝑔.

ELEE 2110U Discrete Mathematics 59


Inverse Function
• A function is invertible if and only if it is one-to-one correspondence. Suppose 𝑓: 𝑋 → 𝑌 is 𝑓 𝑥

a one-to-one correspondence.
• The inverse function of the function 𝑓, denoted by 𝑓 , is the function that assigns to an 𝑥 𝑓 𝑥
element 𝑦 belonging to 𝑌 the unique element 𝑥 in 𝑋 such that 𝑓 𝑥 𝑦. Hence, we have
𝑓 𝑥

𝑓
𝑓 𝑦 𝑥 ↔ 𝑦 𝑓 𝑥 .

• The domain of 𝑓 becomes the codomain of 𝑓 and the codomain of 𝑓 becomes the domain 𝑓
𝑋 𝑌
of 𝑓 . The independent variable 𝑥 for 𝑓 acts as the dependent variable for 𝑓 , and
correspondingly the dependent variable 𝑦 for 𝑓 becomes the independent variable for 𝑓 .
• Example: if we have 𝑓 𝑥 𝑒 , we then have ln 𝑓 𝑥 𝑥. By changing the roles of the
independent and dependent variables, the inverse function of 𝑓 𝑥 𝑒 is then 𝑓 𝑥
ln 𝑥.

ELEE 2110U Discrete Mathematics 60


Example
Determine if the following functions are invertible, where their domains and codomains are the set of real numbers:
(a) ℎ 𝑥 𝑥 1 2
(b) 𝑘 𝑥 𝑥 7

Solution
(a) The function ℎ 𝑥 is not one-to-one correspondence, as it is not even one-to-one. Therefore, it is not invertible. In other
words, its inverse, ℎ 𝑥 𝑥 2 1, is not a function simply because for a given 𝑥 2, we have two distinct
values for ℎ 𝑥 .
(b) The function 𝑘 𝑥 is one-to-one correspondence, as it is both one-to-one and onto. Therefore, it is invertible. In other
words, its inverse, 𝑘 𝑥 𝑥 7, is also a function, for a given 𝑥 0.

ELEE 2110U Discrete Mathematics 61


Relations

ELEE 2110U Discrete Mathematics 62


Forms of Relations
• There are many forms of relations.
• Relationships exist between people, such as parent-child, student-teacher, employer-employee.
• Relationships exist also in mathematics, such as less than, parallel to, a subset of, logarithm of, and factorial of. In fact,
all mathematical functions are a special type of relation.
• A relation considers the existence of a certain connection often between pairs of objects in a definite order.

ELEE 2110U Discrete Mathematics 63


Relation: Definition
• In the context of mathematics of relations, relationships between two sets are often based on ordered pairs made up of
two related elements, each belonging to a set. An ordered pair of elements 𝑎 and 𝑏 is denoted by 𝑎, 𝑏 , while noting that
𝑎, 𝑏 𝑏, 𝑎 , unless 𝑎 𝑏.
• The sets of ordered pairs are called binary relations.
• The binary relations are in contrast to 𝒏-ary relations, which express relationships among elements of 𝑛 sets with 𝑛 2
being an integer and thus involve ordered 𝑛-tuples.
• The term relation by itself generally refers to a binary relation, unless otherwise stated or implied.
• A relation between the sets 𝐴 and 𝐵 is a subset 𝑅 of the Cartesian product 𝐴 𝐵, where the Cartesian product is defined
as 𝐴 𝐵 𝑎, 𝑏 |𝑎 ∈ 𝐴 and 𝑏 ∈ 𝐵 . If 𝑎, 𝑏 ∈ 𝑅, it is then read as 𝑎 is related to 𝑏.
• The set 𝐴 is called the domain of the relation and the set 𝐵 is called the range of the relation. If 𝑎, 𝑏 ∉ 𝑅, it is then
read as 𝑎 is not related to 𝑏. If 𝐴 𝐵, the relation is said to be a relation on 𝐴.

ELEE 2110U Discrete Mathematics 64


Inverse & Complementary Relations
• The relation 𝑅 is a one-to-one relation, if no element of 𝐵 appears as a second coordinate in more than one ordered pair
in 𝑅, and the relation 𝑅 is an onto relation, if every element of 𝐵 appears as a second coordinate in at least one ordered
pair in 𝑅.
• Unlike functions, every relation has an inverse. If 𝑅 is a relation between the sets 𝐴 and 𝐵, then the inverse relation of 𝑅,
denoted by 𝑅 , is a subset of the Cartesian product 𝐵 𝐴. In other words, the inverse relation is defined as follows:
𝑅 𝑏, 𝑎 | 𝑎, 𝑏 ∈ 𝑅 . The domain and range of 𝑅 are equal, respectively, to the range and domain of 𝑅.
• If 𝑅 is a relation on 𝐴, then 𝑅 is also a relation on 𝐴. The complementary relation 𝑅 is the set of ordered pairs, which
is defined as follows: 𝑅 𝑎, 𝑏 | 𝑎, 𝑏 ∉ 𝑅 .

ELEE 2110U Discrete Mathematics 65


Examples
a) Let 𝐴 1, 2, 3 and 𝐵 7, 8, 9 . Determine 𝐴 𝐵 and 𝐵 𝐴.
b) Let 𝐴 12, 14, 18, 20 and 𝐵 6, 8, 10 , and define a relation 𝑅 from 𝐴 to 𝐵 as follows:
𝑅 𝑎, 𝑏 |𝑎 is a multiple of 𝑏 . Determine the domain and range of 𝑅.
a) Let 𝐴 2, 3, 4 and 𝐵 8, 9, 10 . Let 𝑅 be the divisibility relation from 𝐴 to 𝐵, i.e., for all 𝑎, 𝑏 ∈ 𝐴 𝐵, 𝑎 divides
𝑏. Determine 𝑅 and describe it in words.

Solution
(a) 𝐴 𝐵 1, 7 , 1, 8 , 1, 9 , 2, 7 , 2, 8 , 2, 9 , 3, 7 , 3, 8 , 3, 9 .
𝐵 𝐴 7, 1 , 8, 1 , 9, 1 , 7, 2 , 8, 2 , 9, 2 , 7, 3 , 8, 3 , 9, 3 .
(b) Since we have 𝑅 12, 6 , 18, 6 , 20, 10 , the domain of 𝑅 is 12, 18, 20 and the range of 𝑅 is 6, 10 .
(c) Since we have the relation 𝑅 2, 8 , 2, 10 , 3, 9 , 4, 8 , we have the inverse relation
𝑅 8, 2 , 10, 2 , 9, 3 , 8, 4 . Therefore, for all 𝑏, 𝑎 ∈ 𝑅 , 𝑏 is a multiple of 𝑎.

ELEE 2110U Discrete Mathematics 66


Relation: Reflexive Property
• A relation 𝑅 on a set 𝐴 is reflexive if and only if 𝑎, 𝑎 ∈ 𝑅 for every element 𝑎 ∈ 𝐴. In informal terms, in a reflexive
relation, each element is related to itself.
• An example of a reflexive relation is the equality relation on the set of real numbers, as every real number is equal to
itself, another example of a reflexive relation is the divides relation on the set of positive integers, as every positive
integer divides itself.
• Using quantifiers, the relation 𝑅 on the set 𝐴 is reflexive if ∀𝑎 𝑎, 𝑎 ∈ 𝑅 .
• A relation 𝑅 on a set 𝐴 is antireflexive, also known as irreflexive, if and only if 𝑎, 𝑎 ∉ 𝑅 for every element 𝑎 ∈ 𝐴. In
informal terms, no element in 𝐴 is related to itself.
• An example of an antireflexive relation is the greater-than relation on the real numbers.
• Note that antireflexive does not mean not reflexive, as it is possible to define a relation where some elements are related
to themselves but others are not (i.e., neither all nor none are).

ELEE 2110U Discrete Mathematics 67


Examples
(a) Provide examples for reflexive and antireflexive relations as well as for a relation that is neither reflexive nor
antireflexive.
(b) Assuming the following three relations are defined on the set 𝐴 1, 2, 3 , determine which of the relations are reflexive,
which are not reflexive, and which are antireflexive:
𝑅 1, 1 , 1, 2 , 2, 2 , 3, 1 , 3, 3 𝑅 1, 1 , 1, 2 , 2, 3 , 3, 1 , 3, 3 𝑅 1, 3 , 1, 2 , 2, 3 , 3, 1 , 3, 1
Solution
(a) Consider the relation that the product of two positive integers is even on the set 𝐴. If 𝐴 is the set of even numbers, the
relation is then reflexive because the square of an even number is even. If 𝐴 is the set of odd numbers, the relation is then
antireflexive because the square of an odd number is not even. If 𝐴 is the set of natural numbers (i.e., positive integers), the
relation is then neither reflexive nor antireflexive.
(b) 𝑅 is reflexive as it contains all the three pairs 1, 1 , 2, 2 , and 3, 3 . 𝑅 is not reflexive as it does not contain all the
three pairs 1, 1 , 2, 2 , and 3, 3 , more specifically, 2, 2 does not belong to 𝑅 . 𝑅 is antireflexive as it does not contain
even one of the three pairs 1, 1 , 2, 2 , and 3, 3 .

ELEE 2110U Discrete Mathematics 68


Relation: Symmetry Property
• A relation 𝑅 on a set 𝐴 is symmetric if and only if 𝑎, 𝑏 ∈ 𝑅, then 𝑏, 𝑎 ∈ 𝑅, for all 𝑎, 𝑏 ∈ 𝐴. Thus 𝑅 is not symmetric if
there exists 𝑎 ∈ 𝐴 and 𝑏 ∈ 𝐴 such that 𝑎, 𝑏 ∈ 𝑅 but 𝑏, 𝑎 ∉ 𝑅. In informal terms, in a symmetric relation, if any one
element is related to any other element, then the second element is related to the first as well.
• An example of a symmetric relation is the equality relation on the set of real numbers because if 𝑎 𝑏 is true, then 𝑏 𝑎
is also true.
• Using quantifiers, the relation 𝑅 on the set 𝐴 is symmetric if ∀𝑎∀𝑏 𝑎, 𝑏 ∈ 𝑅 → 𝑏, 𝑎 ∈ 𝑅 .
• A relation 𝑅 on a set 𝐴 is antisymmetric if and only if 𝑎, 𝑏 ∈ 𝑅, then 𝑏, 𝑎 ∉ 𝑅, for all 𝑎, 𝑏 ∈ 𝐴 and 𝑎 𝑏. In informal
terms, in an antisymmetric relation, if any one element is related to any other element, then the second element cannot be
related to the first. An example of an antisymmetric relation is the divisibility relation on the natural numbers. Using
quantifiers, the relation 𝑅 on the set 𝐴 is antisymmetric if ∀𝑎∀𝑏 𝑎, 𝑏 ∈ 𝑅 ∧ 𝑏, 𝑎 ∈ 𝑅 → 𝑏 𝑎 .
• A relation 𝑅 is called asymmetric if 𝑎, 𝑏 ∈ 𝑅 implies that 𝑏, 𝑎 ∉ 𝑅. Note that antisymmetric does not mean not
symmetric, as it is possible to define a relation that may lack both these properties. A relation cannot be both symmetric
and antisymmetric if it contains some pair of the form 𝑎, 𝑏 , where 𝑎 𝑏.

ELEE 2110U Discrete Mathematics 69


Examples
Assuming the following four relations are defined on the set 𝐴 1, 2, 3, 4 , determine which of the relations are symmetric
or antisymmetric:
𝑅 1, 1 , 1, 2 , 2, 3 , 1, 3 , 4, 4 .
𝑅 1, 1 , 1, 2 , 2, 1 , 2, 2 , 3, 3 , 4, 4 .
𝑅 1, 3 , 3, 1 , 2, 3 .
𝑅 1, 1 , 2, 2 .

Solution
𝑅 is not symmetric since 1, 2 ∈ 𝑅 , but 2, 1 ∉ 𝑅 . However, 𝑅 is antisymmetric.
𝑅 is not antisymmetric, as 1, 2 and 2, 1 belong to 𝑅 , but 2 1. However, 𝑅 is symmetric.
𝑅 is neither symmetric nor antisymmetric.
𝑅 is both symmetric and antisymmetric.

ELEE 2110U Discrete Mathematics 70


Relation: Transitive Property
• A relation 𝑅 on a set 𝐴 is called transitive if and only if 𝑎, 𝑏 ∈ 𝑅 and 𝑏, 𝑐 ∈ 𝑅, then 𝑎, 𝑐 ∈ 𝑅, for all 𝑎, 𝑏, 𝑐 ∈ 𝐴. In
informal terms, if any one element is related to a second and that second element is related to a third, then the first
element is related to the third.
• Examples of transitive relation may include the less than ( relation or the subset (⊆ relation.
• Using quantifiers, the relation 𝑅 on the set 𝐴 is transitive if ∀𝑎∀𝑏∀𝑐 𝑎, 𝑏 ∈ 𝑅 ∧ 𝑏, 𝑐 ∈ 𝑅 → 𝑎, 𝑐 ∈ 𝑅 .
• The relation 𝑅 is not transitive, also called intransitive, if for all 𝑎, 𝑏, 𝑐 ∈ 𝐴, 𝑎, 𝑏 ∈ 𝑅, 𝑏, 𝑐 ∈ 𝑅, but 𝑎, 𝑐 ∉ 𝑅.
• An example of intransitive relation is if in plane geometry 𝑎 and 𝑏 are perpendicular to one another and 𝑏 and 𝑐 are
perpendicular to one another, then 𝑎 and 𝑐 are not perpendicular to one another. Using quantifiers, the relation 𝑅 on the
set 𝐴 is intransitive if ∀𝑎∀𝑏∀𝑐 𝑎, 𝑏 ∈ 𝑅 ∧ 𝑏, 𝑐 ∈ 𝑅 → 𝑎, 𝑐 ∉ 𝑅 .

ELEE 2110U Discrete Mathematics 71


Relation: Property vs Requirements

Property Requirement

Reflexive 𝑎, 𝑎 ∈ 𝑅 for every element 𝑎 ∈ 𝐴

Irreflexive 𝑎, 𝑎 ∉ 𝑅 for every element 𝑎 ∈ 𝐴

Symmetric 𝑎, 𝑏 ∈ 𝑅  𝑏, 𝑎 ∈ 𝑅, for all 𝑎, 𝑏 ∈ 𝐴

Antisymmetri 𝑎, 𝑏 ∈ 𝑅  𝑏, 𝑎 ∉ 𝑅, for all 𝑎, 𝑏 ∈ 𝐴 and 𝑎 𝑏


c
Transitive 𝑎, 𝑏 ∈ 𝑅 and 𝑏, 𝑐 ∈ 𝑅  𝑎, 𝑐 ∈ 𝑅, for all 𝑎, 𝑏, 𝑐 ∈ 𝐴

Intransitive 𝑎, 𝑏 ∈ 𝑅 and 𝑏, 𝑐 ∈ 𝑅  𝑎, 𝑐 ∉ 𝑅, for all 𝑎, 𝑏, 𝑐 ∈ 𝐴

ELEE 2110U Discrete Mathematics 72


Examples
Determine whether the following relations 𝑅 on the set of all people living in the world is reflexive and/or symmetric and/or
transitive:
a 𝑎, 𝑏 ∈ 𝑅 if and only if 𝑎 has more money than 𝑏.
b 𝑎, 𝑏 ∈ 𝑅 if and only if 𝑎 and 𝑏 were born on the same day.
c 𝑎, 𝑏 ∈ 𝑅 if and only if 𝑎 and 𝑏 have a common grandparent.

Solution
a) The relation is neither reflexive nor symmetric, but it is transitive.
b) The relation is reflexive, symmetric, and transitive.
c) The relation is both reflexive and symmetric, but it is not transitive.

ELEE 2110U Discrete Mathematics 73


Representation of a Relation: Zero-One Matrix
• The zero-one matrix representing a relation on a set can be used to determine the relation properties.
• In a zero-one matrix, columns are labelled by the elements of the finite set 𝐴 and rows are labelled by the elements of the
finite set 𝐵. Note that in the zero-one matrix of a binary relation on a set, the same ordering for the rows as for the
columns are used.
• In the zero-one matrix of the relation 𝑅, denoted by 𝑀 , each entry which belongs to the set of the ordered pairs in the
relation is set to 1, otherwise it is set to 0.
• Whenever the zero-one matrix of a relation on a set, which is a square matrix, has 1s on the main diagonal, the relation is
reflexive, while noting that the elements off the main diagonal can be either 0 or 1.
• Whenever the zero-one matrix of a relation on a set and its transpose are the same (i.e., it is a symmetric matrix), the
relation is symmetric. The relation is antisymmetric if an element in row 𝑖 and column 𝑗 is 1 with 𝑖 𝑗, then the element
in row 𝑗 and column 𝑖 is 0.
• The relation is transitive if and only if whenever an entry in row 𝑖 and column 𝑗 in the square of the zero-one matrix is
nonzero, the entry in row 𝑖 and column 𝑗 in the zero-one matrix is also nonzero.

ELEE 2110U Discrete Mathematics 74


Example
Using zero-one matrix representation of the following relation on 𝑎 , 𝑎 , 𝑎 :

𝑅 𝑎 ,𝑎 , 𝑎 ,𝑎 , 𝑎 ,𝑎 , 𝑎 ,𝑎 , 𝑎 ,𝑎 .
Solution

1 0 1 1 0 1 2 0 2
𝑀 0 1 0 → 𝑀 0 1 0 & 𝑀 0 1 0 .
1 0 1 1 0 1 2 0 2

The relation 𝑅 is reflexive, as all the diagonal elements of the matrix 𝑀 are equal to 1.
Since we have 𝑀 𝑀 , the relation 𝑅 is symmetric.
The relation 𝑅 is not antisymmetric, for there are two 1s symmetrically placed about the main diagonal, i.e., at positions
row 1, column 3 and row 3, column 1.
Whenever entry row 𝑖, column 𝑗 in 𝑀 is nonzero, entry row 𝑖, column 𝑗 in 𝑀 is also nonzero, the relation 𝑅 is thus transitive.

ELEE 2110U Discrete Mathematics 75


Operations on Relations
• Relations can be combined to produce new relations. Let 𝑅 and 𝑆 be any two relations from 𝐴 to 𝐵.
• The union of two relations 𝑅 and 𝑆 is defined as 𝑅 ∪ 𝑆 𝑎, 𝑏 | 𝑎, 𝑏 ∈ 𝑅 and/or 𝑎, 𝑏 ∈ 𝑆 .
• The intersection of two relations 𝑅 and 𝑆 is defined as 𝑅 ∩ 𝑆 𝑎, 𝑏 | 𝑎, 𝑏 ∈ 𝑅 and 𝑎, 𝑏 ∈ 𝑆 .
• The difference of two relations 𝑅 and 𝑆 is defined as 𝑅 𝑆 𝑎, 𝑏 | 𝑎, 𝑏 ∈ 𝑅 and 𝑎, 𝑏 ∉ 𝑆 .
• Suppose the zero-one matrices for the relations 𝑅 and 𝑆 are represented by 𝑀 and 𝑀 , respectively.
• The zero-one matrix representing the union of these relations, denoted by 𝑀 ∪ , has a 1 in the position where either 𝑀
or 𝑀 has a 1 or both of them have a 1.
• The zero-one matrix representing the intersection of these relations, denoted by 𝑀 ∩ , has a 1 in the position where both
𝑀 and 𝑀 have a 1.
• The zero-one matrix representing the difference between the relations 𝑅 and 𝑆, denoted by 𝑀 , has a 1 in the position
where 𝑀 has a 1 but 𝑀 does not have.

ELEE 2110U Discrete Mathematics 76


Example
Consider the following relations on 𝑎 , 𝑎 , 𝑎 :

𝑅 𝑎 ,𝑎 , 𝑎 ,𝑎 , 𝑎 ,𝑎
and
𝑆 𝑎 ,𝑎 , 𝑎 ,𝑎 , 𝑎 ,𝑎 , 𝑎 ,𝑎 , 𝑎 ,𝑎

Identify the zero-one matrices for the relations reflecting the union and intersection of these two relations, and determine the
corresponding relations.

Solution
The zero-one matrices of 𝑅, 𝑆, 𝑅 ∪ 𝑆, and 𝑅 ∩ 𝑆 are as follows:

1 1 0 1 0 1 1 1 1 1 0 0
𝑀 0 0 1 , 𝑀 0 1 1 , 𝑀 ∪ 0 1 1 & 𝑀 ∩ 0 0 1 .
0 0 0 0 0 1 0 0 1 0 0 0

We thus have
𝑅∪𝑆 𝑎 ,𝑎 , 𝑎 ,𝑎 , 𝑎 ,𝑎 , 𝑎 ,𝑎 , 𝑎 ,𝑎 , 𝑎 ,𝑎
and
𝑅∩𝑆 𝑎 ,𝑎 , 𝑎 ,𝑎 .

ELEE 2110U Discrete Mathematics 77


Composition of Relations
• Let 𝐴, 𝐵, and 𝐶 be sets, 𝑅 be a relation from 𝐴 to 𝐵, 𝑆 be a relation from 𝐵 to 𝐶, with 𝑎 ∈ 𝐴, 𝑏 ∈ 𝐵, and 𝑐 ∈ 𝐶, while
noting that 𝐴, 𝐵, and 𝐶 have 𝑚, 𝑛, and 𝑝 elements, respectively.
• 𝑅 and 𝑆 give rise to a relation from 𝐴 to 𝐶, denoted by 𝑆 ∘ 𝑅, called the composition of two relations 𝑅 and 𝑆, and
defined by 𝑎, 𝑐 ∈ 𝑆 ∘ 𝑅 if there exists an element 𝑏 in 𝐵 such that 𝑎, 𝑏 ∈ 𝑅 and 𝑏, 𝑐 ∈ 𝑆.
• The zero-one matrices for the relation 𝑅, 𝑆, and 𝑆 ∘ 𝑅, denoted by 𝑀 , 𝑀 , and 𝑀 ∘ , respectively, display an interesting
connection, as the matrix resulting from the Boolean product of 𝑀 and 𝑀 , i.e., 𝑀 ⨀𝑀 , and the matrix 𝑀 ∘ have the
same nonzero entries, while noting that 𝑀 , 𝑀 , and 𝑀 ∘ have sizes 𝑚 𝑛, 𝑛 𝑝, and 𝑚 𝑝, respectively.
• In other words, we have the following Boolean product:

𝑀 ∘ 𝑀 ⨀𝑀 .

ELEE 2110U Discrete Mathematics 78


Example
Let 𝐴 𝑎 ,𝑎 ,𝑎 , 𝐵 𝑏 , 𝑏 , 𝑏 , 𝑏 , and 𝐶 𝑐 ,𝑐 ,𝑐 ,𝑐 .
Determine 𝑆 ∘ 𝑅, when the relation 𝑅 is defined as 𝑅 𝑎 ,𝑏 , 𝑎 ,𝑏 , 𝑎 ,𝑏 from 𝐴 to 𝐵, and the relation 𝑆 is
defined as 𝑆 𝑏 ,𝑐 , 𝑏 ,𝑐 , 𝑏 ,𝑐 , 𝑏 ,𝑐 , 𝑏 ,𝑐 from 𝐵 to 𝐶.

Solution
The corresponding zero-one matrices are as follows:

0 1 1 0
1 0 1 0 0 1 1 0
𝑀 & 𝑀 1 0 0 1 → 𝑀 𝑀 ⨀𝑀
0 1 0 0 0 0 0 0 ∘ 1 0 0 1 .
0 0 0 0 0 0 0 0
0 0 1 0

The nonzero entries of 𝑀 ∘ indicate that 𝑆 ∘ 𝑅 𝑎 ,𝑐 , 𝑎 ,𝑐 , 𝑎 ,𝑐 , 𝑎 ,𝑐 .

ELEE 2110U Discrete Mathematics 79


Logic
ELEE 2110U Discrete Mathematics 1
Logic
Logic deals with formal principles of reasoning, strict criteria of validity, and necessary rules of thought.
The rules of logic:
• Provide meaning to mathematical statements.
• Verify the correctness of programs and algorithms.
• Help construct some proofs in software systems.
• Help design optimum engineering systems.
• Draw conclusions from experiments.

Although logic is an essential tool in our interactions with other people as well as in our
decisions made every day, it does have limitations, simply because logic cannot help
convince someone out of something they were not reasoned into in the first place.

ELEE 2110U Discrete Mathematics 2


Propositional Logic
• The basic building blocks of logic are propositions.
• A proposition is a declarative statement, which is either true or false, but not both.
• The area of logic that deals with propositions is called the propositional logic.
• It is sometimes difficult to know if a sentence is a proposition, and if it is a proposition, it may not be known for some
reason whether it is true or false.

ELEE 2110U Discrete Mathematics 3


Example
Consider the following statements, identify those that are propositions, and explain your answers:
• How are you?  It is not a proposition, as it is a question.
• What a kind person!  It is not a proposition, as it is an exclamation.
• 2 + 2 = 3.  It is a proposition and it is false.
• Ice floats in water.  It is a proposition and it is true.
• Close the door.  It is not a proposition, as it is a command.
• Winter is beautiful.  It is not a proposition, because it is an opinion.
• Yellow is a primary color.  It is a proposition and it is true.
• The earth is flat.  It is a proposition and it is false.

ELEE 2110U Discrete Mathematics 4


Example
Consider the following statements, identify those that are propositions, and explain your answers:
• 𝑥𝑥 + 1 = 5. 
• It is not a proposition, because 𝑥𝑥 is unknown. However, for a specific value of 𝑥𝑥, it becomes a proposition.
• There is life in outer space. 
• It is a proposition. Since science has not advanced enough to know with certainty, we cannot show if this proposition is
true or false.
• This sentence is false. 
• If we assume the sentence “This sentence is false” is true, then the sentence says it is false, which contradicts our
assumption. If we assume the sentence “This sentence is false” is false, then the sentence says it is true, which again
contradicts our assumption. We can thus conclude that “This sentence is false” is a self-contradictory sentence and
it is not a proposition, but a paradox.
• The number of fish in the earth's surface water is greater than a quintillion (1018 ), but less than a sextillion (1021 ). 
• It is a proposition. Since it is practically impossible to count all fish, we cannot determine if this proposition is true or false.

ELEE 2110U Discrete Mathematics 5


Proposition Types
• We use lowercase letters, such as 𝑝𝑝, 𝑞𝑞, 𝑟𝑟, 𝑠𝑠, and 𝑡𝑡, to denote propositional variables.
• The truth value of a proposition is either true or false.
 If the truth value of a proposition is true, it is denoted by T.
 If the truth value of a proposition is false, it is denoted by F.
• If a proposition cannot be broken down into simpler propositions, it is then called a simple proposition or primitive
proposition. For instance, the proposition “the earth is flat” is a simple proposition, which is false, and the proposition
“the sun is hot” is a simple proposition, which is true.
• If a proposition is a composite, that is, it is composed of more than one proposition, it is then called a compound
proposition. For instance, the proposition “water boils at 50 degrees Celsius or water freezes at 0 degrees” is a compound
proposition, which is true, and “there are more women than men in the world and men can become pregnant” is a
compound proposition, which is false.
• The truth value of a compound proposition is completely determined by the truth values of its components (simple
propositions) together with the way in which they are connected to form the compound proposition.

ELEE 2110U Discrete Mathematics 6


Logical Operators
• Logical operators, also known as logical connectives, are used to combine two or more simple propositions to form a
compound proposition.
• A statement form or a propositional form is an expression consisting of statement variables and logical connectives.
• The truth table for a given statement form presents the truth values that correspond to all possible combinations of truth
values for the statement variables.
• The number of rows in a truth table is 2𝑚𝑚 , as 𝑚𝑚 in the exponent represents the number of propositional variables and 2 in
the base indicates the two possible truth values of each variable.
• Two compound propositions are called logically equivalent or simply equivalent or equal, if they have identical truth
tables, i.e., they have the same truth values, regardless of the truth values of its propositional variables. The notation “≡”
denotes logical equivalence.

ELEE 2110U Discrete Mathematics 7


Logical Operator: Negation
• The negation of the proposition 𝑝𝑝, denoted by 𝑝𝑝,̅ is the statement “it is not the case that 𝑝𝑝.”
• The simple proposition 𝑝𝑝,̅ read “not 𝑝𝑝”, has the truth value that is the opposite of the truth value of 𝑝𝑝.
• The truth table for the negation of a proposition 𝑝𝑝 has two rows corresponding to the two possible truth values of 𝑝𝑝.

ELEE 2110U Discrete Mathematics 8


Logical Operator: Conjunction
• The conjunction of the two propositions 𝑝𝑝 and 𝑞𝑞, denoted by 𝑝𝑝 ∧ 𝑞𝑞 and read “𝑝𝑝 and 𝑞𝑞”, is a compound proposition,
which is true when both 𝑝𝑝 and 𝑞𝑞 are true and is false otherwise.
• The truth table for the conjunction of two variables is as follows:

ELEE 2110U Discrete Mathematics 9


Logical Operator: Disjunction
• The disjunction of the two propositions 𝑝𝑝 and 𝑞𝑞, denoted by 𝑝𝑝 ∨ 𝑞𝑞 and read “𝑝𝑝 or 𝑞𝑞”, is a compound proposition, which
is false when both 𝑝𝑝 and 𝑞𝑞 are false and is true otherwise.
• Note that the word “or” in propositional logic is an inclusive or, meaning a disjunction is true when at least one of the
two propositions is true. In other words, 𝑝𝑝 ∨ 𝑞𝑞 implies “𝑝𝑝 or 𝑞𝑞 or both”, that is it is an inclusive or.
• The truth table for the disjunction of two variables is as follows:

ELEE 2110U Discrete Mathematics 10


Logical Operator: Exclusive OR
• The exclusive or of the two propositions 𝑝𝑝 and 𝑞𝑞, denoted by 𝑝𝑝 ⊕ 𝑞𝑞 and read “exclusive or 𝑝𝑝 and 𝑞𝑞”, is a compound
proposition, which is true when exactly either 𝑝𝑝 or 𝑞𝑞 is true and is false otherwise.
• In other words, when 𝑝𝑝 and 𝑞𝑞 are both true or when they are both false, the exclusive or of 𝑝𝑝 and 𝑞𝑞 is false.
• The truth table for the exclusive or of two variables is as follows:

ELEE 2110U Discrete Mathematics 11


Example
Determine the truth table for the propositional logic (𝑝𝑝̅ ⊕ 𝑞𝑞) ∧ (𝑝𝑝 ∨ 𝑞𝑞� ).

Solution
As 𝑝𝑝 and 𝑞𝑞 each can have two different truth values, there are four possibilities (rows) in the following table:

ELEE 2110U Discrete Mathematics 12


Duality
• The dual of a compound proposition containing only the logical operators negation, conjunction, and disjunction is the
compound proposition obtained by replacing each ∨ by ∧, each ∧ by ∨, each T by F, and each F by T.
• The duals of two equivalent compound propositions are equivalent, where these compound propositions contain only the
logical operators negation, conjunction, and disjunction.
• The dual of the dual proposition of a proposition is logically equivalent to the original proposition.
• A proposition and its dual are equal if and only if the proposition is simply one propositional variable. It is a difficult task
to determine if a compound proposition consisting of only one propositional variable and its dual are logically equivalent.

ELEE 2110U Discrete Mathematics 13


Example
Determine the dual of each of the following compound propositions:
• 𝑝𝑝 ∧ 𝑞𝑞� ∧ 𝑟𝑟̅  𝑝𝑝 ∨ 𝑞𝑞� ∨ 𝑟𝑟̅
• 𝑝𝑝 ∧ 𝑞𝑞 ∧ 𝑟𝑟 ∨ 𝑠𝑠  (𝑝𝑝 ∨ 𝑞𝑞 ∨ 𝑟𝑟) ∧ 𝑠𝑠
• 𝑝𝑝 ∨ 𝐹𝐹 ∧ 𝑞𝑞 ∨ 𝑇𝑇  (𝑝𝑝 ∧ 𝑇𝑇) ∨ (𝑞𝑞 ∧ 𝐹𝐹)
• 𝑝𝑝  𝑝𝑝 (equal to the original proposition)
• 𝑞𝑞 ∧ 𝑇𝑇  𝑞𝑞 ∨ 𝐹𝐹 (logically equivalent to the original proposition)

ELEE 2110U Discrete Mathematics 14


Conditional Statement
• Let 𝑝𝑝 and 𝑞𝑞 be propositions. The conditional statement 𝑝𝑝 → 𝑞𝑞, read “if 𝑝𝑝, then 𝑞𝑞”, “𝑝𝑝 implies 𝑞𝑞”, or “𝑝𝑝 is sufficient for
𝑞𝑞”, is a compound proposition, which is false when 𝑝𝑝 is true and 𝑞𝑞 is false, and true otherwise.
• In the implication 𝑝𝑝 → 𝑞𝑞, 𝑝𝑝 is called the hypothesis or premise and 𝑞𝑞 is called the conclusion or consequence.

• If the implication is true, we do not automatically know that either the hypothesis or the conclusion is true. For instance,
consider the conditional statement “if you obey the law, you never go to prison.” In this implication, if you obey the law,
then you do not expect to go to prison. If you do not obey the law, you may or may not go to prison depending on other
factors. However, if you do obey the law, but you go to prison, you feel outraged. This last scenario corresponds to the
case when 𝑝𝑝 is true but 𝑞𝑞 is false and thus the truth value of the conditional statement 𝑝𝑝 → 𝑞𝑞 is false.

ELEE 2110U Discrete Mathematics 15


Implication, Converse, Inverse, and Contrapositive
• From an implication 𝑝𝑝 → 𝑞𝑞, three well-known conditional statements can be made:
 The converse of 𝑝𝑝 → 𝑞𝑞 is 𝑞𝑞 → 𝑝𝑝,
 The inverse of 𝑝𝑝 → 𝑞𝑞 is 𝑝𝑝̅ → 𝑞𝑞,
� and
 The contrapositive of 𝑝𝑝 → 𝑞𝑞 is 𝑞𝑞� → 𝑝𝑝.̅
• Noting that logically-equivalent propositions have the same truth values, regardless of the truth values of its propositional
variables, the implication (original conditional statement) and its contrapositive are equivalent, and the converse and
inverse of a conditional statement are also equivalent.

ELEE 2110U Discrete Mathematics 16


Example
Find the contrapositive, converse, and inverse of the conditional statement “if you start using drugs, then you are a moron.”

Solution
Noting 𝑝𝑝 represents the statement “you start using drugs” and 𝑞𝑞 represents the statement “you are a moron”, that is for 𝑝𝑝 →
𝑞𝑞, we have the following statements:
• 𝑞𝑞 → 𝑝𝑝)̅ is “if you are not a moron, then you do not start using drugs.”
The contrapositive statement (�
• The converse statement (𝑞𝑞 → 𝑝𝑝 ) is “if you are a moron, then you start using drugs.”
• The inverse statement (𝑝𝑝̅ → 𝑞𝑞)
� is “if you do not start using drugs, then you are not a moron.”

ELEE 2110U Discrete Mathematics 17


Biconditional Statement
• Let 𝑝𝑝 and 𝑞𝑞 be propositions. The biconditional statement 𝑝𝑝 ↔ 𝑞𝑞, read “𝑝𝑝 if and only if 𝑞𝑞” or “𝑝𝑝 iff 𝑞𝑞” or “if 𝑝𝑝, then 𝑞𝑞,
and conversely” or “𝑝𝑝 is necessary and sufficient for 𝑞𝑞”, is a compound proposition, which is true when 𝑝𝑝 and 𝑞𝑞 have the
same truth values, and is false otherwise.

ELEE 2110U Discrete Mathematics 18


Precedence Rules
• In order to construct compound propositions, parentheses are generally used to specify the order in which operators are to
be applied. Note that parenthesized subexpressions are always evaluated first, and with two operators of equal
precedence, the corresponding expression is evaluated from left.
• The precedence rules, which can reduce the number of parentheses required, for logical statements must be performed as
follows:
 the negation operator is applied before all other logical operators
 the conjunction operator takes precedence over the disjunction operator
 use parentheses for the exclusive or operator
 a conditional operator takes precedence over a bidirectional one
 the conditional and bidirectional operators have lower precedence than the logical operators

ELEE 2110U Discrete Mathematics 19


Precedence Rules
Determine how each of the following statements must be evaluated:
𝑝𝑝 → 𝑞𝑞 ∧ 𝑞𝑞� → 𝑝𝑝̅
𝑝𝑝 → 𝑞𝑞 ↔ 𝑞𝑞� → 𝑝𝑝̅
Solution
Using the precedence rule, we have the following statements:
𝑝𝑝 → 𝑞𝑞 ∧ 𝑞𝑞� → 𝑝𝑝̅ ≡ 𝑝𝑝 → 𝑞𝑞 ∧ 𝑞𝑞� → 𝑝𝑝̅
𝑝𝑝 → 𝑞𝑞 ↔ 𝑞𝑞� → 𝑝𝑝̅ ≡ 𝑝𝑝 → 𝑞𝑞 ↔ 𝑞𝑞� → 𝑝𝑝̅

ELEE 2110U Discrete Mathematics 20


Example
Let 𝑝𝑝 and 𝑞𝑞 be the following propositions:
𝑝𝑝: You drive impaired
𝑞𝑞: You die in a car accident.

Write the following propositions using 𝑝𝑝 and 𝑞𝑞 and logical connectivities including negations:
• You do not drive impaired  𝑝𝑝̅
• You drive impaired, but you do not die in a car accident.  𝑝𝑝 ∧ 𝑞𝑞�
• You will die in a car accident if you drive impaired.  𝑝𝑝 → 𝑞𝑞
• If you do not drive impaired, then you will not die in a car accident.  𝑝𝑝̅ → 𝑞𝑞�
• Driving impaired is sufficient for dying in a car accident.  𝑝𝑝 → 𝑞𝑞
• You die in a car accident, but you do not drive impaired.  𝑞𝑞 ∧ 𝑝𝑝̅
• Whenever you die in a car accident, you are driving impaired.  𝑞𝑞 → 𝑝𝑝

ELEE 2110U Discrete Mathematics 21


Propositional Equivalences

ELEE 2110U Discrete Mathematics 22


De Morgan’s Laws
• De Morgan’s laws state that the negation of an “and” statement is logically equivalent to the “or” statement in which each
component is negated and the negation of an “or” statement is logically equivalent to the “and” statement in which each
component is negated.
• In order to avoid any potential confusion in the English language, De Morgan’s laws can be applied if there exist
complete statements on either side of each “and” as well as on either side of each “or”.
• Applying De Morgan’s laws:
 My friend is 2 meters tall and he weighs at least 100 kilograms  My friend is not 2 meters tall or he weighs less
than 100 kilograms.
 The flight was delayed or the airport’s clock was slow  The flight was not delayed and the airport’s clock was not
slow.

ELEE 2110U Discrete Mathematics 23


Example
(a) Prove that the negation of the conditional statement “If 𝑝𝑝, then 𝑞𝑞” is logically equivalent to “𝑝𝑝 and not 𝑞𝑞.”
(b) Write the negation of the conditional statement “If I sleep late at night, then I cannot get up early in the morning.”

Solution
(a) We have 𝑝𝑝 → 𝑞𝑞 ≡ 𝑝𝑝̅ ∨ 𝑞𝑞, therefore its negation using De Morgan’s laws and the double negative law is as follows:
𝑝𝑝 → 𝑞𝑞 ≡ 𝑝𝑝̅ ∨ 𝑞𝑞 ≡ 𝑝𝑝̿ ∧ 𝑞𝑞� ≡ 𝑝𝑝 ∧ 𝑞𝑞,
� which means 𝑝𝑝 and not 𝑞𝑞.

(b) Let 𝑝𝑝 be the proposition “I sleep late at night” and 𝑞𝑞 be the proposition “I can get up early in the morning.” Based on
𝑝𝑝 → 𝑞𝑞� ≡ 𝑝𝑝 ∧ 𝑞𝑞, the negation is “I sleep late at night and I can get up early in the morning.” Note that the negation of an
implication (if-then statement) does not start with the word if.

ELEE 2110U Discrete Mathematics 24


Example
Apply De Morgan’s laws to write the negations for each of the following statements:
(a) My friend is 2 meters tall and he weighs at least 100 kilograms.
(b) The flight was delayed or the airport’s clock was slow.

Solution
Note that in order to avoid any potential confusion in the English language, De Morgan’s laws can be applied if there exist
complete statements on either side of each “and” as well as on either side of each “or.”
(a) My friend is not 2 meters tall or he weighs less than 100 kilograms.
(b) The flight was not delayed and the airport’s clock was not slow.

ELEE 2110U Discrete Mathematics 25


Tautology
• A compound proposition that is always true, regardless of the truth values of the propositional variables, i.e., the
compound proposition contains only 𝑇𝑇 in the last column of its truth table, is called a tautology. Note that the compound
propositions 𝑝𝑝 and 𝑞𝑞 are called logically equivalent if 𝑝𝑝 ↔ 𝑞𝑞 is a tautology.
• Some simple examples of tautology in English are “Parents are older than their children,” “the children will take turns
one after the other,” and “Dead people do not breath.” A simple example of tautology in logic is 𝑝𝑝 ∨ 𝑝𝑝.̅

ELEE 2110U Discrete Mathematics 26


Contradiction
• A compound proposition that is always false, regardless of the truth values of the propositional variables, i.e., the
compound proposition contains only 𝐹𝐹 in the last column of its truth table, is called a contradiction. Note that the
negation of a tautology is a contradiction and the negation of a contradiction is a tautology.
• Some simple examples of contradiction in English are “Some are more equal than others,” “Rich people need a tax cut
because they do not have much money,” “Texting while driving reduces chances of having a car accident,” and
“Imposing economic sanctions on a country brings about democracy to that country.” A simple example of contradiction
in logic is 𝑝𝑝 ∧ 𝑝𝑝.̅

ELEE 2110U Discrete Mathematics 27


Contingency
• A compound proposition that is neither a tautology nor a contradiction is called a contingency. In most practical
applications and statements in logic, the proposition happens to be contingency.
• Some simple examples of contingency in English are “Politicians are dishonest,” and “People in this country are not
racist.” A simple example of contingency in logic is 𝑝𝑝 → 𝑝𝑝.̅

ELEE 2110U Discrete Mathematics 28


Example
Show that the logical expressions 𝑝𝑝 ↔ 𝑞𝑞 and 𝑝𝑝 ⊕ 𝑞𝑞 are logically-equivalent.

Solution
We need to show that 𝑝𝑝 ↔ 𝑞𝑞 ↔ 𝑝𝑝 ⊕ 𝑞𝑞 is a tautology, i.e., the last column of the truth table consists of trues only.

ELEE 2110U Discrete Mathematics 29


Example
Show that 𝑝𝑝 ∨ (𝑞𝑞 ∧ 𝑟𝑟) is a contingency.

Solution
We need to show that the last column of the truth table consists of both truth and false values.

ELEE 2110U Discrete Mathematics 30


Predicate Logic
• A predicate refers to a property that the subject of the statement can have or gives information about the subject.
• A predicate contains a finite number of variables and becomes a propositional statement when specific values are
substituted for the variables.
• The domain, also known as the universe of discourse or the domain of discourse, of a predicate is the sets of all values
that may be substituted in place of the variables.
• A predicate that involves just one variable may be denoted by 𝑃𝑃(𝑥𝑥). The statement 𝑃𝑃(𝑥𝑥) is said to be the value of the
propositional function 𝑃𝑃 at 𝑥𝑥. A propositional function 𝑃𝑃, by itself, is neither true nor false. However, once a value has
been assigned to the variable 𝑥𝑥, 𝑃𝑃(𝑥𝑥) becomes a propositional statement and has a truth value.
• A predicate that involves 𝑛𝑛 variables, called an n-ary predicate, may be denoted by 𝑃𝑃(𝑥𝑥1 , 𝑥𝑥2 , … , 𝑥𝑥𝑛𝑛 ), once a set of values
has been assigned to the variables 𝑥𝑥1 , 𝑥𝑥2 , … , 𝑥𝑥𝑛𝑛 , 𝑃𝑃(𝑥𝑥1 , 𝑥𝑥2 , … , 𝑥𝑥𝑛𝑛 ) has a truth value, as it is then a propositional statement.

ELEE 2110U Discrete Mathematics 31


Example
Consider the statement 𝑥𝑥 ≥ 2, for 𝑥𝑥 = 0 and 𝑥𝑥 = 7.2, where the domain for the variable consists of all real numbers.
Discuss it in the context of predicate logic.

Solution
The statement 𝑥𝑥 > 2 has two parts. The first part is the variable 𝑥𝑥, which is the subject of the statement, and the second part
is the predicate 𝑃𝑃, which denotes “is greater than 2”. The propositional function 𝑃𝑃(𝑥𝑥) denotes the statement 𝑥𝑥 > 2.
Therefore, 𝑃𝑃(0) and 𝑃𝑃(7.2) are both propositional statements, where 𝑃𝑃(0), indicating 0 ≯ 2, is false and 𝑃𝑃(7.2), indicating
7.2 > 2, is true.

ELEE 2110U Discrete Mathematics 32


Example
The statement 𝑥𝑥 2 + 𝑦𝑦 2 = 𝑧𝑧 2 , for 𝑥𝑥 = 3, 𝑦𝑦 = 4, and 𝑧𝑧 = 5 as well as 𝑥𝑥 = 5, 𝑦𝑦 = 6, and 𝑧𝑧 = 7, where the domain for each of
the three variables consists of all positive integers. Discuss it in the context of predicate logic.

Solution
The statement 𝑥𝑥 2 + 𝑦𝑦 2 = 𝑧𝑧 2 has two parts. The first part consists of the variables 𝑥𝑥, 𝑦𝑦, and 𝑧𝑧, and the second part is the
predicate 𝑄𝑄. The propositional function 𝑄𝑄(𝑥𝑥, 𝑦𝑦, 𝑧𝑧) denotes the statement 𝑥𝑥 2 + 𝑦𝑦 2 = 𝑧𝑧 2 . Therefore, 𝑄𝑄(3, 4, 5) and 𝑄𝑄(5, 6, 7)
are both propositional statements, where 𝑄𝑄(3, 4, 5), indicating 9 + 16 = 25, is true and 𝑄𝑄(5, 6, 7), indicating 25 + 36 =
49, is false.

ELEE 2110U Discrete Mathematics 33


Quantifiers
• By assigning a value to the variable 𝑥𝑥, the propositional function 𝑃𝑃(𝑥𝑥) becomes a propositional statement with a truth
value.
• Another way to obtain a proposition from a propositional function is to add quantifiers. For instance, the propositions
“few people are very compassionate,” “some people are racist,” “all people are mortal,” “none of them are good,” “one
even prime number exists” and “every day the sun rises” each contains a word indicating quantity, such as “few,” “some,”
“all,” “none,” “one,” and “every.”
• These words are called quantifiers, as each word reveals for how many elements a given predicate is true.
• There are two types of quantifications:
 Universal quantification
 Existential quantification

ELEE 2110U Discrete Mathematics 34


Universal Quantification
• Universal quantification indicates that a predicate is true for every element under consideration.
• In other words, universal quantification asserts that a predicate is true for all values of a variable in a given domain.
• Since the domain specifies the possible values of a variable, by changing the domain, the meaning of the universal
quantification of a predicate may change.
 Example: if the domain consists of all real numbers greater than 1, then the assertion that the inverse of every
number is less than the number itself is true. However, if the domain changes and includes all positive real numbers,
then the assertion that the inverse of every number is less than the number itself is false.
• The universal quantification of 𝑃𝑃(𝑥𝑥), which is the statement 𝑃𝑃(𝑥𝑥) for all values of 𝑥𝑥 in the domain, is denoted by
∀𝑥𝑥𝑥𝑥(𝑥𝑥). The symbol ∀ is called the universal quantifier and read as “for all” or “for every.”
• The statement ∀𝑥𝑥𝑥𝑥(𝑥𝑥) is defined to be true if and only if 𝑃𝑃(𝑥𝑥) is true for every 𝑥𝑥 in the domain, and to be false for at
least one 𝑥𝑥 in the domain.

ELEE 2110U Discrete Mathematics 35


Example
Determine the truth values of the universal statement ∀𝑥𝑥(𝑥𝑥 ≥ 𝑥𝑥) for the following domains:
(a) All positive integers less than or equal to 3.
(b) All positive real numbers less than or equal to 3.

Solution
(a) The statement is true for each element in the domain, that is for 𝑥𝑥 ∈ 1, 2, 3 , as we have 1 = 1, 2 > 2 and 3 > 3.
Hence, ∀𝑥𝑥(𝑥𝑥 ≥ 𝑥𝑥) is true.
(b) The statement is false for at least one element in the domain 𝑥𝑥 ∈ (0, 3]. As a counterexample, if 𝑥𝑥 = 0.49, we then have
0.49 ≥ 0.49 = 0.7, which in turn mean ∀𝑥𝑥(𝑥𝑥 ≥ 𝑥𝑥) is false. In fact, the statement is false for 𝑥𝑥 ∈ (0, 1). Note that to
prove a universal statement is false, a single example is sufficient.

ELEE 2110U Discrete Mathematics 36


Existential Quantification
• Existential quantification indicates that a predicate is true for at least one element under consideration.
• In other words, existential quantification asserts that a predicate is true for at least one value of a variable in a given
domain.
• Since the domain specifies the possible values of a variable, by changing the domain, the meaning of the existential
quantification of a predicate may change.
 Example: If the domain consists of all females, then the assertion that there is at least one person who is pregnant is
true. However, if the domain changes and includes all males, then the assertion that there is at least one person who
is pregnant is false.
• The existential quantification of 𝑃𝑃(𝑥𝑥), which is the statement 𝑃𝑃(𝑥𝑥) for at least one value of 𝑥𝑥 in the domain, is denoted
by ∃𝑥𝑥𝑥𝑥(𝑥𝑥). The symbol ∃ is called the existential quantifier and read as “for some”, “there exists a” or “for at least one.”
• The statement ∃𝑥𝑥𝑥𝑥(𝑥𝑥) is defined to be true if and only if 𝑃𝑃(𝑥𝑥) is true for at least one 𝑥𝑥 in the domain, and to be false for
every 𝑥𝑥 in the domain.

ELEE 2110U Discrete Mathematics 37


Example
Determine the truth values of the existential statement ∃𝑥𝑥(𝑥𝑥 < 𝑥𝑥) for the following domains:
(a) All positive integers less than or equal to 3.
(b) All positive real numbers less than or equal to 3.

Solution
(a) The statement is false for each element in the domain, that is, for 𝑥𝑥 ∈ 1, 2, 3 , as we have 1 = 1, 2 > 2 and 3 > 3.
Hence, ∃𝑥𝑥𝑥𝑥(𝑥𝑥) is false.
(b) The statement is true for an element in the domain 𝑥𝑥 ∈ (0, 3], as for 𝑥𝑥 = 0.49, we have 0.49 < 0.49 = 0.7. Hence,
∃𝑥𝑥𝑥𝑥(𝑥𝑥) is true. In fact, the statement is true for 𝑥𝑥 ∈ (0, 1). Note that to prove an existential statement is true, a single
example is sufficient.

ELEE 2110U Discrete Mathematics 38


Quantified Statements with a Domain with Finite Elements
• Universal statements are generalizations of “and” and existential statements are generalizations of “or” statements. When
the domain of a quantifier is finite, quantified statements can be expressed using propositional logic.
• When the elements of the domain are 𝑥𝑥1 , 𝑥𝑥2 , … , 𝑥𝑥𝑛𝑛 , where 𝑛𝑛 is a positive integer,
 the universal quantification ∀𝑥𝑥𝑥𝑥(𝑥𝑥) is the same as the conjunction 𝑃𝑃 𝑥𝑥1 ∧ 𝑃𝑃 𝑥𝑥2 ∧ ⋯ ∧ 𝑃𝑃(𝑥𝑥𝑛𝑛 ), because this
conjunction is true if and only if 𝑃𝑃 𝑥𝑥1 , 𝑃𝑃 𝑥𝑥2 , …, and 𝑃𝑃(𝑥𝑥𝑛𝑛 ) are all true, and
 the existential quantification ∃𝑥𝑥𝑥𝑥(𝑥𝑥) is the same as the disjunction 𝑃𝑃 𝑥𝑥1 ∨ 𝑃𝑃 𝑥𝑥2 ∨ ⋯ ∨ 𝑃𝑃(𝑥𝑥𝑛𝑛 ), because this
disjunction is true if and only if at least one of 𝑃𝑃 𝑥𝑥1 , 𝑃𝑃 𝑥𝑥2 , …, and 𝑃𝑃(𝑥𝑥𝑛𝑛 ) is true.

ELEE 2110U Discrete Mathematics 39


Logical Equivalence for Quantified Statements
• In the context of logical equivalence for quantified statements, the statements are logically equivalent if and only if they
have identical truth value no matter what predicates are substituted for the predicate symbols and no matter what domains
are used for the variables in these propositional functions.
• Note that the symbol “≡ " indicates statements are logically equivalent. For instance, if two statements 𝑃𝑃 and 𝑄𝑄 are
logically equivalent, then we have 𝑃𝑃 ≡ 𝑄𝑄.

ELEE 2110U Discrete Mathematics 40


Example
Show that ∃𝑥𝑥 𝑃𝑃(𝑥𝑥) ∨ 𝑄𝑄(𝑥𝑥) and ∃𝑥𝑥𝑥𝑥(𝑥𝑥) ∨ ∃𝑥𝑥𝑥𝑥(𝑥𝑥) are logically equivalent.

Solution
In order to prove these two quantified statements are logically equivalent, we need to prove first if ∃𝑥𝑥 𝑃𝑃(𝑥𝑥) ∨ 𝑄𝑄(𝑥𝑥) is true,
then ∃𝑥𝑥𝑥𝑥(𝑥𝑥) ∨ ∃𝑥𝑥𝑥𝑥(𝑥𝑥) is true, and second if ∃𝑥𝑥𝑥𝑥(𝑥𝑥) ∨ ∃𝑥𝑥𝑥𝑥(𝑥𝑥) is true, then ∃𝑥𝑥 𝑃𝑃(𝑥𝑥) ∨ 𝑄𝑄(𝑥𝑥) is true.
First, suppose that ∃𝑥𝑥 𝑃𝑃(𝑥𝑥) ∨ 𝑄𝑄(𝑥𝑥) is true. This means that there exists a 𝑐𝑐 for which 𝑃𝑃(𝑐𝑐) ∨ 𝑄𝑄(𝑐𝑐) is true. Hence, either
𝑃𝑃(𝑐𝑐) or 𝑄𝑄(𝑐𝑐) or both are true. Therefore, either ∃𝑥𝑥𝑥𝑥(𝑥𝑥) or ∃𝑥𝑥𝑥𝑥(𝑥𝑥) or both are true. This means that ∃𝑥𝑥𝑥𝑥(𝑥𝑥) ∨ ∃𝑥𝑥𝑥𝑥(𝑥𝑥) is
true.
Second, suppose that ∃𝑥𝑥𝑥𝑥 𝑥𝑥 ∨ ∃𝑥𝑥𝑥𝑥 𝑥𝑥 is true. This means that either ∃𝑥𝑥𝑥𝑥 𝑥𝑥 or ∃𝑥𝑥𝑥𝑥 𝑥𝑥 or both are true. Hence, there
exists a 𝑐𝑐 for which either 𝑃𝑃 𝑐𝑐 or 𝑄𝑄 𝑐𝑐 or both are true. Therefore, 𝑃𝑃 𝑐𝑐 ∨ 𝑄𝑄 𝑐𝑐 is true. This means that ∃𝑥𝑥 𝑃𝑃(𝑥𝑥) ∨ 𝑄𝑄(𝑥𝑥)
is true.

ELEE 2110U Discrete Mathematics 41


Negation of Quantified Statements
• Consider the statement “every poor person deserves to live a better life.” This statement is a universal quantification,
namely ∀𝑥𝑥𝑥𝑥(𝑥𝑥), where 𝑃𝑃(𝑥𝑥) represents “𝑥𝑥 deserves to live a better life” and the domain consists of the world’s poor
people.
• The negation of this statement is “it is not the case that every poor person deserves to live a better life” or equivalently
“there is at least one poor person who does not deserve to live a better life.” This negation is simply the existential
quantification of the propositional function, that is, ∃𝑥𝑥𝑃𝑃(𝑥𝑥).
• Consider the statement “some people are caring.” This statement is an existential quantification, namely ∃𝑥𝑥𝑥𝑥(𝑥𝑥), where
𝑃𝑃(𝑥𝑥) represents “𝑥𝑥 is caring” and the domain consists of the world’s people.
• The negation of this statement is “it is not the case that some people are caring” or equivalently “no person is caring.”
This negation is simply the universal quantification of the propositional function, that is, ∀𝑥𝑥𝑃𝑃(𝑥𝑥).

∀𝑥𝑥𝑥𝑥(𝑥𝑥 ) ≡ ∃𝑥𝑥𝑃𝑃(𝑥𝑥 )

∃𝑥𝑥𝑥𝑥 𝑥𝑥 ≡ ∀𝑥𝑥𝑃𝑃(𝑥𝑥 )

ELEE 2110U Discrete Mathematics 42


Quantifiers and De Morgan’s Laws for Quantifiers

ELEE 2110U Discrete Mathematics 43


Example
Determine the negations of the following statements: (a) All prime numbers are odd. (b) There is an honest politician. (c)
Rich people do not have empathy. (d) Some people do not live to be 100 years old.

Solution
(a) Let 𝑃𝑃(𝑥𝑥) denote “𝑥𝑥 is an odd number” and the domain consists of all prime numbers. Then the statement “all prime
numbers are odd” is represented by ∀𝑥𝑥𝑥𝑥 𝑥𝑥 and its negation is ∃𝑥𝑥𝑃𝑃(𝑥𝑥). This negation can be expressed as “there exists
at least one prime number that is not odd.”
(b) Let 𝑃𝑃(𝑥𝑥) denote “𝑥𝑥 is an honest politician” and the domain consists of all politicians. Then the statement “there is an
honest politician” is represented by ∃𝑥𝑥𝑥𝑥(𝑥𝑥) and its negation is ∀𝑥𝑥𝑃𝑃(𝑥𝑥). This negation can be expressed as “all
politicians are dishonest.”
(c) Let 𝑃𝑃(𝑥𝑥) denote “𝑥𝑥 has empathy” and the domain consists of all rich people. Then the statement “rich people do not have
empathy” is represented by ∀𝑥𝑥𝑃𝑃(𝑥𝑥) and its negation is ∃𝑥𝑥𝑥𝑥(𝑥𝑥). This negation can be expressed as “some rich people
have empathy.”
(d) Let 𝑃𝑃(𝑥𝑥) denote “𝑥𝑥 lives to be 100 years old” and the domain consists of all people. Then the statement “some people do
not live to be 100 years old” is represented by ∃𝑥𝑥𝑃𝑃(𝑥𝑥) and its negation is ∀𝑥𝑥𝑥𝑥(𝑥𝑥). This negation can be expressed as “all
people live to be 100 years old.”
ELEE 2110U Discrete Mathematics 44
Negations of Universal Conditional Statements
Noting that in propositional logic, the negation of an implication is logically equivalent to an “and” statement, namely
𝑃𝑃(𝑥𝑥) → 𝑄𝑄(𝑥𝑥) ≡ 𝑃𝑃(𝑥𝑥) ∧ 𝑄𝑄(𝑥𝑥), the negation of a universal conditional statement is thus as follows:

∀𝑥𝑥 𝑃𝑃(𝑥𝑥) → 𝑄𝑄(𝑥𝑥) ≡ ∃𝑥𝑥(𝑃𝑃(𝑥𝑥) ∧ 𝑄𝑄 𝑥𝑥 ).

ELEE 2110U Discrete Mathematics 45


Example
Determine the negations of the following statements:
(a) Every person who is a vegetarian is healthy.
(b) Some people weigh more than 100 kg and are not healthy.

Solution
(a) Let 𝑃𝑃(𝑥𝑥) denote “𝑥𝑥 is a vegetarian” and 𝑄𝑄(𝑥𝑥) denote “𝑥𝑥 is healthy,” where the domain consists of all people. The
statement “every person who is a vegetarian is healthy” is represented by ∀𝑥𝑥 𝑃𝑃(𝑥𝑥) → 𝑄𝑄(𝑥𝑥) , and its negation is thus
∃𝑥𝑥(𝑃𝑃(𝑥𝑥) ∧ 𝑄𝑄 𝑥𝑥 ), i.e., there are some people who are vegetarian and not healthy.
(b) Let 𝑃𝑃(𝑥𝑥) denote “𝑥𝑥 weighs more than 100 kg” and 𝑄𝑄(𝑥𝑥) denote “𝑥𝑥 is healthy,” where the domain consists of all people.
The statement “some people weigh more than 100 kg and are not healthy” is represented by ∃𝑥𝑥(𝑃𝑃(𝑥𝑥) ∧ 𝑄𝑄 𝑥𝑥 ), and its
negation is thus ∀𝑥𝑥 𝑃𝑃(𝑥𝑥) → 𝑄𝑄(𝑥𝑥) , i.e., every person who weighs more than 100 kg is healthy.

ELEE 2110U Discrete Mathematics 46


Nested Quantifiers: Quantification of Two Variables

ELEE 2110U Discrete Mathematics 47


Example
Let 𝑃𝑃(𝑥𝑥, 𝑦𝑦) be the statement 𝑦𝑦 < 𝑥𝑥 2 . Determine the truth values of the following quantifications, where the domain for each
of the two variables consists of all real numbers −∞, ∞ . Note that the inequality 𝑦𝑦 < 𝑥𝑥 2 indicates the region of interest in
the 𝑥𝑥𝑥𝑥 plane that lies under the graph 𝑦𝑦 = 𝑥𝑥 2 .
(a) ∀𝑥𝑥∀𝑦𝑦𝑦𝑦 x, y
(b) ∀𝑦𝑦∀𝑥𝑥𝑥𝑥 𝑥𝑥, 𝑦𝑦
(c) ∀𝑥𝑥∃𝑦𝑦𝑦𝑦 𝑥𝑥, 𝑦𝑦
(d) ∀𝑦𝑦∃𝑥𝑥𝑥𝑥 𝑥𝑥, 𝑦𝑦

Solution
(a) This quantification denotes that the proposition “for all real numbers 𝑥𝑥 and all real numbers 𝑦𝑦 , 𝑦𝑦 < 𝑥𝑥 2 .”
It is false, as any point above the graph does not satisfy the inequality.
(b) This quantification denotes that the proposition “for all real numbers 𝑦𝑦 and all real numbers 𝑥𝑥 , 𝑦𝑦 < 𝑥𝑥 2 .”
It is false, as any point above the graph does not satisfy the inequality.
(c) This quantification denotes that the proposition “for every real number 𝑥𝑥, there is a real number 𝑦𝑦, 𝑦𝑦 < 𝑥𝑥 2 .”
It is true, as every vertical line intersecting the region of interest satisfies the inequality.
(d) This quantification denotes that the proposition “for every real number 𝑦𝑦, there is a real number 𝑥𝑥, 𝑦𝑦 < 𝑥𝑥 2 .”
It is true, as every horizontal line intersecting the region of interest satisfies the inequality.

ELEE 2110U Discrete Mathematics 48


Example
Let 𝑃𝑃(𝑥𝑥, 𝑦𝑦) be the statement 𝑦𝑦 < 𝑥𝑥 2 . Determine the truth values of the following quantifications, where the domain for each
of the two variables consists of all real numbers −∞, ∞ . Note that the inequality 𝑦𝑦 < 𝑥𝑥 2 indicates the region of interest in
the 𝑥𝑥𝑥𝑥 plane that lies under the graph 𝑦𝑦 = 𝑥𝑥 2 .
(a) ∃𝑥𝑥∀𝑦𝑦𝑦𝑦 𝑥𝑥, 𝑦𝑦
(b) ∃𝑦𝑦∀𝑥𝑥𝑥𝑥 𝑥𝑥, 𝑦𝑦
(c) ∃𝑥𝑥∃𝑦𝑦𝑦𝑦 𝑥𝑥, 𝑦𝑦
(d) ∃𝑦𝑦∃𝑥𝑥𝑥𝑥 𝑥𝑥, 𝑦𝑦

Solution
(a) This quantification denotes that the proposition “there is a real number 𝑥𝑥 , for all real numbers 𝑦𝑦 , 𝑦𝑦 < 𝑥𝑥 2 .”
It is false, as there is no vertical line wholly within the region of interest satisfying the inequality.
(b) This quantification denotes that the proposition “there is a real number 𝑦𝑦 , for all real numbers 𝑥𝑥, 𝑦𝑦 < 𝑥𝑥 2 .”
It is true, as there is a horizontal line wholly within the region of interest satisfying the inequality.
(c) This quantification denotes that the proposition “there is a real number 𝑥𝑥, there is a real number 𝑦𝑦, 𝑦𝑦 < 𝑥𝑥 2 .”
It is true, as any point in the region of interest satisfies the inequality.
(d) This quantification denotes that the proposition “there is a real number 𝑦𝑦, there is a real number 𝑥𝑥, 𝑦𝑦 < 𝑥𝑥 2 .”
It is true, as any point in the region of interest satisfies the inequality.

ELEE 2110U Discrete Mathematics 49


Example
(a) Translate the statement “the sum of the squares of two negative numbers is positive, where the domain is all real
numbers” into a logical expression.
(b) Translate the statement “some student has solved at least one exercise in every topic covered in this course” into a
logical expression.
(c) Translate the statement “∀𝑥𝑥 𝑥𝑥 > 0 → ∃𝑦𝑦(𝑦𝑦 = ln 𝑥𝑥)” into English.

Solution

(a) Let 𝑥𝑥 and 𝑦𝑦 represents the two real numbers that are added. The logical expression is thus ∀𝑥𝑥∀𝑦𝑦 �� 𝑥𝑥 < 0 ∧

𝑦𝑦 < 0 � → 𝑥𝑥 2 + 𝑦𝑦 2 > 0�.

(b) Let 𝑃𝑃(𝑥𝑥, 𝑦𝑦) mean that student 𝑥𝑥 has solved exercise 𝑦𝑦, and 𝑄𝑄(𝑦𝑦, 𝑧𝑧) mean that exercise 𝑦𝑦 is in topic 𝑧𝑧 in this course. The
logical expression is thus ∃𝑥𝑥∀𝑧𝑧∃𝑦𝑦 𝑃𝑃(𝑥𝑥, 𝑦𝑦) ∧ 𝑄𝑄(𝑦𝑦, 𝑧𝑧) .
(c) For every positive number 𝑥𝑥, there exists a real number 𝑦𝑦 such that 𝑦𝑦 = ln 𝑥𝑥.

ELEE 2110U Discrete Mathematics 50


Example
Consider the statement ∀𝑥𝑥∃𝑦𝑦∃𝑧𝑧(𝑥𝑥𝑥𝑥 > 𝑧𝑧), where the domains of 𝑥𝑥, 𝑦𝑦, and 𝑧𝑧 are all real numbers.
(a) Translate the statement into English and determine its truth value.
(b) Express the negation of the statement and determine its truth value.

Solution
(a) The English translation of the statement is as follows: “For every 𝑥𝑥, there exist a 𝑦𝑦 and a 𝑧𝑧, such that 𝑥𝑥𝑥𝑥 > 𝑧𝑧.” It is thus
true.
(b) As the statement ∀𝑥𝑥∃𝑦𝑦∃𝑧𝑧(𝑥𝑥𝑥𝑥 > 𝑧𝑧) involves nested quantifiers, it can be negated by sequentially applying the rules for
negating statements with a single quantifier. The resulting quantification denotes the following proposition:

∀𝑥𝑥∃𝑦𝑦∃𝑧𝑧(𝑥𝑥𝑥𝑥 > 𝑧𝑧) ≡ ∃𝑥𝑥∃𝑦𝑦∃𝑧𝑧 𝑥𝑥𝑥𝑥 > 𝑧𝑧 ≡ ∃𝑥𝑥∀𝑦𝑦∃𝑧𝑧 𝑥𝑥𝑥𝑥 > 𝑧𝑧 ≡ ∃𝑥𝑥∀𝑦𝑦∀𝑧𝑧 𝑥𝑥𝑥𝑥 > 𝑧𝑧 ≡ ∃𝑥𝑥∀𝑦𝑦∀𝑧𝑧(𝑥𝑥𝑥𝑥 ≤ 𝑧𝑧).

The negation of the statement is as follows: “There is an 𝑥𝑥, for all real numbers 𝑦𝑦 and 𝑧𝑧, such that 𝑥𝑥𝑥𝑥 ≤ 𝑧𝑧.” It is thus false.

ELEE 2110U Discrete Mathematics 51


Valid Arguments
• In the context of propositional logic, an argument is a sequence of propositional statements.
• All propositions in an argument, except for the final one, are called hypotheses, premises, or assumptions, and the final
proposition that follows from the hypotheses is called the conclusion or consequence.
• A valid argument is a sequence of propositions where the truth of all the premises implies the truth of the conclusion.
• An argument is valid because of its form, not because of its content.
• An argument form is a sequence of compound propositions involving propositional variables.
• In a valid argument form, no matter which particular propositions are substituted for the propositional variables in its
premises, the conclusion is true if all the premises are true.
• To say that an argument is valid means that its form is valid. Therefore, an argument is valid if the conjunction of all
hypotheses logically implies the conclusion, that is, such an implication is a tautology. Otherwise the argument is invalid.

ELEE 2110U Discrete Mathematics 52


Example
Consider the two hypotheses that today there are more residents in a small town than the number of days any resident of the
town has ever lived, and no one was born today. Show that we can conclude at least two residents of the town have the same
age, that is, at least two of them were born on the same day.

Solution
Suppose there are 𝑛𝑛 residents in that small town, where 𝑛𝑛 is obviously a positive integer.
The argument contains two hypotheses, which we assume they are both true. The first hypothesis suggests that the number of
days every resident has ever lived is less than 𝑛𝑛 and the second hypothesis suggests that the number of days every resident
has ever lived is at least one.
If no two residents are of the same age, there must be 𝑛𝑛 positive integers less than 𝑛𝑛, which is impossible. Therefore, at least
two residents have been born on the same day. The logical conclusion agrees with the given conclusion, the argument is thus
valid.

ELEE 2110U Discrete Mathematics 53


Validity of an Argument Form
One effective way to test an argument form for its validity is to take the following steps:
• Identify the premises and conclusion of the argument form and construct a truth table showing their truth values, while
noting that a row of truth table in which all the premises are true is called a critical row.
• Check critical rows. If the conclusion in every critical row is true, the argument form is then valid, otherwise it is not a
valid argument form.

ELEE 2110U Discrete Mathematics 54


Example
Determine the validity of this argument form: If 𝑠𝑠 = 𝑞𝑞 ∨ 𝑟𝑟 and 𝑡𝑡 = 𝑝𝑝 ∧ 𝑟𝑟, then 𝑟𝑟 → 𝑠𝑠 ⊕ 𝑡𝑡 .

Solution
As the truth table reflects, there are critical rows, namely rows 1 and 3, where each row has a false conclusion
𝑟𝑟 → 𝑠𝑠 ⊕ 𝑡𝑡 , but its premises 𝑠𝑠 = 𝑞𝑞 ∨ 𝑟𝑟 and 𝑡𝑡 = 𝑝𝑝 ∧ 𝑟𝑟 are true. Hence this form of argument is invalid.

ELEE 2110U Discrete Mathematics 55


Sound Argument vs Valid Argument
• Noting in a valid argument the truth of all of its premises implies the truth of the conclusion, an argument is called sound
if and only if it is both valid and all of its premises are true, and as a consequence its conclusion is true as well.
• Note that in a sound argument as well as in a valid argument, the conclusion is true. However, in a sound argument, all of
its premises are true, whereas in a valid argument, all of its premises are assumed to be true.

ELEE 2110U Discrete Mathematics 56


Example
(a) Provide an example of an argument that is valid and sound.
(b) Provide an example of an argument that is valid but not sound.

Solution
(a) All human beings need water to survive. My teacher is a human being. Therefore, my teacher needs water to survive.
Because of the logical necessity of the conclusion, this argument is valid. The argument is valid and its premises are true, the
argument is thus sound.
(b) All birds can fly. Ostriches are birds. Therefore, ostriches can fly. This argument is valid because, assuming the premises
are true, the conclusion must be true. However, the first premise is false. Not all birds can fly. Hence, the argument is valid
but not sound.

ELEE 2110U Discrete Mathematics 57


Rules of Inference for Propositional Statements

ELEE 2110U Discrete Mathematics 58


Example

Modus ponens (law of attachment): Suppose that the conditional statement “If the weather is nice tonight, then I will go
for a walk” and its hypothesis “The weather is nice tonight” are both true. Then, it follows that the conclusion of the
conditional statement “I will go for a walk” is also true.

Modus tollens (law of contrapositive): Suppose that the conditional statement “If the weather is nice tonight, then I will go
for a walk” is true, but its conclusion, “I will go for a walk,” is false. Then, it follows that the hypothesis “The weather is
nice tonight” is false too.

ELEE 2110U Discrete Mathematics 59


Example

Hypothetical syllogism (rule of transitivity): As the statements “If a number is divisible by 6, then it is divisible by 3” and
“If a number is divisible by 3, then the sum of its digits is divisible by 3” are both true, the statement “If a number is
divisible by 6, then the sum of its digits is divisible by 3” is also true.

Disjunctive syllogism (rule of elimination): As an example, “Positive integers are either even or odd” and “If a positive
integer is not even, then it must be odd.”
ELEE 2110U Discrete Mathematics 60
Example

Generalization (rule of addition): As an example, “It is sunny today.” Therefore, “it is sunny today or it is cold today.”

Simplification rule: As an example, “It is sunny and cold today.” Therefore, “It is sunny today,” and “It is cold today.”

ELEE 2110U Discrete Mathematics 61


Example

Conjunction rule: As an example, “All students in a math course have passed the course” and “All students in a physics
course have passed the course” are both true, then “Any student who took both courses has passed them both” is true.

Resolution rule: As an example, if the propositions “Lily is happy or Neda is sad” and “Lily is not happy or Mat is happy”
are both true, then the proposition “Neda is sad or Mat is happy” is true.

ELEE 2110U Discrete Mathematics 62


Example
Consider the premises “I am not sad tonight and today is more fun than yesterday.” “I will go out only if I am sad.” “If I do
not go out, I will watch a basketball game on TV.” “If I watch a basketball game on TV, then I sleep late.” Using rules of
inference, show that these premises lead to the conclusion “I will sleep late.”

Solution
Let’s define these propositions: 𝑝𝑝 as “I am sad tonight,” 𝑞𝑞 as “today is more fun than yesterday,” 𝑟𝑟 as “I will go out,” 𝑠𝑠 as “I
will watch a basketball game on TV,” and 𝑡𝑡 as “I will sleep late.” We can thus construct:
i. 𝑝𝑝̅ ∧ 𝑞𝑞 Premise
ii. 𝑝𝑝̅ Simplification using (i)
iii. 𝑟𝑟 → 𝑝𝑝 Premise
iv. 𝑟𝑟̅ Modus tollens using (ii) and (iii)
v. 𝑟𝑟̅ → 𝑠𝑠 Premise
vi. 𝑠𝑠 Modus ponens using (iv) and (v)
vii. 𝑠𝑠 → 𝑡𝑡 Premise
viii. 𝑡𝑡 Modus ponens using (vi) and (vii)

ELEE 2110U Discrete Mathematics 63


Rules of Inference for Quantified Statements

ELEE 2110U Discrete Mathematics 64


Example
Using rules of interference, show that the premises “a student writing an exam cheated,” and “everyone writing the exam
was penalized” imply the conclusion “someone who was penalized had cheated.”

Solution
Let 𝑈𝑈(𝑥𝑥), 𝑉𝑉(𝑥𝑥), and 𝑊𝑊(𝑥𝑥) be propositions “𝑥𝑥 wrote the exam,” “𝑥𝑥 cheated on the exam,” and “𝑥𝑥 was penalized”,
respectively. Using rules of inference for both propositions and qualified statements, we start off with the two premises:
i. ∃𝑥𝑥 𝑈𝑈 𝑥𝑥 ∧ 𝑉𝑉 𝑥𝑥 Hypothesis
ii. 𝑈𝑈 𝑎𝑎 ∧ 𝑉𝑉 𝑎𝑎 Existential instantiation from (i)
iii. 𝑈𝑈 𝑎𝑎 Simplification from (ii)
iv. ∀𝑥𝑥 𝑈𝑈 𝑥𝑥 → 𝑊𝑊 𝑥𝑥 Hypothesis
v. 𝑈𝑈 𝑎𝑎 → 𝑊𝑊 𝑎𝑎 Universal instantiation from (iv)
vi. 𝑊𝑊(𝑎𝑎) Modus ponens from (iii) and (v)
vii. 𝑉𝑉(𝑎𝑎) Simplification from (ii)
viii. 𝑉𝑉 𝑎𝑎 ∧ 𝑊𝑊 𝑎𝑎 Conjunction from (vi) and (vii)
ix. ∃𝑥𝑥(𝑉𝑉(𝑥𝑥) ∧ 𝑊𝑊(𝑥𝑥)) Existential generalization from (viii)

ELEE 2110U Discrete Mathematics 65


Rules of Inference for Propositions and Quantified Statements

ELEE 2110U Discrete Mathematics 66


Example
Write each of the following arguments using quantifiers, variable, and predicate symbols, and state if each is valid.
(a) All humans being are mortal and Rumi is human. We can thus conclude that Rumi is mortal.
(b) All humans being are mortal and Rumi is not mortal. We can thus conclude that Rumi is not human.

Solution
(a) Let 𝑃𝑃(𝑥𝑥) and 𝑄𝑄(𝑥𝑥) be the propositions “𝑥𝑥 is human being,” and “𝑥𝑥 is mortal,” respectively, and let 𝑎𝑎 represent Rumi.
Then the argument (∀𝑥𝑥 𝑃𝑃 𝑥𝑥 → 𝑄𝑄(𝑥𝑥)) ∧ 𝑃𝑃(𝑎𝑎) → 𝑄𝑄(𝑎𝑎) is in the form of universal modus ponens and it is therefore
valid.
(b) Let 𝑃𝑃(𝑥𝑥) and 𝑄𝑄(𝑥𝑥) be the propositions “𝑥𝑥 is human being,” and “𝑥𝑥 is mortal,” respectively, and let 𝑎𝑎 represent Rumi.
Then the argument (∀𝑥𝑥 𝑃𝑃 𝑥𝑥 → 𝑄𝑄(𝑥𝑥)) ∧ 𝑄𝑄 𝑎𝑎 → 𝑃𝑃(𝑎𝑎) is in the form of universal modes tollens and it is therefore
valid.

ELEE 2110U Discrete Mathematics 67


Fallacy
• Fallacies arise in invalid arguments where they resemble rules of inference, but they are based on contingencies rather
than tautologies.
• It is important to note that in logic the words “true” and “valid” have totally different meanings. A valid argument may
have a false conclusion and an invalid argument may have a true conclusion.
• Many people often mistake the concept of validity for the concept of truth and vice versa. If they find an argument valid,
they accept the conclusion as true, and if they find an argument invalid, they take the conclusion as false. This approach
in logic is not correct.
• Flawed, yet common, argument forms are known as fallacies.
• Fallacies are statements that might sound reasonable, seemingly plausible or superficially true but are actually defective.
• Fallacies can be divided into two broad categories: fallacies with irrelevant premises and fallacies with unacceptable
premises. In good arguments, premises must be both relevant and acceptable, and in a fallacious argument at least one of
these two requirements is not met.
• Oftentimes, a person makes a fallacy either intentionally to manipulate and persuade by deception or unintentionally due
to carelessness and ignorance, in either case, it is invalid and appear to be better than it really is.

ELEE 2110U Discrete Mathematics 68


Common Fallacies
Circular Reasoning: The fallacy of making assertions sufficiently different to obscure the fact that the same proposition
occurs as both a premise and a conclusion.
Example: A says “God exists.” B says “How do you know that God exists?” A says “The holy book says so.” B says “Why
should I believe the holy book?” A says “Because it is the word of God.”
Hasty Generalization: The fallacy of jumping to conclusions, making assumptions, reaching results about a group without
adequate evidence, such as atypical or just too-small sample size. It is a mistaken use of inductive reasoning.
Example: My neighbor, who is on welfare, is watching TV all the time and doing nothing, I believe social assistance to
people should be cut off, we do not want lazy citizens.
Genetic Fallacy: The fallacy of assuming a claim is true or false solely due to its origin or judging something is good or bad
on the basis of where it comes from or from whom it comes.
Example: When someone appeals to prejudices surrounding someone’s background. He is not a good citizen of this country,
because his parents were not born here.

ELEE 2110U Discrete Mathematics 69


Common Fallacies
Appeal to Popularity: The fallacy of asserting a claim must be true simply because a lot of people believe it, i.e., using the
popularity of a premise or proposition as evidence for its truthfulness. This fallacy, also known as the bandwagon fallacy, is
difficult to spot as common sense suggests that if something is popular, it must be good/true/valid/right, but this is not so.
Examples: (i) God exists because most people believe in it. (ii) Capital punishment is the right sentence for a convicted
murderer because most people in this country believe it is.
Appeal to Heaven: An extremely dangerous fallacy of asserting that God supports or approves one's own standpoint or
actions so it is right and no further justification is required and no serious challenge is possible.
Examples: (i) God gave us this land, it is thus ours. (ii) God ordered me to kill my son, and I was just following his orders.
Appeal to Authority: In an appeal to biased authority, the authority is one who truly is knowledgeable on the topic, but
unfortunately one who may have professional or personal motivations that render that judgement.
Example: In order to determine whether the military budget is big enough, the views of all generals and the CEOs of military
equipment manufacturers were solicited.

ELEE 2110U Discrete Mathematics 70


Common Fallacies
Appeal to Ignorance: The fallacy of arguing a lack of evidence or an absence of knowledge as proof, that is a claim has to
be true (or false) because it has not been proven to be false (or true).
Examples: (i) God exists because it has not been proven that God does not exist. (ii) Scientists cannot positively prove their
theory that humans evolved from other creatures, because we were not there to see it, it therefore proves the six-day creation
account is literally true as written.
Appeal to Emotion: The fallacy of allowing premises to be based on emotions rather than relevant reasons or manipulating
an emotional response in place of a valid argument.
Example: A good citizen must fight in a war for his country and does not question if the war is just and waging it serves the
best interest of the majority of his fellow countrymen.
Red Herring: The fallacy of raising an irrelevant or invalid point deliberately during an argument with the sole purpose of
distraction, changing the subject or diverting the real question at issue.
Example: The president should not be held accountable for cheating on his income tax returns, after all he was
democratically elected.

ELEE 2110U Discrete Mathematics 71


Common Fallacies
Begging the Question: The fallacy of assuming what is to be proven without having derived it from the premises.
Example: Building a highway in the north of the country that hardly anyone uses is a waste of money, I am therefore against
building this highway. It is true that spending money on a useless highway is something that no one wants, but nobody
proved this highway was useless.
Stacking the Deck: A fallacy in which examples that disprove the point are ignored, and examples that support the case are
listed.
Example: He is a family man who loves his children, goes to church every Sunday, and has been a valued member of his
community for decades. There is no mention that he is a racist.
Othering: A badly corrupted, discriminatory argument where facts, experiences, or objections are arbitrarily disregarded,
ignored, or put down without serious consideration because those involved "are not like us," or "don't think like us."
Example: It's OK for those people overseas to earn a buck an hour by our corporations. If it happened here it is nothing but
brutal exploitation and daylight robbery, but over there, the economy is different and they're not like us.

ELEE 2110U Discrete Mathematics 72


Common Fallacies
Tiny Percentage Fallacy: An amount or action that is quite significant in and of itself somehow becomes insignificant
simply because it's a tiny percentage of something much larger.
Example: The killings of tens of black people in the U.S. by the police every year is a tiny percentage of thousands of black
people who are arrested by the police every year.
The Big Lie Technique: The contemporary fallacy of repeating a lie, slogan, talking-point, nonsense-statement or deceptive
half-truth over and over in different forms particularly in the media until it becomes part of daily discourse and people accept
it without further proof or evidence.
Examples: (i) The non-existent "Weapons of Mass Destruction" in Iraq legitimized the invasion of Iraq. (ii) The U.S.
president-elect in 2016 stated that "millions" of ineligible votes were cast in that year's American presidential election.
Gaslighting: A recently-prominent fallacy denying or invalidating a person's own knowledge and experiences by deliberately
twisting or distorting known facts, memories, events and evidence in order to disorient a vulnerable opponent and to make
someone doubt their sanity.
Example: Who are you going to believe? Me or your own eyes? You're crazy! You seriously need to see a shrink.

ELEE 2110U Discrete Mathematics 73


Terminology Related to Proofs
Definition: A statement expressing the essential nature of a concept and a set of associated properties that describe the
concept.
Axiom: A self-evident (assumed to be) true statement that is unproven, it is also known as postulate.
Theorem: A mathematical statement that can be shown (proved) to be true.
Corollary: A proposition that can be proved is an immediate consequence of some other theorems.
Lemma: A less important theorem that can help prove a more important theorem.
Conjecture: A statement that is being proposed to be a true statement, but not proven yet.

ELEE 2110U Discrete Mathematics 74


Example
Provide specific examples to highlight some terminology related to proofs.

Solution
Definition: A circle is a closed plane curve every point of which is equidistant from a fixed point within the curve.
Axiom: In Euclidean geometry, within a two-dimensional plane, for any given straight line and a point that is not
on the line, there exists exactly one straight line passing through the point that is parallel to the line.
Theorem: If two sides of a triangle are equal, then the angles opposite them are equal.
Corollary: If three sides of a triangle are equal, then all three angles opposite them are equal.
Lemma: If we subtract 1 from a positive integer, then the result is either a positive integer or 0.
𝑥𝑥
Conjecture: If a transformation sends an even integer 𝑥𝑥 to and an odd integer 𝑥𝑥 to 3𝑥𝑥 + 1, then for all positive
2

integers 𝑥𝑥, the repeated application of the transformation will eventually reach integer 1.

ELEE 2110U Discrete Mathematics 75


Proof
• Proof is a sequence of logically valid statements to demonstrate the validity of some precise statement.
• A mathematical proof is an inferential argument for a mathematical statement showing that the stated assumptions
methodically and logically lead to guarantee the conclusion.
• Any statement that is not an axiom or definition needs to be proved.

ELEE 2110U Discrete Mathematics 76


Proofs of Equivalence
Sometimes a theorem states that a group of 𝑛𝑛 ≥ 2 propositions 𝑝𝑝1 , 𝑝𝑝2 , … , 𝑝𝑝𝑛𝑛 are equivalent (𝑝𝑝1 ↔ 𝑝𝑝2 ↔ ⋯ ↔ 𝑝𝑝𝑛𝑛 ) that is
they have the same truth values. In order to show proof of equivalence, we need to show that the 𝑛𝑛 conditional statements
𝑝𝑝1 → 𝑝𝑝2 , 𝑝𝑝2 → 𝑝𝑝3 , … , 𝑝𝑝𝑛𝑛 → 𝑝𝑝1 are all true, that is, we have the following:

𝑝𝑝1 ↔ 𝑝𝑝2 ↔ ⋯ ↔ 𝑝𝑝𝑛𝑛 ↔ 𝑝𝑝1 → 𝑝𝑝2 ∧ 𝑝𝑝2 → 𝑝𝑝3 ∧ … ∧ 𝑝𝑝𝑛𝑛 → 𝑝𝑝1

Instead of bidirectional statements (if and only if statements), implications (if, then statements) are employed.

ELEE 2110U Discrete Mathematics 77


Example
Prove that for every positive integer 𝑛𝑛, 𝑛𝑛 is even if and only if 𝑛𝑛 − 1 is odd.

Solution
There are two statements 𝑝𝑝1 : 𝑛𝑛 is even, and 𝑝𝑝2 : 𝑛𝑛 − 1 is odd. In order to show they are equivalent, i.e., 𝑝𝑝1 ↔ 𝑝𝑝2 , we need to
prove that 𝑝𝑝1 → 𝑝𝑝2 and 𝑝𝑝2 → 𝑝𝑝1 .
We first prove that if 𝑛𝑛 is even, then 𝑛𝑛 − 1 is odd. If 𝑛𝑛 is even, then 𝑛𝑛 = 2𝑘𝑘 for some integer 𝑘𝑘, and thus 𝑛𝑛 − 1 = 2𝑘𝑘 − 1,
which is odd.
We then prove that if 𝑛𝑛 − 1 is odd, then 𝑛𝑛 is even. If 𝑛𝑛 − 1 is odd, then 𝑛𝑛 − 1 = 2𝑘𝑘 + 1 for some integer 𝑘𝑘, and thus 𝑛𝑛 =
2𝑘𝑘 + 2 = 2(𝑘𝑘 + 1), which is even.

ELEE 2110U Discrete Mathematics 78


Proof by Counterexample
• A counterexample is a form of counter proof. To prove that a statement of the form ∀𝑥𝑥𝑥𝑥(𝑥𝑥) is false, we need to find an
element 𝑥𝑥 such that 𝑃𝑃(𝑥𝑥) is false.
• To disprove a statement, we need to find an example in the domain of discourse for which the hypothesis is true and the
conclusion is false, such an example is called a counterexample. For instance, for the statement that all prime numbers
are odd, 2 is a counterexample as it is even.
• A theorem cannot be proved by considering examples unless every possible case is included.

ELEE 2110U Discrete Mathematics 79


Example
Disprove that for every positive integer 𝑛𝑛, 2𝑛𝑛 + 𝑛𝑛 is prime.

Solution
In order to disprove it, we need a counterexample. When 𝑛𝑛 = 4, we have 24 + 4 = 20, which is not prime.

ELEE 2110U Discrete Mathematics 80


Direct Proofs
• Direct proof, which is based on using definitions, axioms, logical equivalences, and the rules of inference, is the most
common proof strategy.
• A direct proof of an implication is constructed with the assumption that the premise is true and a series of intermediate
implications eventually leads to the fact that the conclusion of the implication must also be true.
• In other words, we show that the combination that the premise is true and the conclusion is false never occurs.

ELEE 2110U Discrete Mathematics 81


Example
Prove the statement “if 𝑛𝑛 is an odd integer, then 𝑛𝑛2 is odd” is true.

Solution
Assuming 𝑛𝑛 is odd, i.e., 𝑛𝑛 = 2𝑘𝑘 + 1 for some integer 𝑘𝑘, we have 𝑛𝑛2 = (2𝑘𝑘 + 1)2 = 4𝑘𝑘 2 + 4𝑘𝑘 + 1. Noting that 𝑚𝑚 =
4𝑘𝑘 2 + 4𝑘𝑘 is an even integer as it is a multiple of 4, we can thus conclude that 𝑛𝑛2 = 𝑚𝑚 + 1 is an odd integer.

ELEE 2110U Discrete Mathematics 82


Proof by Contraposition
Proof by contraposition is based on the law of contrapositive, i.e., the conditional statement 𝑝𝑝 → 𝑞𝑞 is equivalent to its
contrapositive 𝑞𝑞� → 𝑝𝑝.̅ In other words, in proof by contraposition of 𝑝𝑝 → 𝑞𝑞, we take 𝑞𝑞� as a premise and we show that 𝑝𝑝̅ must
follow.

ELEE 2110U Discrete Mathematics 83


Example
Prove the following statement using a proof of contraposition.
If a real number is irrational, then its square root is irrational.

Solution
By letting 𝑥𝑥 be an arbitrary real number, we need to prove if 𝑥𝑥 is irrational, then 𝑥𝑥 is irrational. Using a proof of
contraposition, we want to prove that if 𝑥𝑥 is not irrational, then 𝑥𝑥 is not irrational or equivalently if 𝑥𝑥 is rational, then 𝑥𝑥 is
𝑚𝑚 𝑚𝑚2
rational. If 𝑥𝑥 is rational, then 𝑥𝑥 = for some integers 𝑚𝑚 and 𝑛𝑛. As a result, we have 𝑥𝑥 = , which is the quotient of
𝑛𝑛 𝑛𝑛2

integers. Hence, 𝑥𝑥 is rational. We just showed the negation of the hypothesis of the original conditional statement is true.

ELEE 2110U Discrete Mathematics 84


Proof by Contradiction
• Proof by contradiction is based on the law of reductio ad absurdum (meaning reduction to absurdity), i.e., assuming the
given hypothesis 𝑝𝑝 is true and the given conclusion 𝑞𝑞 is false, then a contradiction is reached. In other words, in a proof
by contradiction of 𝑝𝑝 → 𝑞𝑞, we prove that 𝑝𝑝 ∧ 𝑞𝑞� results in an absurdity or a contradiction.
• Noting that a contradiction is a proposition of the form 𝑟𝑟 ∧ 𝑟𝑟,̅ where 𝑟𝑟 may be any proposition, we prove that 𝑝𝑝 is true if
we show 𝑝𝑝̅ → 𝑟𝑟 ∧ 𝑟𝑟̅ for some proposition 𝑟𝑟.

ELEE 2110U Discrete Mathematics 85


Example
Prove that the statement 2 is irrational using a proof of contradiction.

Solution
𝑝𝑝
If 2 is not irrational, then it is rational and can be thus written as the fraction of two integers 𝑝𝑝 and 𝑞𝑞, where we assume is
𝑞𝑞
in lowest terms so 𝑝𝑝 and 𝑞𝑞 are not both even.
𝑚𝑚 𝑚𝑚2
We therefore have 2= → 2= → 𝑚𝑚2 = 2𝑛𝑛2 → 𝑚𝑚2 is even → 𝑚𝑚 is even → 𝑚𝑚 = 2𝑘𝑘 → 𝑚𝑚2 = 2𝑛𝑛2 = 4𝑘𝑘 2 →
𝑛𝑛 𝑛𝑛2
𝑛𝑛2 = 2𝑘𝑘 2 → 𝑛𝑛2 is even → 𝑛𝑛 is even.
We showed that if 2 is not irrational, then both 𝑚𝑚 and 𝑛𝑛 are even, which contradicts our assumption that 𝑚𝑚 and 𝑛𝑛 are not
both even. Therefore, 2 is irrational.

ELEE 2110U Discrete Mathematics 86


Proof by Cases
Sometimes we need to partition the proof into several disjoint parts whose union is the complete theorem and then prove
each part individually. To prove a conditional statement of the form 𝑝𝑝1 ∨ 𝑝𝑝2 ∨ ⋯ ∨ 𝑝𝑝𝑛𝑛 → 𝑞𝑞, the tautology �(𝑝𝑝1 ∨ 𝑝𝑝2 ∨ ⋯ ∨

𝑝𝑝𝑛𝑛 ) → 𝑞𝑞 � ↔ 𝑝𝑝1 → 𝑞𝑞 ∧ 𝑝𝑝2 → 𝑞𝑞 ∧ ⋯ ∧ 𝑝𝑝𝑛𝑛 → 𝑞𝑞 can be used as a rule of inference. It is then called proof by cases.

ELEE 2110U Discrete Mathematics 87


Example
Assuming 𝑘𝑘 is a positive integer, show that 𝑚𝑚 = 𝑘𝑘 3 − 𝑘𝑘 is an even integer.

Solution
Using a proof by cases, we consider two mutually exclusive cases for 𝑘𝑘, i.e., 𝑘𝑘 is even and 𝑘𝑘 is odd, as every positive integer
falls into one of these two cases. Assuming 𝑘𝑘 is even, we then have 𝑘𝑘 = 2𝑛𝑛 → 𝑚𝑚 = 𝑘𝑘 3 − 𝑘𝑘 = 𝑘𝑘(𝑘𝑘 + 1)(𝑘𝑘 − 1) =
2𝑛𝑛 2𝑛𝑛 + 1 2𝑛𝑛 − 1 , that is, 𝑚𝑚 is even, as it is a multiple of 2. Assuming 𝑘𝑘 is odd, we then have 𝑘𝑘 = 2𝑛𝑛 + 1 → 𝑚𝑚 = 𝑘𝑘 3 −
𝑘𝑘 = (𝑘𝑘 − 1)𝑘𝑘(𝑘𝑘 + 1) = 2𝑛𝑛 2𝑛𝑛 + 1 2𝑛𝑛 + 2 , that is, 𝑚𝑚 is even, as it is a multiple of 2.

ELEE 2110U Discrete Mathematics 88


Proof by Exhaustion
A proof by cases must check all possible cases that arise in a theorem. However, when each case involves checking a single
example, such as proof is called proof by exhaustion. Note that when the number of cases is infinitely many or just very
large, then neither proof by cases nor proof by exhaustion are possible or even feasible.

ELEE 2110U Discrete Mathematics 89


Example
Assuming 𝑚𝑚 and 𝑛𝑛 are positive integers, show that 4𝑚𝑚2 + 9𝑛𝑛2 = 36 has no solutions.

Solution
Since 4𝑚𝑚2 and 9𝑛𝑛2 are both positive, we can conclude 4𝑚𝑚2 < 36 → 2𝑚𝑚 < 6 → 𝑚𝑚 < 3 and 9𝑛𝑛2 < 36 → 3𝑛𝑛 < 6 → 𝑛𝑛 < 2.
Using a proof by exhaustion, this leaves the cases that 𝑚𝑚 =1 or 𝑚𝑚 = 2 as well as 𝑛𝑛 = 1. Neither when we have 𝑚𝑚 = 1 and
𝑛𝑛 = 1 nor when we have 𝑚𝑚 = 2 and 𝑛𝑛 = 1 can make the left-hand side of the equation equal to 36. It is therefore impossible
for 4𝑚𝑚2 + 9𝑛𝑛2 = 36 to hold when 𝑚𝑚 and 𝑛𝑛 are positive integers.

ELEE 2110U Discrete Mathematics 90

You might also like