0% found this document useful (0 votes)
225 views246 pages

All Tutorials

The document provides information about random variables and probability distributions. It begins with defining a random variable as a function that assigns a real number to each possible outcome of an experiment. Examples are then given to illustrate random variables, including the sums of dice rolls. The expected value, variance, and standard deviation of random variables are defined. Several probability distributions are covered, including the binomial, Bernoulli, discrete uniform, and Poisson distributions. Examples are used to demonstrate calculating probabilities and distribution properties for each type of distribution. The last example discusses the expected number of rolls needed to get a 6 when rolling a fair die repeatedly.

Uploaded by

Angad Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
225 views246 pages

All Tutorials

The document provides information about random variables and probability distributions. It begins with defining a random variable as a function that assigns a real number to each possible outcome of an experiment. Examples are then given to illustrate random variables, including the sums of dice rolls. The expected value, variance, and standard deviation of random variables are defined. Several probability distributions are covered, including the binomial, Bernoulli, discrete uniform, and Poisson distributions. Examples are used to demonstrate calculating probabilities and distribution properties for each type of distribution. The last example discusses the expected number of rolls needed to get a 6 when rolling a fair die repeatedly.

Uploaded by

Angad Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 246

Tutorial

Week 10

1
Random Variables
A random variable is a function from the sample space of an experiment to the set of real numbers.
It assigns a real number to each possible outcome.

2
Example:

Let X be the sum of the numbers that appear when a pair of dice is rolled. What are the values of this
random variable for the 36 possible outcomes (i, j ), where i and j are the numbers that appear on the
first die and the second die, respectively, when these two dice are rolled?

Solution:

X((1, 1)) = 2,
X((1, 2)) = X((2, 1)) = 3,
X((1, 3)) = X((2, 2)) = X((3, 1)) = 4,
X((1, 4)) = X((2, 3)) = X((3, 2)) = X((4, 1)) = 5,
X((1, 5)) = X((2, 4)) = X((3, 3)) = X((4, 2)) = X((5, 1)) = 6,
X((1, 6)) = X((2, 5)) = X((3, 4)) = X((4, 3)) = X((5, 2)) = X((6, 1)) = 7,
X((2, 6)) = X((3, 5)) = X((4, 4)) = X((5, 3)) = X((6, 2)) = 8,
X((3, 6)) = X((4, 5)) = X((5, 4)) = X((6, 3)) = 9,
X((4, 6)) = X((5, 5)) = X((6, 4)) = 10,
X((5, 6)) = X((6, 5)) = 11,
X((6, 6)) = 12.

3
Example:

The probability mass function for the previous example:

Solution:

If we rolled two six-sided dice, and let X be the sum, then X could take on any value in the
set {2,3,4,5,6,7,8,9,10,11,12}.

The probability mass function for this X is:

4
Expected value of a random variable: the weighted average of a random variable, with
values of the random variable weighted by the probability of outcomes, that is,

Example: Expected Value of a Die Let X be the number that comes up when a fair die
is rolled. What is the expected value of X?

Solution:

The random variable X takes the values 1, 2, 3, 4, 5, or 6, each with probability 1/6.
It follows that:

5
Variance of Random Variable shows the spread of random values in its distribution.

V (X) = E(X2) − E(X)2

Example: Variance of the Value of a Die What is the variance of the random variable X, where X is
the number that comes up when a fair die is rolled?

Solution:

V (X) = E(X2) − E(X)2

6
Example: What is the variance of the number of heads that come up when a fair coin is
flipped 10 times?

Solution:

7
Standard Deviation: The square root of the variance of 𝑋,

Example:

Find the variance and standard deviation of the random variable X whose value when two fair
dice are rolled is X((i, j )) = i + j , where i is the number appearing on the first die and j is the
number appearing on the second die.

Solution:

Let X1 and X2 be the random variables defined by X1((i, j )) = i and X2((i, j )) = j for a roll of the dice.
Then X = X1 + X2, and X1 and X2 are independent.

V (X) = V (X1) + V (X2).

Previous example gives us: V (X1) = V (X2) = 35/12. Hence,


V (X) = 35/12 + 35/12 = 35/6
σ(X) = 35/6.

8
Example:

Find the mode of the discrete random variable X that has the following
probability distribution table:

Solution:

Mode: x = 4

9
Bernoulli Distribution : Used for modelling of processes with only two possible outcomes.

Probability of K successes in n independent Bernoulli trails.

If we perform a random experiment by repeating n independent Bernoulli trials, then the random
variable X representing the number of successes in the n trials has a binomial distribution.

10
Example:

Determine which can be defined as a Bernoulli trial:


a) Rolling a die and recording the number that comes up.
b) Rolling a die 5 times and recording the number of 3s that come up.
c) Spinning a spinner numbered 1 to 8 and recording the number that is obtained.
d) Tossing a coin 7 times and recording the number of heads obtained.
e) Drawing a card 5 times from a fair deck, without replacement and recording the number of red cards.
f) Drawing a card 5 times from a fair deck, with replacement and recording the number of red cards.

Solution:

a) No, because the outcome is 1,2,3,4,5 or 6.


b) Yes, because the outcome is either 3 or not 3.
c) No, because the outcome is more than 2.
d) Yes, outcome is either a H or T.
e) No, the outcome is dependent because the probabilities are not the same for each trial.
f) Yes, the outcome is independent and is either red or black.

11
Example:

A coin is biased so that the probability of heads is 2/3. What is the probability that exactly four
heads come up when the coin is flipped seven times, assuming that the flips are independent?

Solution:
There are 27 = 128 possible outcomes when a coin is flipped seven times. The number
Of ways four of the seven flips can be heads is C(7, 4). Because the seven flips are independent, the
probability of each of these outcomes (four heads and three tails) is (2/3)4(1/3)3. Consequently,
the probability that exactly four heads appear is:

12
Example:

Suppose that the probability that a 0 bit is generated is 0.9, that the probability that a 1 bit
is generated is 0.1, and that bits are generated independently. What is the probability that
exactly eight 0 bits are generated when 10 bits are generated?

Solution:
The probability that exactly eight 0 bits are generated

13
Example: Suppose 40% of a very large population of registered voters favor candidate Obama. A random
sample of n = 5 voters will be selected, and X, the number favoring Obama out of 5, is to be observed.
a) What is the probability of getting 2 person who favors Obama? P(X = 2) =?

Solution:

p = P(success) = 0.40
1 − p = P(failure) = 0.60
Either ‘Yes’(S) or ‘No’ (F) on each of 5 draws.
5
P( X=2) = (0.4)²(0.6)3 = 0.34560
2

14
Discrete uniform distribution

Discrete uniform random variable occurs when outcomes are equally likely.
Probability Mass function defined as:

15
Example: A telephone number is selected at random from a directory. Suppose X denote the last digit of
selected telephone number. Find the probability that the last digit of the selected number is
a. 6
b. greater than or equal to 8

Solution:
Let X denote the last digit of randomly selected telephone number. The possible values of X are 0,1,2,⋯,9.
All the numbers 0,1,2,⋯,9 are equally likely. Thus the random variable X follows a discrete uniform
distribution. The probability mass function of X is:

1 1
P(X=x) = 9−0+1 = 10 ; x = 0,1,2…9
1
a. The probability that the last digit of the selected number is 6: P(X=6) = 10 = 0.1
b. The probability that the last digit of the selected telephone number is greater than or equal to 8

1 1
P(X≥8)=P(X=8)+P(X=9) = 10 + 10 = 0.1+0.1 = 0.2

16
Example: Let the random variable X have a discrete uniform distribution on the integers 9≤x≤11.
Determine mean and variance of X.

Solution:

Let the random variable X have a discrete uniform


distribution on the integers 9≤x≤11.
All the integers 9,10,11 are equally likely.
The probability mass function of X is:

1 1
P(X=x) = = ; x = 9,10,11.
11−9+1 3

Mean of X is:

17
Example: Suppose that the probability that a coin comes up tails is p. This coin is flipped repeatedly until
it comes up tails. What is the expected number of flips until this coin comes up tails?

Solution:
the sample space is the set {T, HT, HHT, HHHT, HHHHT, . . .}. (an infinite sample space)
P(H) = 1 − p
p(T ) = p
p(HT ) = (1 − p)p , p(HHT)= (1 − p)2p, …
The coin is flipped n times, that is, n − 1 heads come up followed by a tail, is (1 − p)n−1p.
Now let X be the random variable equal to the number of flips in an element in the sample space.
X(T ) = 1, X(HT)= 2, X(HHT)= 3,….
So, p(X = j) = (1 − p)j-1p.
The expected number of flips until the coin comes up tails equals E(X).

When the coin is fair we have p = 1/2, so the expected number of flips until it comes up tails
is 1/(1/2) = 2.
18
Example: Suppose that we roll a fair die until a 6 comes up.
a) What is the probability that we roll the die n times?
b) What is the expected number of times we roll the die?

Solution:

19
Poisson Distribution: The Poisson distribution is a discrete probability distribution for the counts of
events that occur randomly in a given interval of time (or space).
The probability of observing x events in a given interval is given by:

X = The number of events in a given interval.


λ = The mean number of events per interval

20
Example:
Births in a hospital occur randomly at an average rate of 1.8 births per hour.
a) What is the probability of observing 4 births in a given hour at the hospital?
b) What is the probability of observing more than or equal to 2 births in a given hour at the
hospital?

Solution:
a) Let X = No. of births in a given hour
Mean rate λ = 1.8

b) We want P(X ≥ 2) = P(X = 2) + P(X = 3) + . . .


Or,

21
Example:
Suppose there is a disease, whose average incidence is 2 per million people. What is the
probability that a city of 1 million people has at least twice the average incidence?

Solution:
Twice the average incidence would be 4 cases.
Suppose,
X=number of cases in 1 million people

22
Tutorial
Week 9
Topics covered: Counting & Discrete Probability

1
Counting

2
Example:

A particular brand of shirt comes in 12 colors, has a male version and a female version, and comes in
three sizes for each sex. How many different types of this shirt are made?

Solution:

By the product rule there are 12 · 2 · 3 = 72 different types of shirt.

3
Example:

How many different license plates can be made if each plate contains a sequence of three uppercase English
letters followed by three digits (and no sequences of letters are prohibited)?

Solution:

There are 26 choices for each of the three uppercase English letters and 10 choices for each of the three digits.
Hence, by the product rule there are a total of 26 ⋅ 26 ⋅ 26 ⋅ 10 ⋅ 10 ⋅ 10 =
17,576,000 possible license plates.

___ ___ ___ ___ ___ ___

26 choices 10 choices
for each for each
letter digit

4
Example:

How many license plates can be made using either three uppercase English letters followed by
three digits or four uppercase English letters followed by two digits?

Solution:

263103 + 264102 = 63,273,600

5
Example:

Each user on a computer system has a password, which is six to eight characters long, where each character is an
uppercase letter or a digit. Each password must contain at least one digit. How many possible passwords are there?

Solution:

Let P be the total number of possible passwords, and let P6, P7, and P8 denote the number of possible passwords of
length 6, 7, and 8, respectively. By the sum rule, P = P6 + P7 + P8. We will now find P6, P7, and P8. Finding P6
directly is difficult. To find P6 it is easier to find the number of strings of uppercase letters and digits that are six
characters long, including those with no digits, and subtract from this the number of strings with no digits. By the
product rule, the number of strings of six characters is 366, and the number of strings with no digits is 266.
Hence,

P6 = 366 − 266 = 2,176,782,336 − 308,915,776 = 1,867,866,560.


P7 = 367 − 267 = 78,364,164,096 − 8,031,810,176 = 70,332,353,920
P8 = 368 − 268 = 2,821,109,907,456 − 208,827,064,576 = 2,612,282,842,880.
Consequently,

P = P6 + P7 + P8 = 2,684,483,063,360.

6
Example:

How many strings of four decimal digits


a) do not contain the same digit twice?
b) end with an even digit?
c) have exactly three digits that are 9s?

Solution:

a) There are 10 ways to choose the first digit, 9 ways to choose the second, and so on; therefore the answer is:
10 · 9 · 8 · 7 = 5040.

b) There are 10 ways to choose each of the first three digits and 5 ways to choose the last; therefore the answer
is 103 · 5 = 5000.

c) There are 4 ways to choose the position that is to be different from 9, and 9 ways to choose the digit to go
there.
Therefore there are 4 · 9 = 36 such strings.

7
Example:

A computer company receives 350 applications from computer graduates for a job planning a line of new Web
servers. Suppose that 220 of these applicants majored in computer science, 147 majored in business, and 51
majored both in computer science and in business. How many of these applicants majored neither in computer
science nor in business?

Solution:

By the subtraction rule the number of students who majored either in computer science or in business (or both):

|A1 ∪ A2| = |A1| + |A2| − |A1 ∩ A2| = 220 + 147 − 51 = 316.

So, 350 − 316 = 34 of the applicants majored neither in computer science nor in business.

8
THE PIGEONHOLE PRINCIPLE

The pigeonhole principle states that there must be at least two objects in the same box when
there are more objects than boxes.

Example: Among any group of 367 people, there must be at least two with the same birthday, because
there are only 366 possible birthdays.

THE GENERALIZED PIGEONHOLE PRINCIPLE

If N objects are placed into k boxes, then there is at least one box containing at least N/k objects.

9
Example: A bowl contains 10 red balls and 10 blue balls. A woman selects balls at random without looking at them.
a) How many balls must she select to be sure of having at least three balls of the same color?
b) How many balls must she select to be sure of having at least three blue balls?

Solution:

We assume that the woman does not replace the balls after drawing them.

a) There are two colors: these are the pigeonholes. We want to know the least number of pigeons
needed to insure that at least one of the pigeonholes contains three pigeons. By the generalized
pigeonhole principle, the answer is 5. If five balls are selected, at least 5/𝟐 = 3 must have the same
color. On the other hand, four balls is not enough, because two might be red and two might be blue.
Note that the number of balls was irrelevant (assuming that it was at least 5).

b) She needs to select 13 balls in order to insure at least three blue ones. If she does so, then at most 10
of them are red, so at least three are blue. On the other hand, if she selects 12 or fewer balls, then 10
of them could be red, and she might not get her three blue balls. This time the number of balls did
matter.
10
𝑘 distinguishable objects from a set of 𝑛 ≥ 𝑘 objects

11
Example:

How many permutations of the letters ABCDEFGH contain the string ABC ?

Solution:

Because the letters ABC must occur as a block, we can find the answer by finding the number of
permutations of six objects, namely, the block ABC and the individual letters D, E, F, G, and H. Because
these six objects can occur in any order, there are 6! = 720 permutations of the letters ABCDEFGH in
which ABC occurs as a block.

12
Example:

How many ways are there to select five players from a 10-member tennis team to make a trip to
a match at another school?

Solution:

The answer is given by the number of 5-combinations of a set with 10 elements. The number of
such combinations is:

10!
C(10, 5) = 5! 5! = 252.

13
Example:

Seven women and nine men are on the faculty in the mathematics department at a school.

a) How many ways are there to select a committee of 5 office members of the department if at least one
woman must be on the committee?
b) How many ways are there to select a committee of five members of the department if at least one
woman and at least one man must be on the committee?

Solution:

a) There are C (16, 5) ways to select a committee if there are no restrictions. There are C (9, 5) ways to select
a committee from just the 9 men. Therefore there are C (16, 5) − C (9, 5) = 4368 − 126 = 4242 committees
with at least one woman.
b) There are C (16, 5) ways to select a committee if there are no restrictions. There are C (9, 5) ways to select
a committee from just the 9 men. There are C(7,5) ways to select a committee from just the 7 men. These
two possibilities do not overlap, since there are no ways to select a committee containing neither men nor
women. Therefore there are C (16, 5) − C (9, 5) − C (7, 5) = 4368 − 126 − 21 = 4221 committees with at
least one woman and at least one man.

14
Example:

How many ways are there for 10 women and six men to stand in a line so that no two men stand next to each other?
[Hint: First position the women and then consider possible positions for the men.]

Solution:

First position the women relative to each other. Since there are 10 women, there are P(10,10) ways to do this. This
creates 11 slots where a man (but not more than one man) may stand: in front of the first woman, between the first
and second women, . . . , between the ninth and tenth women, and behind the tenth woman. We need to choose six of
these positions, in order, for the first through six man to occupy (order matters, because the men are distinct people).
This can be done is P(11,6) ways. Therefore, the answer is P (10, 10) · P (11, 6) = 10! · 11!/5! = 1,207,084,032,000 .

15
Example:

How many ways are there to distribute hands of 5 cards to each of four players from the standard
deck of 52 cards?

Solution:

We will use the product rule to solve this problem. To begin, note that the first player can be dealt 5
cards in C(52, 5) ways. The second player can be dealt 5 cards in C(47, 5) ways, because only 47 cards
are left. The third player can be dealt 5 cards in C(42, 5) ways. Finally, the fourth player can be dealt 5
cards in C(37, 5) ways. Hence, the total number of ways to deal four players 5 cards each is:

52! 47! 42! 37! 52!


C(52, 5)C(47, 5)C(42, 5)C(37, 5) = . . . =
47! 5! 42! 5! 37! 5! 32! 5! 5! 5! 5! 5! 32!

16
Discrete Probability

17
Example:

What is the probability that when two dice are rolled, the sum of the numbers on the two dice
is 7?

Solution:

There are a total of 36 equally likely possible outcomes when two dice are rolled. (The product
rule can be used to see this; because each die has six possible outcomes, the total number of
outcomes when two dice are rolled is 62= 36.) There are six successful outcomes, namely, (1,
6), (2, 5), (3, 4), (4, 3), (5, 2), and (6, 1), where the values of the first and second dice are
represented by an ordered pair. Hence, the probability that a seven comes up when two fair dice
are rolled is 6/36 = 1/6.

18
Example:

A sequence of 10 bits is randomly generated. What is the probability that at least one of these bits
is 0?
Solution:

Let E be the event that at least one of the 10 bits is 0. Then E is the event that all the bits are 1s. Because
the sample space S is the set of all bit strings of length 10, it follows that

Hence, the probability that the bit string will contain at least one 0 bit is 1023/1024. It is quite difficult
to find this probability directly without using the above Theorem.
19
Example:

What is the probability that a positive integer selected at random from the set of positive
integers not exceeding 100 is divisible by either 2 or 5?

Solution:

Let E1 be the event that the integer is divisible by 2,


let E2 be the event that it is divisible by 5.
Then E1 ∪ E2 is the event that it is divisible by either 2 or 5.
E1 ∩ E2 is the event that it is divisible by both 2 and 5, equivalently, that it is divisible by 10.
Because |E1| = 50, |E2| = 20, and |E1 ∩ E2| = 10, it follows that

p(E1 ∪ E2) = p(E1) + p(E2) − p(E1 ∩ E2)

20
The two conditions be met while assigning a probability p(s) to each outcome s from the sample space S:

Example:
What probabilities should we assign to the outcomes H (heads) and T (tails) when a fair coin is flipped? What
probabilities should be assigned to these outcomes when the coin is biased so that heads comes up twice as often as
tails?

Solution:
For a fair coin, the outcomes are equally likely. Consequently, we assign the probability 1/2 to each of the two
possible outcomes, that is, p(H) = p(T ) = 1/2. For the biased coin we have:
p(H) = 2p(T ).
Because
p(H) + p(T ) = 1,
it follows that
2p(T ) + p(T ) = 3p(T ) = 1.
We conclude that p(T ) = 1/3 and p(H) = 2/3.
21
Example:
A bit string of length four is generated at random so that each of the 16 bit strings of length four is equally likely.
What is the probability that it contains at least two consecutive 0s, given that its first bit is a 0? (We assume that 0
bits and 1 bits are equally likely.)

Solution:
Let E -> the event that a bit string of length four contains at least two consecutive 0s,
let F -> be the event that the first bit of a bit string of length four is a 0.
The probability that a bit string of length four has at least two consecutive 0s, given that its first bit is a 0, is shown
above.
Because E ∩ F = {0000, 0001, 0010, 0011, 0100}, we see that p(E ∩ F) = 5/16. Because there are eight bit strings of
length four that start with a 0, we have p(F) = 8/16 = 1/2. Consequently,

22
Example:

Suppose a manufacturer orders n processor chips. The probability that a particular chip is bad is 0.1. Based
on the Monte Carlo algorithm, determine the minimum number of chips which needs to be tested so the
probability of finding not even a defective chip among those tested is less than one in a 1,000,000.

Solution:

The probability that an item is defective is 𝑝 when random testing is done. Probability of finding not even a
defective one is (1 − 𝑝)𝑘 , which does not depend on 𝑛.

(1 − 𝑝)𝑘 = (1 − 0.1)𝑘 ≤ 10−6 → 0.9𝑘 ≤ 10−6 → log(0.9𝑘 ) ≤ log(10−6 ) → k ≥ 132.

We can thus conclude that when more than 132 tested chips are all good, where the probability of such an
occurrence is less than one in a million, we could say the entire batch of n chips, even those not tested, is
good, of course with some probability of error.

23
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,

where the events 𝐵1, 𝐵2, … , 𝐵n are all mutually exclusive events whose union makes the entire
sample space 𝑆.

24
Example: Suppose that one person in 100,000 has a particular rare disease for which there is a fairly accurate
diagnostic test. This test is correct 99.0% of the time when given to a person selected at random who has the
disease; it is correct 99.5% of the time when given to a person selected at random who does not have the
disease. Given this information can we find
(a) the probability that a person who tests positive for the disease has the disease?
(b) the probability that a person who tests negative for the disease does not have the disease? Should a person
who tests positive be very concerned that he or she has the disease?

Solution:
(a) Let F -> event that a person selected at random has the disease
let E -> event that a person selected at random tests positive for the disease.
To compute p(F | E) using Bayes’ theorem, we need to find p(E | F), p(E | Fത ), p(F), and p(Fത ). So,
p(F) = 1/100,000 = 0.00001
ത = 1 − 0.00001 = 0.99999
p(𝐅)
p(E | F) = 0.99
ഥ| F) = 1 − p(E | F) = 1 − 0.99 = 0.01
p(E
we know that p(E ഥ | Fത ) = 0.995.
Finally, we see that p(E | 𝐅)ത = 1 − p(E
ഥ | Fത ) = 1 − 0.995 = 0.005.
By Bayes’ theorem, we know that:

25
Continuation…

26
Bayesian Spam Filters

p(w) is the probability that the message contains the word w given that the message is spam.
q(w) is the probability that the message contains the word w, given that the message is not spam.

r(w) estimates the probability that the message is spam, given that it contains the word w. If r(w) is
greater than a threshold that we set, such as 0.9, then we classify the message as spam.

27
Example:
Suppose that we train a Bayesian spam filter on a set of 2000 spam messages and 1000 messages that are
not spam. The word “stock” appears in 400 spam messages and 60 messages that are not spam, and the
word “undervalued” appears in 200 spam messages and 25 messages that are not spam. Estimate the
probability that an incoming message containing both the words “stock” and “undervalued” is spam,
assuming that we have no prior knowledge about whether it is spam. Will we reject such messages as spam
when we set the threshold at 0.9?

Solution:
Using the counts of each of these two words in messages known to be spam or known not to be spam, we
obtain the following estimates:

p(stock) = 400/2000 = 0.2, q(stock) = 60/1000 = 0.06, p(undervalued) = 200/2000 = 0.1, and q(undervalued) =
25/1000 = 0.025. Using these probabilities, we can estimate the probability that the message s spam by

As the r(stock,undervalued) > 0.9, an incoming e-mail containing all these two words will be rejected.
28
Tutorial Week 08

1
Spanning Tree
• Let G be a simple graph. A spanning tree of G is a subgraph of G that is a tree containing very vertex of G.
Example: Find a spanning tree of the simple graph G shown in the Figure.

Solution:
• The graph G is connected, but it is not a tree because it contains simple circuits.
• Remove the edge {a, e}. This eliminates one simple circuit.
• Next remove the edge {e, f } to eliminate a second simple circuit
• Finally, remove edge {c, g} to produce a simple graph with no simple circuits.
• This subgraph is a spanning tree, because it is a tree that contains every vertex of G.

2
Spanning Tree

3
Spanning Tree using DFS

Use depth-first search to find a spanning tree for the graph G shown in the Figure

4
Spanning Tree using DFS
Steps:
• We arbitrarily start with the vertex f.
• This produces a path f , g, h, k, j .
• Next, backtrack to k. There is no path beginning at k containing vertices not already visited.
• So, we backtrack to h. Form the path h, i.
• Then backtrack to h, and then to f . From f build the path f , d, e, c, a.
• Then backtrack to c and form the path c, b. This produces the spanning tree.

5
Spanning Tree using DFS

6
Spanning Tree using DFS
• Finally, the constructed Spanning Tree using DFS

7
Spanning Tree using BFS
• Use Breadth-first search to find a spanning tree for the graph G shown in the Figure

8
Spanning Tree using BFS
Steps:
• We choose the vertex e to be the root.
• Then we add edges incident with all vertices adjacent to e, so edges from e to b, d, f , and i are added.
• These four vertices are at level 1 in the tree.
• Next, add the edges from these vertices at level 1 to adjacent vertices not already in the tree
• Hence, the edges from b to a and c are added, as are edges from d to h, from f to j and g, and from i to k.
• The new vertices a, c, h, j , g, and k are at level 2.
• Next, add edges from these vertices to adjacent vertices not already in the graph. This adds edges from g to l
and from k to m.

9
Spanning Tree using BFS

10
Minimum Spanning Tree
• A minimum spanning tree in a connected weighted graph is a spanning tree that has the smallest possible sum of
weights of its edges.
Prim’s Algorithm
I. Start with a vertex.
II. Choose an edge with the least weight connected to the selected vertex.
III. 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.
IV. Repeat step (iii) until 𝑛 -1 edges have been added, where 𝑛 is the number of vertices in the graph

11
The execution of Prim's algorithm
8 7
the root b c d
4 9
vertex
2
a 11 i 4 14 e
7 6
8 10
h g f
1 2

8 7
b c d
4 9
2
a 11 i 4 14 e
7 6
8 10
h g f
1 2 12
8 7
b c d
4 9
2
a 11 i 4 14 e
7 6
8 10
h g f
1 2

8 7
b c d
4 9
2
a 11 i 4 14 e
7 6
8 10
h g f
1 2
13
8 7
b c d
4 9
2
a 11 i 4 14 e
7 6
8 10
h g f
1 2

8 7
b c d
4 9
2
a 11 i 4 14 e
7 6
8 10
h g f
1 2
14
8 7
b c d
4 9
2
a 11 i 4 14 e
7 6
8 10
h g f
1 2

8 7
b c d
4 9
2
a 11 i 4 14 e
7 6
8 10
h g f
1 2
15
8 7
b c d
4 9
2
a 11 i 4 14 e
7 6
8 10
h g f
1 2

16
Kruskal’s Algorithm

Steps:
I. Arrange the edges in nondecreasing order of weights.
II. Choose an edge with the least weight.
III. Add an edge of the least weight, while avoiding to make a simple circuit with the edges already in the
tree.
IV. Repeat step (iii) until 𝑛 - 1 edges have been added, where 𝑛 is the number of vertices in the graph.

17
The execution of Kruskal's algorithm

•The edges are considered by the algorithm in sorted order by weight.

•The edge under consideration at each step is shown with a red weight number.

8 7
b c d
4 9
2
a 11 i 4 14 e
7 6
8 10
h g f
1 2
18
8 7
b c d
4 9
2
a 11 i 4 14 e
7 6
8 10
h g f
1 2

8 7
b c d
4 9
2
a 11 i 4 14 e
7 6
8 10
h g f
1 2
19
8 7
b c d
4 9
2
a 11 i 4 14 e
7 6
8 10
h g f
1 2

8 7
b c d
4 9
2
a 11 i 4 14 e
7 6
8 10
h g f
1 2
20
8 7
b c d
4 9
2
a 11 i 4 14 e
7 6
8 10
h g f
1 2

8 7
b c d
4 9
2
a 11 i 4 14 e
7 6
8 10
h g f
1 2
21
8 7
b c d
4 9
2
a 11 i 4 14 e
7 6
8 10
h g f
1 2

8 7
b c d
4 9
2
a 11 i 4 14 e
7 6
8 10
h g f
1 2
22
8 7
b c d
4 9
2
a 11 i 4 14 e
7 6
8 10
h g f
1 2

8 7
b c d
4 9
2
a 11 i 4 14 e
7 6
8 10
h g f
1 2
23
Huffman Tree
Use Huffman coding to encode the following symbols with the frequencies listed: A: 0.08, B: 0.10, C: 0.12, D:
0.15, E: 0.20, F: 0.35. What is the average number of bits used to encode a character?

24
Huffman Tree

25
Huffman Tree

26
Huffman Tree

The encoding produced encodes A by 111, B by 110, C by 011, D by 010, E by 10, and F by 00. The average
number of bits used to encode a symbol using this encoding is

3 * 0.08 + 3 * 0.10 + 3 * 0.12 + 3 * 0.15 + 2 * 0.20 + 2 * 0.35 = 2.45 bits per symbol

27
Thank You

28
Tutorial week 07
Recursion

▪ process of defining a problem or the solution to a problem in terms of a simpler version of itself
▪ Methods for solving recurrence relations, namely, by iteration, characteristic equations, and generating
functions
• An equation expressing a term of a sequence as a function of prior terms in the sequence is known as a
recurrence 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.
Example

• Let {ai} be the sequence defined by:


• ak = ak−1 + 2 with a0 = 1.
• Plugging values of k into the relation, we get:
• a1 = a0 + 2 = 1 + 2
• a2 = a1 + 2 = 1 + 2 + 2 = 1 + 2(2)
• a3 = a2 + 2 = 1 + 2 + 2 + 2 = 1 + 3(2)
• a4 = a3 + 2 = 1 + 2 + 2 + 2 + 2 = 1 + 4(2)
• Continuing in this fashion reinforces the apparent pattern that an = 1 + n(2) = 1 + 2n.
Example

Let a and b be non-zero constants, and consider:

sk = ask-1 with s0 = b.
s1 = as0 = ab
• s2 = as1 = a(ab) = a2b
• s3 = as2 = a(a2b) = a3b
• s4 = as3 = a(a3b) = a4b
• From this, we can make the conjecture that:
sn = anb.
• Note: if b = 1, then sn = an.
Example

• Let {ai} be the sequence given by:


• ak = ak−1 + k with a0 = 0.
• Solve this recurrence relation
• a1 = a0 + 1 = 1 + 0
• a2 = a1 + 2 = 2 + 1 + 0
• a3 = a2 + 3 = 3 + 2 + 1 + 0
• a4 = a3 + 4 = 4 + 3 + 2 + 1 + 0

• Thus an = n + (n−1) + (n−2) +...+ 3 + 2 + 1 + 0

• so an = n(n+1)/2.
Iteration method

▪ Solve the recurrence relation by iteration


▪ T(n) = n* T(n-1) ; 1 if n =1
T(n) = n * T (n-1) …………….(1)
T(n-1) = (n-1) * T(n-1 -1)
= (n-1) * T(n-2)………(2)
T(n-2) = (n-2) * T(n-3)………….(3)
T(n )= n * T(n -1)
= n * (n-1) * T(n-2)
= n * (n-1) *(n-2) * T(n-3)
so we have,

n * (n-1) *(n-2) * (n-3) ………* 1


Example

n * (n-1) *(n-2) * (n-3) ………* 3 * 2 * 1


1 2 3
n * n(1 - 𝑛) * n( 1 - 𝑛 ) *……. n(𝑛 )
T(n) = 𝑛𝑛
Generating Function

Solve the recurrence relation 𝑎𝑛+2 − 3𝑎𝑛+1 + 2𝑎𝑛 = 0, 𝑎0 = 2, 𝑎1 = 3


• Multiply the eqn. with 𝑥 𝑛 and sum from 0 to ∞
• σ∞ 𝑛 ∞ 𝑛 ∞
𝑛=0 𝑎𝑛+2 𝑥 − 3 σ𝑛=0 𝑎𝑛+1 𝑥 + 2 σ𝑛=0 𝑎𝑛 𝑥 = 0
𝑛

• Expanding we get,
• (𝑎2 + 𝑎3 x + 𝑎4 x2 +………) - 3 (𝑎1 + 𝑎2 x + 𝑎3 x2 +………) + 2 (𝑎0 + 𝑎1 x + 𝑎2 x2 +…… ) = 0
• We know G(x) = 𝑎0 + 𝑎1 x + 𝑎2 x2 +……
• We manipulate above eqn. to obtain expression in terms of G
𝑎2 𝑥 2 + 𝑎3 𝑥 3 + 𝑎4 𝑥 4 + …… 𝑎0 +𝑎1 𝑥 + 𝑎2 𝑥 2 + 𝑎3 𝑥 3 + 𝑎4 𝑥 4 +⋯ −𝑎0 − 𝑎1 𝑥
• =
𝑥2 𝑥2
𝐺(𝑥) −𝑎0 − 𝑎1 𝑥
• 𝑥2
by doing for rest two we get,
𝐺(𝑥) −𝑎0 − 𝑎1 𝑥 𝐺(𝑥) −𝑎0
𝑥2
−3 𝑥
+ 2 G(x) = 0
Example

• Substituting the initial values 𝑎0 = 2, 𝑎1 = 3


𝐺(𝑥) −2−3𝑥 𝐺 𝑥 −2
−3 + 2 G(x) = 0
𝑥2 𝑥
G(x) ( 1- 3x + 2𝑥 2 ) – (2 - 3x) = 0
2 − 3x
G(x) = 2𝑥 2 − 3x + 1
Using partial fraction decomposition ,

2 − 3x 1 1
= +
2𝑥 2 − 3x + 1 1−𝑥 1−2𝑥
Example
1 1
• G(x) = 1−𝑥 + 1−2𝑥
• G(x) = σ∞ 𝑛 ∞ 𝑛 𝑛 ∞ 𝑛 𝑛
𝑛=0 𝑎𝑛 𝑥 = σ𝑛=0 1 𝑥 + σ𝑛=0 2 𝑥
• Reducing the expression, we get,
• 𝑎𝑛 = 1 + 2𝑛
Graph

• 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.
Dijkstra’s Algorithm

• Let distance of start vertex = 0


• Let distance of all other vertices from start = ∞
Repeat
Visit the unvisited vertex with the smallest known distance from the start vertex
For the current vertex, examine its unvisited neighbors
For the current vertex, calculate distance of each neighbor from start vertex
If the calculated distance of a vertex is less than the known distance, update the shortest distance
Update the previous vertex for each of the updated distances
Add the current vertex to the list of visited vertices
Until all vertices visited
Dijkstra’s Algorithm to Find a Shortest Path from a to z

Example: Use Dijkstra’s algorithm to find the length of a shortest path between the vertices a and z in the
weighted graph shown in below.
Dijkstra’s Algorithm to Find a Shortest Path from a to z
Dijkstra’s Algorithm to Find a Shortest Path from a to z
Dijkstra’s Algorithm to Find a Shortest Path from a to z
Thank You
Tutorial week 06
Deductive Reasoning

❑ 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.

✓ A = B, B = C then we can conclude A = C

✓ All numbers ending in 0 or 5 are divisible by 5. The number 35 ends with a 5, so it must be divisible by 5.

✓ In summary, deductive reasoning requires one to start with a few general ideas, called premises, and apply
them to a specific situation.
Inductive Reasoning

❑ Process of reasoning in which the premises are viewed as supplying some evidence for the truth of the
conclusion.

✓ makes broad generalizations from specific observations.

✓ The first pen I pulled from my bag is red. The second pen I pulled from my bag is red. Therefore, all the pen
in my bag are red.

✓ In summary, inductive reasoning uses a set of specific observations to reach an overarching conclusion.

Therefore, a few premises create a pattern that gives way to a broad idea that is possibly true.
Inductive vs Deductive Reasoning

❑ The difference between the two kinds of reasoning lies in the relationship between the premises and the
conclusion.

I. 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.

II. 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.
Mathematical Induction Statement

❑ Let P (n) be a propositional function, where 𝑛 is a positive integer, that is, 𝑛 ∈ 𝑵.

A proof by mathematical induction consists of two steps:

✓ Basis Step: We verify that P (1) is true

✓ Inductive Step: We show that the conditional statement P(k) → P(k + 1) is true for all positive integers k.

✓ The principle of mathematical induction states that by proving these two key steps we can conclude that the
predicate P (𝑛) is true for every positive integer 𝑛 ∈ 𝑵.

(P (1) ∧ ∀k(P(k) → P(k + 1))) → ∀nP (n)


Basis and Inductive Steps

❑ Both are essential in the principle of mathematical induction, but not sufficient, to guarantee the proposition is
true.
✓ Consider the summation formula
2n = 2n , for every positive integer n.
Basis step 21 = 2 . 1 is true when n =1
Inductive step 2k ≠ 2k and 2k+1 ≠ 2 (k+1) where, k > 2
Example 1

➢ Show that if n is a positive integer, then


𝑛( 𝑛+1)
1+ 2 + ………..+ n = 2
Solution:
1( 1+1)
✓ Basis step: n = 1, 1 = 𝑡ℎ𝑎𝑡 𝑚𝑒𝑎𝑛𝑠 𝑃 1 𝑖𝑠 𝑡𝑟𝑢𝑒
2
𝑘 (𝑘+1)
✓ Inductive step: P(k ) = 1 + 2 + …. + k = 2
under the assumption it must be shown that p (k +1 ) is true as,
𝑘+1 [ 𝑘+1 +1] 𝑘+1 𝑘+2
1 + 2 + …. + k + (k + 1) = =
2 2
✓ By adding k+1 to both sides of equation P(k) we have,
𝑘 (𝑘+1) 𝑘+1 𝑘+2
1 + 2 + …. + k + (k + 1) = + ( k+1) =
2 2
Which shows that P (k +1) is true under the assumption that p (k) is true.
Example 2

➢ Use mathematical induction to prove this formula


𝑎𝑟 𝑛+1 − 𝑎
a + ar + ar2 +……..+ arn = when r ≠ 1 and n is a nonnegative integer.
𝑟−1
Solution:
✓ Basis step: P(0) is true because,
a=a
✓ Inductive: P(k) is true where k is an arbitrary nonnegative integer. We write P(k) as
𝑎𝑟 𝑘+1 − 𝑎
a + ar + ar2 +……..+ ark =
𝑟−1
To complete the inductive step, we must show that if P(k) is true, then P(k + 1) is also true.
By adding ark+1 to both sides of P(k),
𝑎𝑟 𝑘+1 − 𝑎 𝑎𝑟 𝑘+2 − 𝑎
a + ar + ar2 +……..+ ark + k
ar =+1 + ark+1 =
𝑟−1 𝑟−1
Example 3

➢ Use mathematical induction to prove that 2n < n! for every integer n with n ≥ 4. (Note that this inequality is
false for n = 1, 2, and 3)
Solution
✓ Let P(n) be the proposition that 2n < n!
✓ Basis step: To prove the inequality for n ≥ 4 requires that the basis step be P(4). Note that P(4) is true, because
24 = 16 < 24 = 4!
✓ Inductive : P(k) is true where, 2k < k! for positive integer k ≥ 4
then P(k +1) i.e 2k+1 < (k+1)! is also true
2k+1 = 2 · 2k by definition of exponent
< 2 · k! by the inductive hypothesis
< (k + 1)k! because 2 < k + 1
< (k + 1)! by definition of factorial function.
✓ This shows that P(k + 1) is true when P(k) is true.
Example 4

➢ Use mathematical induction to prove that 7n+2 + 82n+1 is divisible by 57 for every nonnegative integer n.
Solution:
✓ Basis step: P (0) is true.
70+2 + 82·0+1 = 72 + 81 = 57 is divisible by 57
✓ Induction:
P(k) = 7k+2 + 82k+1 is true, then P(k+1) is also divisible by 57.
So we have,
P(k+1) = 7k+1+2 + 82(k+1)+1 = 7k+3 + 82k+3
= 7 · 7k+2 + 82 · 82k+1
= 7 · 7k+2 + 64 · 82k+1
= 7(7k+2 + 82k+1) + 57 · 82k+1
Strong Induction

➢ When the truth of 𝑃(k) 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.

✓ Inductive step, we show that for all positive integers k ≥ 1, if P(1), P(2), ………P(k-1), P(k). Called the
inductive hypothesis are all true, then P(k+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.
Example

❑ Let an be the sequence defined by a1 = 1, a2 = 8 and an = an-1 + 2 an-2 for n ≥ 3. Prove that
an = 3. 2 n-1 + 2 (-1)n for all n € N
Solution:
Basis step: when n =1 then
an = a1 = 1, and rightside = 1
Inductive: Let k € N with k ≥ 2
ak+1 = ak + 2 ak-1
= 3. 2 k-1 + 2 (-1)k + 2 (3. 2 k-2 + 2 (-1)k-1 )
= 3. (2 k-1 + 2 k-1 ) + 2 ( ((-1)k + 2 (-1)k -1))
= 3. 2 k + 2 (-1) k+1
Thus the above equation holds for n = k+1.
By the strong induction principle, it follows that an = 3. 2 n-1 + 2 (-1)n is true for all n € N.
Thank You
Tutorial week 05
Cryptography & Algorithm
Cryptography

 Cryptography the way of secure communications techniques that allow only the sender and intended
recipient of a message to view its contents.

Transformed
 Encryption plaintext (Original msg) Coded msg(Ciphertext)

 Decryption reverse process of encryption when the ciphertext received or retrieved

 The process of encryption and decryption requires a secret key where key is a number or value.
Caesar Cipher

 A simple encryption method based on substitution


 It shifts each letter in the alphabet by 3 letters forward. for example, the letter G(6) becomes J(6+3)
 Caesar’s encryption method can be represented by the function f that
Encryption  f (p) = ( p + 3) mod 26
--1
Decryption f (p) = (p - 3) mod 26
where, p is a nonnegative integer, P < = 25
Caesar Cipher Example

 Exp 1: What is the secret message produced from the message “MEET YOU IN THE PARK” using the
Caesar cipher?
Solution:
 First replace the letters in the message with numbers. This produces
M E ET Y O U I N T H E P AR K
12 4 4 19 24 14 20 8 13 19 7 4 15 0 17 10

 Now replace each of these numbers p by f (p) = (p + 3) mod 26. This gives
15 7 7 22 1 17 23 11 16 22 10 7 18 3 20 13

 Translating this back to letters produces the encrypted message “PHHW BRX LQ WKH SDUN”.
Shift Cipher

 A slight generalization of the Caesar Cipher is called Shift cipher where, the value 3 is replaced by integer b,
called a key.
 The function representation is,
Encryption  f (p) = ( p + b) mod 26
--1
Decryption  f (p) = (p - b) mod 26
Shift Cipher Example

 Exp 2: Encrypt the plaintext message “STOP GLOBAL WARMING” using the shift cipher with shift K = 11
Solution:
 S T O PG LO BAL WAR M I N G
18 19 14 15 6 11 14 1 0 11 22 0 17 12 8 13 6
 We now apply the shift f (p) = (p + 11) mod 26 to each number in this string.
 We obtain
3 4 25 0 17 22 25 12 11 22 7 11 2 23 19 24 17
 Translating this last string back to letters, we obtain the ciphertext “DEZA RWZMLW HLCXTYR”.
Shift Cipher Example

 Exp 3: Decrypt the ciphertext message “LEWLYPLUJL PZ H NYLHA ALHJOLY” that was encrypted
with the shift cipher with shift k = 7
Solution:
 To decrypt the cipher text, first translate the letters to the corresponding number
11 4 22 11 24 15 11 20 9 11 15 25 7 13 24 11 7 0 0 11 7 9 14 11 24
--1
 Apply f (p) = (p - 7) mod 26 to each number. Then we have,
4 23 15 4 17 8 4 13 2 4 8 18 0 6 17 4 0 19 19 4 0 2 7 4 17
 Finally, translate these numbers back to letters to obtain plain text.
“EXPERIENCE IS A GREAT TEACHER”.
Cryptography Categories

 Private key Cryptography


 The same key (secret key) is used for encryption and decryption.
 Key is symmetric because the only key is copy or share by another party to decrypt the cipher text

 Public key Cryptography


 Two keys are used
 One key (public key) is used for encrypt the plain text to convert it into cipher text
 Another key (private key) is used by receiver to decrypt the cipher text to read the message
RSA Cryptosystem

 RSA steps
 Select p, q where p & q both prime, p ≠ q
 Calculate n = p × q
 Calculate Ø(n) = (p-1) × (q-1)
 Select integer e such that gcd (Ø(n), e) = 1; 1<e< Ø(n)
 Calculate d, d ≡ e-1 (mod Ø(n)) or d.e ≡ 1 (mod Ø(n))
 Public Key : PU = { e, n }
 Private Key : PR = { d, n }
e
 Cyphertext C = M mod n
d
 Plaintext M =C mod n
RSA Example

 Exp 4: we have a message M = 572. Construct a valid RSA encryption and decryption key by finding two
primes p and q and an integer e, e > 1 and relatively prime to (p − 1)(q − 1).
Solution:
 Suppose sender arbitrarily chooses two prime numbers p = 23, q = 31
 n = p q = 23 × 31 = 713
 ɸ (n) = (p -1) × (q -1) = 660
 The sender then choose an arbitrary e, such that
e < ɸ (n)
gcd (e, ɸ (n) ) = 1
 e = 29 (arbitrary)
So, our public key = {e, n}= {29, 713}
e
Ciphertext C = M mod n = 57229 mod 713 = 113
RSA Example

 For private key we have to calculate d such as


d < ɸ (n)
d.e ≡ 1 (mod ɸ (n))
 Use Euclidean algorithm to calculate d.
 We can write 29 × d mod 660 =1
 By applying successive division, we have,
660 = 22 . 29 +22
29 = 1. 22 +7
22 = 3. 7 +1
 Use the result in reverse order to find the coefficient of 29
1 = 22 - 3.7
= 22 – 3 (29 – 1. 22) = 22 – 3. 29 + 3. 22
= 4. 22 – 3.29 = 4 (660 – 22. 29) + 3.29 = 4. 660 – 91.29
RSA Example

 Now we have,
1 = 4. 660 – 91.29
If the coefficient is a positive number, then that is value of d.
If the coefficient is a negative number, then d = ɸ (n) – 91 = 660 – 91 = 569
569
 Our plaintext M = 113 mod 713 = 572
 Replacing each exponent by its binary expansion and then using the modular exponentiation algorithm, 𝐶 and
𝑀 were calculated.
Algorithm

 An algorithm is a 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.
 Complexity of algorithm
 Time complexity
 Space complexity
 The estimates of resources required by an algorithm are represented by the big-Oh (𝑂), big-Omega (Ω), and
big-Theta (Θ)notations
Big-O Notation

 The growth of a function is representing by big-O notation

 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 𝑥 > 𝑘
 Theorem 1: Let f (x) = a n x n + a n−1 x n−1 +・ ・ ・+a1 x + a0, where a0, a1, . . . , a n−1, a n are real numbers
then f (x) is O( x n)
 Theorem 2: Suppose that f1(x) is O(g1(x)) and f2(x) is O(g2(x)). Then (f1 f2)(x) is O(g1(x)g2(x))
Example

 Exp 5: Show that f (n) = (n2 + 8) (n + 1) is O(n3)


Solution:
 By simplifying we have f (n) = n3 + n2 + 8n + 8
 If k =1, n > k then n3 > n2, n3 > n & n3 > 1
 n3 + n2 + 8n + 8 ≤ n3 + n3 +8 n3 + 8 n3 = 18 n3
 So, n3 + n2 + 8n + 8 ≤ 18 n3
This means our function is O(n3) with witness k =1 and c =18
Example

 Exp 6: Give a big-O estimate for f (x) = (x + 1) log(x2 + 1) + 3x2


Solution:
 (x +1 )  O (x)
 x2 + 1 ≤ 2x2 when x > 1
 log(x2 + 1) ≤ log(2x2) = log 2 + log x2 = log 2 + 2 log x ≤ 3 log x
 From theorem 2 we have, f (x) is O(max(x log x, x2)). Because x log x ≤ x2, for x > 1,
it follows that f (x) is O(x2)
Big Omega (Ω) notation

 provides a lower bound for the size of 𝑓(𝑥) for large values of 𝑥

 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 𝑥 > 𝑘
Example

 Show that f(n) = 2n2 + 3n + 5 is Ω(n2)


Solution:
 For big omega notation we have,
| 𝑓(n) | ≥ 𝐶| 𝑔(n)
2n2 + 3n + 5 ≥ c. n2
we find c = 2 , diving both side by n2
so, 2n2 + 3n + 5 ≥ 2n2
Big Theta(Θ) 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 there are real constants 𝐶 and 𝑘 such that
C1|g(x)| ≤ | 𝑓(𝑥) | ≤ 𝐶2| 𝑔(𝑥) |, whenever 𝑥 > 𝑘
Example

 Give a big-Θ estimate for 𝑓(𝑥) = 5𝑥3 +10𝑥2 log2 𝑥


Solution:
Assuming x > 1
x > log2 𝑥 > 0
x.10 𝑥2 > 10 𝑥2 log2 𝑥 > 0
5𝑥3 + 10 𝑥3 > 5𝑥3 +10𝑥2 log2 𝑥 > 5𝑥3
15𝑥3 > f(x) > 5𝑥3
C1 = 5, C2 = 15 for k =1
Binary Search algorithm

 Binary search is a fast search algorithm with run-time complexity of Ο(log n)


 array ={10,14,19,26,27,31,33,35,42,44}
 Find the location of value 31.
Solution:
 Mid = (L+R)/2 where Mid = middle position, R = right most position, L = left most position
Thank You
Tutorial Week 04

1
Quotient-Remainder Theorem

 The process of long division is known as the division algorithm or the quotient-remainder theorem.

2
Prime Number
 An integer p that 1>P, is called prime if the only positive factors of p are 1 and
p.
 A positive integer that is greater than 1 and is not prime is called composite.
 The integer 7 is prime because its only positive factors are 1 and 7, whereas the
integer 9 is composite because it is divisible by 3.

3
 Every integer greater than 1 can be written
Prime-Power Factorization uniquely as a prime or as the product of two or
more primes.

4
Greatest Common Divisor

 Let a and b be integers, not both zero. The largest integer d such that d | a and d | b is called the greatest common
divisor of a and b and denoted by gcd (a, b).
 What is the greatest common divisor of 24 and 36?
 The positive common divisors of 24 and 36 are 1, 2, 3, 4, 6, and 12.
Hence, GCD (24, 36) = 12.

5
Greatest Common Divisor

 Another way to find the greatest common divisor of two positive integers is to use the prime
factorizations of these integers. Suppose that the prime factorizations of the positive integers a and b
are

 prime factorizations of 120 and 500 are 120 = 23 . 3. 5 and 500 = 22. 5 . 30

6
Determining GCD: The Euclidean Algorithm

Suppose that a and b are positive integers with a ≥ b. Let r0 = a and r1 = b.


By Successive application of the division we have,

7
Determining GCD: The Euclidean Algorithm
 Find the greatest common divisor of 414 and 662 using the Euclidean algorithm.
 By applying successive uses of the division algorithm, we have,
662/414 = 1, r =248
414/ 248 =1, r =166
At the end we have, 82/2 = 41, r =0 so we conclude.
Hence, gcd(414, 662) = 2, because 2 is the last nonzero remainder

8
Congruences
 If a and b are integers and m is a positive integer, then a is congruent to b modulo m if m|(a -b).
 The notation a ≡ b( mod m) says that a is congruent to b modulo m.
 Determine Whether 17 is congruent to 5 modulo 6, and Whether 24 and 14 are congruent modulo 6
 17 ≡ 5 ( mode 6), because 6 divides (17-5) = 12

9
Fermat's Little Theorem

 Fermat’s little theorem is extremely useful in computing the remainders modulo p of large powers of integers.
Fermat’s little theorem states that if 𝑝 is prime and 𝑎 is an integer not divisible by 𝑝, then

10
Example
222
Find 7 mod 11
Solution: By Fermat’s Little theorem we have, 710 ≡ 1 (mod 11)
So (710 )k ≡ 1 (mod 11) for every positive integer k.
We can write exponent 222 = 22. 10 +2 ( dividing by 10)
222
Now, 7 = 7 22. 10 +2 = (1)22 . 49 ≡ 5 (mod 11)

11
Linear Congruences
 A congruence of the form
ax ≡ b (mod m)
where m is a positive integer, a and b are integers, and x is a variable, is called a linear congruence
 How can we find the integers x that satisfy this congruence?
 For all integers a and m >1, if gcd(a , m) = 1(relatively prime) , then there exists a unique integer aˉ
such that a . aˉ ≡ 1 (mod m), where the integer aˉ is called an inverse of a module m.

12
An inverse of a module m Exp.

 Find an inverse of 101 modulo 4620


 Both are relatively prime, gcd(101, 4620) =1
 we will use extended Euclidian Algorithm in order to find an inverse of 101.
 Use the result in reverse order to find the inverse of 101

13
Example cont.
That −35 . 4620 + 1601 . 101 = 1.
And 1601 is an inverse of 101 modulo 4620.
we have, 1601 × 101 ≡ 1 (mod 4620).

14
Modular Exponentiation
 (a + b) mod m = (( a mod m) + (b mod m )) mod m
 (a × b) mod m = (( a mod m) × (b mod m )) mod m
 a n mod m = (( a mod m)n) mod m

15
Example
Find 3644 mod 645.
Solution:
 Binary Expansion of exponent 644 = (1010000100)2
 So we have
 Now, we have to calculate only

16
Example Cont.

17
Example Cont.

Now we have,

= (111 × 396 × 81) mod 645 = 36

18
Hashing Function
 In order to map data of arbitrarily large size to small fixed size, a hashing function ℎ is used to assign memory
location.
A hashing function h assigns memory location h(k) to the record that has k as its key.
h(k) = k mod m
where m is the number of available memory locations.
Example: Find the memory locations assigned by the hashing function h(k) = k mod 111 to the records of customers
with Social Security numbers 064212848 and 037149212.
Solution:
 The record of the customer with Social Security number 064212848 is assigned tmemory location 14, because
h(064212848) = 064212848 mod 111 = 14.
 h(037149212) = 037149212 mod 111 = 65, the record of the customer with Social Security number 037149212 is
assigned to memory location 65.

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

20
Example Cont.

 What is the decimal expansion of the integer that has (101011111)2 as its binary expansion?

Solution:
(101011111)2 = 1. 28 + 0. 27+ 1. 26+ 0. 25+ 1. 24+ 1. 23+ 1. 22 + 1. 21 + 1. 20
= 351

21
Example Cont.
 Find the binary expansion of (241)10 .

So, we have (241)10 = (11110001)2

22
Thank You

23
TUTORIAL WEEK 3

1
Functions

2
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.

If 𝑓 is a function from 𝑋 to
𝑌, we then write
𝑓: 𝑋 → 𝑌.

y = f(x) With 𝑓 as a function from 𝑋 to 𝑌,


x
• set 𝑋 is the domain of the function 𝑓
• 𝑌 is the codomain of 𝑓.
• 𝑦 is the image of 𝑥
• 𝑥 is a pre-image or an inverse image of 𝑦.
• The range of 𝑓 is the set of all images of elements of 𝑋.
• Variable 𝑥 is called the independent variable.
• Variable 𝑦 is called the dependent variable.
X Y
The Function f Maps X to Y.
3
Example: Assignment of Grades in a Discrete
Mathematics Class.

Q1: What are the domain, codomain, and range of the


function that assigns grades to students?

Solution: Let G be the function that assigns a grade to a student


in our discrete mathematics class.
Note that G(Adams) = A, for instance.
The domain of G is the set :
{Adams, Chou, Goodfriend, Rodriguez, Stevens}
The codomain is the set:
{A,B,C,D, F}
Remark: Functions are sometimes also called The range of G is the set:
mappings or transformations. {A,B,C, F}
(because each grade except D is assigned to some student.)

4
Q2: Let S = {−1, 0, 2, 4, 7}. Find f (S) if
a) f (x) = 1. b) f (x) = 2x + 1.

Solution 2:

In all parts, we simply need to compute the values f(−1), f(0), f(2), f(4), and f(7) and collect
the values into a set.

a) {1} (all five values are the same)


b) {−1, 1, 5, 8, 15}

5
Q3. Determine whether f is a function from Z to R if
a) f (n) = ±n
b) f (n) = 𝑛2 + 1
c) f (n) = 1/(n2 − 4).

Solution 3:

a) This is not a function because the rule is not well-defined. We do not know whether f(3) = 3 or f(3) = −3.
For a function, it cannot be both at the same time.

b) This is a function. For all integers n, 𝑛2 + 1 is a well-defined real number.

c) This is not a function with domain Z, since for n = 2 (and also for n = −2) the value of f(n) is not defined by the
given rule. In other words, f(2) and f(−2) are not specified since division by 0 makes no sense.

6
Sum and Product of Functions

Let 𝑓: 𝑋 → 𝑹 and 𝑔: 𝑋 → 𝑹. The sum and product of 𝑓 and 𝑔, denoted by 𝑓 + 𝑔 and 𝑓𝑔 respectively, are also
functions from 𝑋 to 𝑹 defined for all 𝑥 ∈ 𝑋 by:
(f + g)(x) = f(x) + g(x),
(fg)(x) = f(x)g(x).

Q4: Let f1 and f2 be functions from R to R such that f1(x) = x2 and f2(x) = x − x2.
What are the functions f1 + f2 and f1f2?

Solution 4: From the definition of the sum and product of functions, it follows that
(f1 + f2)(x) = f1(x) + f2(x) = x2 + (x − x2) = x
and
(f1 f2)(x) = x2 (x − x2 ) = x3 − x4.

7
Increasing and Decreasing Functions

Piece-Wise Defined Functions

Functions which consist of more than one formula


depending on the values of 𝑥.
Example: Absolute-value function

• THE FLOOR FUNCTION

Also known as the greatest integer function. The floor of 𝑥


rounds down 𝑥 and is denoted by ‫ۂ 𝑥ہ‬.

• THE CEILING FUNCTION

Also known as the least integer function. The ceiling of 𝑥


rounds up 𝑥 and is denoted by ‫ۀ 𝑥ڿ‬.

Examples:

8
Q5:

Solution 5:

9
One-to-One Function One-to-One Correspondence Onto Functions
(injection) (Bijection) (surjection)

If it is both one-to-one and onto


• It should be invertible.

An onto function is such that for


Given any y there is only one x that every element in the codomain
can be paired with the given y. there exists an element in domain
which maps to it.
Examples of Different Types of Correspondences.

10
Q6: Determine whether the function f from {a, b, c, d} to {1, 2, 3, 4, 5} with
f (a) = 4, f (b) = 5, f (c) = 1, and f (d) = 3 is one-to-one.

Solution: The function f is one-to-one because f takes on different values at


the four elements of its domain. This is illustrated in the Figure.

Q7: Is the function f (x) = x2 from the set of integers to the set of integers onto?

Solution:
The function f is not onto because there is no integer x with x2 = −1, for instance.

Q8: Let f be the function from {a, b, c, d} to {1, 2, 3, 4} with f (a) = 4, f (b) = 2, f (c) = 1, and f (d) = 3.
Is f a bijection?

Solution:
The function f is one-to-one and onto. It is one-to-one because no two values in the domain are assigned the same
function value. It is onto because all four elements of the codomain are images of elements in the domain. Hence,
f is a bijection.

11
The Horizontal Line Test

Using the graph of a function (geometric characterizations) to determine whether a function is one-to-one or not:

Injection: number of intersection points ≤ 1.


Surjection: number of intersection points ≥ 1.

(a) The function is not one-to-one since it is


possible to draw a horizontal line that
crosses the graph twice.
(b) Is a one-to-one function since it appears to
be impossible to draw a horizontal line that
(a) (b) crosses the graph more than once.

If case (a) also mentioned the domain and range as R→R, then we can also say that (a) is not onto as
well because it won’t be covering all the values in the range R. The range of the function in (a) is all
real numbers ≥ 1.

12
Inverse Function
Domain of f Range of f

• A function is invertible if and only if it is one-to-


one correspondence.
• The inverse function of the function 𝑓, denoted
by f−1, is the function that assigns to an element 𝑦
belonging to 𝑌 the unique element 𝑥 in 𝑋 such that
f−1 (y) = x ↔ y = f(x)
Range of f-1 Domain of f-1

Q9: Let f be the function from {a, b, c} to {1, 2, 3} such that f (a) = 2, f (b) = 3, and f (c) = 1.
Is f invertible, and if it is, what is its inverse?

Solution: The function f is invertible because it is a one-to-one correspondence. The inverse function f −1 reverses the
correspondence given by f , so f −1(1) = c, f −1(2) = a, and f −1(3) = b.

13
Q10: Let f be the function from R to R defined by f (x) = x2.
Find
a) f −1({1}).
b) f −1({x | 0 <x< 1}).
c) f −1({x | x > 4}).

Solution 10:
a) The answer is the set of all solutions to x2= 1, namely {1,−1}.

b) In order for x2 to be strictly between 0 and 1, we need x to be either strictly between 0 and 1 or strictly
between −1 and 0. Therefore the answer is { x | −1 < x < 0 , 0 < x < 1 }.

c) In order for x2 to be greater than 4, we need either x > 2 or x < −2. Therefore the answer is
{ x | x > 2 , x < −2 }.

14
Q11: Determine whether each of these functions from {a, b, c, d} to itself is one-to-one.
a) f (a) = b, f (b) = a, f (c) = c, f (d) = d
b) f (a) = b, f (b) = b, f (c) = d, f (d) = c
c) f (a) = d, f (b) = b, f (c) = c, f (d) = d

Solution 5:
a) This is one-to-one.
b) This is not one-to-one, since b is the image of both a and b.
c) This is not one-to-one, since d is the image of both a and d.

Q12. Which functions in the above question are onto?

Solution 6:
Only the function in part (a)

Q13: Determine whether the following function is one-to-one:


f = {(1,2), (3, 4), (5, 6), (8, 6), (10, -1)}

Solution 7: This function is not one-to-one since the ordered pairs (5, 6) and (8, 6) have different first
coordinates and the same second coordinate.

15
(x-5)/2

Q14. Determine whether each of these functions is a bijection


from R to R.
a) f (x) = −3x + 4
b) f (x) = −3x2+ 7

Solution 14:
If we can find an inverse, the function is a bijection.
a) This is a bijection since the inverse function is f−1(x) = (4 − x)/3.
b) This is not one-to-one since f(17) = f(−17), for instance.

16
Compositions of Functions

Let g be a function from the set A to the set B and let f be a function from the set B to the set C. The
composition of the functions f and g, denoted for all a ∈ A by f ◦ g, is defined by (f ◦ g)(a) = f (g(a)).

The Composition of the Functions f and g.

17
Q15. Find f ◦ g and g ◦ f , where f (x) = x2 + 1 and g(x) = x + 2, are functions from R to R.

Solution 15:
We have (f ◦ g )(x) = f(g(x)) = f(x + 2) = (x + 2)2+ 1 = x2 + 4x + 5,
whereas (g ◦ f )(x) = g(f(x)) = g(x2 + 1) = x2 + 1 + 2 = x2 + 3.
Note that they are not equal.

Q16: Let f (x) = ax + b and g(x) = cx + d, where a, b, c and d are constants. Determine necessary and
sufficient conditions on the constants a, b, c, and d so that f ◦ g = g ◦ f .

Solution 16:
Forming the compositions, we have
(f ◦ g)(x) = acx +ad +b
and (g ◦ f )(x) = cax +cb +d.
These are equal if and only if ad+b = cb+d.
In other words, equality holds for all 4-tuples (a, b, c, d) for which ad+b = cb+d.

18
Relations
There are many forms: such as less than, parallel to, a subset of, logarithm of, and factorial of.

All mathematical functions are a special type of relation.

19
• Relationships between two sets are often based on ordered pairs.
• An ordered pair of elements 𝑎 and 𝑏 is denoted by (𝑎, 𝑏),
while noting that (𝑎, 𝑏)≠(𝑏, 𝑎), unless 𝑎 = 𝑏.
• Set 𝐴 is called the domain of the relation and the set 𝐵 is called the range of the relation.
• The relation 𝑅 is a one-to-one relation, if no element of 𝐵 appears as a second coordinate in more
than one ordered pair in 𝑅.
• 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.
• inverse relation is defined as follows:
𝑅-1 = {(b,𝑎)|(𝑎, 𝑏) ∈ 𝑅}.
• The complementary relation 𝑅ത is the set of ordered pairs, which is defined as follows:
𝑅ത = {(a,b)|(𝑎, 𝑏) ∉ 𝑅}.

20
Zero-one Matrix Representation

The relation R can be represented by the matrix MR = [mij ], where

Q1. Represent each of these relations on {1, 2, 3, 4} with a matrix (with the elements of this set listed in
increasing order).
a) {(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)}
b) {(1, 1), (1, 4), (2, 2), (3, 3), (4, 1)}
c) {(1, 2), (1, 3), (1, 4), (2, 1), (2, 3), (2, 4), (3, 1), (3, 2), (3, 4), (4, 1), (4, 2), (4, 3)}
d) {(2, 4), (3, 1), (3, 2), (3, 4)}
Solution :

21
Q2: Let R be the relation represented by the matrix

Find the matrix representing


a) R-1 b) 𝑅ത

Solution 2:

Matrix representing the inverse is obtained by simply taking the transpose of that matrix

22
Properties:

23
Q3. Consider the following relations on {1, 2, 3, 4}:
R1 = {(1, 1), (1, 2), (2, 1), (2, 2), (3, 4), (4, 1), (4, 4)},
R2 = {(1, 1), (1, 2), (2, 1)},
R3 = {(1, 1), (1, 2), (1, 4), (2, 1), (2, 2), (3, 3), (4, 1), (4, 4)},
R4 = {(2, 1), (3, 1), (3, 2), (4, 1), (4, 2), (4, 3)},
R5 = {(1, 1), (1, 2), (1, 3), (1, 4), (2, 2), (2, 3), (2, 4), (3, 3), (3, 4), (4, 4)},
R6 = {(3, 4)}.
Which of these relations are reflexive?

Solution 3:

The relations R3 and R5 are reflexive because they both contain all pairs of the form (a, a), namely, (1, 1), (2,
2), (3, 3), and (4, 4). The other relations are not reflexive because they do not contain all of these ordered pairs.
In particular, R1, R2, R4, and R6 are not reflexive because (3, 3) is not in any of these relations.

24
Q4: Determine whether the relation R on the set of all real numbers is reflexive, symmetric, antisymmetric, and/or
transitive, where (x, y) ∈ R if and only if:

a) x + y = 0. b) x − y is a rational number.

Solution 4:
a) Since 1 + 1 ≠ 0, this relation is not reflexive. Since x + y = y + x, it follows that x + y = 0 if and
only if y + x = 0, so the relation is symmetric.
Since (1,−1) and (−1, 1) are both in R, the relation is not antisymmetric.
The relation is not transitive; for example, (1,−1) ∈ R and (−1, 1) ∈ R, but (1, 1) ∉ R.

b) The relation is reflexive, since x − x = 0 is a rational number.


The relation is symmetric, because if x − y is rational, then so is −(x − y) = y − x.
Since (1,−1) and (−1, 1) are both in R, the relation is not antisymmetric.
To see that the relation is transitive, note that if (x, y) ∈ R and (y, z) ∈ R, then x − y and y − z are rational numbers.
Therefore, their sum x − z is rational, and that means that (x, z) ∈ R.

25
Operations on Relations
• The matrix representing the UNION of these relations has a 1 in the positions where either MR1 or MR2 has a 1.
• The matrix representing the INTERSECTION of these relations has a 1 in the positions where both MR1 and
MR2 have a 1.

• The DIFFERENCE of two relations 𝑅 and 𝑆 is defined as: 𝑅 - 𝑆 = {𝑎, 𝑏 | 𝑎, 𝑏 ∈ 𝑅 and 𝑎, 𝑏 ∉ 𝑆} .

Q 5: Suppose that the relations R1 and R2 on a set A are represented by the matrices:

What are the matrices representing R1 ∪ R2 and R1 ∩ R2?

Solution 5:

26
Composition of Relations
• Let 𝐴, 𝐵, and 𝐶 be sets, 𝑅 be a relation from 𝐴 to 𝐵, 𝑆 be a relation from 𝐵 to 𝐶, with 𝑎 ∈ 𝐴, 𝑏 ∈
𝐵, and 𝑐 ∈ 𝐶. 𝑅 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 𝑀R, 𝑀S, and 𝑀𝑆 ∘ 𝑅
• 𝑀𝑆 ∘ 𝑅 : Is the matrix resulting from the Boolean product of 𝑀R and 𝑀S

Q6: Find the matrix representing the relations S ◦R, where the matrices representing R and S are:

Solution 6: The matrix for S ◦R is

27
Q7: Find the matrix representing the relation R2, where the matrix representing R is

Solution 7: The matrix for R2 is

Q8: Let R1 and R2 be relations on a set A represented by the matrices shown below. Find the matrices that
represent
a) R1 ∪ R2. b) R1 ∩ R2. c) R2 ◦R1.
d) R1 ◦R1. e) R1 ⊕ R2.

Solution 8:
a) b) c) d) e)

28
Tutorial
Week-2
Introduction to Proofs
Direct Proofs
A direct proof of a conditional statement p → q is constructed when the first step is the assumption that p is true;
subsequent steps are constructed using rules of inference, with the final step showing that q must also be true.

Proof by Contraposition
Sometimes we will see that attempts at direct proofs often reach dead ends. Proofs by contraposition make use of
the fact that the conditional statement p → q is equivalent to its contrapositive, ¬q →¬p.

Proofs by Contradiction
Proof by contradiction starts by assuming the given hypothesis 𝑝 is true and the given conclusion 𝑞 is false, then a
contradiction is reached.

Proof by Counterexample
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.

Proofs Of Equivalence
To prove a theorem that is a biconditional statement, that is, a statement of the form p ↔ q, we show that p → q
and q → p are both true.
1. Use a direct proof to show that the product of two odd numbers is odd.

2. Prove that if m + n and n + p are even integers, where m, n, and p are integers, then m + p is even. What kind
of proof did you use?

3. Use a proof by contradiction to prove that the sum of an irrational number and a rational number is irrational.
1. An odd number is one of the form 2n + 1, where n is an integer. We are given two odd numbers, say 2a + 1 and 2b + 1. Their product is
(2a + 1)(2b + 1) = 4ab + 2a + 2b + 1 = 2(2ab + a + b) + 1. This last expression shows that the product is odd, since it is of the form 2n + 1,
with n = 2ab + a + b.

2. Let m+n and n+p be even integers, thus m+n=2k and n+p=2l by definition of even
m+p= 2k-n + 2l-n substitution
= 2k+2l-2n
=2 (k+l-n)
=2x, where x=k+l-n ∈Z (integers)
Hence, m+p is even by direct proof.

3. Assume that a is rational, b is irrational, and a+b is rational. Since a and a+b are rational, we can write them as fractions.
𝑑 𝑚
Let a = 𝑐 and a + b = 𝑛
𝑑 𝑚
Substituting a = 𝑐 in a + b = 𝑛 gives the following:
𝑑 𝑚
𝑐
+ b= 𝑛
Now, let's subtract dc from both sides of the equation.
𝑚 𝑑
b= 𝑛
− 𝑐 , or
𝑚 𝑑
b= 𝑛
+ (− 𝑐
)​
𝑚 𝑑
Since the rational numbers are closed under addition, b= 𝑛 + (− 𝑐 )​ is a rational number. However, the assumptions said that b is
irrational, and b cannot be both rational and irrational. This is our contradiction, so it must be the case that the sum of a rational and an
irrational number is always irrational.
4. Prove that if n is an integer and 3n + 2 is even, then n is even using
a) a proof by contraposition.
b) a proof by contradiction.

5. Show that these three statements are equivalent, where a and b are real numbers: (i) a is less than
b, (ii) the average of a and b is greater than a, and (iii) the average of a and b is less than b.

6. Find a counterexample to the statement that every positive integer can be written as the sum of
the squares of three integers.
4.
a) We must prove the contrapositive: If n is odd, then 3n + 2 is odd. Assume that n is odd. Then we can write n =
2k + 1 for some integer k . Then 3n + 2 = 3(2k + 1) + 2 = 6k + 5 = 2(3k + 2) + 1. Thus 3n + 2 is two times some
integer plus 1, so it is odd.

b) Suppose that 3n + 2 is even and that n is odd. Since 3n + 2 is even, so is 3n. If we add subtract an odd number
from an even number, we get an odd number, so 3n − n = 2n is odd. But this is obviously not true. Therefore our
supposition was wrong, and the proof by contradiction is complete.

5.
We write these in symbols: a < b, (a + b)/2 > a, and (a + b)/2 < b. The latter two are equivalent to a + b > 2a and a +
b < 2b, respectively, and these are in turn equivalent to b > a and a < b, respectively. It is now clear that all three
statements are equivalent.

6.
We must find a number that cannot be written as the sum of the squares of three integers. We claim that 7 is such a
number (in fact, it is the smallest such number). The only squares that can be used to contribute to the sum are 0, 1,
and 4. We cannot use two 4’s, because their sum exceeds 7. Therefore we can use at most one 4, which means that
we must get 3 using just 0’s and 1’s. Clearly three 1’s are required for this, bringing the total number of squares
used to four. Thus 7 cannot be written as the sum of three squares.
Proof Methods and Strategy
PROOF BY CASES
A proof by cases must cover all possible cases that arise in a
theorem.

EXHAUSTIVE PROOF
Some theorems can be proved by examining a relatively small
number of examples. Such proofs are called exhaustive proofs,
or proofs by exhaustion because these proofs proceed by
exhausting all possibilities.
1. Prove that n2 + 1 ≥ 2n when n is a positive integer with 1 ≤ n ≤ 4.

2. Prove that if n is an integer, then n² ≥ n.


Ans1: We use a proof by exhaustion. We only need
verify the inequality when n = 1, 2, 3, and 4.

Ans2:

We can prove that n2 ≥ n for every integer by considering three cases, when n = 0, when n ≥ 1, and when n ≤
−1.We split the proof into three cases because it is straightforward to prove the result by considering zero,
positive integers, and negative integers separately.

Case (i): When n = 0, because 02 = 0, we see that 02 ≥ 0. It follows that n2 ≥ n is true in this case.
Case (ii): When n ≥ 1, when we multiply both sides of the inequality n ≥ 1 by the positive integer n, we obtain
n · n ≥ n · 1. This implies that n2 ≥ n for n ≥ 1.
Case (iii): In this case n ≤ −1. However, n2 ≥ 0. It follows that n2 ≥ n.

Because the inequality n2 ≥ n holds in all three cases, we can conclude that if n is an integer, then n2 ≥ n.
SETS
• Sets are used to group objects together. sets is a means to study such collections in an organized
fashion.
• Often, but not always, the objects in a set have similar properties.
For instance, all the students who are currently enrolled in your school make up a set.
All the students currently taking a course in discrete mathematics at any school make up a set.

A set is an unordered collection of objects, called elements or members of the set. A set is
said to contain its elements. We write a ∈ A to denote that a is an element of the set A. The
notation a ∉ A denotes that a is not an element of the set A.

• Represented by {}
• Ways to specify a set:
• set roaster method by which all the elements of the set are listed between curly brackets, such as
{3, 6, 9}.
• 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.
• The universal set, denoted by 𝑈, is defined to include all possible elements in a given setting
and every set under the discussion.

• Equality of sets: Two sets 𝐴 and 𝐵 are equal if and only if they have exactly the same elements

• 𝐵 ⊆ 𝐴 thus implies 𝐵 is a subset of 𝐴

• The empty set or null set, denoted by ∅, is defined as the set with no elements.

• A set with one element is called a singleton set

• The sets 𝐴 and 𝐵 are known as disjoint, if and only if the sets 𝐴 and 𝐵 have no common
elements.

• A partition of a nonempty set 𝐴 is a finite collection of 𝑛 nonempty subsets, 𝐴1, 𝐴2, … , 𝐴n,
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
1. List the members of these sets.
c) {x | x is the square of an integer and x < 100}

2. Use set builder notation to give a description of each of


these sets.
a) {0, 3, 6, 9, 12}
b) {−3,−2,−1, 0, 1, 2, 3}
c) {m, n, o, p}

3. For each of these pairs of sets, determine whether the first is a subset of the second, the second is a
subset of the first, or neither is a subset of the other.
a) the set of people who speak English, the set of people who speak English with an Australian accent
b) the set of fruits, the set of citrus fruits
c) the set of students studying discrete mathematics, the set of students studying data structures
1. set will include all perfect squares less than 100
Hence, S={0,1,4,9,16,25,36,49,64,81}.

2. There are of course an infinite number of correct answers.


a) { 3n | n = 0, 1, 2, 3, 4 } or { x | x is a multiple of 3 ∧ 0 ≤ x ≤ 12 }.
b) { x | −3 ≤ x ≤ 3 }, where we are assuming that the domain (universe of discourse) is the set of integers.
c) {x | x is a letter of the word monopoly other than l or y }.

3. Recall that one set is a subset of another set if every element of the first set is also an element of the second.
a) The second condition imposes an extra requirement, so clearly the second set is a subset of the first, but not vice versa.
b) Again the second condition imposes an extra requirement, so the second set is a subset of the first, but not vice versa.
c) There could well be students studying discrete mathematics but not data structures (for example, pure math majors)
and students studying data structure but not discrete mathematics (at least not this semester—one could argue that the
knowing the latter is necessary to really understand the former!), so neither set is a subset of the other.
4. Determine whether each of these pairs of sets are equal.
a) {1, 3, 3, 3, 5, 5, 5, 5, 5}, {5, 3, 1}
b) {{1}}, {1, {1}}
c) ∅, {∅}

4.
a) YES, We need to look only at the distinct elements, not the repetitions or the order.
The sets contain common elements 1,3 and 5, hence they are equal sets.

b) NO, The first set is a subset of the second set. The first set consists of an element
which is a set containing 1, i.e., {1}, whereas, the second has two distinct elements 1
and {1}, so they cannot be equal.

c) NO, The first set is an empty set whereas the second set is a set containing an empty
set. Just like the previous case, they are distinct.
SET OPERATIONS
Set Operation:
• Union • Complement

• Intersection • Symmetric Difference

• Difference
Set Identities
1. Let A = {a, b, c, d, e} and B = {a, b, c, d, e, f, g, h}. Find:
a) A ∪ B. b) A ∩ B.
c) A − B. d) B − A.

2. Prove the idempotent laws in the Table by showing that


a) A ∪ A = A. b) A ∩ A = A.

3. Find the sets A and B if A − B = {1, 5, 7, 8}, B − A = {2, 10}, and A ∩ B = {3, 6, 9}.
1. Note that A ⊆ B.
a) {a, b, c, d, e, f, g, h} = B
b) b) {a, b, c, d, e} = A
c) There are no elements in A that are not in B, so the answer is Ø.
d) {f, g, h}

2.
a) A ∪ A = { x | x ∈A ∨ ∈ A} = { x | x ∈ A} = A
b) A ∩ A = { x | x ∈A ∧ x ∈ A} = { x | x ∈ A} = A

3.
Since A = (A − B) ∪ (A ∩ B), we conclude that A = {1, 5, 7, 8} ∪ {3, 6, 9} = {1, 3, 5, 6, 7, 8, 9}.
Similarly B = (B − A) ∪ (A ∩ B) = {2, 10} ∪ {3, 6, 9} = {2, 3, 6, 9, 10}.
Principle of duality, where the dual of an identity can be obtained by replacing each occurrence of ∪,
∩, 𝑈, and ∅ in the identity by ∩, ∪, ∅, and 𝑈, respectively.

De Morgan’s laws are used when the complements of sets are easier to define than the sets themselves.

Methods to Prove a Set Identity:

→ the element argument. In other words, to prove 𝑀 = 𝐾, we need to prove 𝑀 ⊆ 𝐾 and 𝐾 ⊆ 𝑀.


→ the algebraic proof: Transform one side into the other side step by step by employing the other known set
identities.
→ 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.
Membership Table
eg:

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.

4. Use a membership table to show that A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C).

5.
Ans4.

Ans5.

(algebraic proof)
• Cardinality of a set (Section 2.1): The number of distinct elements in a set 𝐴 is called the
cardinality of 𝐴, written as 𝐴 .

• 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:

• Cartesian Product of Sets: denoted by 𝐴 x 𝐵 and read as 𝐴 cross 𝐵, is the set of all
ordered pairs (𝑎, 𝑏), where 𝑎 ∈ 𝐴 and 𝑏 ∈ 𝐵.

𝐴 x 𝐵 ≠ 𝐵 x 𝐴, unless 𝐴 = ∅ or 𝐵 = ∅ or 𝐴 = 𝐵.

• A subset R of the Cartesian product A × B is called a relation from the set A to the set B.

• The cardinality of the union of two finite sets 𝐴 and 𝐵 can be found using the Principle of
inclusion–exclusion:
|A ∪ B| = |A| + |B| − |A ∩ B|.
6. What is the power set of the set {0, 1, 2}?

7. What is the Cartesian product A × B × C, where A = {0, 1}, B = {1, 2}, and C = {0, 1, 2} ?

6. The power set P({0, 1, 2}) is the set of all subsets of {0, 1, 2}. Hence,
P({0, 1, 2}) = {∅, {0}, {1}, {2}, {0, 1}, {0, 2}, {1, 2}, {0, 1, 2}}.
Note that the empty set and the set itself are members of this set of subsets.

7. Solution: The Cartesian product A × B × C consists of all ordered triples (a, b, c),
where a ∈ A, b ∈ B, and c ∈ C. Hence,
A × B × C = {(0, 1, 0), (0, 1, 1), (0, 1, 2), (0, 2, 0), (0, 2, 1), (0, 2, 2),
(1, 1, 0), (1, 1, 1), (1, 1, 2), (1, 2, 0), (1, 2, 1), (1, 2, 2)}.
Computer Representation of Sets

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., a1, a2, . . . , an, each containing a 1, and a subset 𝐴 of
𝑈 is an array with 𝑛 bits, where the 𝑖th bit in this string is 1 if 𝑎i belongs to 𝐴 and is 0 if 𝑎i does
not belong to 𝐴.

8. Suppose that the universal set is U = {1, 2, 3, 4,5, 6, 7, 8, 9, 10}. Express each of these
sets with bit strings where the ith bit in the string is 1 if i is in the set and 0 otherwise.
a) {3, 4, 5}
b) {1, 3, 6, 10}
c) {2, 3, 4, 7, 8, 9}

Ans8.
a) 00 1110 0000 b) 10 1001 0001 c) 01 1100 1110
Multisets are unordered collections of elements where an element can occur as a member more than once.

9. Let A and B be the multisets {3 ・ a, 2 ・ b, 1 ・ c} and {2 ・ a, 3 ・ b, 4 ・ d}, respectively.


Find
a) A ∪ B. b) A ∩ B. c) A − B.
d) B − A. e) A + B.

Ans 9:
a) {3 · a, 3 · b, 1 · c, 4 · d} b) {2 · a, 2 · b} c) {1 · a, 1 · c}
d) {1 · b, 4 · d} e) {5 · a, 5 · b, 1 · c, 4 · d}
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.

Each element in the universal set U has a degree of membership, which is a real number between 0 and 1
(including 0 and 1), in a fuzzy set S. The fuzzy set S is denoted by listing the elements with their degrees
of membership (elements with 0 degree of membership are not listed).

Classical sets (Crisp sets) are special cases of fuzzy sets,


and that is when the membership functions of fuzzy sets
only take values 0 or 1.

Operations on Fuzzy Sets:


10. Find the union of two fuzzy sets F ∪ R of rich or famous people.

F = {0.6 Alice, 0.9 Brian, 0.4 Fred, 0.1 Oscar, 0.5 Rita}
R = {0.4 Alice, 0.8 Brian, 0.2 Fred, 0.9 Oscar, 0.7 Rita}.

Ans 10:

F ∪ R = {0.6 Alice, 0.9 Brian, 0.4 Fred, 0.9 Oscar, 0.7 Rita}.
Logic
Practice Questions- Section 1.1
Important Points:

• A proposition is a declarative statement, which is either true or false, but not


both

• We use lowercase letters, such as 𝑝, 𝑞, 𝑟, 𝑠, and 𝑡, to denote propositional


variables.

• The truth value of a proposition is either true or false.

• Logical operators, also known as logical connectives, are used to combine two or
more simple propositions to form a compound proposition.
Logical Operators:

Negation Exclusive OR

Conjunction (and)

The dual of a compound proposition containing


Disjunction (or) 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.
Conditional Statement Biconditional Statement
Q1: Which of these are propositions? What are the truth values of those that are propositions?

a) Do not pass go.


b) What time is it?
c) 2𝑛 ≥ 100.

Q2. Suppose that Smartphone A has 256 MB RAM and 32GB ROM, and the resolution of its
camera is 8 MP; Smartphone B has 288 MB RAM and 64 GB ROM, and the resolution of its
camera is 4 MP; and Smartphone C has128 MB RAM and 32 GB ROM, and the resolution of its
camera is 5 MP. Determine the truth value of each of these propositions.

a) Smartphone B has the most RAM of these three smartphones.


b) Smartphone C has more ROM or a higher resolution camera than Smartphone B.
c) Smartphone B has more RAM, more ROM, and a higher resolution camera than Smartphone A.
d) If Smartphone B has more RAM and more ROM than Smartphone C, then it also has a higher
resolution camera.
e) Smartphone A has more RAM than Smartphone B if and only if Smartphone B has more RAM than
Smartphone A.
Ans 1:

Propositions must have clearly defined truth values, so a proposition must be a declarative sentence with no free
variables.
a) This is not a proposition; it’s a command.
b) This is not a proposition; it’s a question.

Ans 2:

a) True, because 288 > 256 and 288 > 128.


b) True, because C has 5 MP resolution compared to B’s 4 MP resolution. Note that only one of these conditions
needs to be met because of the word or.
c) False, because its resolution is not higher (all of the statements would have to be true for the conjunction to be
true).
d) False, because the hypothesis of this conditional statement is true and the conclusion is false.
e) False, because the first part of this biconditional statement is false and the second part is true.
Q3. Let p and q be the propositions
p : It is below freezing.
q : It is snowing.
Write these propositions using p and q and logical connectives (including negations).

a) It is below freezing and snowing.


b) It is below freezing but not snowing.
c) It is not below freezing and it is not snowing.
d) It is either snowing or below freezing (or both).
e) If it is below freezing, it is also snowing.
f ) Either it is below freezing or it is snowing, but it is not snowing if it is below freezing.

Q4. Let p, q, and r be the propositions


p :You have the flu.
q :You miss the final examination.
r :You pass the course.
Express each of these propositions as an English sentence.

a) p → q b) ¬q ↔ r
c) q →¬r d) p ∨ q ∨ r
e) (p →¬r) ∨ (q →¬r) f ) (p ∧ q) ∨ (¬q ∧ r)
Ans 3:

a) p ∧q
b) p ∧¬q
c) ¬ p ∧¬ q
d) p ∨q
e) p → q
f) (p ∨q)∧(p → ¬ q)

Ans 4:

a) If you have the flu, then you miss the final exam.
b) You do not miss the final exam if and only if you pass the course.
c) If you miss the final exam, then you do not pass the course.
d) You have the flu, or miss the final exam, or pass the course.
e) It is either the case that if you have the flu then you do not pass the course or the case that if you miss
the final exam then you do not pass the course (or both, it is understood).
f) Either you have the flu and miss the final exam, or you do not miss the final exam and do pass the course.
Q5. For each of these sentences, determine whether an inclusive or, or an exclusive or, is intended. Explain your
answer.
a)A triangle can be defined as a polygon with 3 sides or as a polygon with 3 vertices.
b) To enter the country you need a passport or a voter registration card.
c) This morning I can go to school or I can stay at home.

Q6. Write each of these statements in the form “if p, then q” in English. {Conditional Statements}
a) To be a citizen of this country, it is sufficient that you were born in the United States.
b) The beach erodes whenever there is a storm.

Q7. Write each of these propositions in the form “p if and only if q” in English. {Biconditional Statements}
a) For you to get an A in this course, it is necessary and sufficient that you learn how to solve discrete mathematics
problems.
c) It rains if it is a weekend day, and it is a weekend day if it rains.

Q8. State the converse, contrapositive, and inverse of each of these conditional statements. {pq}
a) If it snows tonight, then I will stay at home.
b) I go to the beach whenever it is a sunny summer day.
c) When I stay up late, it is necessary that I sleep until noon.
Ans 5:
a) Inclusive or
b) If a person happened to have both forms of identification, so much the better, so this is clearly an inclusive or.
c) Exclusive or

Ans6:
a) If you were born in the United States, then you are a citizen of this country.
b) If there is a storm, then the beach erodes.

Ans7:
a) You will get an A in this course if and only if you learn how to solve discrete mathematics problems.
b) It rains if and only if it is a weekend day.

Ans8:
a) Converse: If I stay home, then it will snow tonight. Contrapositive: If I do not stay at home, then it will not snow
tonight. Inverse: If it does not snow tonight, then I will not stay home.
b) Converse: Whenever I go to the beach, it is a sunny summer day. Contrapositive: Whenever I do not go to the
beach, it is not a sunny summer day. Inverse: Whenever it is not a sunny day, I do not go to the beach.
c) Converse: If I sleep until noon, then I stayed up late. Contrapositive: If I do not sleep until noon, then I did not stay
up late. Inverse: If I don’t stay up late, then I don’t sleep until noon.
Q9. How many rows appear in a truth table for each of these compound propositions?
a) (q →¬p) ∨ (¬p →¬q)
b) (p ∨¬t) ∧ (p ∨¬s)
c) (p → r) ∨ (¬s →¬t) ∨ (¬u → v)
d) (p ∧ r ∧ s) ∨ (q ∧ t) ∨ (r ∧¬t)

Q10. Construct a truth table for each of these compound propositions.


a) (p ⊕ q) ∨ (p ⊕¬q) b ) (p ⊕ q) ∧ (p ⊕¬q)

Q11. Evaluate each of these expressions.


a) 11000 ∧ (01011 ∨ 11011)
b) (01010 ⊕ 11011) ⊕ 01000
Ans9:

A truth table will need 2n rows if there are n variables.


a) 2² = 4
b) 2³ = 8
c) 26 = 64
d) 25 = 32

Ans10:

Ans11:
a) 1 1000 ∧ (0 1011 ∨ 1 1011) = 1 1000 ∧ 1 1011 = 1 1000
b) (0 1010 ⊕ 1 1011) ⊕ 0 1000 = 1 0001 ⊕ 0 1000 = 1 1001
Section 1.3
Propositional Equivalences
The compound proposition p and q are called logically equivalent if p<->q is a
tautology. The notion p≡q denotes that p and q are logically equivalent.
Tautology  A compound proposition that is always true, containing only 𝑇 in the last
column of its truth table.

Contradiction A compound proposition that is always false, containing only 𝐹 in the last column
of its truth table.

Contingency A compound proposition that is neither a tautology nor a contradiction.


Q1. Use truth tables to verify the associative law
a) (p ∨ q) ∨ r ≡ p ∨ (q ∨ r).

Q2. Use a truth table to verify the first De Morgan law


¬(p ∧ q) ≡ ¬p ∨¬q.

Q3. Use De Morgan’s laws to find the negation of each of the following statements.
a) Kwame will take a job in industry or go to graduate school.
b) Yoshiko knows Java and calculus.

Q4. Show that the conditional statement is a tautology by using truth table.
[¬p ∧ (p ∨ q)] → q

Q5. Find the dual of each of these compound propositions.


a) p ∨¬q b) p ∧ (q ∨ (r ∧ T))
c) (p ∧¬q) ∨ (q ∧ F)
Ans1: We construct the relevant truth table and note that the fifth and
seventh columns are identical.

Ans2: We see that the fourth and seventh columns are identical.

Ans3: We need to negate each part and swap “and” with “or.”
a) Kwame will not take a job in industry and will not go to graduate
school.
b) Yoshiko does not know Java or does not know calculus.

Ans4: We construct a truth table for each conditional statement and


note that the relevant column contains only T’s.

Ans5: We apply the rules stated in the preamble.


a) p ∧ ¬q b) p ∨ (q ∧ (r ∨ F)) c) (p ∨ ¬q) ∧ (q ∨ T)
Section 1.4
Predicates and Quantifiers
• A predicate contains a finite number of variables and becomes a propositional
statement when specific values are substituted for the variables.

• The statement 𝑃(𝑥) is said to be the value of the propositional function 𝑃


at 𝑥.

• 𝑃(𝑥) becomes a propositional statement once x is assigned a value.

• The domain, of a predicate is the sets of all values that may be substituted in place of the variables.
• Quantifiers: reveals for how many elements a given predicate is true. Examples: “few,”
“some,”
“all,” “none,” “one,” and “every.” Two types:

 Universal quantification indicates that a predicate is true for every element under
consideration.
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.”

 Existential quantification indicates that a predicate is true for at least one element under
consideration.

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.”
Q1. Let P(x) be the statement “the word x contains the letter a.” What are these truth values?
a) P(orange) b) P(lemon)
c) P(true) d) P(false)

Q2. State the value of x after the statement if P(x) then x := 1 is executed, where P(x) is the
statement “x > 1,” if the value of x when this statement is reached is

a) x = 0. b) x = 1.
c) x = 2.

Q3. Let N(x) be the statement “x has visited North Dakota,” where the domain consists of the
students in your school. Express each of these quantifications in English.

a) ∃xN(x) b) ∀xN(x) c) ¬∃xN(x)

Q4. Translate these statements into English, where R(x) is “x is a rabbit” and H(x) is “x
hops” and the domain consists of all animals.

a) ∀x(R(x) → H(x)) b) ∀x(R(x) ∧ H(x))


Ans1:
a) This is true, since there is an a in orange.
b) This is false, since there is no a in lemon.
c) This is false, since there is no a in true.
d) This is true, since there is an a in false

Ans2:
a) Here x is still equal to 0, since the condition is false.
b) Here x is still equal to 1, since the condition is false.
c) This time x is equal to 1 at the end, since the condition is true, so the statement x := 1 is
executed.

Ans3:
a) Some student in the school has visited North Dakota.
b) Every student in the school has visited North Dakota.
c) No student in the school has visited North Dakota.

Ans4:
a) If an animal is a rabbit, then that animal hops. (Alternatively, every rabbit hops.)
b) Every animal is a rabbit and hops
Q5. Let C(x) be the statement “x has a cat,” let D(x) be the statement “x has a dog,” and let F(x) be the
statement “x has a ferret.” Express each of these statements in terms of C(x), D(x), F(x), quantifiers, and
logical connectives. Let the domain consist of all students in your class.
a) A student in your class has a cat, a dog, and a ferret.
b) All students in your class have a cat, a dog, or a ferret.
c) Some student in your class has a cat and a ferret, but not a dog.
d) No student in your class has a cat, a dog, and a ferret.
e) For each of the three animals, cats, dogs, and ferrets, there is a student in your class who has this animal as a pet.

Ans5:
a) We assume that this means that one student has all three animals: ∃x(C(x) ∧ D(x) ∧ F(x)).
b) ∀x(C(x) ∨ D(x) ∨ F(x)) c) ∃x(C(x) ∧ F(x) ∧ ¬D(x))
d) This is the negation of part (a): ¬∃x(C(x) ∧ D(x) ∧ F(x)).
e) Here the owners of these pets can be different: (∃x C(x))∧(∃x D(x))∧(∃x F(x)). There is no harm in using
the same dummy variable, but this could also be written, for example, as (∃x C(x)) ∧ (∃y D(y)) ∧ (∃z F(z)).
Section 1.5
Nested Quantifiers
Q1. Translate these statements into English, where the domain for each variable consists of all real
numbers.
a) ∃x∀y(xy = y)
c) ∀x∀y∃z(x = y + z)

Q2. Let C(x, y) mean that student x is enrolled in class y, where the domain for x consists of all students
in your school and the domain for y consists of all classes being given at your school. Express each of
these statements by a simple English sentence.
a) C(Randy Goldberg, CS 252)
b) ∃xC(x, Math 695)
c) ∃yC(Carol Sitea, y)

Q3. Let F(x, y) be the statement “x can fool y,” where the domain consists of all people in theworld. Use
quantifiers to express each of these statements.
a) Everybody can fool Fred.
f ) No one can fool both Fred and Jerry.
Ans1:
a) There exists a real number x such that for every real number y , xy = y . (This is asserting the
existence of a multiplicative identity for the real numbers, and the statement is true, since we
can take x = 1.)
b) For every real number x and real number y , there exists a real number z such that x = y + z .
(This is a true statement, since we can take z = x − y in each case.)

Ans2:
a) Randy Goldberg is enrolled in CS 252.
b) Someone is enrolled in Math 695.
c) Carol Sitea is enrolled in some course.

Ans3:
a) ∀xF(x, Fred)
b) ¬∃x(F(x, Fred) ∧ F(x, Jerry))
Section 1.6
Rules of Inference

Instead of truth tables we can first establish the validity of some relatively simple argument forms, called
rules of inference to construct more complicated valid argument forms.
Widely used rules of inference for propositional logic:
Q1. Find the argument form for the following argument and determine whether it is valid. Can we conclude
that the conclusion is true if the premises are true?
If George does not have eight legs, then he is not a spider.
George is a spider.
∴ George has eight legs.

Q2. What rule of inference is used in each of these arguments?

a) Kangaroos live in Australia and are marsupials. Therefore, kangaroos are marsupials.

b) It is either hotter than 100 degrees today or the pollution is dangerous. It is less than 100 degrees outside
today. Therefore, the pollution is dangerous.

c) Linda is an excellent swimmer. If Linda is an excellent swimmer, then she can work as a lifeguard. Therefore,
Linda can work as a lifeguard.

d) Steve will work at a computer company this summer. Therefore, this summer Steve will work at a computer
company or he will be a beach bum.
Ans1: p : “George does not have eight legs”
q : “George is not a spider.
pq
-q (Modus tollens)
-p
We can therefore conclude that the conclusion of the argument (third statement) is true, given that the
hypotheses (the first two statements) are true.

Ans2:
a) We have taken the conjunction of two propositions and
asserted one of them. According to Table, simplification.

b) We have taken the disjunction of two propositions and the


negation of one of them, and asserted the other. According to
Table, disjunctive syllogism.

c) modus ponens
d) addition
e) hypothetical syllogism
Q3. For each of these arguments, explain which rules of inference are used for each step.
a) “Linda, a student in this class, owns a red convertible. Everyone who owns a red convertible
has gotten at least one speeding ticket. Therefore, someone in this class has gotten a speeding
ticket.”

Ans3:
a) Let c(x) be “x is in this class,” let r(x) be “x owns a red
convertible,” and let t(x) be “x has gotten a speeding ticket.” We
are given premises c(Linda), r(Linda), ∀x(r(x)  t(x)), and we
want to conclude ∃x(c(x) ∧ t(x)).
Fallacy: Several common fallacies arise in incorrect arguments. These fallacies resemble rules of inference,
but are based on contingencies rather than tautologies.

Q4. Is the following argument valid?


If you do every problem in this book, then you will learn discrete mathematics. You learned discrete mathematics.
Therefore, you did every problem in this book.

Ans4: Let p: “You did every problem in this book.”


q: “You learned discrete mathematics.” Then this argument is of the form:
p→q
q
∴p

This is an example of an incorrect argument using the fallacy of affirming the conclusion.
Indeed, it is possible for you to learn discrete mathematics in someway other than by doing every
problem in this book. (You may learn discrete mathematics by reading, listening to lectures,
doing some, but not all, the problems in this book, and so on.)
Thank You!

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy