Lecture Notes in Discrete Mathematics
Lecture Notes in Discrete Mathematics
Marcel B. Finan
Arkansas Tech University
c All Rights Reserved
Preface
Marcel B. Finan
May 2001
4 PREFACE
Contents
Preface 3
6 CONTENTS
Fundamentals of Mathematical
Logic
p:1+1=3
Example 1.1
Which of the following are propositions? Give the truth value of the propo-
sitions.
a. 2 + 3 = 7.
b. Julius Caesar was president of the United States.
c. What time is it?
d. Be quiet !
Solution.
a. A proposition with truth value (F).
b. A proposition with truth value (F).
c. Not a proposition since no truth value can be assigned to this statement.
d. Not a proposition
Example 1.2
Which of the following are propositions? Give the truth value of the propo-
sitions.
a. The difference of two primes.
b. 2 + 2 = 4.
c. Washington D.C. is the capital of New York.
d. How are you?
Solution.
a. Not a proposition.
b. A proposition with truth value (T).
c. A proposition with truth value (F).
d. Not a proposition
Example 1.3
Let
p: 5<9
q : 9 < 7.
Solution.
The conjunction of the propositions p and q is the proposition
p ∨ q : 5 < 9 or 9 < 7
Example 1.4
Consider the following propositions
p: It is Friday
q: It is raining.
Solution.
The conjunction of the propositions p and q is the proposition
p ∧ q : It is Friday and it is raining.
The disjunction of the propositions p and q is the proposition
p ∨ q : It is Friday or It is raining
A truth table displays the relationships between the truth values of propo-
sitions. Next, we display the truth tables of p ∧ q and p ∨ q.
p q p∧q p q p∨q
T T T T T T
T F F T F T
F T F F T T
F F F F F F
Let p and q be two propositions. The exclusive or of p and q, denoted p ⊕ q,
is the proposition that is true when exactly one of p and q is true and is false
otherwise. The truth table of the exclusive ‘or’ is displayed below
p q p⊕q
T T F
T F T
F T T
F F F
Example 1.5
a. Construct a truth table for (p ⊕ q) ⊕ r.
b. Construct a truth table for p ⊕ p.
Solution.
a.
p q r p⊕q (p ⊕ q) ⊕ r
T T T F T
T T F F F
T F T T F
T F F T T
F T T T F
F T F T T
F F T F T
F F F F F
b.
p p⊕p
T F
F F
The final operation on a proposition p that we discuss is the negation of p.
The negation of p, denoted ∼ p, is the proposition not p. The truth table of
∼ p is displayed below
p ∼p
T F
F T
Example 1.6
Consider the following propositions:
p: Today is Thursday.
q: 2 + 1 = 3.
r: There is no pollution in New Jersey.
Construct the truth table of [∼ (p ∧ q)] ∨ r.
Solution.
p q r p ∧q ∼ (p ∧ q) [∼ (p ∧ q)] ∨ r
T T T T F T
T T F T F F
T F T F T T
T F F F T T
F T T F T T
F T F F T T
F F T F T T
F F F F T T
Example 1.7
Find the negation of the proposition p : −5 < x ≤ 0.
Solution.
The negation of p is the proposition ∼ p : x > 0 or x ≤ −5
Example 1.8
a. Construct the truth table of the proposition (p∧q)∨(∼ p∨ ∼ q). Determine
if this proposition is a tautology.
b. Show that p∨ ∼ p is a tautology.
Solution.
a.
p q ∼p ∼q ∼ p∨ ∼ q p∧q (p ∧ q) ∨ (∼ p∨ ∼ q)
T T F F F T T
T F F T T F T
F T T F T F T
F F T T T F T
Two propositions are equivalent if they have exactly the same truth values
under all circumstances. We write p ≡ q.
Example 1.9
a. Show that ∼ (p ∨ q) ≡∼ p∧ ∼ q.
b. Show that ∼ (p ∧ q) ≡∼ p∨ ∼ q.
c. Show that ∼ (∼ p) ≡ p.
a. and b. are known as DeMorgan’s laws.
Solution.
a.
p q ∼p ∼q p∨q ∼ (p ∨ q) ∼ p∧ ∼ q
T T F F T F F
T F F T T F F
F T T F T F F
F F T T F T T
b.
p q ∼p ∼q p∧q ∼ (p ∧ q) ∼ p∨ ∼ q
T T F F T F F
T F F T F T T
F T T F F T T
F F T T F T T
c.
p ∼p ∼ (∼ p)
T F T
F T F
Example 1.10
a. Show that p ∧ q ≡ q ∧ p and p ∨ q ≡ q ∨ p.
b. Show that (p ∨ q) ∨ r ≡ p ∨ (q ∨ r) and (p ∧ q) ∧ r ≡ p ∧ (q ∧ r).
c. Show that (p ∧ q) ∨ r ≡ (p ∨ r) ∧ (q ∨ r) and (p ∨ q) ∧ r ≡ (p ∧ r) ∨ (q ∧ r).
Solution.
a.
p q p∧q q∧p
T T T T
T F F F
F T F F
F F F F
p q p∨q q∨p
T T T T
T F T T
F T T T
F F F F
b.
p q r p∨q q∨r (p ∨ q) ∨ r p ∨ (q ∨ r)
T T T T T T T
T T F T T T T
T F T T T T T
T F F T F T T
F T T T T T T
F T F T T T T
F F T F T T T
F F F F F F F
p q r p∧q q∧r (p ∧ q) ∧ r p ∧ (q ∧ r)
T T T T T T T
T T F T F F F
T F T F F F F
T F F F F F F
F T T F T F F
F T F F F F F
F F T F F F F
F F F F F F F
c.
Example 1.11
Show that ∼ (p ∧ q) 6≡∼ p∧ ∼ q
Solution.
We will use truth tables to prove the claim.
p q ∼p ∼q p∧q ∼ (p ∧ q) ∼ p∧ ∼ q
T T F F T F F
T F F T F T 6= F
F T T F F T 6 = F
F F T T F T T
A compound proposition that has the value F for all possible values of the
propositions in it is called a contradiction.
Example 1.12
Show that the proposition p∧ ∼ p is a contradiction.
Solution.
p ∼p p∧ ∼ p
T F F
F T F
Review Problems
Problem 1.1
Indicate which of the following sentences are propositions.
a. 1,024 is the smallest four-digit number that is perfect square.
b. She is a mathematics major.
c. 128 = 26
d. x = 26 .
Problem 1.2
Consider the propositions:
p: Juan is a math major.
q: Juan is a computer science major.
Problem 1.3
In the following sentence is the word “or” used in its inclusive or exclusive
sense? “A team wins the playoffs if it wins two games in a row or a total of
three games.”
Problem 1.4
Write the truth table for the proposition: (p ∨ (∼ p ∨ q))∧ ∼ (q∧ ∼ r).
Problem 1.5
Let t be a tautology. Show that p ∨ t ≡ t.
Problem 1.6
Let c be a contradiction. Show that p ∨ c ≡ p.
Problem 1.7
Show that (r ∨ p) ∧ [(∼ r ∨ (p ∧ q)) ∧ (r ∨ q)] ≡ p ∧ q.
Problem 1.8
Use De Morgan’s laws to write the negation for the proposition: “This com-
puter program has a logical error in the first ten lines or it is being run with
an incomplete data set.”
Problem 1.9
Use De Morgan’s laws to write the negation for the proposition: “The dollar
is at an all-time high and the stock market is at a record low.”
Problem 1.10
Assume x ∈ IR. Use De Morgan’s laws to write the negation for the proposition:0 ≥
x > −5.
Problem 1.11
Show that the proposition s = (p ∧ q) ∨ (∼ p ∨ (p∧ ∼ q)) is a tautology.
Problem 1.12
Show that the proposition s = (p∧ ∼ q) ∧ (∼ p ∨ q) is a contradiction.
Problem 1.13
a. Find simpler proposition forms that are logically equivalent to p ⊕ p and
p ⊕ (p ⊕ p).
b. Is (p ⊕ q) ⊕ r ≡ p ⊕ (q ⊕ r)? Justify your answer.
c. Is (p ⊕ q) ∧ r ≡ (p ∧ r) ⊕ (q ∧ r)? Justify your answer.
Problem 1.14
Show the following:
a. p ∧ t ≡ p, where t is a tautology.
b. p ∧ c ≡ c, where c is a contradiction.
c. ∼ t ≡ c and ∼ c ≡ t.
d. p ∨ p ≡ p and p ∧ p ≡ p.
Example 2.1
Construct the truth table of the implication p → q.
Solution.
The truth table is
p q p→q
T T T
T F F
F T T
F F T
Example 2.2
Show that p → q ≡∼ p ∨ q.
Solution.
p q ∼p p→q ∼p∨q
T T F T T
T F F F F
F T T T T
F F T T T
It follows from the previous example that the proposition p → q is always
true if the hypothesis p is false, regardless of the truth value of q. We say
that p → q is true by default or vacuously true.
In terms of words the proposition p → q also reads:
(a) if p then q.
(b) p implies q.
(c) p is a sufficient condition for q.
(d) q is a necessary condition for p.
(e) p only if q.
Example 2.3
Use the if-then form to rewrite the statement “I am on time for work if I
catch the 8:05 bus.”
Solution.
If I catch the 8:05 bus then I am on time for work
Example 2.4
a. Show that ∼ (p → q) ≡ p∧ ∼ q.
b. Find the negation of the statement “ If my car is in the repair shop, then
I cannot go to class.”
Solution.
a. We use De Morgan’s laws as follows.
∼ (p → q) ≡ ∼ (∼ p ∨ q)
≡ ∼ (∼ p)∧ ∼ q
≡ p∧ ∼ q.
Example 2.5
Find the converse, opposite, and the contrapositive of the implication: “ If
today is Thursday, then I have a test today.”
Solution.
The converse: If I have a test today then today is Thursday.
The opposite: If today is not Thursday then I don’t have a test today.
The contrapositive: If I don’t have a test today then today is not Thursday
Example 2.6
Show that p → q ≡∼ q →∼ p.
Solution.
We use De Morgan’s laws as follows.
p→q ≡ ∼p∨q
≡ ∼ (p∧ ∼ q)
≡ ∼ (∼ q ∧ p)
≡ ∼∼ q∨ ∼ p
≡ q∨ ∼ p
≡ ∼ q →∼ p
Example 2.7
Using truth tables show the following:
a. p → q 6≡ q → p
b. p → q 6≡∼ p →∼ q
Solution.
a. It suffices to show that ∼ p ∨ q 6≡∼ q ∨ p.
p q ∼p ∼q ∼p∨q ∼q∨p
T T F F T T
T F F T F 6= T
F T T F T 6 = F
F F T T T T
b. We will show that ∼ p ∨ q 6≡ p∨ ∼ q.
p q ∼p ∼q ∼p∨q p∨ ∼ q
T T F F T T
T F F T F 6= T
F T T F T 6 = F
F F T T T T
Example 2.8
Show that ∼ q →∼ p ≡ p → q
Solution.
We use De Morgan’s laws as follows.
∼ q →∼ p ≡ q∨ ∼ p
≡ ∼ (∼ q ∧ p)
≡ ∼ (p∧ ∼ q)
≡ ∼ p∨ ∼∼ q
≡ ∼p∨q
≡ p→q
Example 2.9
Construct the truth table for p ↔ q.
Solution.
p q p↔q
T T T
T F F
F T F
F F T
Example 2.10
Show that the biconditional proposition of p and q is logically equivalent to
the conjunction of the conditional propositions p → q and q → p.
Solution.
1. ∼
2. ∧, ∨ in any order.
3. →, ↔ in any order.
Review Problems
Problem 2.1
Rewrite the following proposition in if−then form: “ This loop will repeat
exactly N times if it does not contain a stop or a go to.”
Problem 2.2
Construct the truth table for the proposition: ∼ p ∨ q → r.
Problem 2.3
Construct the truth table for the proposition: (p → r) ↔ (q → r).
Problem 2.4
Write negations for each of the following propositions. (Assume that all
variables represent fixed quantities or entities, as appropriate.)
a. If P is a square, then P is a rectangle.
b. If today is Thanksgiving, then tomorrow is Friday.
c. If r is rational, then the decimal expansion of r is repeating.
d. If n is prime, then n is odd or n is 2.
e. If x ≥ 0, then x > 0 or x = 0.
f. If Tom is Ann’s father, then Jim is her uncle and Sue is her aunt.
g. If n is divisible by 6, then n is divisible by 2 and n is divisible by 3.
Problem 2.5
Write the contrapositives for the propositions of Problem 2.4.
Problem 2.6
Write the converse and inverse for the propositions of Problem 2.4.
Problem 2.7
Use the contrapositive to rewrite the proposition “ The Cubs will win the
penant only if they win tomorrow’s game” in if−then form in two ways.
Problem 2.8
Rewrite the proposition : “Catching the 8:05 bus is sufficient condition for
my being on time for work” in if−then form.
Problem 2.9
Use the contrapositive to rewrite the proposition “being divisible by 3 is a
necessary condition for this number to be divisible by 9” in if−then form in
two ways.
Problem 2.10
Rewrite the proposition “A sufficient condition for Hal’s team to win the
championship is that it wins the rest of the games” in if−then form.
Problem 2.11
Rewrite the proposition “A necessary condition for this computer program
to be correct is that it not produce error messages during translation” in
if−then form.
Example 3.1
Show that the propositions “The star is made of milk, and strawberries are
red. My dog has fleas.” do not form an argument.
Solution.
Indeed, the truth or falsity of each of the propositions has no bearing on that
of the others
Example 3.2
Show that the propositions: “Mark is a lawyer. So Mark went to law school
since all lawyers have gone to law school” form an argument.
Solution.
This is an argument. The truth of the conclusion, “Mark went to law school,”
is inferred or deduced from its premises, “Mark is a lawyer” and “all lawyers
have gone to law school.”
Now, suppose that the premises of an argument are all true. Then the
conclusion may be either true or false. When the conclusion is true then the
argument is said to be valid. When the conclusion is false then the argument
is said to be invalid.
To test an argument for validity one proceeds as follows:
(1) Identify the premises and the conclusion of the argument.
(2) Construct a truth table including the premises and the conclusion.
(3) Find rows in which all premises are true.
(4) In each row of Step (3), if the conclusion is true then the argument is
valid; otherwise the argument is invalid.
Example 3.3
Show that the argument
p → q
q → p
..˙ p ∨ q
is invalid
Solution.
We construct the truth table as follows.
p q p→q q→p p∨q
T T T T T
T F F T T
F T T F T
F F T T F
From the last row we see that the premises are true but the conclusion is
false. The argument is then invalid
Example 3.4 (Modus Ponens or the method of affirming)
a. Show that the argument
p → q
p
..˙ q
is valid.
b. Show that the argument
∼p∨q → r
∼p∨q
..˙ r
is valid.
Solution.
a. The truth table is as follows.
p q p→q
T T T
T F F
F T T
F F T
Example 3.5
Show that the argument
p → q
q
..˙ p
is invalid.
Solution.
The truth table is as follows.
p q p→q
T T T
T F F
F T T
F F T
Because of the third row the argument is invalid. An argument of this form is
referred to as converse error because the conclusion of the argument would
follows from the premises if p → q is replaced by its converse q → p
Solution.
The truth table is as follows.
p q p→q ∼q ∼p
T T T F F
T F F T F
F T T F T
F F T T T
The last row shows that the argument is valid
Example 3.7
Show that the argument
p → q
∼p
..˙ ∼ q
is invalid.
Solution.
The truth table is as follows.
p q p→q ∼q ∼p
T T T F F
T F F T F
F T T F T
F F T T T
The third row shows that the argument is invalid. This is known as inverse
error because the conclusion of the argument would follow from the premises
if p → q is replaced by the inverse ∼ p →∼ q
Solution.
a. The truth table is as follows.
p q p∨q
T T T
T F T
F T T
F F F
The first and second rows show that the argument is valid.
b. The first and third rows show that the argument is valid
Solution.
The truth table is as follows.
p q p∧q
T T T
T F F
F T F
F F F
Solution.
a. The truth table is as follows.
p q p∧q
T T T
T F F
F T F
F F F
The first row shows that the argument is valid.
b. The first row shows that the argument is valid
Example 3.11 (Disjunctive Syllogism)
a. Show that the argument
p∨q
∼q
..˙ p
is valid.
b. Show that the argument
p∨q
∼p
..˙ q
is valid.
Solution.
a. The truth table is as follows.
p q ∼p ∼q p∨q
T T F F T
T F F T T
F T T F T
F F T T F
The second row shows that the argument is valid.
b. The third row shows that the argument is valid
Example 3.12 (Hypothetical Syllogism)
Show that the argument
p→q
q→r
..˙ p→r
is valid.
Solution.
The truth table is as follows.
p q r p→q q→r p→r
T T T T T T
T T F T F F
T F T F T T
T F F F T F
F T T T T T
F T F T F T
F F T T T T
F F F T T T
The first , fifth, seventh, and eighth rows show that the argument is valid
Solution.
Constructing the truth table we find
c p ∼p→c
F T T
F F F
Review Problems
Problem 3.1
Use modus ponens or modus tollens to fill in the blanks in the argument
below so as to produce valid inferences.
√ √
If 2 is rational, then 2 = ab for some integers a and b.
√
It is not true that 2 = ab for some integers a and b.
..˙
Problem 3.2
Use modus ponens or modus tollens to fill in the blanks in the argument
below so as to produce valid inferences.
Problem 3.6
Use symbols to write the logical form of the given argument. If the argument
is valid, identify the rule of inference that guarantees its validity. Otherwise
state whether the converse or the inverse error is made.
If Jules solved this problem correctly, then Jules obtained the answer 2.
Jules obtained the answer 2.
..˙ Jules solved this problem correctly.
Problem 3.7
Use symbols to write the logical form of the given argument. If the argument
is valid, identify the rule of inference that guarantees its validity. Otherwise
state whether the converse or the inverse error is made.
Problem 3.8
Use the valid argument forms of this section to deduce the conclusion from
the premises.
∼p∨q →r
s∨ ∼ q
∼t
p→t
∼ p ∧ r →∼ s
..˙ ∼q
Problem 3.9
Use the valid argument forms of this section to deduce the conclusion from
the premises.
∼ p → r∧ ∼ s
t→s
u →∼ p
∼w
u∨w
..˙ ∼t∨w
Example 4.1
Let Q(x, y) : x = y+3 with domain the collection of natural numbers (i.e. the
numbers 0, 1, 2, · · · ). What are the truth values of the propositions Q(1, 2)
and Q(3, 0)?
Solution.
By substitution in the expression of Q we find: Q(1, 2) is false since 1 = x 6=
y + 3 = 5. On the contrary, Q(3, 0) is true since x = 3 = 0 + 3 = y + 3
If P (x) and Q(x) are two predicates with a common domain D then the
notation P (x) ⇒ Q(x) means that every element in the truth set of P (x) is
also an element in the truth set of Q(x).
Example 4.2
Consider the two predicates P (x) : x is a factor of 4 and Q(x) : x is a factor
of 8. Show that P (x) ⇒ Q(x).
Solution.
Finding the truth set of each predicate we have: TP = {1, 2, 4} and TQ =
{1, 2, 4, 8}. Since every number appearing in TP also appears in TQ we have
P (x) ⇒ Q(x)
If two predicates P (x) and Q(x) with a common domain D are such that
TP = TQ then we use the notation P (x) ⇔ Q(x).
Example 4.3
Let D = IR. Consider the two predicates P (x) : −2 ≤ x ≤ 2 and Q(x) :
|x| ≤ 2. Show that P (x) ⇔ Q(x).
Solution.
Indeed, if x in TP then the distance from x to the origin is at most 2. That
is, |x| ≤ 2 and hence x belongs to TQ . Now, if x is an element in TQ then
|x| ≤ 2,i.e. (x−2)(x+2) ≤ 0. Solving this inequality we find that −2 ≤ x ≤ 2.
That is, x ∈ TP
The proposition ∀x ∈ D, P (x) is false if P (x) is false for at least one value
of x. In this case x is called a counterexample.
Example 4.4
1
Show that the proposition ∀x ∈ IR, x > x
is false.
Solution.
A counterexample is x = 21 . Clearly, 1
2
< 2 = 11 .
2
Example 4.5
Write in the form ∀x ∈ D, P (x) the proposition : “every real number is either
positive, negative or 0.”
Solution.
∀x ∈ IR, x > 0, x < 0, or x = 0.
Example 4.6
Let P (x) denote the statement “x > 3.” What is the truth value of the
proposition ∃x ∈ IR, P (x).
Solution.
Since 4 ∈ IR and 4 > 3, the given proposition is true
Example 4.7
Rewrite the proposition “if a real number is an integer then it is a rational
number” as a universal conditional proposition.
Solution.
∀x ∈ IR, if x is an integer then x is a rational number
Example 4.8
a. What is the negation of the proposition ∀x ∈ D, P (x)?
b. What is the negation of the proposition ∃x ∈ D, P (x)?
c. What is the negation of the proposition ∀x ∈ D, P (x) → Q(x)?
Solution.
a. ∃x ∈ D, ∼ P (x).
b. ∀x ∈ D, ∼ P (x).
c. Since P (x) → Q(x) ≡ (∼ P (x)) ∨ Q(x), we have ∼ (∀x ∈ D, P (x) →
Q(x)) ≡ ∃x ∈ D, P (x)∧ ∼ Q(x)
Example 4.9
Consider the universal conditional proposition
Solution.
a. ∀x ∈ D, if ∼ Q(x) then ∼ P (x).
b. ∀x ∈ D, if Q(x) then P (x).
c. ∀x ∈ D, if ∼ P (x) then ∼ Q(x)
Example 4.10
Write the negation of each of the following propositions:
Solution.
a. ∃x ∈ IR, x > 3 and x2 ≤ 9.
b. There exists a polynomial that is not continuous everywhere.
c. For any triangle, the sum of the angles is less than or equal to 180◦
Example 4.11
a. Let P (x, y) denote the statement “x + y = y + x.” What is the truth value
of the proposition (∀x ∈ IR)(∀y ∈ IR), P (x, y)?
b. Let Q(x, y) denote the statement “x + y = 0.” What is the truth value of
the proposition (∃y ∈ IR)(∀x ∈ IR), Q(x, y)?
Solution.
a. The given proposition is always true.
b. The proposition is false. For otherwise, one can choose x 6= −y to obtain
0 6= x + y = 0 which is impossible
Example 4.12
Find the negation of the following propositions:
a. ∀x∃y, P (x, y).
b. ∃x∀y, P (x, y).
Solution.
a. ∃x∀y, ∼ P (x, y).
b. ∀x∃y, ∼ P (x, y)
Example 4.13
The symbol ∃! stands for the phrase “there exists a unique”. Which of the
following statements are true and which are false.
Solution.
a. True. Let x = 1.
b. False since 1 and −1 are both integers with integer reciprocals
Review Problems
Problem 4.1
By finding a counterexample, show that the proposition: “For all positive
integers n and m, m.n ≥ m + n” is false.
Problem 4.2
Consider the statement
∃x ∈ IR such that x2 = 2.
Problem 4.3
Rewrite the following propositions informally in at least two different ways
without using the symbols ∃ and ∀ :
a. ∀ squares x, x is a rectangle.
b. ∃ a set A such that A has 16 subsets.
Problem 4.4
Rewrite each of the following statements in the form “∃ x such that ”:
Problem 4.5
Rewrite each of the following statements in the form “∀ , if then .”:
Problem 4.6
Which of the following is a negation for “Every polynomial function is con-
tinuous”?
Problem 4.12
Given the proposition: ∀x ∈ IR, ∃ a real number y such that x + y = 0.
a. Rewrite this proposition in English without the use of the quantifiers.
b. Find the negation of the given proposition.
Problem 4.13
Given the proposition: ∃x ∈ IR, ∀y ∈ IR, x + y = 0.
a. Rewrite this proposition in English without the use of the quantifiers.
b. Find the negation of the given proposition.
Problem 4.14
Consider the proposition “Somebody is older than everybody.” Rewrite this
proposition in the form “∃ a person x such that ∀ .”
Problem 4.15
Given the proposition: “There exists a program that gives the correct answer
to every question that is posed to it.”
a. Rewrite this proposition using quantifiers and variables.
b. Find a negation for the given proposition.
Problem 4.16
Given the proposition: ∀x ∈ IR, ∃y ∈ IR such that x < y.
a. Write a proposition by interchanging the symbols ∀ and ∃.
b. State which is true: the given proposition, the one in part (a), neither, or
both.
Problem 4.17
Find the contrapositive, converse, and inverse of the proposition “∀x ∈ IR, if
x(x + 1) > 0 then x > 0 or x < −1.”
Problem 4.18
Rewrite the following proposition in if-then form : “Earning a grade of C −
in this course is a sufficient condition for it to count toward graduation.”
Problem 4.19
Rewrite the following proposition in if-then form : “Being on time each day
is a necessary condition for keeping this job.”
Problem 4.20
Rewrite the following proposition without using the words “necessary” or
“sufficient” : “Divisibility by 4 is not a necessary condition for divisibility by
2.”
Example 5.1
Use universal instantiation to fill in valid conclusion for the following argu-
ment.
Solution.
All positive integers are greater than or equal to 1
3 is a positive integer
..˙ 3 ≥ 1
Example 5.2
Use the rule of the universal modus ponens to fill in valid conclusion for the
following argument.
Solution.
∀n ∈ IN, if n = 2k for some k ∈ IN then n is even.
0 = 2.0
..0
˙ is even
Example 5.3
Use the rule of the universal modus tonens to fill in valid conclusion for the
following argument.
Solution.
All healthy people eat an apple a day.
Harry does not eat an apple a day.
..˙ Harry is not healthy
Example 5.4
What kind of error does the following invalid argument exhibit?
Solution.
This invalid argument exhibits the converse error
Example 5.5
What kind of error does the following invalid argument exhibit?
Solution.
This invalid argument exhibits the inverse error
Review Problems
Problem 5.1
Use the rule of universal modus ponens to fill in valid conclusion for the ar-
gument.
Problem 6.1
Construct the truth tables of the gates discussed in this section.
If you are given a set of input signals for a circuit, you can find its output
by tracing through the circuit gate by gate.
Problem 6.2
Give the output signal S for the following circuit, given that P = 0, Q = 1,
and R = 0 :
Problem 6.3
Write the input/output table for the circuit of the previous problem.
Problem 6.4
Find the Boolean expression that corresponds to the circuit of Problem 6.2.
Problem 6.5
Construct the circuit corresponding to the Boolean expression: (P ∧ Q)∨ ∼
R.
Problem 6.6
For the following input/output table, construct (a) the corresponding Boolean
expression and (b) the corresponding circuit:
P Q R S
1 1 1 0
1 1 0 1
1 0 1 0
1 0 0 0
0 1 1 1
0 1 0 0
0 0 1 0
0 0 0 0
Two digital logic circuits are equivalent if, and only if, their corresponding
Boolean expressions are logically equivalent.
Problem 6.7
Show that the following two circuits are equivalent:
Problem 6.8
Consider the following circuit
Let P and Q be single binary digits and P + Q = RS. Complete the fol-
lowing table
P Q R S
1 1
1 0
0 1
0 0
The given circuit is called a half-adder. It computes the sum of two single
binary digits.
Several methods have been used for expressing negative numbers in the com-
puter. The most obvious way is to convert the number to binary and stick
on another bit to indicate sign, 0 for positive and 1 for negative. Suppose
that integers are stored using this signed-magnitude technique in 8 bits so
that the leftmost bit holds the sign while the remaining bits represent the
magnitude. Thus, +4110 = 00101001 and −4110 = 10101001.
The above procedure has a gap. How one would represent the bit 0? Well,
there are two ways for storing 0. One way is 00000000 which represents
+0 and a second way 10000000 represents −0. A method for representing
numbers that avoid this problem is called the two’s complement. Con-
sidering −4110 again, first, convert the absolute value to binary obtaining
4110 = 00101001. Then take the complement of each bit obtaining 11010110.
This is called the one complement of 41. To complete the procedure, in-
crement by 1 the one’s complement to obtain −4110 = 11010111.
Conversion of +4110 to two’s complement consists merely of expressing the
number in binary, i.e. +4110 = 00101001.
Problem 6.9
Express the numbers 104 and −104 in two’s complement representation with
8 bits.
Problem 6.10
What is the decimal representation for the integer with two’s complement
10101001?
For example,
n = bk bk−1 · · · b1 b0 ,
where bi is either 0 or 1.
Problem 7.1
Find the decimal value of the following binary numbers:
a. 11001012
b. 1101102
n10 = rk rk−1 · · · r1 r0 .
Problem 7.2
Represent the following decimal integers in binary notation:
a. 129710
b. 45810
Problem 7.3
Evaluate the following sums:
a. 110111012 + 10010110102
b. 1011012 + 111012
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
where A, B, C, D, E, F stand for 10, 11, 12, 13, 14, and 15 respectively.
The conversion of a number from base 16 to base 10 is similar to the conver-
sion of numbers from base 2 to base 10. The conversion of a number from
base 10 to base 16 is similar to the conversion of a decimal number to base
2.
Problem 7.4
Convert the number A2BC16 to base 10.
Problem 7.5
Convert the number B53DF 816 to base 2.
Problem 7.6
Convert the number 1011011110001012 to base 16.
Fundamentals of Mathematical
Proofs
In this chapter we discuss some common methods of proof and the standard
terminology that accompanies them.
Example 8.1
The Euclidean geometry furnishes an example of mathematical system:
• points and lines are examples of undefined terms.
• An example of a definition: Two angles are supplementary if the sum of
their measures is 180◦ .
• An example of an axiom: Given two distinct points, there is exactly one
line that contains them.
• An example of a theorem: If two sides of a triangle are equal, then the
angles opposite them are equal.
• An example of a corollary: If a triangle is equilateral, then it is equiangular.
53
First we discuss methods for proving a theorem of the form “∃x such that
P (x).” This theorem guarantees the existence of at least one x for which the
predicate P (x) is true. The proof of such a theorem is constructive: that
is, the proof is either by finding a particular x that makes P (x) true or by
exhibiting an algorithm for finding x.
Example 8.2
Show that there exists a positive integer whose square can be written as the
sum of the squares of two positive integers.
Solution.
Indeed, one example is 52 = 32 + 42
Example 8.3
Show that there exists an integer x such that x2 = 15, 129.
Solution.
Applying the well-known algorithm of extracting the square root we find that
x = 123
Theorems are often of the form “∀x ∈ D if P (x) then Q(x).” We call P (x)
the hypothesis and Q(x) the conclusion.
Example 8.4
Show that for each integer 1 ≤ n ≤ 10, n2 − n + 11 is a prime number.
Solution.
The given proposition can be written in the form “∀n ∈ IN, if 1 ≤ n ≤ 10 then
The most powerful technique for proving a universal proposition is one that
works regardless of the size of the domain over which the proposition is
quantified. It is called the method of generalizing from the generic
particular.
The method consists of picking an arbitrary element x of the domain (known
as a generic element) for which the hypothesis P (x) is satisfied, and then
using definitions, previously established results, and the rules of inference to
conclude that Q(x) is also true.
By a direct method of proof we mean a method that consists of showing
that if P (x) is true for x ∈ D then Q(x) is also true.
Theorem 8.1
For all n, m ∈ Z , if m and n are even then so is m + n.
Proof.
Let m and n be two even integers. Then there exist integers k1 and k2 such
that n = 2k1 and m = 2k2 . We must show that m + n is even, that is, an
integer multiple of 2. Indeed,
m + n = 2k1 + 2k2
= 2(k1 + k2 )
= 2k
Example 8.5
Prove the following theorem.
Solution.
n
Proof. Let n be an arbitrary integer. Then n = 1
. By the definition of
rational numbers, n is rational
Theorem 8.2
If a, b ∈ Q
I then a + b ∈ Q.
I
Proof.
Let a and b be two rational numbers. Then there exist integers a1 , a2 , b1 6= 0,
and b2 6= 0 such that a = ab11 and b = ab22 . By the property of addition of two
fractions we have
a + b = ab11 + ab22
= a1 bb21+a
b2
2 b1
Corollary 8.1
The double of a rational number is rational.
Proof.
Let a = b in the previous theorem we see that 2a = a + a = a + b ∈ Q
I
Next, we point out of some common mistakes that must be avoided in prov-
ing theorems.
• Using the same letters to mean two different things. For example, sup-
pose that m and n are any two given even integers. Then by writing m = 2k
and n = 2k this would imply that m = n which is inconsistent with the
statement that m and n are arbitrary.
• Begging the question. By that we mean that the author of a proof uses in
his argument a fact that he is supposed to prove.
Example 8.6
Disprove the proposition ∀a, b ∈ IR, if a < b then a2 < b2 .
Solution.
A counterexample is the following. Let a = −2 and b = −1. Then a < b but
a2 > b2
Review Problems
A real number r is called rational if there exist two integers a and b 6= 0
such that r = ab . A real number that is not rational is called irrational.
Problem 8.1
Show that the number r = 6.321521521... is a rational number.
Problem 8.2
Prove the following theorem.
Problem 8.3
Use the previous exercise to prove the following.
Problem 8.4
Use the method of constructive proof to show that if r and s are two real
numbers with r < s then there exists a real number x such that r < x < s.
Problem 8.5
The following Pascal program segment does not find the minimum value in
a data set of N integers. Find a counterexample.
MINN := 0;
FOR I := 1 TO N DO
BEGIN
READLN (A);
If A < MINN THEN MINN := A
END
Example 9.1
Use the method of vacuous proof to show that if x ∈ ∅ then David is playing
pool.
Solution.
Since the proposition x ∈ ∅ is always false, the given proposition is vacuously
true
Example 9.2
Use the method of trivial proof to show that if n is an even integer then n is
divisible by 1.
Solution.
Since the proposition n is divisible by 1 is always true, the given implication
is trivially true
Example 9.3
Show that if n is a positive integer then n3 + n is even.
Solution.
We use the method of proof by cases.
Example 9.4
Use the proof by cases to prove the triangle inequality: |x + y| ≤ |x| + |y|.
Solution.
Case 1. x ≥ 0 and y ≥ 0. Then x + y ≥ 0 and so |x + y| = x + y = |x| + |y|.
Case 2. x ≥ 0 and y < 0. Then x + y < x + 0 < |x| ≤ |x| + |y|. On the
other hand, −(x + y) = −x + (−y) ≤ 0 + (−y) = |y| ≤ |x| + |y|. Thus,
if |x + y| = x + y then |x + y| < |x| + |y| and if |x + y| = −(x + y) then
|x + y| ≤ |x| + |y|.
Case 3. The case x < 0 and y ≥ 0 is similar to case 2.
Case 4. Suppose x < 0 and y < 0. Then x + y < 0 and therefore |x + y| =
−(x + y) = (−x) + (−y) = |x| + |y|.
So in all four cases |x + y| ≤ |x| + |y|.
Now, given a real number x, the largest integer n such that n ≤ x < n + 1
is called the floor of x and is denoted by ⌊x⌋. The smallest integer n such
that n − 1 < x ≤ n is called the ceiling of x and is denoted by ⌈x⌉.
Example 9.5
Compute ⌊x⌋ and ⌈x⌉ of the following values of x :
a. 37.999 b. − 57
2
c. −14.001
Solution.
a. ⌊37.999⌋ = 37, ⌈37.999⌉ = 38.
b. ⌊− 57
2
⌋ = −29, ⌈− 57
2
⌉ = −28.
c. ⌊−14.001⌋ = −15, ⌈−14.001⌉ = −14.
Example 9.6
Use the proof by a counterexample to show that the proposition “∀x, y ∈
IR, ⌊x + y⌋ = ⌊x⌋ + ⌊y⌋” is false.
Solution.
Let x = y = 0.5. Then ⌊x + y⌋ = 1 and ⌊x⌋ + ⌊y⌋ = 0
Proof.
Let n be any integer. Then we consider the following two cases.
Review Problems
Problem 9.1
Prove that for any integer n the product n(n + 1) is even.
Problem 9.2
Prove that the square of any integer has the form 4k or 4k + 1 for some
integer k
Problem 9.3
Prove that for any integer n, n(n2 − 1)(n + 2) is divisible by 4.
Theorem 9.2
Given any nonnegative integer n and a positive integer d there exist integers
q and r such that n = dq + r and 0 ≤ r < d. The number q is called the
quotient of the division of n by d and we write q = n div d. The number r
is called the remainder and we write r = n mod d or n ≡ r(mod d).
Proof.
The proof uses the fact that any nonempty subset of IN has a smallest ele-
ment. So let S = {n − d · k ∈ IN : k ∈ Z }. This set is nonempty. Indeed, if
n ∈ IN then n = n−0·d ≥ 0 and if n < 0 then n−d·n = n·(1−d) ≥ 0. Thus,
S is a nonempty subset of IN so it has a smallest element, called r. That is,
there is an integer q such that n − d · q = r or n = d · q + r. It remains to show
that r < d. Suppose the contrary, i.e. r ≥ d. Then n − d · (q + 1) = r − d ≥ 0
so that n − d · (q + 1) ∈ S. Hence, r ≤ n − d · (q + 1) = r − d, a contradiction.
Hence, r < d
dq ≤ n < dq + d.
Problem 9.4
State a necessary and sufficient condition for the floor function of a real
number to equal that number
Problem 9.5
Prove that if n is an even integer then ⌊ n2 ⌋ = n2 .
Problem 9.6
Show that the equality ⌊x − y⌋ = ⌊x⌋ − ⌊y⌋ is not valid for all real numbers
x and y.
Problem 9.7
Show that the equality ⌈x + y⌉ = ⌈x⌉ + ⌈y⌉ is not valid for all real numbers
x and y.
Problem 9.8
Prove that for all real numbers x and all integers m, ⌈x + m⌉ = ⌈x⌉ + m.
Problem 9.9
Show that if n is an odd integer then ⌈ n2 ⌉ = n+1
2
.
Theorem 10.1
If n2 is an even integer so is n.
Proof.
Suppose the contrary. That is suppose that n is odd. Then there is an integer
k such that n = 2k + 1. In this case, n2 = 2(2k 2 + 2k) + 1 is odd and this
contradicts the assumption that n2 is even. Hence, n must be even
Theorem 10.2
√
The number 2 is irrational.
Proof. √
Suppose not. That is, suppose that 2 is rational. Then √ there exist two
integers m and n with no common divisors such that 2 = m n
. Squaring
2 2 2
both sides of this equality we find that 2n = m . Thus, m is even. By
Theorem 10.1, m is even. That is, 2 divides m. But then m = 2k for some
integer k. Taking the square we find that 2n2 = m2 = 4k 2 , that is n2 = 2k 2 .
This says that n2 is even and by Theorem 10.1, n is even. We conclude that
2 divides both m and n and this contradicts
√ our assumption that m and n
have no common divisors. Hence, 2 must be irrational
Theorem 10.3
The set of prime numbers is infinite.
Proof.
Suppose not. That is, suppose that the set of prime numbers is finite. Then
these prime numbers can be listed, say, p1 , p2 , · · · , pn . Now, consider the inte-
ger N = p1 p2 · · · pn +1. By the Unique Factorization Theorem, ( See Problem
12.5) N can be factored into primes. Thus, there is a prime number pi such
that pi |N. But since pi |p1 p2 · · · pn we have pi |(N − p1 p2 · · · pn ) = 1, a contra-
diction since pi > 1
Theorem 10.4
If n is an integer such that n2 is odd then n is also odd.
Proof.
Suppose that n is an integer that is even. Then there exists an integer k such
that n = 2k. But then n2 = 2(2k 2 ) which is even
Review Problems
Problem 10.1
Use the proof by contradiction to prove the proposition “There is no greatest
even integer.”
Problem 10.2
Prove by contradiction that the difference of any rational number and any
irrational number is irrational.
Problem 10.3
Use the proof by contraposition to show that if a product of two positive real
numbers is greater than 100, then at least one of the numbers is greater than
10.
Problem 10.4
Use the proof by contradiction to show that the product of any nonzero
rational number and any irrational number is irrational.
F OR I := 1 T O N DO
If you want to verify that the loop does something regardless of the particular
integral value of N, you need mathematical induction.
Also, sums of the form
n
X n(n + 1)
k=
k=1
2
are very useful in analysis of algorithms and a proof of this formula is math-
ematical induction.
Next we examine this method. We want to prove that a predicate P (n) is
true for any nonnegative integer n ≥ n0 . The steps of mathematical induc-
tion are as follows:
Example 11.1
Use the technique of mathematical induction to show that
n(n + 1)
1 + 2 + 3 + ··· + n = , n ≥ 1.
2
Solution.
Let P (n) : 1 + 2 + · · · + n = n(n+1)
2
. Then
(i) (Basis of induction) P (1) : 1 = 1(1+1)
2
. That is, P (1)is true.
(ii) (Induction hypothesis) Assume P (n) is true. That is, P (n) : 1 + 2 + 3 +
· · · + n = n(n+1)
2
.
n+1
X n
X
k
ar = ark + arn+1
k=0 k=0
1 − rn+1 1−r
=a + arn+1
1−r 1−r
n+1 n+1
1−r +r − rn+2
=a
1−r
1 − rn+2
=a .
1−r
b. By a. we have
1 1 1 1 − ( 21 )n
1+ + 2 + · · · + n−1 =
2 2 2 1 − 21
1
=2(1 − ( )n )
2
1
=2 − n−1
2
≤2
Solution.
We use the method of proof by mathematical induction.
n+1
X n
X
(a + (k − 1)r) = (a + (k − 1)r) + a + (n + 1 − 1)r
k=1 k=1
n
= [2a + (n − 1)r] + a + nr
2
2an + n2 r − nr + 2a + 2nr
=
2
2a(n + 1) + n(n + 1)r
=
2
n+1
= [2a + nr]
2
We next exhibit a theorem whose proof uses mathematical induction.
Theorem 11.1
For all integers n ≥ 1, 22n − 1 is divisible by 3.
Proof.
Let P (n) : 22n − 1 is divisible by 3. Then
(i) (Basis of induction) P (1) is true since 3 is divisible by 3.
(ii) (Induction hypothesis) Assume P (n) is true. That is, 22n − 1 is divisible
by 3.
(iii) (Induction step) We must show that 22n+2 − 1 is divisible by 3. Indeed,
Since 3|(22n − 1) and 3|(22n · 3) we have 3|(22n · 3 + 22n − 1). This ends a proof
of the theorem
Example 11.4
a. Use induction to prove that n < 2n for all non-negative integers n.
b. Use induction to prove that 2n < n! for all non-negative integers n ≥ 4.
Solution.
a. Let P (n) : n < 2n We want to show that P (n) is valid for all n ≥ 0. By
the method of mathematical induction we have
(i) (Basis of induction) 20 − 0 = 1 > 0. That is, 0 < 20 . Thus, P (0)is true.
(ii) (Induction hypothesis) Assume P (n) is true. That is, n < 2n .
(iii) (Induction step) We must show that P (n + 1) is also true. That is,
n + 1 < 2n+1 . Indeed,
(1 + nh) ≤ (1 + h)n , n ≥ 0.
Solution.
Let P (n) : (1 + nh) ≤ (1 + h)n . We want to show that P (n) is valid for all
nonnegative integers. (i) (Basis of induction) (1 + h)0 − (1 + 0h) = 0. That
is, P (0)is true.
(ii) (Induction hypothesis) Assume P (n) is true. That is, (1+nh) ≤ (1+h)n .
(iii) (Induction step) We must show that P (n + 1) is true. That is, (1 + (n +
1)h) ≤ (1 + h)n+1 . Indeed,
Example 11.6
Define the following sequence of numbers: a1 = 2 and for n ≥ 2, an = 5an−1 .
Find a formula for an and then prove its validity by mathematical induction.
Solution.
Listing the first few terms we find, a1 = 2, a2 = 10, a3 = 50, a4 = 250. Thus,
an = 2.5n−1 . We will show that P (n) : an = 2 · 5n−1 is valid for all n ≥ 1 by
the method of mathematical induction.
(i) (Basis of induction) a1 = 2 = 2.51−1 . That is, P (1) is true.
an+1 =5an
=5(2.5n−1 )
=2.5n
Review Problems
Problem 11.1
Use the method of induction to show that
2 + 4 + 6 + · · · + 2n = n2 + n
Problem 11.2
Use mathematical induction to prove that
1 + 2 + 22 + · · · + 2n = 2n+1 − 1
Problem 11.3
Use mathematical induction to show that
n(n + 1)(2n + 1)
12 + 2 2 + · · · + n2 =
6
for all integers n ≥ 1.
Problem 11.4
Use mathematical induction to show that
2
3 3 3 n(n + 1)
1 + 2 + ··· + n =
2
Problem 11.5
Use mathematical induction to show that
1 1 1 n
+ + ··· + =
1·2 2·3 n(n + 1) n+1
Problem 11.6
Use the formula
n(n + 1)
1 + 2 + ··· + n =
2
to find the value of the sum
3 + 4 + · · · + 1, 000.
Problem 11.7
Find the value of the geometric sum
1 1 1
1 + + 2 + ··· + n.
2 2 2
Problem 11.8
Let S(n) = nk=1 (k+1)!
k
P
. Evaluate S(1), S(2), S(3), S(4), and S(5). Make a
conjecture about a formula for this sum for general n, and prove your con-
jecture by mathematical induction.
Problem 11.9
For each positive integer n let P (n) be the proposition 4n − 1 is divisible by
3.
a. Write P (1). Is P (1) true?
b. Write P (k).
c. Write P (k + 1).
d. In a proof by mathematical induction that this divisibility property holds
for all integers n ≥ 1, what must be shown in the induction step?
Problem 11.10
For each positive integer n let P (n) be the proposition 23n − 1 is divisible by
7. Prove this property by mathematical induction.
Problem 11.11
Show that 2n < (n + 2)! for all integers n ≥ 0.
Problem 11.12
a. Use mathematical induction to show that n3 > 2n + 1 for all integers
n ≥ 2.
b. Use mathematical induction to show that n! > n2 for all integers n ≥ 4.
Problem 11.13
A sequence a1 , a2 , · · · is defined recursively by a1 = 3 and an = 7an−1 for
n ≥ 2. Show that an = 3 · 7n−1 for all integers n ≥ 1.
Problem 12.1
Let m and n be two integers.
a. Is 6m + 8n an even integer?
b. Is 6m + 4n2 + 3 odd?
Problem 12.2
Prove the following theorem.
Theorem 12.1
Let a 6= 0, b 6= 0, and c be integers.
(i) If a|b and a|c then a|(b ± c).
(ii) If a|b then a|bc.
(iii) If a|b and b|c then a|c.
A positive integer p > 1 is called prime if 1 and p are the only positive
divisors of p. An integer ≥ 2 which is not prime is called a composite
number. For example, 3 is prime whereas 10 is composite.
Problem 12.3
Let m and n be positive integers with m > n. Is m2 − n2 composite?
Problem 12.4
Write the first 7 prime numbers.
Problem 12.5
If a positive number p is composite then one can always write p as the product
of primes, where the prime factors are written in increasing order. This result
is known as the Fundamental Theorem of Arithmetic or the Unique
Factorization Theorem. Write the prime factorization of 180.
Theorem 12.2
If
√ n is a composite integer, then n has a prime divisor less than or equal to
n.
Proof.
Since n is composite,
√ there√is a divisor a of n√such
√ that 1 < a < n. Write
n = ab. If a > n √ and b > n√ then n = ab > n n = n, a false conclusion.
Thus, either a ≤ n√or b ≤ n. Hence, n has a positive divisor which is
less than or equal to n. This divisor is either prime or, by the Fundamental
Theorem of Arithmetic has √ a prime divisor. In either case, n has a prime
divisor less than or equal to n
Problem 12.6
Use the previous theorem to show that the number 101 is prime.
Problem 13.1
(i) Find gcd(120, 500).
(ii) Show that 17 and 22 are relatively prime.
Problem 13.2
Find lcm(120, 500).
Problem 13.3
Recall that a ≡ b mod n if and only if a − b = kn for some integer k.
(i) Show that if a ≡ b mod n and c ≡ d mod n then a + c ≡ b + d mod n.
(ii) Show that if a ≡ b mod n and c ≡ d mod n then ac ≡ bd mod n.
(iii) What are the solutions of the linear congruence 3x ≡ 4(mod7)?
Proof.
Let d1 = gcd(a, b) and d2 = gcd(b, r). We will show that d1 = d2 . Since d2 |b,
d2 |bq. Also d2 |r. Consequently d2 |(bq + r) that is d2 |a. Hence, d2 ≤ d1 . A
similar argument shows that d1 ≤ d2 . We conclude that d1 = d2
a and b with b 6= 0.
Dividing a by b we obtain
a = bq + r1 , where 0 ≤ r1 < b.
r1 = r2 q2 + r3 , where 0 ≤ r3 < r2 .
Problem 13.4
a. Use the Euclidean algorithm to find gcd(414, 662).
b. Use the Euclidean algorithm to find gcd(287, 91).
Two matrices are said to be equal if they have the same size and their cor-
responding entries are all equal. If the matrix A is not equal to the matrix
B we write A 6= B.
Problem 14.1
Find x1 , x2 and x3 such that
x1 + x2 + 2x3 0 1 9 0 1
2 3 2x1 + 4x2 − 3x3 = 2 3 1
4 3x1 + 6x2 − 5x3 5 4 0 5
Problem 14.2
Solve the following matrix equation for a, b, c, and d
a−b b+c 8 1
=
3d + c 2a − 4d 7 6
Problem 14.3
Consider the matrices
2 1 2 1 2 1 0
A= ,B = ,C =
3 4 3 5 3 4 0
Problem 14.4
Consider the matrices
2 3 4 0 2 7
A= ,B =
1 2 1 1 −3 5
Compute A − 3B.
Problem 14.5
Let A be an m × n matrix. The transpose of A, denote by AT , is the n × m
whose columns are the rows of A. Find the transpose of the matrix
2 3 4
A= .
1 2 1
Problem 14.6
Consider the matrices
4 1 4 3
1 2 4
A= , B = 0 −1 3 1 .
2 6 0
2 7 5 2
Problem 14.7
Prove by induction on n ≥ 1 that
n n
2 1 2 n2n−1
= .
0 2 0 2n
Set is the most basic term in mathematics and computer science. Hardly
any discussion in either subject can proceed without set or some synonym
such as class or collection. In this chapter we introduce the concept of sets
and its various operations and then study the properties of these operations.
15 Basic Definitions
We first consider the following known as the barber puzzle: “The army
captain orders his company barber to shave all members of the company
provided they do not shave themselves. The barber is so busy at first that
his own beard begins to be unsightly. Just as he lathers up, the impossibility
of his position strikes him: If he shaves himself, he disobeys the captain’s or-
der. If he does not shave himself, then by the captain’s order he is supposed
to shave himself.”
A situation like this is known as a paradox. To resolve the problem one has
to take the barber out of the company. Another well known paradox is
83
Example 15.1
List the elements of the following sets.
a. {x|x is a real number such that x2 = 1}.
b. {x|x is an integer such that x2 − 3 = 0}.
Solution.
a. {−1, 1}.
b. ∅
Example 15.2
Use a property to give a description of each of the following sets.
a. {a, e, i, o, u}.
b. {1, 3, 5, 7, 9}.
Solution.
a. {x|x is a vowel}.
b. {n ∈ IN∗ |n is odd and less than 10}
Example 15.3
Suppose that A = {2, 4, 6}, B = {2, 6}, and C = {4, 6}. Determine which of
these sets are subsets of which other(s) of these sets.
15 BASIC DEFINITIONS 85
Solution.
B ⊆ A and C ⊆ A
Example 15.4
Represent A ⊆ B using a Venn diagram.
Solution.
Example 15.5
Determine whether each of the following pairs of sets are equal.
(a) {1, 3, 5} and {5, 3, 1}.
(b) {{1}} and {1, {1}}.
Solution.
(a) {1, 3, 5} = {5, 3, 1}.
(b) {{1}} = 6 {1, {1}} since 1 6∈ {{1}}
Example 15.6
I IN using ⊂
Order the sets of numbers: Z , IR, Q,
Solution.
IN ⊂ Z ⊂ Q
I ⊂ IR
Example 15.7
Determine whether each of the following statements is true or false.
(a) x ∈ {x} (b) {x} ⊆ {x} (c) {x} ∈ {x}
(d) {x} ∈ {{x}} (e) ∅ ⊆ {x} (f) ∅ ∈ {x}
Solution.
(a) True (b) True (c) False (d) True (e) True (f) False
Ac = {x ∈ U |x 6∈ A}.
B − A = {x ∈ U |x ∈ B and x 6∈ A}.
Example 15.8
Let U = IR. Consider the sets A = {x ∈ IR|x < −1 or x > 1} and
B = {x ∈ IR|x ≤ 0}. Find
a. Ac .
b. B − A.
Solution.
a. Ac = [−1, 1].
b. B − A = [−1, 0]
A ∪ B = {x|x ∈ A or x ∈ B}.
15 BASIC DEFINITIONS 87
where the ‘or’ is inclusive. This definition can be extended to more than two
sets. More precisely, if A1 , A2 , · · · , are sets then
∪∞
n=1 An = {x|x ∈ Ai f or some i}.
Example 15.9
Let A = {a, b, c}, B = {b, c, d}, and C = {b, c, e}.
Solution.
a. A ∪ (B ∩ C) = A, (A ∪ B) ∩ C = {b, c}, (A ∪ B) ∩ (A ∪ C) = {b, c} =
(A ∪ B) ∩ C.
b. A ∩ (B ∪ C) = {b, c}, (A ∩ B) ∪ C = C, (A ∩ B) ∪ (A ∩ C) = {b, c} =
A ∩ (B ∪ C).
c. A − (B − C) = A and (A − B) − C = {a} = 6 A − (B − C).
Example 15.10
For each n ≥ 1, let An = {x ∈ IR : x < 1 + n1 }. Show that
∩∞
n=1 An = {x ∈ IR : x ≤ 1}.
Solution.
The proof is by double inclusions method. Let y ∈ {x ∈ IR : x ≤ 1}. Then
for all positive integer n we have y ≤ 1 < 1 + n1 . That is, y ∈ ∩∞ n=1 An . This
shows that {x ∈ IR : x ≤ 1} ⊆ ∩∞ A
n=1 n .
Conversely, let y ∈ ∩∞ n=1 An . Then y < 1 + n1 for all n ≥ 1. Now take the limit
of both sides as n → ∞ to obtain y ≤ 1. That is, y ∈ {x ∈ IR : x ≤ 1}. This
shows that ∩∞ n=1 An ⊆ {x ∈ IR : x ≤ 1}.
Example 15.11
The symmetric difference of A and B, denoted by A∆B, is the set contain-
ing those elements in either A or B but not both. Find A∆B if A = {1, 3, 5}
and B = {1, 2, 3}.
Solution.
A∆B = {2, 5}
A1 × A2 × · · · × An = {(a1 , a2 , · · · , an ) : a1 ∈ A1 , a2 ∈ A2 , · · · , an ∈ An }
Example 15.12
Let A = {x, y}, B = {1, 2, 3}, and C = {a, b}. Find
a. A × B × C.
b. (A × B) × C.
Solution.
a.
A × B × C = {(x, 1, a), (x, 2, a), (x, 3, a), (y, 1, a), (y, 2, a),
(y, 3, a), (x, 1, b), (x, 2, b), (x, 3, b), (y, 1, b)
(y, 2, b), (y, 3, b)}
b.
(A × B) × C = {((x, 1), a), ((x, 2), a), ((x, 3), a), ((y, 1), a), ((y, 2), a),
((y, 3), a), ((x, 1), b), ((x, 2), b), ((x, 3), b), ((y, 1), b)
((y, 2), b), ((y, 3), b)}
15 BASIC DEFINITIONS 89
words in the latest edition of the Webster’s World dictionary of the American
Language.
The empty word or the null word is the string with no letters. It is de-
noted by ǫ.
We define the length of a word w to be the number of letters from Σ in
w and we write |w|. Note that in order to define the length of a word the
restriction given in the definition is needed. To be more precise, suppose that
Σ = {a, b, ab}. Then what is the length of the word aab? Is this a word with
two letters a and ab or three letters a, a, and b? So obviously there is no way
to tell. This ambiguity is resolved by making the restriction stated in the
definition of alphabet.
Finally, by Σn we mean the set of all words over Σ of length n. That is, Σn
is the cartesian product of n copies of Σ.
Example 15.13
Let Σ = {a, b}. List all the elements of the set
A = {w ∈ Σ∗ : |w| = 2}.
Solution.
Review Problems
Problem 15.1
Which of the following sets are equal?
a. {a, b, c, d}
b. {d, e, a, c}
c. {d, b, a, c}
d. {a, a, d, e, c, e}
Problem 15.2
Let A = {c, d, f, g}, B = {f, j}, and C = {d, g}. Answer each of the following
questions. Give reasons for your answers.
a. Is B ⊆ A?
b. Is C ⊆ A?
c. Is C ⊆ C?
d. Is C a proper subset of A?
Problem 15.3
a. Is 3 ∈ {1, 2, 3}?
b. Is 1 ⊆ {1}?
c. Is {2} ∈ {1, 2}?
d. Is {3} ∈ {1, {2}, {3}}?
e. Is 1 ∈ {1}?
f. Is {2} ⊆ {1, {2}, {3}}?
g. Is {1} ⊆ {1, 2}?
h. Is 1 ∈ {{1}, 2}?
i. Is {1} ⊆ {1, {2}}?
j. Is {1} ⊆ {1}?
Problem 15.4
Let A = {b, c, d, f, g} and B = {a, b, c}. Find each of the following:
a. A ∪ B.
b. A ∩ B.
c. A − B.
d. B − A.
Problem 15.5
Indicate which of the following relationships are true and which are false:
a. Z + ⊆ Q.
I
15 BASIC DEFINITIONS 91
b. IR− ⊂ Q.
I
I ⊂ Z.
c. Q
d. Z + ∪ Z − = Z .
I ∩ IR = Q.
e. Q I
I ∪ Z = Z.
f. Q
g. Z + ∩ IR = Z +
h. Z ∪ QI = Q.
I
Problem 15.6
Let A = {x, y, z, w} and B = {a, b}. List the elements of each of the following
sets:
a. A × B
b. B × A
c. A × A
d. B × B.
Problem 15.7
Let Σ = {x, y} be an alphabet.
a. Let L1 be the language consisting of all strings over Σ that are palindromes
and have length ≤ 4. List the elements L1 .
b. Let L2 be the language consisting of all strings over Σ that begins with x
and have length ≤ 3. List the elements L2 .
c. Let L3 be the language consisting of all strings over Σ with length ≤ 3
and for which all the x′ s appear to the left of all the y ′ s. List the elements
L3 .
d. List the elements of Σ4 , the set of all strings of length 4 over Σ.
e. Let A = Σ3 ∪ Σ4 . Describe A, B, and A ∪ B in words.
16 Properties of Sets
The following exercise shows that the operation ⊆ is reflexive and transitive,
concepts that will be discussed in the next chapter.
Example 16.1
a. Suppose that A, B, C are sets such that A ⊆ B and B ⊆ C. Show that
A ⊆ C.
b. Find two sets A and B such that A ∈ B and A ⊆ B.
c. Show that A ⊆ A.
Solution.
a. We need to show that every element of A is an element of C. Let x ∈ A.
Since A ⊆ B, we hav x ∈ B. But B ⊆ C so that x ∈ C.
b. A = {x} and B = {x, {x}}.
c. The proposition if x ∈ A then x ∈ A is always true. Thus, A ⊆ A
Theorem 16.1
Let A and B be two sets. Then
a. A ∩ B ⊆ A and A ∩ B ⊆ B.
b. A ⊆ A ∪ B and B ⊆ A ∪ B.
Proof.
a. If x ∈ A ∩ B then x ∈ A and x ∈ B. This still imply that x ∈ A. Hence,
A ∩ B ⊆ A. A similar argument holds for A ∩ B ⊆ B.
b. The proposition “if x ∈ A then x ∈ A ∪ B” is always true. Hence,
A ⊆ A ∪ B. A similar argument holds for B ⊆ A ∪ B
Theorem 16.2
Let A be a subset of a universal set U. Then
a. ∅c = U.
b. U c = ∅.
c. (Ac )c = A.
d. A ∪ Ac = U.
e. A ∩ Ac = ∅.
Proof.
a. If x ∈ U then x ∈ U and x 6∈ ∅. Thus, U ⊆ ∅c . Conversely, suppose that
x ∈ ∅c . Then x ∈ U and x 6∈ ∅. This implies that x ∈ U. Hence, ∅c ⊆ U.
16 PROPERTIES OF SETS 93
Theorem 16.3
If A and B are subsets of U then
a. A ∪ U = U.
b. A ∪ A = A.
c. A ∪ ∅ = A.
d. A ∪ B = B ∪ A.
e. (A ∪ B) ∪ C = A ∪ (B ∪ C).
Proof.
a. Clearly, A ∪ U ⊆ U. Conversely, let x ∈ U . Then definitely, x ∈ A ∪ U.
That is, U ⊆ A ∪ U.
b. If x ∈ A then x ∈ A or x ∈ A. That is, x ∈ A ∪ A and consequently
A ⊆ A ∪ A. Conversely, if x ∈ A ∪ A then x ∈ A. Hence, A ∪ A ⊆ A.
c. If x ∈ A ∪ ∅ then x ∈ A since x 6∈ ∅. Thus, A ∪ ∅ ⊆ A. Conversely, if x ∈ A
then x ∈ A or x ∈ ∅. Hence, A ⊆ A ∪ ∅.
d. If x ∈ A ∪ B then x ∈ A or x ∈ B. But this is the same thing as saying
x ∈ B or x ∈ A. That is, x ∈ B ∪ A. Now interchange the roles of A and B
to show that B ∪ A ⊆ A ∪ B.
e. Let x ∈ (A ∪ B) ∪ C. Then x ∈ (A ∪ B) or x ∈ C. Thus, (x ∈ A or x ∈ B)
or x ∈ C. This implies x ∈ A or (x ∈ B or x ∈ C). Hence, x ∈ A ∪ (B ∪ C).
The converse is similar
Theorem 16.4
Let A and B be subsets of U . Then
a. A ∩ U = A.
b. A ∩ A = A.
c. A ∩ ∅ = ∅.
d. A ∩ B = B ∩ A.
e. (A ∩ B) ∩ C = A ∩ (B ∩ C).
Proof.
a. If x ∈ A ∩ U then x ∈ A. That is , A ∩ U ⊆ A. Conversely, let x ∈ A.
Then definitely, x ∈ A and x ∈ U. That is, x ∈ A ∩ U. Hence, A ⊆ A ∩ U.
b. If x ∈ A then x ∈ A and x ∈ A. That is, A ⊆ A ∩ A. Conversely, if
x ∈ A ∩ A then x ∈ A. Hence, A ∩ A ⊆ A.
c. Clearly ∅ ⊆ A ∩ ∅. Conversely, if x ∈ A ∩ ∅ then x ∈ ∅. Hence, A ∩ ∅ ⊆ ∅.
d. If x ∈ A ∩ B then x ∈ A and x ∈ B. But this is the same thing as saying
x ∈ B and x ∈ A. That is, x ∈ B ∩ A. Now interchange the roles of A and B
to show that B ∩ A ⊆ A ∩ B.
e. Let x ∈ (A ∩ B) ∩ C. Then x ∈ (A ∩ B) and x ∈ C. Thus, (x ∈ A and
x ∈ B) and x ∈ C. This implies x ∈ A and (x ∈ B and x ∈ C). Hence,
x ∈ A ∩ (B ∩ C). The converse is similar
Theorem 16.5
If A, B, and C are subsets of U then
a. A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C).
b. A ∪ (B ∩ C) = (A ∪ B) ∩ (A ∪ C).
Proof.
a. Let x ∈ A ∩ (B ∪ C). Then x ∈ A and x ∈ B ∪ C. Thus, x ∈ A and (x ∈ B
or x ∈ C). This implies that (x ∈ A and x ∈ B) or (x ∈ A and x ∈ C).
Hence, x ∈ A ∩ B or x ∈ A ∩ C, i.e. x ∈ (A ∩ B) ∪ (A ∩ C). The converse is
similar.
b. Let x ∈ A ∪ (B ∩ C). Then x ∈ A or x ∈ B ∩ C. Thus, x ∈ A or (x ∈ B
and x ∈ C). This implies that (x ∈ A or x ∈ B) and (x ∈ A or x ∈ C).
Hence, x ∈ A ∪ B and x ∈ A ∪ C, i.e. x ∈ (A ∪ B) ∩ (A ∪ C). The converse
is similar
16 PROPERTIES OF SETS 95
Proof.
a. Let x ∈ (A ∪ B)c . Then x ∈ U and x 6∈ A ∪ B. Hence, x ∈ U and (x 6∈ A
and x 6∈ B). This implies that (x ∈ U and x 6∈ A) and (x ∈ U and x 6∈ B).
It follows that x ∈ Ac ∩ B c . Now, go backward for the converse.
b. Let x ∈ (A ∩ B)c . Then x ∈ U and x 6∈ A ∩ B. Hence, x ∈ U and (x 6∈ A
or x 6∈ B). This implies that (x ∈ U and x 6∈ B) or (x ∈ U and x 6∈ A). It
follows that x ∈ Ac ∪ B c . The converse is similar
Theorem 16.7
Suppose that A ⊆ B. Then
a. A ∩ B = A.
b. A ∪ B = B.
Proof.
a. If x ∈ A ∩ B then by the definition of intersection of two sets we have
x ∈ A. Hence, A ∩ B ⊆ A. Conversely, if x ∈ A then x ∈ B as well since
A ⊆ B. Hence, x ∈ A ∩ B. This shows that A ⊆ A ∩ B.
b. If x ∈ A ∪ B then x ∈ A or x ∈ B. Since A ⊆ B we have x ∈ B.
Hence, A ∪ B ⊆ B. Conversely, if x ∈ B then x ∈ A ∪ B. This shows that
B ⊆ A ∪ B.
Example 16.2
Let A and B be arbitrary sets. Show that (A − B) ∩ B = ∅.
Solution.
Suppose not. That is, suppose (A − B) ∩ B 6= ∅. Then there is an element x
that belongs to both A − B and B. By the definition of A − B we have that
x 6∈ B. Thus, x ∈ B and x 6∈ B which is a contradiction
(i) A = ∪nk=1 Ak .
(ii) Ai ∩ Aj = ∅ for all i 6= j.
Example 16.3
Let A = {1, 2, 3, 4, 5, 6}, A1 = {1, 2}, A2 = {3, 4}, A3 = {5, 6}. Show that
{A1 , A2 , A3 } is a partition of A.
Solution.
(i) A1 ∪ A2 ∪ A3 = A.
(ii) A1 ∩ A2 = A1 ∩ A3 = A2 ∩ A3 = ∅.
Example 16.4
What is the cardinality of each of the following sets.
(a) ∅.
(b) {∅}.
(c) {a, {a}, {a, {a}}}.
Solution.
(a) |∅| = 0
(b) |{∅}| = 1
(c) |{a, {a}, {a, {a}}}| = 3
Let A be a set. The power set of A, denoted by P(A), is the empty set
together with all possible subsets of A.
Example 16.5
Find the power set of A = {a, b, c}.
Solution.
Theorem 16.8
If A ⊆ B then P(A) ⊆ P(B).
Proof.
Let X ∈ P(A). Then X ⊆ A. Since A ⊆ B, we have X ⊆ B. Hence,
X ∈ P(B)
Example 16.6
a. Use induction to show that if |A| = n then |P(A)| = 2n .
b. If P(A) has 256 elements, how many elements are there in A?
16 PROPERTIES OF SETS 97
Solution.
a. If n = 0 then A = ∅ and in this case P(A) = {∅}. Thus |P(A)| = 1.
As induction hypothesis, suppose that if |A| = n then |P(A)| = 2n . Let
B = A ∪ {an+1 }. Then P(B) consists of all subsets of A and all subsets of A
with the element an+1 added to them. Hence, |P(B)| = 2n +2n = 2·2n = 2n+1 .
b. Since |P(A)| = 256 = 28 , we have |A| = 8
Review Problems
Problem 16.1
Let A, B, and C be sets. Prove that if A ⊆ B then A ∩ C ⊆ B ∩ C.
Problem 16.2
Find sets A, B, and C such that A ∩ C = B ∩ C but A 6= B.
Problem 16.3
Find sets A, B, and C such that A ∩ C ⊆ B ∩ C and A ∪ C ⊆ B ∪ C but
A 6= B.
Problem 16.4
Let A and B be two sets. Prove that if A ⊆ B then B c ⊆ Ac .
Problem 16.5
Let A, B, and C be sets. Prove that if A ⊆ C and B ⊆ C then A ∪ B ⊆ C.
Problem 16.6
Let A, B, and C be sets. Show that A × (B ∪ C) = (A × B) ∪ (A × C).
Problem 16.7
Let A, B, and C be sets. Show that A × (B ∩ C) = (A × B) ∩ (A × C).
Problem 16.8
a. Is the number 0 in ∅? Why?
b. Is ∅ = {∅}? Why?
c. Is ∅ ∈ {∅}? Why?
Problem 16.9
Let A and B be two sets. Prove that (A − B) ∩ (A ∩ B) = ∅.
Problem 16.10
Let A and B be two sets. Show that if A ⊆ B then A ∩ B c = ∅.
Problem 16.11
Let A, B and C be three sets. Prove that if A ⊆ B and B ∩ C = ∅ then
A ∩ C = ∅.
16 PROPERTIES OF SETS 99
Problem 16.12
Find two sets A and B such that A ∩ B = ∅ but A × B 6= ∅.
Problem 16.13
Suppose that A = {1, 2} and B = {2, 3}. Find each of the following:
a. P(A ∩ B).
b. P(A).
c. P(A ∪ B).
d. P(A × B).
Problem 16.14
a. Find P(∅).
b. Find P(P(∅)).
c. Find P(P(P(∅))).
Problem 16.15
Determine which of the following statements are true and which are false.
Prove each statement that is true and give a counterexample for each state-
ment that is false.
a. P(A ∪ B) = P(A) ∪ P(B).
b. P(A ∩ B) = P(A) ∩ P(B).
c. P(A) ∪ P(B) ⊆ P(A ∪ B).
d. P(A × B) = P(A) × P(B).
Problem 17.1
Show that if S is a collection of propositions with finite propositional variables
then (S, ∨, ∧) is a Boolean algebra.
Problem 17.2
Show that for a given nonempty set S, (P(S), ∪, ∩) is a Boolean algebra.
The reader is familiar with many relations which are used in mathematics
and computer science, i.e. “is a subset of”, “ is less than” and so on.
One frequently wants to compare or contrast various members of a set, per-
haps to arrange them in some appropriate order or to group together those
with similar properties. The mathematical framework to describe this kind
of organization of sets is the theory of relations.
There are three kinds of relations which we discuss in this chapter: (i) equiv-
alence relations, (ii) order relations, (iii) functions.
18 Equivalence Relations
Let A be a given set. An ordered pair (a, b) of elements in A is defined
to be the set {a, {a, b}}. The element a (resp. b) is called the first (resp.
second) component.
Example 18.1
a. Show that if a 6= b then (a, b) 6= (b, a).
b. Show that (a, b) = (c, d) if and only if a = c and b = d.
Solution.
a. If a 6= b then {a, {a, b}} =
6 {b, {a, b}}. That is, (a, b) 6= (b, a).
b. (a, b) = (c, d) if and only if {a, {a, b}} = {c, {c, d}} and this is equivalent
to a = c and {a, b} = {c, d} by the definition of equality of sets. Thus, a = c
and b = d.
Example 18.2
Find x and y such that (x + y, 0) = (1, x − y).
101
Solution.
By the previous exercise we have the system
x + y = 1
x − y = 0
1
Solving by the method of elimination one finds x = 2
and y = 21 .
If A and B are sets, we let A × B denote the set of all ordered pairs (a, b)
where a ∈ A and b ∈ B. We call A × B the Cartesian product of A and
B.
Example 18.3
a. Show that if A is a set with m elements and B is a set of n elements then
A × B is a set of mn elements.
b. Show that if A × B = ∅ then A = ∅ or B = ∅.
Solution.
a. Consider an ordered pair (a, b). There are m possibilities for a. For each
fixed a, there are n possibilities for b. Thus, there are m × n ordered pairs
(a, b). That is, |A × B| = mn.
b. We use the proof by contrapositive. Suppose that A 6= ∅ and B 6= ∅. Then
there is at least an a ∈ A and an element b ∈ B. That is, (a, b) ∈ A × B
and this shows that A × B 6= ∅. A contradiction to the assumption that
A×B =∅
Example 18.4
Let A = {1, 2}, B = {1}. Show that A × B 6= B × A.
Solution.
We have A × B = {(1, 1), (2, 1)} =
6 {(1, 1), (1, 2)} = B × A.
Example 18.5
a. Let A = {2, 3, 4} and B = {3, 4, 5, 6, 7}. Define the relation R by aRb if
and only if a divides b. Find, R, Dom(R), Range(R).
b. Let A = {1, 2, 3, 4}. Define the relation R by aRb if and only if a ≤ b.
Find, R, Dom(R), Range(R).
Solution.
a. R = {(2, 4), (2, 6), (3, 3), (3, 6), (4, 4)}, Dom(R) = {2, 3, 4}, and Range(R) =
{3, 4, 6}.
b. R = {(1, 1), (1, 2), (1, 3), (1, 4), (2, 2), (2, 3), (2, 4), (3, 3), (3, 4), (4, 4)}, Dom(R) =
A, Range(R) = A.
Example 18.6
a. Show that the relation
Solution.
a. Note that each element of A has exactly one image. Hence, f is a function
with domain A and range Range(f ) = {a, b}.
b. The relation f does not define a function since the element 1 has two
images, namely a and b.
Example 18.7
Draw the directed graph of the relation in part (b) of Problem 18.5.
Solution.
Next we discuss three ways of building new relations from given ones. Let R
be a relation from a set A to a set B. The inverse of R is the relation R−1
from Range(R) to Dom(R) such that
R−1 = {(b, a) ∈ B × A : (a, b) ∈ R}.
Example 18.8
Let R = {(1, y), (1, z), (3, y)} be a relation from A = {1, 2, 3} to B =
{x, y, z}.
a. Find R−1 .
b. Compare (R−1 )−1 and R.
Solution.
a. R−1 = {(y, 1), (z, 1), (y, 3)}.
b. (R−1 )−1 = R.
Example 18.9
Given the following two relations from A = {1, 2, 4} to B = {2, 6, 8, 10} :
Solution.
We have
R ={(1, 2), (1, 6), (1, 8), (1, 10), (2, 2), (2, 6), (2, 8), (2, 10), (4, 8)}
S ={(2, 6), (4, 8)}
R ∪ S =R
R ∩ S =S
Example 18.10
Let
R ={(1, 2), (1, 6), (2, 4), (3, 4), (3, 6), (3, 8)}
S ={(2, u), (4, s), (4, t), (6, t), (8, u)}
Find S ◦ R.
Solution.
S ◦ R = {(1, u), (1, t), (2, s), (2, t), (3, s), (3, t), (3, u)}
Example 18.11
a. Show that the relation a ≤ b on the set A = {1, 2, 3, 4} is reflexive.
b. Show that the relation on IR defined by aRb if and only if a < b is not
reflexive.
Solution.
a. By Example 18.7, each vertex has a loop.
b. Indeed, for any real number a we have a − a = 0 and not a − a < 0.
Example 18.12
a. Let A = {a, b, c, d} and R = {(a, a), (b, c), (c, b), (d, d)}. Show that R is
symmetric.
b. Let IR be the set of real numbers and R be the relation aRb if and only
if a < b. Show that R is not symmetric.
Solution.
a. bRc and cRb so R is symmetric.
b. 2 < 4 but 4 6< 2.
Example 18.13
a. Let IN be the set of nonnegative integers and R the relation aRb if and
only if a divides b. Show that R is antisymmetric.
b. Let A = {a, b, c, d} and R = {(a, a), (b, c), (c, b), (d, d)}. Show that R is
not antisymmetric.
Solution.
a. Suppose that a|b and b|a. We must show that a = b. Indeed, by the def-
inition of division, there exist positive integers k1 and k2 such that b = k1 a
and a = k2 b. This implies that a = k2 k1 a and hence k1 k2 = 1. Since k1 and
k2 are positive integers, we must have k1 = k2 = 1. Hence, a = b.
Example 18.14
a. Let A = {a, b, c, d} and R = {(a, a), (b, c), (c, b), (d, d)}. Show that R is
not transitive.
b. Let Z be the set of integers and R the relation aRb if a divides b. Show
that R is transitive.
Solution.
a. (b, c) ∈ R and (c, b) ∈ R but (b, b) 6∈ R.
b. Suppose that a|b and b|c. Then there exist integers k1 and k2 such that
b = k1 a and c = k2 b. Thus, c = (k1 k2 )a which means that a|c.
Theorem 18.1
The relation R defined above is reflexive, symmetric, and transitive.
Proof.
• R is reflexive: If x ∈ A then by (i) x ∈ Ak for some 1 ≤ k ≤ n. Thus, x
and x belong to Ak so that x R x.
• R is symmetric: Let x, y ∈ A such that x R y. Then there is an index k
such that x, y ∈ Ak . But then y, x ∈ Ak . That is, y R x.
• R is transitive: Let x, y, z ∈ A such that x R y and y R z. Then there exist
indices i and j such that x, y ∈ Ai and y, z ∈ Aj . Since y ∈ Ai ∩ Aj , by (ii)
we must have i = j. This implies that x, y, z ∈ Ai and in particular x, z ∈ Ai .
Hence, x R z.
Example 18.15
Let Z be the set of integers and n ∈ Z . Let R be the relation on Z defined
by aRb if a − b is a multiple of n. We denote this relation by a ≡ b (mod n)
read “a congruent to b modulo n.” Show that R is an equivalence relation
on Z .
Solution.
≡ is reflexive: For all a ∈ Z , a − a = 0 · n. That is, a ≡ a (mod n).
≡ is symmetric: Let a, b ∈ Z such that a ≡ b (mod n). Then there is an
integer k such that a − b = kn. Multiply both sides of this equality by (−1)
and letting k ′ = −k we find that b − a = k ′ n. That is b ≡ a (mod n).
≡ is transitive: Let a, b, c ∈ Z be such that a ≡ b (mod n) and b ≡ c (mod n).
Then there exist integers k1 and k2 such that a − b = k1 n and b − c = k2 n.
Adding these equalities together we find a − c = kn where k = k1 + k2 ∈ Z
which shows that a ≡ c (mod n).
Theorem 18.2
Let R be an equivalence relation on A. For each a ∈ A let
[a] = {x ∈ A|xRa}
Proof.
By the definition of [a] we have that [a] ⊆ A. Hence, ∪a∈A [a] ⊆ A. We next
show that A ⊆ ∪a∈A [a]. Indeed, let a ∈ A. Since A is reflexive, a ∈ [a] and
consequently a ∈ ∪b∈A [b]. Hence, A ⊆ ∪b∈A [b]. It follows that A = ∪a∈A [a].
This establishes (i).
It remains to show that if [a] 6= [b] then [a] ∩ [b] = ∅ for a, b ∈ A. Suppose the
contrary. That is, suppose [a] ∩ [b] 6= ∅. Then there is an element c ∈ [a] ∩ [b].
This means that c ∈ [a] and c ∈ [b]. Hence, a R c and b R c. Since R is sym-
metric and transitive, a R b. We will show that the conclusion a R b leads to
[a] = [b]. The proof is by double inclusions. Let x ∈ [a]. Then x R a. Since
a R b and R is transitive, x R b which means that x ∈ [b]. Thus, [a] ⊆ [b].
Now interchange the letters a and b to show that [b] ⊆ [a]. Hence, [a] = [b]
which contradicts our assumption that [a] 6= [b]. This establishes (ii). Thus,
A/R is a partition of A.
The sets [a] defined in the previous exercise are called the equivalence
classes of A given by the relation R. The element a in [a] is called a repre-
sentative of the equivalence class [a].
Review Problems
Problem 18.1
Let X = {a, b, c}. Recall that P(X) is the power set of X. Define a binary
relation R on P(X) as follows:
Problem 18.2
Let Σ = {a, b}. Then Σ4 is the set of all strings over Σ of length 4. Define a
relation R on Σ4 as follows:
a. Is abaa R abba?
b. Is aabb R bbaa?
c. Is aaaa R aaab?
Problem 18.3
Let A = {4, 5, 6} and B = {5, 6, 7} and define the binary relations R, S, and
T from A to B as follows:
(x, y) ∈ A × B, (x, y) ∈ R ⇔ x ≥ y.
Problem 18.4
Let A = {3, 4, 5} and B = {4, 5, 6} and define the binary relation R as
follows:
(x, y) ∈ A × B, (x, y) ∈ R ⇔ x < y.
List the elements of the sets R and R−1 .
Problem 18.5
Let A = {2, 4} and B = {6, 8, 10} and define the binary relations R and S
from A to B as follows:
(x, y) ∈ A × B, x S y ⇔ y − 4 = x.
List the elements of A × B, R, S, R ∪ S, and R ∩ S.
Problem 18.6
Consider the binary relation on IR defined as follows:
x, y ∈ R, x R y ⇔ x ≥ y.
Problem 18.7
Consider the binary relation on IR defined as follows:
x, y ∈ R, x R y ⇔ xy ≥ 0.
Problem 18.8
Let Σ = {0, 1} and A = Σ∗ . Consider the binary relation on A defined as
follows:
x, y ∈ A, x R y ⇔ |x| < |y|,
where |x| denotes the length of the string x. Is R reflexive? symmetric?
transitive?
Problem 18.9
Let A 6= ∅ and P(A) be the power set of A. Consider the binary relation on
P(A) defined as follows:
X, Y ∈ P(A), X R Y ⇔ X ⊆ Y.
Problem 18.10
Let E be the binary relation on Z defined as follows:
a E b ⇔ m ≡ n (mod 2).
Show that E is an equivalence relation on Z and find the different equivalence
classes.
Problem 18.11
Let I be the binary relation on IR defined as follows:
a I b ⇔ a − b ∈ Z.
Show that I is an equivalence relation on IR and find the different equivalence
classes.
Problem 18.12
Let A be the set all straight lines in the cartesian plane. Let || be the binary
relation on A defined as follows:
l1 ||l2 ⇔ l1 is parallel to l2 .
Show that || is an equivalence relation on A and find the different equivalence
classes.
Problem 18.13
Let A = IN × IN. Define the binary relation R on A as follows:
(a, b) R (c, d) ⇔ a + d = b + c.
a. Show that R is reflexive.
b. Show that R is symmetric.
c. Show that R is transitive.
d. List five elements in [(1, 1)].
e. List five elements in [(3, 1)].
f. List five elements in [(1, 2)].
g. Describe the distinct equivalence classes of R.
Problem 18.14
Let R be a binary relation on a set A and suppose that R is symmetric and
transitive. Prove the following: If for every x ∈ A there is a y ∈ A such that
x R y then R is reflexive and hence an equivalence relation on A.
Example 19.1
Show that the set Z of integers together with the relation of inequality ≤ is
a poset.
Solution.
≤ is reflexive: For all x ∈ Z we have x ≤ x since x = x.
≤ is antisymmetric: By the trichotomy law of real numbers, for a given pair
of numbers x and y only one of the following is true: x < y, x = y, or x > y.
So if x ≤ y and y ≤ x then we must have x = y.
≤ is transitive: By the transitivity property of < in IR if x < y and y < z
then x < z. Thus, if x ≤ y and y ≤ z then the definition of ≤ and the above
property imply that x ≤ z.
Example 19.2
Show that the relation a|b in IN∗ is a partial order relation.
Solution.
Reflexivity: Since a = 1 · a, we have a|a.
Antisymmetry: Suppose that a|b and b|a. Then there exist positive integers
k1 and k2 such that b = k1 a and a = k2 b. Hence, a = k1 k2 a which implies
that k1 k2 = 1. Since k1 , k2 ∈ IN∗ , we must have k1 = k2 = 1; that is, a = b.
Transitivity: Suppose that a|b and b|c. Then there exist positive integers k1
and k2 such that b = k1 a and c = k2 b. Thus, c = k1 k2 a which means that
a|c.
Example 19.3
Let A be a collection of subsets. Let R be the relation defined by
A R B ⇔ A ⊆ B.
Solution.
⊆ is reflexive: For any set X ∈ A, X ⊆ X.
To figure out which of two words comes first in an English dictionary, one
compares their letters one by one from left to right. If all the letters have
been the same to a certain point and one word runs out of letters, that word
comes first in the dictionary. For example, play comes before playground. If
all the letters up to a certain point are the same and the next letters differ,
then the word whose next letter is located earlier in the alphabet comes first
in the dictionary. For example, playground comes before playmate. This type
of order relation is called lexicographic or dictionary order. A general def-
inition is the following:
Let Σ∗ be the set of words with letters from an ordered set Σ. Define the
relation ≤ on Σ∗ as follows: for all w, z ∈ Σ∗ , w ≤ z if and only if either
Example 19.4
Let Σ = {a, b} and suppose that Σ has the partial order relation R =
{(a, a), (a, b), (b, b)}. Let ≤ be the corresponding lexicographic order on Σ∗ .
Indicate which of the following statements are true.
a. aab ≤ aaba.
b. bbab ≤ bba.
c. ǫ ≤ aba.
d. aba ≤ abb.
e. bbab ≤ bbaa.
f. ababa ≤ ababaa.
g. bbaba ≤ bbabb.
Solution.
a. True since aaba = (aab)a.
Example 19.5
Let A = {1, 2, 3, 9, 18} and the “divides” relation on A. Draw the Hasse
diagram of this relation.
Solution.
The directed graph of the given relation is
Now, given the Hasse diagram of a partial order relation one can find the
digraph as follows:
• reinsert the direction markers on the arrows making all arrows point up-
ward
• add loops at each vertex
• for each sequence of arrows from one point to a second point and from that
second point to a third point, add an arrow from the first point to the third.
Example 19.6
Let A = {1, 2, 3, 4} be a poset. Find the directed graph corresponding to the
following Hasse diagram on A.
Solution.
Example 19.7
Consider the “divides” relation defined on the set A = {5, 15, 30}. Prove that
this relation is a total order on A.
Solution.
The fact that the “divides” relation is a partial order is easy to verify. Since
5|15, 5|30, and 15|30, any pair of elements in A are comparable. Thus, the
“divides” relation is a total order on A.
Example 19.8
Show that the “divides” relation on IN∗ is not a total order.
Solution.
A counterexample of two noncomparable numbers are 2 and 3, since 2 does
not divide 3 and 3 does not divide 2.
Review Problems
Problem 19.1
Let Σ = {a, b} and let Σ∗ be the set of all strings over Σ. Define the relation
R on Σ∗ as follows: for all s, t ∈ Σ∗ ,
s R t ⇔ l(s) ≤ l(t),
Problem 19.2
Define a relation R on Z as follows: for all m, n ∈ Z
m R n ⇔ m + n is even.
Problem 19.3
Define a relation R on IR as follows: for all m, n ∈ IR
m R n ⇔ m2 ≤ n2 .
Problem 19.4
Let S = {0, 1} and consider the partial order relation R defined on S × S as
follows: for all ordered pairs (a, b) and (c, d) in S × S
Problem 19.5
Consider the “divides” relation defined on the set A = {1, 2, 22 , · · · , 2n },
where n is a nonnegative integer.
a. Prove that this relation is a total order on A.
b. Draw the Hasse diagram for this relation when n = 3.
Using a. we find
n
X 3n(n + 1)
3 k2 + + n = n3 + 3n2 + 3n.
k=1
2
Example 20.4
Let A = {a, b, c}. Define the function f : P(A) → IN by f (X) = |X|. Find
the range of f.
Solution.
By applying f to each member of P(A) we find Range(f ) = {0, 1, 2, 3}.
Example 20.5
Consider the alphabet Σ = {a, b} and the function f : Σ∗ → Z defined as
follows: for any string s ∈ Σ∗
Solution.
f (ǫ) = 0, f (ababb) = 2, and f (bbbaa) = 2.
Solution. √
A simple argument by the method of proof by cases shows that x2 = |x|.
Solution.
H(00101, 01110) = 3 and H(10001, 01111) = 4.
Example 20.8 (Boolean functions)
An n-place Boolean function f is a function from the Cartesian product
{0, 1}n to {0, 1}. Consider the 3-place Boolean function f : {0, 1}3 → {0, 1}
defined by
f (x1 , x2 , x3 ) = (x1 + x2 + x3 ) mod 2.
Describe f using an input/output table.
Solution.
x1 x2 x3 f (x1 , x2 , x3 )
1 1 1 1
1 1 0 0
1 0 1 0
1 0 0 1
0 1 1 0
0 1 0 1
0 0 1 1
0 0 0 0
Solution.
We have E(0110) = 000111111000 and D(111111000111) = 1101.
Example 20.10
Consider the power function fa (x) = xa , where a, x ∈ IR+ ∪ {0}. Graph on
the same Cartesian plane the functions f0 (x), f1 (x), f 1 (x), and f2 (x).
2
Solution.
Example 20.11
Graph the functions f (x) = ⌊x⌋ and g(x) = ⌈x⌉ on the closed interval [−4, 4].
Solution.
Example 20.12 √
Graph the function f : IN → IR defined by f (n) = n.
Solution.
Example 20.13
Let Df be the domain of a function f and S ⊆ Df . We say that f is increas-
ing on S if and only if, for all x1 , x2 ∈ S, if x1 < x2 then f (x1 ) < f (x2 ).
Show that the function f : IR → IR defined by f (x) = 2x − 3 is increasing
on IR.
Solution.
Indeed, for any real numbers x1 and x2 such that x1 < x2 , we have 2x1 − 3 <
2x2 − 3. That is, f (x1 ) < f (x2 ) so that f is increasing.
Example 20.14
Let Df be the domain of a function f and S ⊆ Df . We say that f is de-
creasing on S if and only if, for all x1 , x2 ∈ S, if x1 < x2 then f (x1 ) > f (x2 ).
x+2
Show that the function f : IR → IR defined by f (x) = x+1 is decreasing on
(−∞, −1) and (−1, ∞).
Solution.
Indeed, for any real numbers x1 , x2 ∈ (−∞, −1) or x1 , x2 ∈ (−1, ∞) such that
x1 < x2 , we have (x1 + 1)(x2 + 1) > 0. This implies, that f (x1 ) − f (x2 ) =
x2 −x1
(x1 +1)(x2 +1)
> 0. Thus, f is decreasing on the given intervals.
Review Problems
Problem 20.1
2x3 +2x
Let f, g : IR → IR be the functions f (x) = 2x and g(x) = x2 +1
. Show that
f = g.
Problem 20.2
Let H, K : IR → IR be the functions H(x) = ⌊x⌋ + 1 and K(x) = ⌈x⌉. Does
H = K? Explain.
Problem 20.3
Find functions defined on the set of nonnegative integers that define the
sequences whose first six terms are given below.
a. 1, − 31 , 15 , − 71 , 91 , − 11
1
.
b. 0, −2, 4, −6, 8, −10.
Problem 20.4
Let A = {1, 2, 3, 4, 5} and let F : P(A) → Z be defined as follows:
0 if X has an even number of elements
F (X) =
1 if X has an odd number of elements
Find the following
a. F ({1, 3, 4})
b. F (∅).
c. F ({2, 3}).
d. F ({2, 3, 4, 5}).
Problem 20.5
Let Σ = {a, b} and Σ∗ be the set of all strings over Σ.
a. Define f : Σ∗ → Z as follows:
the number of b′ s to the lef t of the lef tmost a in s
f (s) =
0 if s contains no a′ s
Find f (aba), f (bbab), and f (b). What is the range of f ?
b. Define g : Σ∗ → Σ∗ as follows:
g(s) = the string obtained by writing the characters of s in reverse order.
Find g(aba), g(bbab), and g(b). What is the range of g?
Problem 20.6
Let E and D be the encoding and decoding functions.
a. Find E(0110) and D(111111000111).
b. Find E(1010) and D(000000111111).
Problem 20.7
Let H denote the Hamming distance function on Σ5 .
a. Find H(10101, 00011).
b. Find H(00110, 10111).
Problem 20.8
Consider the three-place Boolean function f : {0, 1}3 → {0, 1} defined as
follows:
f (x1 , x2 , x3 ) = (3x1 + x2 + 2x3 ) mod 2
a. Find f (1, 1, 1) and f (0, 1, 1).
b. Describe f using an input/output table.
Problem 20.9
Draw the graphs of the power functions f 1 (x) and f 1 (x) on the same set of
3 4
1 1
axes. When, 0 < x < 1, which is greater: x 3 or x 4 ? When x > 1, which is
1 1
greater x 3 or x 4 ?
Problem 20.10
Graph the function f (x) = ⌈x⌉ − ⌊x⌋ on the interval (−∞, ∞).
Problem 20.11
Graph the function f (x) = x − ⌊x⌋ on the interval (−∞, ∞).
Problem 20.12
Graph the function h : IN → IR defined by h(n) = ⌊ n2 ⌋.
Problem 20.13
x−1
Let k : IR → IR be the function defined by the formula k(x) = x
for all
nonzero real numbers x.
a. Show that k is increasing on (0, ∞).
b. Is k increasing or decreasing on (−∞, 0)? Prove your answer.
Example 21.1
a. Show that the identity function IA on a set A is injective.
b. Show that the function f : Z → Z defined by f (n) = n2 is not injective.
Solution.
a. Let x, y ∈ A. If IA (x) = IA (y) then x = y by the definition of IA . This
shows that IA is injective.
b. Since 12 = (−1)2 and 1 6= −1, f is not injective.
Example 21.2 (Hash Functions)
Let m > 1 be a positive integer . Show that the function h : Z → Z defined
by h(n) = n mod m is not injective.
Solution.
Indeed, since m > 1, we have 2m + 1 6= m + 1 and h(m + 1) = h(2m + 1) = 1.
So h is not injective.
Example 21.3
Show that if f : IR → IR is increasing then f is one-to-one.
Solution.
Suppose that x1 6= x2 . Then without loss of generality we can assume that
x1 < x2 . Since f is increasing, f (x1 ) < f (x2 ). That is, f (x1 ) 6= f (x2 ). Hence,
f is one-to-one.
Example 21.4
Show that the composition of two injective functions is also injective.
Solution.
Let f : A → B and g : B → C be two injective functions. We will show that
g ◦ f : A → C is also injective. Indeed, suppose that (g ◦ f )(x1 ) = (g ◦ f )(x2 )
for x1 , x2 ∈ A. Then g(f (x1 )) = g(f (x2 )). Since g is injective, f (x1 ) = f (x2 ).
Now, since f is injective, x1 = x2 . This completes the proof that g ◦ f is
injective.
Example 21.5
a. Show that the function f : IR → IR defined by f (x) = 3x − 5 is surjective.
b. Show that the function f : Z → Z defined by f (n) = 3n − 5 is not
surjective.
Solution.
a. Let y ∈ IR. Is there an x ∈ IR such that f (x) = y? That is, 3x − 5 = y.
But solving for x we find x = y+5
3
∈ IR and f (x) = y. Thus, f is onto.
b. Take m = 3. If f is onto then there should be an n ∈ Z such that f (n) = 3.
That is, 3n − 5 = 3. Solving for n we find n = 38 which is not an integer.
Hence, f is not onto.
Solution.
We prove that prA is surjective. Indeed, let a ∈ A. Since B is not empty,
there is a b ∈ B. But then (a, b) ∈ A × B and prA (a, b) = a. Hence, prA is
surjective. The proof that prB is surjective is similar.
Example 21.7
Show that the composition of two surjective functions is also surjective.
Solution.
Let f : A → B and g : B → C, where Range(f ) ⊆ C, be two surjective
functions. We will show that g ◦ f : A → D is also surjective. Indeed, let
z ∈ D. Since g is surjective, there is a y ∈ B such that g(y) = z. Since f is
Example 21.8
a. Show that the function f : IR → IR defined by f (x) = 3x − 5 is a bijective
function.
b. Show that the function f : IR → IR defined by f (x) = x2 is not bijective.
Solution.
a. First we show that f is injective. Indeed, suppose that f (x1 ) = f (x2 ).
Then 3x1 − 5 = 3x2 − 5 and this implies that x1 = x2 . Hence, f is injective.
f is surjective by Example 21.5 (a).
b. f is not injective since f (−1) = f (1) but −1 6= 1. Hence, f is not bijective.
Example 21.9
Show that the composition of two bijective functions is also bijective.
Solution.
This follows from Example 21.4 and Example 21.7
Theorem 21.1
Let f : X → Y be a bijective function. Then there is a function f −1 : Y → X
with the following properties:
Proof.
For each y ∈ Y there is a unique x ∈ X such that f (x) = y since f is
bijective. Thus, we can define a function f −1 : Y → X by f −1 (y) = x where
f (x) = y.
a. Follows from the definition of f −1 .
Example 21.10
Show that f : IR → IR defined by f (x) = 3x − 5 is bijective and find a
formula for its inverse function.
Solution.
We have already proved that f is bijective. We will just find the formula
for its inverse function f −1 . Indeed, if y ∈ Y we want to find x ∈ X such
that f −1 (y) = x, or equivalently, f (x) = y. This implies that 3x − 5 = y and
solving for x we find x = y+53
. Thus, f −1 (y) = y+5
3
Review Problems
Problem 21.1
a. Define g : Z → Z by g(n) = 3n − 2.
(i) Is g one-to-one? Prove or give a counterexample.
(ii) Is g onto? Prove or give a counterexample.
b. Define G : IR → IR by G(x) = 3x − 2. Is G onto? Prove or give a
counterexample.
Problem 21.2
x+1
Determine whether the function f : IR → IR given by f (x) = x
is one-to-
one or not.
Problem 21.3
x
Determine whether the function f : IR → IR given by f (x) = x2 +1
is one-to-
one or not.
Problem 21.4
Let f : IR → Z be the floor function f (x) = ⌊x⌋.
a. Is f one-to-one? Prove or give a counterexample.
b. Is f onto? Prove or give a counterexample.
Problem 21.5
Let Σ = {0, 1} and let l : Σ∗ → IN denote the length function.
a. Is l one-to-one? Prove or give a counterexample.
b. Is l onto? Prove or give a counterexample.
Problem 21.6
If f : IR → IR and g : IR → IR are one-to-one functions, is f + g also
one-to-one? Justify your answer.
Problem 21.7
Define F : P{a, b, c} → IN to be the number of elements of a subset of
P{a, b, c}.
a. Is F one-to-one? Prove or give a counterexample.
b. Is F onto? Prove or give a counterexample.
Problem 21.8
If f : IR → IR and g : IR → IR are onto functions, is f + g also onto? Justify
your answer.
Problem 21.9
Let Σ = {a, b} and let l : Σ∗ → IN be the length function. Let f : IN →
{0, 1, 2} be the hash function f (n) = n mod 3. Find (f ◦l)(abaa), (f ◦l)(baaab),
and (f ◦ l)(aaa).
Problem 21.10
y−2
Show that the function F −1 : IR → IR given by F −1 (y) = 3
is the inverse
of the function F (x) = 3x + 2.
Problem 21.11
If f : X → Y and g : Y → Z are functions and g ◦ f : X → Z is one-to-one,
must both f and g be one-to-one? Prove or give a counterexample.
Problem 21.12
If f : X → Y and g : Y → Z are functions and g ◦ f : X → Z is onto, must
both f and g be onto? Prove or give a counterexample.
Problem 21.13
If f : X → Y and g : Y → Z are functions and g ◦ f : X → Z is one-to-one,
must f be one-to-one? Prove or give a counterexample.
Problem 21.14
If f : X → Y and g : Y → Z are functions and g ◦ f : X → Z is onto, must
g be onto? Prove or give a counterexample.
Problem 21.15
Let f : W → X, g : X → Y and h : Y → Z be functions. Must h ◦ (g ◦ f ) =
(h ◦ g) ◦ f ? Prove or give a counterexample.
Problem 21.16
Let f : X → Y and g : Y → Z be two bijective functions. Show that (g ◦f )−1
exists and (g ◦ f )−1 = f −1 ◦ g −1 .
22 RECURSION 133
22 Recursion
A recurrence relation for a sequence a0 , a1 , · · · is a relation that defines
an in terms of a0 , a1 , · · · , an−1 . The formula relating an to earlier values in
the sequence is called the generating rule. The assignment of a value to
one of the a’s is called an initial condition.
Example 22.1
The Fibonacci sequence
1, 1, 2, 3, 5, · · ·
is a sequence in which every number after the first two is the sum of the
preceding two numbers. Find the generating rule and the initial conditions.
Solution.
The initial conditions are a0 = a1 = 1 and the generating rule is an =
an−1 + an−2 , n ≥ 2.
Example 22.2
Let n ≥ 0 and find the number sn of words from the alphabet Σ = {0, 1} of
length n not containing the pattern 11 as a subword.
Solution.
Clearly, s0 = 1(empty word) and s1 = 2. We will find a recurrence relation
for sn , n ≥ 2. Any word of length n with letters from Σ begins with either
0 or 1. If the word begins with 0, then the remaining n − 1 letters can be
any sequence of 0’s or 1’s except that 11 cannot happen. If the word begins
with 1 then the next letter must be 0 since 11 can not happen; the remaining
n − 2 letters can be any sequence of 0’s and 1’s with the exception that 11
is not allowed. Thus the above two categories form a partition of the set of
all words of length n with letters from Σ and that do not contain 11. This
implies the recurrence relation
sn = sn−1 + sn−2 , n ≥ 2
22 RECURSION 135
Example 22.5
Consider the geometric sequence
an = ran−1 , n ≥ 1
Solution.
Listing the first four terms of the sequence after a0 we find
a1 =ra0
a2 =r2 a0
a3 =r3 a0
a4 =r4 a0
Example 22.6
Find a solution to the recurrence relation
a0 =0
an =an−1 + (n − 1), n ≥ 1
Solution.
Writing the first five terms of the sequence we find
a0 =0
a1 =0
a2 =0 + 1
a3 =0 + 1 + 2
a4 =0 + 1 + 2 + 3
We guess that
n(n − 1)
an = 0 + 1 + 2 + · · · + (n − 1) = .
2
We next show that the formula is valid by using induction on n ≥ 0.
22 RECURSION 137
Solution.
Computing the first few terms of the sequence we find
a1 =1
a2 =2
a3 =2
a4 =4
a5 =4
a6 =4
a7 =4
a8 = · · · = a15 = 8
an = 2⌊log2 n⌋ , n ≥ 1.
an+1 =2 · a⌊ n+1 ⌋
2
=2 · a n+1
2
n+1
⌊log2 ⌋
=2 · 2 2
=2⌊log2 (n+1)−1⌋+1
=2⌊log2 (n+1)⌋−1+1
=2⌊log2 (n+1)⌋
When iteration does not apply, other methods are available for finding ex-
plicit formulas for special classes of recursively defined sequences. The method
explained below works for sequences of the form
an = Aan−1 + Ban−2 (22.1)
where n is greater than or equal to some fixed nonnegative integer k and A
and B are real numbers with B 6= 0. Such an equation is called a second-
order linear homogeneous recurrence relation with constant coeffi-
cients.
Example 22.9
Does the Fibonacci sequence satisfy a second-order linear homogeneous re-
lation with constant coefficients?
Solution.
Recall that the Fibonacci sequence is defined recursively by an = an−1 + an−2
for n ≥ 2 and a0 = a1 = 1. Thus, an satisfies a second-order linear homoge-
neous relation with A = B = 1
Theorem 22.1
Equation (22.1) is satisfied by the sequence 1, t, t2 , · · · , tn , · · · where t 6= 0 if
and only if t is a solution to the characteristic equation
t2 − At − B = 0 (22.2)
Proof.
(=⇒): Suppose that t is a nonzero real number such that the sequence
1, t, t2 , · · · satisfies (22.1). We will show that t satisfies the equation t2 −
At − B = 0. Indeed, for n ≥ k we have
tn = Atn−1 + Btn−2 .
Since t 6= 0 we can divide through by tn−2 and obtain t2 − At − B = 0.
(⇐=) : Suppose that t is a nonzero real number such that t2 − At − B = 0.
Multiply both sides of this equation by tn−2 to obtain
tn = Atn−1 + Btn−2 .
This says that the sequence 1, t, t2 , · · · satisfies (22.1)
22 RECURSION 139
Example 22.10
Consider the recurrence relation
an = an−1 + 2an−2 , n ≥ 2.
Find two sequences that satisfy the given generating rule and have the form
1, t, t2 , · · · .
Solution.
According to the previous theorem t must satisfy the characteristic equation
t2 − t − 2 = 0.
Are there other solutions than the ones provided by Theorem 22.1? The
answer is yes according to the following theorem.
Theorem 22.2
If sn and tn are solutions to (22.1) then for any real numbers C and D the
sequence
an = Csn + Dtn , n ≥ 0
is also a solution.
Proof.
Since sn and tn are solutions to (22.1), for n ≥ 2 we have
sn =Asn−1 + Bsn−2
tn =Atn−1 + Btn−2
Therefore,
Example 22.11
Find a solution to the recurrence relation
a0 =1, a1 = 8
an =an−1 + 2an−2 , n ≥ 2.
Solution.
By the previous theorem and Example 22.10, an = C2n + D(−1)n , n ≥ 2 is
a solution to the recurrence relation
an = an−1 + 2an−2 .
Example 22.12
Find an explicit formula for the Fibonacci sequence
a0 =a1 = 1
an =an−1 + an−2
Solution.
The roots of the characteristic equation
t2 − t − 1 = 0
√ √
1− 5 1+ 5
are t = 2
and t = 2
. Thus,
√ √
1+ 5 n 1− 5 n
an = C( ) + D( )
2 2
is a solution to
an = an−1 + an−2 .
22 RECURSION 141
Next, we discuss the case when the characteristic equation has a single root.
Theorem 22.3
Let A and B be real numbers and suppose that the characteristic equation
t2 − At − B = 0
has a single root r. Then the sequences {1, r, r2 , · · · } and {0, r, 2r2 , 3r3 , · · · , nrn , · · · }
both satisfy the recurrence relation
an = Aan−1 + Ban−2 .
Proof.
Since r is a root to the characteristic equation, the sequence {1, r, r2 , · · · } is
a solution to the recurrence relation
an = Aan−1 + Ban−2 .
Now, since r is the only solution to the characteristic equation we have
(t − r)2 = t2 − At − B.
This implies that A = 2r and B = −r2 . Let sn = nrn , n ≥ 0. Then
Asn−1 + Bsn−2 =A(n − 1)rn−1 + B(n − 2)rn−2
=2r(n − 1)rn−1 − r2 (n − 2)rn−2
=2(n − 1)rn − (n − 2)rn
=nrn = sn
So sn is a solution to an = Aan−1 + Ban−2 .
Example 22.13
Find an explicit formula for
a0 =1, a1 = 3
an =4an−1 − 4an−2 , n ≥ 2
Solution.
Solving the characteristic equation
t2 − 4t + 4 = 0
an = C2n + Dn2n
C =1
2C + 2D =3
Example 22.14
Let A1 , A2 , · · · , An be subsets of a set S.
a. Give a recursion definition for ∪ni=1 Ai .
b. Give a recursion definition for ∩ni=1 Ai .
Solution.
a. ∪1i=1 Ai = A1 and ∪ni=1 Ai = (∪n−1
i=1 Ai ) ∪ An , n ≥ 2.
b. ∩i=1 Ai = A1 and ∩i=1 Ai = (∩n−1
1 n
i=1 Ai ) ∩ An , n ≥ 2.
Example 22.15
Use mathematical induction to prove the following generalized De Morgan’s
law.
(∪ni=1 Ai )c = ∩ni=1 Aci
Solution.
Basis of induction: (∪1i=1 Ai )c = Ac1 = ∩1i=1 Aci .
22 RECURSION 143
(∪n+1 c n
i=1 Ai ) =((∪i=1 Ai ) ∪ An+1 )
c
=(∪ni=1 Ai )c ) ∩ Acn+1
=(∩ni=1 Aci ) ∩ Acn+1
= ∩n+1
i=1 Ai
c
Example 22.16
Let a1 , a2 , · · · , an be numbers. P
a. Give a recursion definition for ni=1 ai .
b. Give a recursion definition for Πni=1 ai .
Solution.
a. 1i=1 ai = a1 and ni=1 ai = ( n−1
P P P
i=1 ai ) + an , n ≥ 2.
b. Π1i=1 ai = a1 and Πni=1 ai = (Πn−1
i=1 ai ) · an , n ≥ 2.
Example 22.17
A function is said to be defined recursively or to be a recursive function
if its rule of definition refers to itself. Define the factorial function recursively.
Solution.
We have
f (0) =1
f (n) =nf (n − 1), n ≥ 1
Example 22.18
Let G : IN → Z be the relation given by
1, if n = 1
G(n) = 1 + G( n2 ), if n is even
G(3n − 1), if n > 1 is odd
Solution.
Assume that G is a function so that G(5) exists. Listing the first five values
of G we find
G(1) =1
G(2) =2
G(3) =G(8) = 1 + G(4) = 2 + G(2) = 4
G(4) =1 + G(2) = 3
G(5) =G(14) = 1 + G(7)
=1 + G(20)
=2 + G(10)
=3 + G(5)
But the last equality implies that 0 = 3 which is impossible. Hence, G does
not define a function.
22 RECURSION 145
Review Problems
Problem 22.1
Find the first four terms of the following recursively defined sequence:
v1 =1, v2 = 2
vn =vn−1 + vn−2 + 1, n ≥ 3.
Problem 22.2
Prove each of the following for the Fibonacci sequence:
a. Fk2 − Fk−1
2
= Fk Fk+1 − Fk+1 Fk−1 , k ≥ 1.
2 2 2
b. Fk+1 − Fk − Fk−1 = 2Fk Fk−1 , k ≥ 1.
2 2
c. Fk+1 − Fk = Fk−1 Fk+2 , k ≤ 1.
2
d. Fn+2 Fn − Fn+1 = (−1)n for all n ≥ 0.
Problem 22.3
Find limn→∞ FFn+1
n
where F0 , F1 , F2 , · · · is the Fibonacci sequence. (Assume
that the limit exists.)
Problem 22.4
Define x0 , x1 , x2 , · · · as follows:
p
xn = 2 + xn−1 , x0 = 0.
Find limn→∞ xn .
Problem 22.5
a. Make a list of all bit strings of lengths zero, one, two, three, and four that
do not contain the pattern 111.
b. For each n ≥ 0 let dn = the number of bit strings of length n that do not
contain the bit pattern 111. Find d0 , d1 , d2 , d3 , and d4 .
c. Find a recurrence relation for d0 , d1 , d2 , · · ·
d. Use the results of (b) of (c) to find the number of bit strings of length five
that do not contain the pattern 111.
Problem 22.6
Find a formula for each of the following sums:
a. 1 + 2 + · · · + (n − 1), n ≥ 2.
b. 3 + 2 + 4 + 6 + 8 + · · · + 2n, n ≥ 1.
c. 3 · 1 + 3 · 2 + 3 · 3 + · · · 3 · n, n ≥ 1.
Problem 22.7
Find a formula for each of the following sums:
a. 1 + 2 + 22 + · · · + 2n−1 , n ≥ 1.
b. 3n−1 + 3n−2 + · · · + 32 + 3 + 1, n ≥ 1.
c. 2n + 3 · 2n−2 + 3 · 2n−3 + · · · + 3 · 22 + 3 · 2 + 3, n ≥ 1.
d. 2n − 2n−1 + 2n−2 − 2n−3 + · · · + (−1)n−1 · 2 + (−1)n , n ≥ 1.
Problem 22.8
Use iteration to guess a formula for the following recursively defined sequence
and then use mathematical induction to prove the validity of your formula:
c1 = 1, cn = 3cn−1 + 1, for all n ≥ 2.
Problem 22.9
Use iteration to guess a formula for the following recursively defined sequence
and then use mathematical induction to prove the validity of your formula:
w0 = 1, wn = 2n − wn−1 , for all n ≥ 2.
Problem 22.10
Determine whether the recursively defined sequence: a1 = 0 and an = 2an−1 +
n − 1 satisfies the recursive formula an = (n − 1)2 , n ≥ 1.
Problem 22.11
Which of the following are second-order homogeneous recurrence relations
with constant coefficients?
a. an = 2an−1 − 5an−2 .
b. bn = nbn−1 + bn−2 .
c. cn = 3cn−1 · c2n−2 .
d. dn = 3dn−1 + dn−2 .
e. rn = rn−1 − rn−2 − 2.
f. sn = 10sn−2 .
Problem 22.12
Let a0 , a1 , a2 , · · · be the sequence defined by the recursive formula
an = C · 2n + D, n ≥ 0
22 RECURSION 147
Problem 22.13
an = C · 2n + D, n ≥ 0
where C and D are real numbers. Show that for any choice of C and D,
an = 3an−1 − 2an−2 , n ≥ 2.
Problem 22.14
Let a0 , a1 , a2 , · · · be the sequence defined by the recursive formula
a0 =1, a1 = 2
an =2an−1 + 3an−2 , n ≥ 2.
Problem 22.15
Let a0 , a1 , a2 , · · · be the sequence defined by the recursive formula
a0 =1, a1 = 4
an =2an−1 − an−2 , n ≥ 2.
Problem 22.16
The triangle inequality for absolute value states that for all real numbers a
and b, |a+b| ≤ |a|+|b|. Use the recursive definition of summation, the triangle
inequality, the definition of absolute value, and mathematical induction to
prove that for all positive integers n, if a1 , a2 , · · · , an are real numbers then
n
X n
X
| ak | ≤ |ak |.
k=1 k=1
Problem 22.17
Use the recursive definition of union and intersection to prove the following
general distributive law: For all positive integers n, if A and B1 , B2 , · · · , Bn
are sets then
A ∩ (∪nk=1 Bk ) = ∪nk=1 (A ∩ Bk ).
Problem 22.18
Use mathematical induction to prove the following generalized De Morgan’s
law.
(∩ni=1 Ai )c = ∪ni=1 Aci
Problem 22.19
Show that the relation F : IN → Z given by the rule
1 if n = 1.
n
F (n) = F(2) if n is even
1 − F (5n − 9) if n is odd and n > 1
The “bi” in binary relation R refers to the fact that R is a subset of the
cartesian product of two sets. Let A1 , A2 , · · · , An be given sets. If R is a
subset of A1 × A2 × · · · × An then we call R an n-ary relation. An n-ary
relation can be represented by a table or a set of ordered n-tuples.
Example 23.1
Problem 23.1
a. Express the above 4-ary relation as a set of 4-tuples.
b. Answer the query: PLAYER[Name]
c. Answer the query: PLAYER[Name, Position]
Part II: Representing a Relation by a Matrix.
If the numbers on the main diagonal of M (R) are all equal to 1 then R is
reflexive. If M (R)T = M (R), where M (R)T is the transpose of M (R), then
the relation R is symmetric. If mij = 0 or mji = 0 for i 6= j then R is
antisymmetric.
Problem 23.2
Let A = {1, 2, 3} and R = {(1, 1), (1, 2), (2, 2), (2, 3), (3, 1), (3, 2), (3, 3)}.
Find M (R) and use it to determine if the relation R is reflexive, symmetric
or antisymmetric.
Part III: Cryptology
An important application to congruences is cryptology, which is the study of
secret messages.
Problem 23.4
What is the message produced from the encrypted message “PHHW BRX
LQ WKH SDUN”?
Problem 25.1
Ten persons have first names George, William, and Laura and last names
Bush, Perry, and Gramm. Show that at least two persons have the same
first and last names.
Problem 25.2
Let S be a finite set and {A1 , A2 , · · · , An } be a partition of S. Use the method
of contradiction to show that there is an index 1 ≤ i ≤ n such that |Ai | ≥ |S| n
.
One can use the previous exercise to solve the following exercise.
Problem 25.3
Let S and T be two finite sets such that |S| > k|T | where k is a positive
integer. Show that for any function f : S → T there is a t ∈ T such that the
set {s ∈ S : f (s) = t} has more than k elements.
Hint: Show that the family At = {s ∈ S : f (s) = t}, where t ∈ T, partitions
S into n sets with n ≤ |T |. Then apply the previous exercise.
Problem 25.4
If S and T are finite sets such that |S| > |T | then any function f : S → T is
not one-to-one.
Problem 26.1
Show that the function f : IN∗ → IN given by f (n) = n − 1 is a bijective
function. Thus, IN is countably infinite.
Problem 26.2
Show that the function f : IN∗ → Z defined by
n
2
if n is even
f (n) = 1−n
2
if n is odd
Problem 26.3
Show that the function f : Z → 2ZZ defined by f (n) = 2n is a bijective
function. Hence, the set of even integers is countably infinite.
Problem 26.4
Show that the set of rational numbers Q
I is countably infinite.
Hint:
Problem 27.1
Consider the finite-state automaton defined by the transition diagram
Problem 27.2
Consider the finite-state automaton defined by the following transition dia-
gram.
a. To what states does A go if the symbols of the following words are input
to A in sequence starting from the initial state?
(i) 1101 (ii) 0011 (iii) 0101010.
b. Which of the words in part (a) send A to an accepting state?
c. Show that L(A) = {0(10)n : n ≥ 0} where (10)n = 1010 · · · with n copies
of 10 juxtaposed into one word.
Problem 27.4
Design a finite-state machine that recognizes words of the form 01, 011, 0111, 01111, · · · .
159
an algorithm; that is, the longest running time for any input of size n.
Since we are considering asymptotic efficiency of algorithms, basically we will
be focusing on the leading term of T (n). For example, if T (n) = 4n3 − 2n2 +
n + 5 then T (n) = n3 (4 − n2 + n12 + n53 ) and for large n we have T (n) ∼ n3 .
We say that T (n) has a growth of order n3 .
We say that one algorithm is more efficient than another if its worst case
running time has a lower order of growth.
Example 28.1
Estimate the time complexity of the following algorithm:
i := 1
p := 1
for i := 1 to n
p := p · i
i := i + 1
next i
Solution.
Prior to entering the loop, it takes two assignment statements to initialize
the variables i and p. The loop is executed n times, and each time it executes
the two assignment statements in the body of the loop with a total of two
arithmetic operations. Thus, the time complexity of the algorithm is given
by
T (n) = 4n + 2
so the growth is of order n.
Example 28.2
What is the run-time complexity based on n for the following program seg-
ment:
for i := 1 To n
for j := 1 To n
A(i,j) := x
next j
next i
Solution.
The inner loop is executed n times and the outer loop also is executed n
In the above two problems we found a precise expression for the time com-
plexity of the algorithm. What usually interests us is the order of growth.
We next introduce some of the concepts of growth orders. Let g : IN → IR.
We define the set
s := 0
for i := 1 To n
for j := 1 To i
s := s + j · (i − j + 1)
next j
next i
Solution.
Prior to entering the loop there is one assignment statement. Now, there are
two additions, one subtraction, one multiplication and one assignment for
each iteration of the inner loop. The total number of time the inner loop is
executed is
n(n + 1)
1 + 2 + 3 + ··· + n =
2
n(n+1)
Hence, T (n) = 5 · 2
+ 1 ≤ 5n2 , n ≥ 1 so that C = 5 and n0 = 2. Hence,
T (n) ∈ O(n2 ).
Example 28.5
Show that
1 + 2 + 3 + · · · + n = O(n2 ).
Solution.
Indeed, since n ≥ 1 we have
1 + 2 + 3 + · · · + n ≤ n + n + n + · · · + n = n2
so that C = 1 and n0 = 1.
Example 28.6
Show that n3 6∈ O(n2 ).
Solution.
We proceed by contradiction. Suppose that n3 ∈ O(n2 ). Then there exist
constants C and n0 such that n3 ≤ Cn2 for all n ≥ n0 . Dividing through by
n2 to obtain n ≤ C. This leads to a contradiction since the left-hand side can
be made as large as we please whereas the right-hand side is constant.
Example 28.7
Show that if f (n) ∈ O(g(n)) and g(n) ∈ O(h(n)) then f (n) ∈ O(h(n)).
Solution.
Since f (n) ∈ O(g(n)), there exist n1 and C1 such that |f (n)| ≤ C1 |g(n)| for all
n ≥ n1 . Similarly, there exist constants C2 and n2 such that |g(n)| ≤ C2 |h(n)|
for all n ≥ n2 . Let n0 = max{n1 , n2 } and C = C1 C2 . Then for n ≥ n0 we
have
|f (n)| ≤ C1 |g(n)| ≤ C1 C2 |h(n)| = C|h(n)|
Example 28.8
Suppose we want to arrange the elements of a one dimensional array a[1], a[2], · · · , a[n]
in increasing order. An insertion sort compares every pair of elements,
switching the values of those that are out of order, a[i − 1] > a[i].
a. How many possible pairs are compared?
b. What is the maximum number of exchanges?
c. What is time the complexity of this algorithm in the worst case?
d. Is this a polynomial-time algorithm?
Solution.
a. The number of possible pairs to compare in the algorithm is
n(n − 1)
1 + 2 + · · · + (n − 1) = .
2
n(n−1)
b. From part a. it follows that the maximum number of exchanges is 2
.
c. T (n) = n(n−1)
2
.
2
d. For n ≥ 1, T (n) ≤ n2 so that T (n) ∈ O(n2 ).
Theorem 28.1
(n)
Suppose that limn→∞ fg(n) = L with L ≥ 0. Then f (n) ∈ O(g(n)). Moreover,
a. if L > 0 then g(n) ∈ O(f (n)), and
b. if L = 0 then g(n) 6∈ O(f (n)).
Proof.
(n)
Let ǫ = 1. Then there is a positive integer n0 such that | fg(n) −L| < 1 whenever
(n)
n ≥ n0 . This implies that | fg(n) | < 1 + L for n ≥ n0 . Hence, |f (n)| < C|g(n)|
where C = (1 + L) and n ≥ n0 . But this is just saying that f (n) ∈ O(g(n)).
a. Now, suppose that L > 0. Then limn→∞ fg(n) (n)
= L1 . Interchange the roles
of f and g in the previous argument to find that |g(n)| < C|f (n)| where
C = 1 + L1 and n ≥ n0 for some positive integer n0 . Hence, g(n) ∈ O(f (n)).
b. Now suppose that L = 0. We use contradiction to show that g(n) 6∈
O(f (n)). So suppose that g(n) ∈ O(f (n)). Then there exist positive constants
C and M1 such that |g(n)| ≤ C|f (n)| for all n ≥ M1 . On the other hand, by
(n)
letting ǫ = C1 we can find a positive integer M2 such that | fg(n) | < ǫ whenever
n ≥ M2 . Let n0 = max{M1 , M2 }. Then for n ≥ n0 we have
g(n)
C<| |≤C
f (n)
Review Problems
Problem 28.1
Find the worst case running time of the following segment of an algorithm:
for i := 1 to n
for j := 1 to ⌊ i+1
2
⌋
a := (n − i) · (n − j)
next j
next i
Problem 28.2
Find the worst case running time of the following segment of an algorithm:
for i := 1 to n
for j := 1 to 2n
for k := 1 to n
x := i · j · k
next k
next j
next i
Problem 28.3
Construct a table showing the result of each step when insertion sort is
applied to the array a[1] = 6, a[2] = 2, a[3] = 1, a[4] = 8, a[5] = 4.
Problem 28.4
How many comparisons actually occur when insertion sort is applied to the
array of the previous exercise?
Problem 28.5
Selection sort is another algorithm for arranging the elements of a one-
dimensional array a[1], a[2], · · · , a[n] in increasing order. The sorting works
by selecting the smallest item in the list, moving it to the front of the list,
and then finding the smallest of the remaining items and moving it to the
second position in the list, and so on. When two items in the list, say a[k]
and a[m], have to be interchanged, we write switch(a[k], a[m]). The following
is the selection algorithm:
for i := 1 to n − 1
min := i
for j := i + 1 to n
if a[min] > a[j] then
switch(a[min], a[j])
next j
next i
Construct a table showing the result of each step when selection sort is ap-
plied to the array a[1] = 5, a[2] = 3, a[3] = 4, a[4] = 6, a[5] = 2.
Problem 28.6
How many comparisons actually occur when selection sort is applied to the
array of the previous exercise?
Problem 28.7
√ √
Show that ⌊ n⌋ ∈ O( n).
Problem 28.8
Show that
12 + 22 + · · · + n2 ∈ O(n3 ).
Problem 28.9
Show that
13 + 23 + · · · + n3 ∈ O(n4 ).
Problem 28.10
a. Use mathematical induction to show that
1 1 1 4
13 + 23 + · · · + n3 ≤ n3
for all n ≥ 1.
b. What can you conclude from part (a) about the order of the above sum?
Theorem 29.1
For any a > 1, O(loga n) = O(log2 n).
Proof.
We must show that there exist constants C1 , C2 and n0 such that loga n ≤
C1 log2 n and log2 n ≤ C2 loga n for all n ≥ n0 . By the change of bases formula
we have
log2 n
loga n = .
log2 a
1
Now, let C1 = log2 a
, C2 = log2 a, and n0 = 1.
Example 29.1
Show that n + n log2 n ∈ O(n log2 n).
Solution.
Since limn→∞ n logn n = 0, there is a positive integer n0 such that n < n log2 n
2
for all n ≥ n0 . Thus,n + n log2 n < 2nlog2 n = Cn log2 n, n ≥ n0 . This shows
that n + n log2 n ∈ O(n log2 n).
Example 29.2
a. Show that n! = O(nn ).
b. Show that n = O(2n ).
c. Use b. to show that log2 n = O(n).
Solution.
a. Since n − i ≤ n for 0 ≤ i ≤ n we have
n! = n(n − 1)(n − 2) · · · 2 · 1
≤ n · n · n · · · n · n = nn
n+1 ≤n+n
≤ 2n + 2n = 2n+1
Hence, n = O(2n ).
c. Take the logarithm of both sides of b. to obtain log2 n ≤ n, n ≥ 1. That
is, log2 n = O(n).
Example 29.3
a. Show that log2 n! = O(n log2 n).
b. Show that n log2 n = O(log2 n!).
Solution.
a. We have shown that n! = O(nn ). That is, n! ≤ nn for n ≥ 1. Take loga-
rithm of both sides to obtain log2 n! ≤ n log2 n. That is, log2 n! = O(n log2 n).
b. It is easy to see that (n − i)(i + 1) ≥ n for all 0 ≤ i ≤ n − 1. In this case
(n!)2 = [n · (n − 1) · · · 2 · 1][1 · 2 · · · (n − 1) · n]
= (n · 1)[(n − 1) · 2] · · · [2 · (n − 1)](1 · n)
≥ n · n···n · n
= nn .
Now take the logarithm of both sides to obtain n log2 n ≤ 2 log2 n!. That is,
n log2 n = O(log2 n!).
Example 29.4
a. Show that if f1 (n) ∈ O(g(n)) and f2 (n) ∈ O(g(n)) then f1 (n) + f2 (n) ∈
O(g(n)).
b. Show that if f1 (n) ∈ O(g1 (n)) and f2 (n) ∈ O(g2 (n)) then f1 (n) · f2 (n) ∈
O(g1 (n) · g2 (n)).
c. Use a. and b. to show that
Solution.
a. Since f1 (n) ∈ O(g(n)), there exist n1 and C1 such that |f1 (n)| ≤ C1 |g(n)|
for all n ≥ n1 . Similarly, there exist constants C2 and n2 such that |f2 (n)| ≤
C2 |g(n)| for all n ≥ n2 . Let n0 = max{n1 , n2 } and C = C1 + C2 . Then for
n ≥ n0 we have
b. Now since f1 (n) ∈ O(g1 (n)), there exist n1 and C1 such that |f1 (n)| ≤
C1 |g1 (n)| for all n ≥ n1 . Similarly, there exist constants C2 and n2 such that
|f2 (n)| ≤ C2 |g2 (n)| for all n ≥ n2 . Let n0 = max{n1 , n2 } and C = C1 · C2 .
Then for n ≥ n0 we have
Review Problems
Problem 29.1
Show that 1 + 2 + 22 + · · · + 2n ∈ O(2n+1 ).
Problem 29.2
Show that 2n
3
+ 2n
32
+ 2n
33
+ ··· + 2n
3n
∈ O(n).
Problem 29.3
Show that n2 + 2n ∈ O(2n ).
Problem 29.4
a. Show that 21 + 13 + · · · + n1 ≤ ln n, n ≥ 2.
b. Use part a. to show that for n ≥ 3
1 1
1+ + · · · + ≤ ln n.
2 n
n n n
c. Use b. to show that n + 2
+ 3
+ ··· + n
∈ O(n ln n).
Problem 29.5
Show that 2n ∈ O(n!).
30 Θ- and Ω-Notations
The O-notation asymptotically bounds a function from above. When we
have bounds from above and below, we use Θ notation. For a given function
g(n), we denote by Θ(g(n)) to be the set of all functions f such that there
exist positive constants C1 , C2 , and n0 such that C1 |g(n)| ≤ |f (n)| ≤ C2 |g(n)|
for all n ≥ n0 . If f ∈ Θ(g(n)) we write f (n) = Θ(g(n)).
Example 30.1
Show that 21 n2 − 3n = Θ(n2 ).
Solution.
Let C1 and C2 be positive constants such that
1
C1 n2 ≤ n2 − 3n ≤ C2 n2 .
2
This is equivalent to
1 3
C1 ≤ − ≤ C2 .
2 n
Since 12 − n3 ≤ 12 for all n ≥ 1, we choose C2 ≥ 21 . Since 1
2
− 3
n
≥ 1
4
for all
n ≥ 12, we choose C1 ≤ 41 . Finally, we choose n0 = 12.
Example 30.2
Show that 6n3 6= Θ(n2 ).
Solution.
We use the argument by contradiction. Suppose that 6n3 = Θ(n2 ). Then
there exist positive constants C1 , C2 and n0 such that
C1 n2 ≤ 6n3 ≤ C2 n2
Theorem 30.1
For given two functions f (n) and g(n), f (n) = Θ(g(n)) if and only if f (n) =
O(g(n)) and g(n) = O(f (n)).
Proof.
Suppose that f (n) = Θ(g(n)). Then there exist positive constants C1 , C2 ,
and n0 such that C1 |g(n)| ≤ |f (n)| ≤ C2 |g(n)| for all n ≥ n0 . The left-hand
side inequality implies that g(n) = O(f (n)) whereas the right-hand side in-
equality implies that f (n) = O(g(n)). Now go backward for the converse.
Example 30.3
Show that log2 n! = Ω(n log2 n).
Solution.
Since (n!)2 ≥ nn for all n ≥ 1 we find n log2 n ≤ 2 log2 n!. That is, 12 n log2 n ≤
log2 n! for n ≥ 1. This says that log2 n! = Ω(n log2 n).
Theorem 30.2
For given two functions f (n) and g(n), f (n) = Θ(g(n)) if and only if f (n) =
O(g(n)) and f (n) = Ω(g(n)).
Proof.
Suppose first that f (n) = Θ(g(n)). Then there exist positive constants C1 , C2
and n0 such that C1 |g(n)| ≤ |f (n)| ≤ C2 |g(n)| for n ≥ n0 . The right-hand
side inequality implies that f (n) = O(g(n)) whereas the left-hand side in-
equality implies that f (n) = Ω(g(n)).
Conversely, suppose that f (n) = O(g(n)) and f (n) = Ω(g(n)). Then there
exist constants C1 , C2 , n1 and n2 such that |f (n)| ≤ C2 |g(n)| for n ≥ n2 and
C1 |g(n)| ≤ |f (n)| for n ≥ n1 . Let n0 = max{n1 , n2 }. Then for n ≥ n0 we
have C1 |g(n)| ≤ |f (n)| ≤ C2 |g(n)|. That is, f (n) = Θ(g(n)).
Example 30.4
Let f (n) and g(n) be two given functions. We say that f (n) = o(g(n)) if and
(n)
only if limn→∞ fg(n) = 0.
a. Show that if f (n) = o(g(n)) then f (n) = O(g(n)).
b. Find two functions f (n) and g(n) such that f (n) = O(g(n) but f (n) 6=
o(g(n)).
Solution.
a. Suppose that f (n) = o(g(n)). Then there is a positive integer n0 such
(n)
that | fg(n) | ≤ 1 for n ≥ n0 . That is, |f (n)| ≤ |g(n)| for all n ≥ n0 . Hence,
f (n) = O(g(n)).
b. Let f (n) = 2n2 and g(n) = n2 .
The major goal of this chapter is to establish several techniques for counting
large finite sets without actually listing their elements. Also, the fundamen-
tals of probability theory are discussed.
31 Elements of Counting
For a set X, |X| denotes the number of elements of X. It is easy to see that
for any two sets A and B we have the following result known as the Inclu-
sion - Exclusion Principle
Solution.
Basis of induction: For n = 2 the result holds by the Inclusion-Exclusion
175
Principle.
Induction hypothesis: Suppose that for any collection {A1 , A2 , · · · , An } of
pairwise disjoint sets we have
Example 31.2
A total of 35 programmers interviewed for a job; 25 knew FORTRAN, 28
knew PASCAL, and 2 knew neither languages. How many knew both lan-
guages?
Solution.
Let A be the group of programmers that knew FORTRAN, B those who
knew PASCAL. Then A ∩ B is the group of programmers who knew both
languages. By the Inclusion-Exclusion Principle we have
That is,
33 = 25 + 28 − |A ∩ B|.
Solving for |A ∩ B| we find |A ∩ B| = 20.
Another important rule of counting is the multiplication rule. It states
that if a decision consists of k steps, where the first step can be made in n1
different ways, the second step in n2 ways, · · · , the kth step in nk ways, then
the decision itself can be made in n1 n2 · · · nk ways.
Example 31.3
a. How many possible outcomes are there if 2 distinguishable dice are rolled?
b. Suppose that a state’s license plates consist of 3 letters followed by four
digits. How many different plates can be manufactured? (no repetitions)
Solution.
a. By the multiplication rule there are 6 × 6 = 36 possible outcomes.
b. By the multiplication rule there are 26 × 25 × 24 × 10 × 9 × 8 × 7 possible
license plates.
Example 31.4
Let Σ = {a, b, c, d} be an alphabet with 4 letters. Let Σ2 be the set of all
words of length 2 with letters from Σ. Find the number of all words of length
2 where the letters are not repeated. First use the product rule. List the
words by means of a tree diagram.
Solution.
By the multiplication rule there are 4 × 3 = 12 different words. Constructing
a tree diagram
Example 31.6
How many license plates are there that start with three letters followed by 4
digits (no repetitions)?
Solution.
P (26, 3) · P (10, 4) = 78, 624, 000.
P (n, r) n!
C(n, r) = = .
r! r!(n − r)!
Example 31.7
In how many different ways can a hand of 5 cards be selected from a deck of
52 cards?(no repetition)
Solution.
C(52, 5) = 2, 598, 960.
Example 31.8
Prove the following identities:
a. C(n, 0) = C(n, n) = 1 and C(n, 1) = C(n, n − 1) = n.
b. Symmetry property: C(n, r) = C(n, n − r), r ≤ n.
c. Pascal’s identity: C(n + 1, k) = C(n, k − 1) + C(n, k), n ≥ k.
Solution.
a. Follows immediately from the definition of of C(n, r).
b. Indeed, we have
n!
C(n, n − r) = (n−r)!(n−n+r)!
n!
= r!(n−r)!
= C(n, r)
c.
n! n!
C(n, k − 1) + C(n, k) = (k−1)!(n−k+1)!
+ k!(n−k)!
n!k n!(n−k+1)
= k!(n−k+1)!
+ k!(n−k+1)!
n!
= k!(n−k+1)!
(k + n − k + 1)
(n+1)!
= k!(n+1−k)!
= C(n + 1, k)
Proof.
The proof is by induction.
Indeed, we have
Example 31.9
Expand (x + y)6 using the binomial theorem.
Solution.
By the Binomial Theorem and Pascal’s triangle we have
Example 31.10
a. Show that Pnk=0 C(n, k) = 2n .
P
b. Show that nk=0 (−1)k C(n, k) = 0.
Solution.
a. Letting x = y = 1 in the binomial theorem we find
n
X
n n
2 = (1 + 1) = C(n, k).
k=0
Review Problems
Problem 31.1
a. How many ways can we get a sum of 4 or a sum of 8 when two distin-
guishable dice are rolled?
b. How many ways can we get a sum of 8 when two undistinguishable dice
are rolled?
Problem 31.2
a. How many 4-digit numbers can be formed using the digits, 1, 2, · · · , 9
(with repetitions)? How many can be formed if no digit can be repeated?
b. How many different license plates are there that involve 1, 2, or 3 letters
followed by 4 digits (with repetitions)?
Problem 31.3
a. In how many ways can 4 cards be drawn, with replacement, from a deck
of 52 cards?
b. In how many ways can 4 cards be drawn, without replacement, from a
deck of 52 cards?
Problem 31.4
In how many ways can 7 women and 3 men be arranged in a row if the three
men must always stand next to each other.
Problem 31.5
A menu in a Chinese restaurant allows you to order exactly two of eight
main dishes as part of the dinner special. How many different combinations
of main dishes could you order?
Problem 31.6
Find the coefficient of a5 b7 in the binomial expansion of (a − 2b)12 .
Problem 31.7
Use the binomial theorem to prove that
n
X
n
3 = 2k C(n, k).
k=0
Example 32.1
Which of the following numbers cannot be the probability of some event? (a)
0.71 (b)−0.5 (c) 150% (d) 34 .
Solution.
(a) Yes. (b) No. Since the number is negative. (c) No since the number is
greater than 1. (d) No.
Example 32.2
What is the probability of drawing an ace from a well-shuffled deck of 52
playing cards?
Solution.
4 1
P (Ace) = 52 = 13
.
Example 32.3
What is the probability of rolling a 3 or a 4 with a fair die?
Solution.
2
P (3 or 4) = 6
= 13 .
Example 32.4
Records show (over a period of time) that 468 of 600 jets from Dallas to
Phoenix arrived on time. Estimate the probability that any one jet from
Dallas to Phoenix will arrive on time.
Solution.
P (E) = nf = 468
600
= 39
50
Example 32.5
The probability that a college student without a flu shot will get the flu is
0.45. What is the probability that a college student without the flu shot will
not get the flu?
Solution.
The probability is 1 − 0.45 = .55.
Next, we discuss some of the rules of probability. The union of two events
A and B is the event A ∪ B whose outcomes are either in A or in B. The
intersection of two events A and B is the event A ∩ B whose outcomes
are outcomes of both events A and B. Two events A and B are said to be
mutually exclusive if they have no outcomes in common. In this case
A ∩ B = ∅.
Example 32.6
If A and B are mutually exclusive then what is P (A ∩ B)?
Solution.
P (∅) = 0.
Theorem 32.1
For any events A and B the probability of A ∪ B is given by the addition
rule
P (A ∪ B) = P (A) + P (B) − P (A ∩ B).
If A and B are mutually exclusive then by Example 32.6 the above formula
reduces to
P (A ∪ B) = P (A) + P (B).
Proof.
By the Inclusion-Exclusion Principle we have
Thus,
|A ∪ B|
P (A ∪ B) =
|S|
|A| |B| |A ∩ B|
= + −
|S| |S| |S|
=P (A) + P (B) − P (A ∩ B)
Example 32.7 P
For any event E of a sample space S show that P (E) = x∈E P (x).
Solution.
This follows from the previous theorem
Example 32.8
M &M plain candies come in a variety of colors. According to the manufac-
turer, the color distribution is:
(a) Orange: 15% (b) Green: 10% (c) Red: 20% (d) Yellow: 20% (e)
Brown: 30% (f) Tan: 5%.
Suppose you have a large bag of plain candies and you reach in and take one
candy at random. Find
Solution.
1. P(orange candy Or tan candy) = .15 + .05 = .2 = 20%. The outcomes
are mutually exclusive.
2. P(not brown candy) = 1 − .3 = .7 = 70%
Example 32.9
If A is the event “drawing an ace” from a deck of cards and B is the event
“drawing a spade”. Are A and B mutually exclusive? Find P (A ∪ B).
Solution.
The events are not mutually exclusive since there is an ace that is also a
spade.
4 13 1
P (A ∪ B) = P (A) + P (B) − P (A ∩ B) = + − = 31%
52 52 52
Now, given two events A and B belonging to the same sample space S.
The conditional probability P (A|B) denotes the probability that event A
will occur given that event B has occurred. It is given by the formula
P (A ∩ B)
P (A|B) = .
P (B)
Example 32.10
Consider the experiment of tossing two dice. What is the probability that
the sum of two dice equals six given that the first die is a four?
Solution.
The possible outcomes of our experiment are
{(4, 1), (4, 2), (4, 3), (4, 4), (4, 5), (4, 6)}.
Thus, the probability that the sum is six given that the first die is four is 61 .
Assuming that the experiment consists of tossing the two dice then by letting
B be the event that the first die is 4 and A be the event that the sum of the
two dice is 6 then
1
P (A ∩ B) 36 1
P (A|B) = = 6 =
P (B) 36
6
If P (A|B) = P (A), we say that the two events A and B are independent.
That is, the occurrence of A is independent whether or not B occurs. If two
events are not independent, we say that they are dependent.
Example 32.11
Show that A and B are independent if and only if
P (A ∩ B) = P (A) · P (B).
Solution.
Suppose that A and B are independent. Then P (A) = P (A|B) = P P(A∩B) (B)
.
That is, P (A ∩ B) = P (A) · P (B). Conversely, if P (A ∩ B) = P (A) · P (B)
then P (A|B) = P P(A∩B)
(B)
= P (A).
Example 32.12
You roll two fair dice: a green one and a red one.
a. Are the outcomes on the dice independent?
b. Find P(5 on green die and 3 on red die).
c. Find P(3 on green die and 5 on red die).
d. Find P((5 on green die and 3 on red die) or (3 on green die and 5 on red
die)).
Solution.
a. Yes.
b. P(5 on green die and 3 on red die) = 16 · 16 = 36
1
.
1
c. P(3 on green die and 5 on red die) = 36 .
d. P((5 on green die and 3 on red die) or (3 on green die and 5 on red die))
1 1 1
= 36 + 36 = 18 .
Example 32.13
Show that
P (B) · P (A|B)
P (B|A) = .
P (A)
Solution.
This follows from the fact that P (A ∩ B) = P (B ∩ A) and the formula of
P (A|B) given above.
Example 32.14
Prove Bayes’ Theorem
P (B|A)P (A)
P (A|B) = .
P (B|A)P (A) + P (B|Ac )P (Ac )
Solution.
Note first that {Ac ∩ B, A ∩ B} form a partition of B. Thus,
Example 32.15
Consider two urns. The first contains two white and seven black balls and
the second contains five white and six black balls. We flip a fair coin and
then draw a ball from the first urn or the second urn depending on whether
the outcome was head or tail. What is the conditional probability that the
outcome of the toss was head given that a white ball was selected?
Solution.
Let W be the event that a white ball is drawn, and let H be the event that
the coin comes up heads. The desired probability P (H|W ) may be calculated
as follows:
P (H ∩ W )
P (H|W ) =
P (W )
P (W |H)P (H)
=
P (W )
P (W |H)P (H)
=
P (W |H)P (H) + P (W |H c )P (H c )
21
92
=21 5 1
92
+ 11 2
22
=
67
It frequently occurs that in performing an experiment we are mainly inter-
ested in some functions of the outcome as opposed to the outcome itself. For
example, in tossing dice we are interested in the sum of the dice and are not
really concerned about the actual outcome. These real-valued functions de-
fined on the sample space are known as random variables. If the range is
a finite subset of IN then the random variable is called discrete. Otherwise,
the random variable is said to be continuous. Discrete random variables
are usually the result of a count whereas a continuous random variable is
usually the result of a measurement.
A probability distribution is a correspondence that assigns probabilities
to the values of a random variable. The graph of a probability distribution
is called a histogram.
Example 32.16
Let f denote the random variable that is defined as the sum of two fair dice.
Find the probability distribution of f.
Solution.
1
P (f = 2) = P ({(1, 1)}) = 36 ,
2
P (f = 3) = P ({(1, 2), (2, 1)}) = 36 ,
3
P (f = 4) = P ({(1, 3), (2, 2), (3, 1)}) = 36 ,
4
P (f = 5) = P ({(1, 4), (2, 3), (3, 2), (4, 1)}) = 36
,
5
P (f = 6) = P ({(1, 5, (5, 1), (2, 4), (4, 2), (3, 3)}) = 36 ,
6
P (f = 7) = P ({(1, 6), (6, 1), (2, 5), (5, 2), (4, 3), (3, 4)}) = 36
,
5
P (f = 8) = P ({(2, 6), (6, 2), (3, 5), (5, 3), (4, 4)}) = 36 ,
4
P (f = 9) = P ({(3, 6), (6, 3), (4, 5), (5, 4)}) = 36 ,
3
P (f = 10) = P ({(4, 5), (5, 4), (5, 5)}) = 36 ,
2
P (f = 11) = P ({(5, 6), (6, 5)}) = 36 ,
1
P (f = 12) = P ({(6, 6)}) = 36 .
Example 32.17
Construct the histogram of the random variable of Example 32.19.
Solution.
In other words, E(f ) is a weighted average of the possible values that f can
take on, each value being weighted by the probability that f assumes that
value.
Example 32.18
Find E(f ) where f is the outcome when we roll a fair die.
Solution.
1
Since P (1) = P (2) = · · · = P (6) = 6
we find
1 1 1 7
E(f ) = 1( ) + 2( ) + · · · + 6( ) =
6 6 6 2
Example 32.20
Calculate V ar(f ) when f represents the outcome when a fair die is rolled.
Solution.
First note that
91
E(f 2 ) = (f (1))2 P (1) + · · · + (f (6))2 P (6) = .
6
By the above theorem we have
91 7 35
V ar(f ) = E(f 2 ) − (E(f ))2 = − ( )2 =
6 2 12
Review Problems
Problem 32.1
What is the probability of drawing a red card from a well-shuffled deck of 52
playing cards?
Problem 32.2
If we roll a fair die, what are the probabilities of getting
a. a 1 or a 6;
b. an even number?
Problem 32.3
A department store’s records show that 782 of 920 women who entered the
store on a Saturday afternoon made at least one purchase. Estimate the
probability that a woman who enters the store on a Saturday afternoon will
make at least one purchase.
Problem 32.4
Which of the following are mutually exclusive? Explain your answers.
a. A driver getting a ticket for speeding and a ticket for going through a red
light.
b. Being foreign-born and being President of the United States.
Problem 32.5
If A and B are the events that a consumer testing service will rate a given
stereo system very good or good, P (A) = 0.22, P (B) = 0.35. Find
a. P (Ac );
b. P (A ∪ B);
c. P (A ∩ B).
Problem 32.6
If the probabilities are 0.20, 0.15, and 0.03 that a student will get a failing
grade in Statistics, in English, or in both, what is the probability that the
student will get a failing grade in at least one of these subjects?
Problem 32.7
If the probability that a research project will be well planned is 0.60 and the
probability that it will be well planned and well executed is 0.54, what is the
probability that a well planned research project will be well executed?
Problem 32.8
Given three events A, and B such that P (A) = 0.50, P (B) = 0.30, and
P (A ∩ B) = 0.15. Show that the events A and B are independent.
Problem 32.9
There are 16 equally likely outcomes by flipping four coins. Let f repre-
sent the number of heads. Find the probability distribution and graph the
corresponding histogram.
p + q = 1.
Also, we assume that the trials are independent, that is what happens in
one trial does not affect the probability of a success in any other trial. The
central question of a binomial experiment is to find the probability of r suc-
cesses out of n trials. Now, anytime we make selections from a population
without replacement, we do not have independent trials. For example, se-
lecting a ball from a box that contains balls of two different colors. If the
selection is without replacement then the trials are dependent.
Example 33.1
The registrar of a college noted that for many years the withdrawal rate from
an introductory chemistry course has been 35% each term. We wish to find
the probability that 55 students out of 80 will complete the course.
Solution.
a. The decision of each student to withdraw or complete the course can be
thought of as a trial. Thus, there are a total of 80 trials.
b. S = completing the course, F = withdrawing from course.
c. n = 80, p = .65, q = .35, r = 55.
Example 33.2
Harper’s Index states that 10% of all adult residents in Washington D.C.,
are lawyers. For a random sample of 15 adult Washington, D.C., residents,
we want to find the probability that 3 are lawyers.
Example 33.4
The probability that an entering college student will graduate is 0.4. Deter-
mine the probability that out of 5 students (a) none, (b) 1, (c) at least 1, (d)
all will graduate.
Solution.
(a) C(5, 0)(.6)5 .
(b) C(5, 1)(.4)(.6)4 .
(c) 1 − C(5, 0)(.6)5 .
(d) C(5, 5)(.4)5 .
Example 33.5
Find the probability of guessing correctly at least 6 of the 10 answers on a
true-false examination.
Solution.
P (6) + P (7) + P (8) + P (9) + P (10).
We next derive formulas for finding the expected value and standard de-
viation for the binomial random variable.
Theorem 33.1
a. The mean of a binomial random variable is given by µ = np.
b. The variance of a binomial random variable is given by σ 2 = npq.
Proof.
a. Using the definition of µ we have
n
X
µ= iP (i)
i=0
Xn
= iC(n, i)pi q n−i
i=1
n
X (n − 1)!
=np pi−1 q n−i
i=1
(i − 1)!(n − i)
n
X (n − 1)! i n−i−1
=np pq
i=1
i!(n − i)
n−1
X
=np C(n − 1, i)pi q n−i−1
i=0
n−1
X
=np
i=0
=np(p + q)n−1 = np.
b. Note first that i2 = i(i − 1) + i. Then
n
X
2
E(X ) = i2 P (i)
i=0
Xn
= i(i − 1)C(n, i)pi q n−i + µ
i=0
n
X n!
= pi q n−i + µ
i=2
(n − i)!(i − 2)!
n
2
X (n − 2)!
=n(n − 1)p pi q n−i + µ
i=2
(n − i)!(i − 2)!
n−2
X
=n(n − 1)p2 C(n − 2, j)pj q n−2−j + µ
j=0
2
=n(n − 1)p (p + q)n−2 + µ
=n(n − 1)p2 + µ
It follows that
σ 2 =E(X 2 ) − µ2
=n(n − 1)p2 + np − n2 p2
=npq
Review Problems
Problem 33.1
At Community Hospital, the nursing staff is large enough so that 80% of the
time a nurse can respond to a room call within 3 minutes. Last night there
were 73 room calls. We wish to find the probability nurses responded to 62
of them within 3 minutes.
Problem 33.2
Find the probability that in a family of 4 children there will be (a) at least 1
boy and (b) at least 1 boy and 1 girl. Assume that the probability of a male
birth is 12 .
Problem 33.3
An insurance salesperson sells policies to 5 men, all of identical age and in
good health. According to the actuarial tables, the probability that a man
of this particular age will be alive 30 years is 32 . Find the probability that in
30 years (a) all 5 men, (b) at least 3 men, (c) only 2 men, (d) none will be
alive.
In this chapter we present the basic concepts related to graphs and trees such
as the degree of a vertex, connectedness, Euler and Hamiltonian circuits,
isomorphisms of graphs, rooted and spanning trees.
Example 34.1
Consider the following graph G
201
a. Find EG and VG .
b. List the isolated vertices.
c. List the loops.
d. List the parallel edges.
e. List the vertices adjacent to v3 ..
f. Find all edges incident on v4 .
Solution.
a. EG = {e1 , e2 , e3 , e4 , e5 , e6 } and VG = {v1 , v2 , v3 , v4 , v5 , v6 , v7 }.
b. There is only one isolated vertex, v5 .
c. There is only one loop, e5 .
d. {e2 , e3 }.
e. {v2 , v4 }.
f. {e1 , e4 , e5 }.
Example 34.2
Which one of the following graphs is simple.
Solution.
a. G is not simple since it has a loop and parallel edges.
b. G is simple.
Solution.
A graph in which the vertices can be partitioned into two disjoint sets V1
and V2 with every edge incident on one vertex in V1 and one vertex of V2 is
called bipartite graph.
Example 34.4
a. Show that the graph G is bipartite.
Solution.
a. Clear from the definition and the graph.
b. Any two sets of vertices of K3 will have one set with at least two vertices.
Thus, according to the definition of bipartite graph, K3 is not bipartite.
A complete bipartite graph Km,n , is the graph that has its vertex set
partitioned into two disjoint subsets of m and n vertices, respectively. More-
over, there is an edge between two vertices if and only if one vertex is in the
first set and the other vertex is in the second set.
Example 34.5
Draw K2,3 , K3,3 .
Solution.
Example 34.6
What are the degrees of the vertices in the following graph
Solution.
deg(v1 ) = 0, deg(v2 ) = 2, deg(v3 ) = 4.
Theorem 34.1
For any graph G = (VG , EG ) we have
X
2|EG | = deg(v).
v∈V (G)
Proof.
Suppose that VG = {v1 , v2 , · · · , vn } and |EG | = m. Let e ∈ EG . If e is a loop
then it contributes 2 to the total degree of G. If e is not a loop then let vi and
vj denote the endpoints of e. Then e contributes 1 to deg(vi ) and contributes
1 to the deg(vj ). Therefore, e contributes 2 to the total degree of G. Since e
was chosen arbitrarily, this shows that each edge of G contributes 2 to the
total degree of G. Thus,
X
2|EG | = deg(v)
v∈V (G)
Theorem 34.2
In any graph there are an even number of vertices of odd degree.
Proof.
Let G = (VG , EG ) be a graph. By the previous theorem, the sum of all the
degrees of the vertices is T = 2|EG |, an even number. Let E be the sum of
the numbers deg(v), each which is even and O the sum of numbers deg(v)
each which is odd. Then T = E + O. That is, O = T − E. Since both T and
E are even, O is also even. This implies that there must be an even number
of the odd degrees. Hence, there must be an even number of vertices with
odd degree.
Example 34.7
Find a formula for the number of edges in Kn .
Solution.
Since G is complete, each vertex is adjacent to the remaining vertices. Thus,
the degree of each of the n vertices is n − 1, and we have the sum of the de-
grees of all of the vertices being n(n−1). By Theorem 34.1, n(n−1) = 2|EG |.
Example 34.8
In the graph below, determine whether the following sequences are paths,
simple paths, circuits, or simple circuits.
a. v0 e1 v1 e10 v5 e9 v2 e2 v1 .
b. v3 e5 v4 e8 v5 e10 v1 e3 v2 .
c. v1 e 2 v2 e 3 v1 .
d. v5 e 9 v2 e 4 v3 e 5 v4 e 6 v4 e 8 v5 .
Solution.
a. a path (no repeated edge), not a simple path (repeated vertex v1 ), not a
circuit
b. a simple path
c. a simple circuit
d. a circuit, not a simple circuit (vertex v4 is repeated)
Example 34.9
Determine which graph is connected and which one is disconnected.
Solution.
a. Connected.
b. Disconnected since there is no path connecting the vertices v1 and v4 .
A simple path that contains all edges of a graph G is called an Euler path.
If this path is also a circuit, it is called an Euler circuit.
Theorem 34.3
If a graph G has an Euler circuit then every vertex of the graph has even
degree.
Proof.
Let G be a graph with an Euler circuit. Start at some vertex on the circuit
and follow the circuit from vertex to vertex, erasing each edge as you go
along it. When you go through a vertex you erase one edge going in and one
edge going out, or else you erase a loop. Either way, the erasure reduces the
degree of the vertex by 2. Eventually every edge gets erased and all the ver-
tices have degree 0. So all vertices must have had even degree to begin with.
It follows from the above theorem that if a graph has a vertex with odd
degree then the graph can not have an Euler circuit.
The following provides a converse to the above theorem.
Example 34.10
Show that the following graph has no Euler circuit.
Solution.
Vertices v1 and v3 both have degree 3, which is odd. Hence, by the remark
following the previous theorem, this graph does not have an Euler circuit.
Example 34.11
Find a Hamiltonian circuit in the graph
Solution.
vwxyzv
Example 34.12
Show that the following graph has a Hamiltonian path but no Hamiltonian
circuit.
Solution.
vwxyz is a Hamiltonian path. There is no Hamiltonian circuit since no cycle
goes through v.
Review Problems
Problem 34.1
The union of two graphs G1 = (V1 , E1 ) and G2 = (V2 , E2 ) is the graph
G1 ∪ G2 = (V1 ∪ V2 , E1 ∪ E2 ). The intersection of two graphs G1 = (V1 , E1 )
and G2 = (V2 , E2 ) is the graph G1 ∩ G2 = (V1 ∩ V2 , E1 ∩ E2 ).
Find the union and the intersection of the graphs
Problem 34.2
Graphs can be represented using matrices. The adjacency matrix of a graph
G with n vertices is an n×n matrix AG such that each entry aij is the number
of edges connecting vi and vj . Thus, aij = 0 if there is no edge from vi to vj .
a. Draw a graph with the adjacency matrix
0 1 1 0
1 0 0 1
1 0 0 1
0 1 1 0
Problem 34.3
A graph H = (VH , EH ) is a subgraph of G = (VG , EG ) if and only if VH ⊆ VG
and EH ⊆ EG .
Find all nonempty subgraphs of the graph
Problem 34.4
Find the in-degree and out-degree of each of the vertices in the graph G with
directed edges.
Problem 34.5
Show that for a digraph G = (VG , EG ) we have
X X
|EG | = deg − (v) = deg + (v).
v∈V (G) v∈V (G)
Problem 34.6
Find the incidence matrix corresponding to the graph
Problem 34.7
If each vertex of an undirected graph has degree k then the graph is called a
regular graph of degree k.
How many edges are there in a graph with 10 vertices each of degree 6?
Problem 34.8
Two simple graphs G1 and G2 are isomorphic, in symbol, G1 ≃ G2 , if there
is one-to-one onto function, f : V (G1 ) → V (G2 ) and (u, v) ∈ EG1 if and only
if (f (u), f (v)) ∈ EG2 . Show that the following graphs are isomorphic.
Warning: The number of vertices, the number of edges, and the degrees of
the vertices are all invariants under isomorphism. If any of these quantities
differ in two graphs, these graphs cannot be isomorphic. However, when these
invariants are the same, it does not necessarily mean that the two graphs are
isomorphic.
The isomorphism between two graphs G1 = (VG1 , EG1 ) and G2 = (VG2 , EG2 )
with parallel edges or loops requires two bijections f : VG1 → VG2 and g :
EG1 → EG2 such that if e ∈ EG1 is an edge with endpoints (u, v) then
g(e) ∈ EG2 is an edge with endpoints (f (u), f (v)).
Problem 34.9
Show that the following graphs are not isomorphic.
Problem 34.10
Show that the following graph has no Hamiltonian path.
35 TREES 215
35 Trees
An undirected graph is called a tree if each pair of distinct vertices has
exactly one path between them. Thus, a tree has no parallel edges and no
loops.
We next show a result that is needed for the proof of our first main theorem
of trees.
Theorem 35.1
Any tree with more than one vertex has one vertex of degree 1.
Proof.
Let T be a tree with a number of vertices ≥ 1. Pick a vertex v at random
and search outward from v on a path along edges from one vertex to another
looking for a vertex of degree one. As each new vertex is reached, check
whether it has degree 1. If so, a vertex of degree 1 has been found. If not, it
is possible to exit from the new vertex along a different edge from that used
to reach the vertex. Because T is a tree, it is circuit-free, and so the path
never returns to a previously used vertex. Since the number of vertices of
T is finite, the process of building a path must eventually terminate. When
that happens, the final vertex of the path must have degree 1
The following is the first of the two main theorems about trees:
Theorem 35.2
A tree with n vertices has exactly n − 1 edges.
Proof.
The proof is by induction on n ≥ 1. Let P (n) be the property: Any tree with
n vertices has n − 1 edges.
Basis of induction: P (1) is valid since a tree with one vertex has zero edges.
Induction hypothesis: Suppose that P (n) holds up to n ≥ 1.
Induction Step: We must show that any tree with n + 1 vertices has n
edges. Indeed, let T be any tree with n + 1 vertices. Since n + 1 ≥ 2, by the
previous theorem, T has a vertex v of degree 1. Let T0 be the graph obtained
by removing v and the edge attached to v. Then T0 is a tree with n vertices.
By the induction hypothesis, T0 has n − 1 edges and so T has n edges
Example 35.1
Which of the following graphs are trees?
Solution.
The first graph satisfies the definition of a tree. The second and third graphs
do not satisfy the conclusion of Theorem 35.2 and therefore they are not
trees.
The second major theorem about trees is the following theorem whose proof
is omitted.
Theorem 35.3
Any connected graph with n vertices and n − 1 edges is a tree.
A rooted tree is a tree in which a particular vertex is designated as the
root. The level of a vertex v is the length of the simple path from the
root to v. The height of a rooted tree is the maximum level number that
occurs.
Example 35.2
Find the level of each vertex and the height of the following rooted tree.
35 TREES 217
Solution.
v1 is the root of the given tree.
vertex level
v2 1
v3 1
v4 2
v5 2
v6 2
v7 2
The height of the tree is 2.
Solution.
a. v2 .
b. v1 , v3 , v7 .
c. v7 , v8 , v9 .
d. None.
e. {v2 , v3 , v4 , v5 }.
f. {v4 , v5 , v6 , v8 , v9 , v10 , v11 , v12 , v13 }.
g.
A binary tree is a rooted tree such that each vertex has at most two chil-
dren. Moreover, each child is designated as either a left child or a right
child.
Example 35.4
a. Show that the following tree is a binary tree.
35 TREES 219
Solution.
a. Follows from the definition of a binary tree.
b. The left child is v6 and the right child is v7 .
c.
Example 35.5
A forest is a simple graph with no circuits. Which of the following graphs
is a forest?
Solution.
The first graph is a forest whereas the second is not.
Example 35.6
a. Let T be a subgraph of a graph G such that T is a tree containing all of
the vertices of G. Such a tree is called a spanning tree. Find a spanning
tree of the following graph.
v1 , v2 , , · · · , vn
35 TREES 221
that (v1 , x) does not produce a circuit. If no edges can be added, stop (T is
a spanning tree)
3. Replace S by the children in T of S ordered consistently with the original
ordering. Go to step 2.
Use the above algorithm to find the spanning tree of part a.
Solution.
a.
Review Problems
Problem 35.1
Find the level of each vertex and the height of the following rooted tree.
Problem 35.2
Consider the rooted tree
35 TREES 223
then the subtrees T1 , T2 , · · · , Tn are listed, from left to right, in order of their
roots. The preorder traversal begins by visiting r. It continues by travers-
ing T1 in preorder, thenT2 in preorder, and so on, until Tn is traversed in
preorder. In which order does a preorder traversal visit the vertices in the
following rooted tree?