Discrete Mathematics Exercises

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

Name:...........................................

Class:...........................................

Discrete Mathematics
and Its Applications
Exercise Book

1
Chapter 1: The Foundations: Logic and Proofs
1.1 Propositional Logic
1. Which of these sentences are propositions? What are the truth values of those that are
propositions?
a) Boston is the capital of Massachusetts. b) Miami is the capital of Florida.
c) 2 + 3 = 5. d) 5 + 7 = 10.
e) x + 2 = 11. f ) Answer this question.
2. What is the negation of each of these propositions?
a) Mei has an MP3 player. b) There is no pollution in New Jersey.
c) 2 + 1 = 3. d) The summer in Maine is hot and sunny.

3. Let p and q be the propositions

p : I bought a lottery ticket this week.

q : I won the million dollar jackpot.

Express each of these propositions as an English sentence.

a) ¬p b) p ∨ q c) p → q

d) p ∧ q e) p ↔ q f ) ¬p → ¬q

g) ¬p ∧ ¬q h) ¬p ∨ (p ∧ q)

4. Let p and q be the propositions

p : It is below freezing.

q : It is snowing.

Write these propositions using p and q and logical connectives (including negations).

a) It is below freezing and snowing.

b) It is below freezing but not snowing.

c) It is not below freezing and it is not snowing.

d) It is either snowing or below freezing (or both).


2
5. Let p and q be the propositions

p : You drive over 65 miles per hour.

q : You get a speeding ticket.

Write these propositions using p and q and logical connectives (including negations).

a) You do not drive over 65 miles per hour.

b) You drive over 65 miles per hour, but you do not get a speeding ticket.

c) You will get a speeding ticket if you drive over 65 miles per hour.

d) If you do not drive over 65 miles per hour, then you will not get a speeding ticket.

e) Driving over 65 miles per hour is sufficient for getting a speeding ticket.

f ) You get a speeding ticket, but you do not drive over 65 miles per hour.

g) Whenever you get a speeding ticket, you are driving over 65 miles per hour.

6. Determine whether these biconditionals are true or false.

a) 2 + 2 = 4 if and only if 1 + 1 = 2.

b) 1 + 1 = 2 if and only if 2 + 3 = 4.

c) 1 + 1 = 3 if and only if monkeys can fly.

d) 0 > 1 if and only if 2 > 1.

7. Determine whether each of these conditional statements is true or false.

a) If 1 + 1 = 2, then 2 + 2 = 5.

b) If 1 + 1 = 3, then 2 + 2 = 4.

c) If 1 + 1 = 3, then 2 + 2 = 5.

d) If monkeys can fly, then 1 + 1 = 3.

8. Determine whether each of these conditional statements is true or false.

a) If 1 + 1 = 3, then unicorns exist. b) If 1 + 1 = 3, then dogs can fly.

c) If 1 + 1 = 2, then dogs can fly. d) If 2 + 2 = 4, then 1 + 2 = 3.

3
9. Write each of these statements in the form “if p, then q”

a) It is necessary to wash the boss’s car to get promoted.

b) Winds from the south imply a spring thaw.

c) A sufficient condition for the warranty to be good is that you bought the computer less than
a year ago.

d) Willy gets caught whenever he cheats.

e) You can access the website only if you pay a subscription fee.

f ) Getting elected follows from knowing the right people.

g) Carol gets seasick whenever she is on a boat.

10. How many rows appear in a truth table for each of these compound propositions?

a) p → ¬p b) (p ∨ ¬r) ∧ (q ∨ ¬s) c) q ∨ p ∨ ¬s ∨ ¬r ∨ ¬t ∨ u

d) (p ∧ r ∧ t) ↔ (q ∧ t) e) (q → ¬p) ∨ (¬p → ¬q) f) (p ∨ ¬t) ∧ (p ∨ ¬s)

g) (p → r) ∨ (¬s → ¬t) ∨ (¬u → v) h) (p ∧ r ∧ s) ∨ (q ∧ t) ∨ (r ∧ ¬t)

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

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

e) (p → q) ↔ (¬q → ¬p) f ) (p → q) → (q → p)

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

a) p → ¬p b) p ↔ ¬p c) p ⊕ (p ∨ q) d) (p ∧ q) → (p ∨ q)

e) (q → ¬p) ↔ (p ↔ q) f ) (p ↔ q) ⊕ (p ↔ ¬q)

13. What is the value of x after each of these statements is encountered in a computer program,
if x = 1 before the statement is reached?

a) if x + 2 = 3 then x := x + 1

b) if (x + 1 = 3) OR (2x + 2 = 3) then x := x + 1

c) if (2x + 3 = 5) AND (3x + 4 = 7) then x := x + 1

d) if (x + 1 = 2) XOR (x + 2 = 3) then x := x + 1

4
14. Find the bitwise OR, bitwise AND, and bitwise XOR of each of these pairs of bit strings.

a) 101 1110, 010 0001 b) 1111 0000, 1010 1010

c) 00 0111 0001, 10 0100 1000 d) 11 1111 1111, 00 0000 0000

15. Evaluate each of these expressions.

a) 1 1000 ∧ (0 1011 ∨ 1 1011) b) (0 1111 ∧ 1 0101) ∨ 0 1000

c) (0 1010 ⊕ 1 1011) ⊕ 0 1000 d) (1 1011 ∨ 0 1010) ∧ (1 0001 ∨ 1 1011)

5
1.2-Propositional Equivalences
1. Show that each of these conditional statements is a tautology by using truth tables.

a) (p ∧ q) → p b) p → (p ∨ q) c) ¬p → (p → q)

d) (p ∧ q) → (p → q) e) ¬(p → q) → p f ) ¬(p → q) → ¬q

2. Show that each of these conditional statements is a tautology by using truth tables.

a) [¬p ∧ (p ∨ q)] → q b) [(p → q) ∧ (q → r)] → (p → r)

c) [p ∧ (p → q)] → q d) [(p ∨ q) ∧ (p → r) ∧ (q → r)] → r

3. Determine whether (¬p ∧ (p → q)) → ¬q is a tautology.

4. Determine whether (¬q ∧ (p → q)) → ¬p is a tautology.

5. Show that (p ∨ q) ∧ (¬p ∨ r) → (q ∨ r) is a tautology.

6. Show that (p → q) → r and p → (q → r) are not logically equivalent.

7. Show that (p ∧ q) → r and (p → r) ∧ (q → r) are not logically equivalent.

8. Show that (p → q) → (r → s) and (p → r) → (q → s) are not logically equivalent.

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

a) p ∨ ¬q b) p ∧ (q ∨ (r ∧ T)) c) (p ∧ ¬q) ∨ (q ∧ F)

6
1.4 Predicates and Quantifiers
1. Let P(x) denote the statement “x ≤ 4”. What are these truth values?

a) P(0) b) P(4) c) P(6)

2. Let P(x) be the statement “the word x contains the letter a.” What are these truth values?

a) P (orange) b) P (lemon) c) P (true) d) P (false)

3. Let Q(x, y) denote the statement “x is the capital of y”. What are these truth values?

a) Q(Denver, Colorado) b) Q(Detroit, Michigan)

c) Q(Massachusetts, Boston) d) Q(New York, New York)

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

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

5. Let P(x) be the statement “x spends more than five hours every weekday in class,” where
the domain for x consists of all students. Express each of these

a) ∃xP(x) b) ∀xP(x) c) ∃x ¬P(x) d) ∀x ¬P(x)

6. Translate these statements into English, where C(x) is “x is a comedian” and F(x) is “x is
funny” and the domain consists of all people.

a) ∀x(C(x) → F(x)) b) ∀x(C(x) ∧ F(x))

c) ∃x(C(x) → F(x)) d) ∃x(C(x) ∧ F(x))

7. Let P(x) be the statement “x = x2”. If the domain consists of the integers, what are these
truth values?

a) P(0) b) P(1) c) P(2)

d) P(−1) e) ∃xP(x) f ) ∀xP(x)

8. Let Q(x) be the statement “x + 1 > 2x.” If the domain consists of all integers, what are these
truth values?

a) Q(0) b) Q(−1) c) Q(1)

d) ∃xQ(x) e) ∀xQ(x) f ) ∃x¬Q(x)

7
9. Determine the truth value of each of these statements if the domain consists of all integers.

a) ∀n(n + 1 > n) b) ∃n(2n = 3n) c) ∃n(n = −n) d) ∀n(3n ≤ 4n)

10. Determine the truth value of each of these statements if the domain consists of all real
numbers.

a) ∃x(x3 = −1) b) ∃x(x4 < x2)

c) ∀x((−x)2 = x2) d) ∀x(2x > x)

11. Determine the truth value of each of these statements if the domain for all variables consists
of all integers.

a) ∀n(n2 ≥ 0) b) ∃n(n2 = 2) c) ∀n(n2 ≥ n) d) ∃n(n2 < 0)

12. Suppose that the domain of the propositional function P(x) consists of the integers 0, 1, 2,
3, and 4. Write out each of these propositions using disjunctions, conjunctions, and negations.

a) ∃xP(x) b) ∀xP(x) c) ∃x¬P(x)

d) ∀x¬P(x) e) ¬∃xP(x) f ) ¬∀xP(x)

13. Suppose that the domain of the propositional function P(x) consists of the integers 1, 2, 3,
4, and 5. Express these statements without using quantifiers, instead using only negations,
disjunctions, and conjunctions.

a) ∃xP(x) b) ∀xP(x) c) ¬∃xP(x) d) ¬∀xP(x)

8
1.5 Rules of Inference
1. Find the argument form for the following argument and determine whether it is valid. Can
we conclude that the conclusion is true if the premises are true?

If Socrates is human, then Socrates is mortal.

Socrates is human.

∴ Socrates is mortal.
2. Use rules of inference to show that the hypotheses “Randy works hard”, “If Randy works
hard, then he is a dull boy”, and “If Randy is a dull boy, then he will not get the job” imply the
conclusion “Randy will not get the job”.

3. For each of these collections of premises, what relevant conclusion or conclusions can be
drawn? Explain the rules of inference used to obtain each conclusion from the premises.

a) “If I take the day off, it either rains or snows”. “I took Tuesday off or I took Thursday off”.
“It was sunny on Tuesday”. “It did not snow on Thursday”.

b) “If I eat spicy foods, then I have strange dreams”. “I have strange dreams if there is thunder
while I sleep”. “I did not have strange dreams”.

c) “I am either clever or lucky”. “I am not lucky”. “If I am lucky, then I will win the lottery”

d) “Every computer science major has a personal computer”. “Ralph does not have a personal
computer”. “Ann has a personal computer”.

e) “What is good for corporations is good for the United States”. “What is good for the United
States is good for you”. “What is good for corporations is for you to buy lots of stuff”.

f ) “All rodents gnaw their food”. “Mice are rodents”. “Rabbits do not gnaw their food”. “Bats
are not rodents.

4. Determine whether each of the following arguments is valid or not valid.

a) All parrots like fruit. My pet bird is not a parrot. Therefore, my pet bird does not like fruit.

b) Everyone who eats granola every day is healthy. Linda is not healthy. Therefore, Linda does
not eat granola every day.

c) No man is an island. Manhattan is an island. Therefore, Manhattan is not a man.

9
d) A convertible car is fun to drive. Isaac's car is not a convertible. Therefore, Isaac's car is not
fun to drive.

e) If Mai knows French, Mai is smart. But Mai doesn't know French. So, she is not smart.

f) Lin can't go fishing if she doesn't have a bike. Last week, Lin went fishing with her friends.
Therefore, she has got a bike.

10
Chapter 2: Basic Structures: Sets, Functions, Sequences,
and Sums
2.1 Sets
1. List the members of these sets.
a) {x | x is a real number such that x2 = 1}
b) {x | x is a positive integer less than 12}
c) {x | x is the square of an integer and x < 100}
d) {x | x is an integer such that x2 = 2}
2. For each of the following sets, determine whether 2 is an element of that set.
a) {x ∈ R | x is an integer greater than 1} b) {x ∈ R | x is the square of an integer}
c) {2,{2}} d) {{2},{{2}}} e) {{2},{2,{2}}} f ) {{{2}}}
3. Determine whether each of these statements is true or false.
a) 0 ∈ ∅ b) ∅ ∈ {0} c) {0} ⊂ ∅ d) ∅ ⊂ {0}
e) {0} ∈ {0} f ) {0} ⊂ {0} g) {∅} ⊆ {∅}
4. Determine whether each of these statements is true or false.
a) x ∈ {x} b) {x} ⊆ {x} c) {x} ∈ {x}
d) {x} ∈ {{x}} e) ∅ ⊆ {x} f ) ∅ ∈ {x}
5. What is the cardinality of each of these sets?
a) {a} b) {{a}} c) {a, {a}} d) {a, {a}, {a, {a}}}
6. What is the cardinality of each of these sets?
a) ∅ b) {∅} c) {∅, {∅}} d) {∅, {∅}, {∅, {∅}}}
7. Find the power set of each of these sets, where a and b are distinct elements.
a) {a} b) {a, b} c) {∅, {∅}}
8. How many elements does each of these sets have where a and b are distinct elements?
a) P({a, b, {a, b}}) b) P({∅, a, {a}, {{a}}}) c) P(P(∅))

11
9. Find A2 and A3 if
a) A = {1, 3} b) A = {1, a }

10. Let A  1,2,3 and B  1, a . What is the cardinality of each of these sets?

a) A  B b) A2 c) P  B  d) P  B  A e) A  B

11. Find the truth set of each of these predicates where the domain is the set of integers.
a) P (x): x2 < 3 b) Q(x): x2 > x c) R(x): 2x + 1 = 0

12
2.2 Set operations
1. Let A = {1, 2, 3, 4, 5} and B = {0, 3, 6}. Find
a) A ∪ B b) A ∩ B c) A − B d) B − A.
2. Let A = {a, b, c, d, e} and B = {a, b, c, d, e, f, g, h}. Find
a) A ∪ B b) A ∩ B c) A − B d) B − A.
3. Find the sets A and B if A − B = {1, 5, 7, 8}, B − A = {2, 10}, and A ∩ B = {3, 6, 9}.
4. Let A and B be sets. Show that
a) (A ∩ B) ⊆ A b) A ⊆ (A ∪ B) c) A − B ⊆ A
d) A ∩ (B − A) = ∅ e) A ∪ (B − A) = A ∪ B f) A ⊕ B = (A ∪ B) − (A ∩ B).
5. Suppose that the universal set is U = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}. Express each of these
sets with bit strings where the ith bit in the string is 1 if i is in the set and 0 otherwise.
a) {3, 4, 5} b) {1, 3, 6, 10} c) {2, 3, 4, 7, 8, 9}

13
2.3 Functions
1. Why is f not a function from R to R if

a) f (x) = 1/x? b) f (x) = x ? c) f (x) =  x 2  1 ?

2. Determine whether f is a function from Z to R if

1
a) f (n) = ±n b) f  n   n 2  1 c) f  n  
n 4
2

3. Find these values

a) 1.1 b)  0.1 c)  4 d) 3.2

1  2 
e)  5.2  e)  2 e)     
 2  3 
4. Determine whether each of these functions from {a, b, c, d} to itself is one-to-one (onto)
a) f (a) = b, f (b) = a, f (c) = c, f (d) = d
b) f (a) = b, f (b) = b, f (c) = d, f (d) = c
c) f (a) = d, f (b) = b, f (c) = c, f (d) = d
5. Determine whether each of these functions from Z to Z is one-to-one (onto)

n
a) f (n) = n − 1 b) f (n) = n2 + 1 c) f (n) = n3 d) f  n    
2 
6. Determine whether f : Z × Z → Z is onto if
a) f (m, n) = 2m − n b) f (m, n) = m2 − n2 c) f (m, n) = m + n + 1
d) f (m, n) = |m| − |n| e) f (m, n) = m2 − 4 f) f (m, n) = m + n
7. Determine whether each of these functions is a bijection from R to R.
a) f (x) = −3x + 4 b) f (x) = −3x2 + 7 c) f (x) = (x + 1)/(x + 2) d) f (x) = x5 + 1
8. Let S = {−1, 0, 2, 4, 7}. Find f (S) if

x
a) f (x) = 1 b) f (x) = 2x + 1 c) f  x    
 
5

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

15
2.4 Sequences and Summations
1. 1. Find these terms of the sequence {a n}, where an = 2 (−3)n + 5n.

a) a0 b) a1 c) a4 d) a5

2. What is the term a8 of the sequence {an} if an equals

a) 2n−1? b) 7? c) 1 + (−1)n? d) −(−2)n?

3. Find the first five terms of the sequence defined by each of these recurrence relations and
initial conditions.

a) an = 6an−1, a0 = 2 b) an  an21 , a1  2 c) an = an−1 + 3an−2, a0 = 1, a1 = 2

4. Find the solution to each of these recurrence relations and initial conditions.

a) an = −an−1, a0 = 5 b) an = an−1 + 3, a0 = 1 c) an = an−1 − n, a0 = 4

d ) an = 2nan−1, a0 = 3 e) an = 5an−1 − 6an−2, a0 = 2, a1 = −1

5. What are the values of these sums?


5 4 2 3 3 4

  k  1   j  2   2i  3 j   ij
2
a) b) c) d)
k 1 j i 0 j 1 i 1 j  2

6. What are the values of these sums, where S = {1, 3, 5, 7}?

 1
a)  j  j 
b) j 2
c) 2
jS  jS jS

7. What are the values of the following products?


10 100 4
a)  i   1  i!
i
b) c)
i 0 i1 i 0

16
Chapter 3: The Fundamentals: Algorithms, the Integers,
and Matrices
3.1 Algorithms
1. List all the steps used by Algorithm "max" to find the maximum of the list 1, 8, 12, 9, 11,
2, 14, 5, 10, 4.
2. Devise an algorithm that finds the sum of all the integers in a list.
3. List all the steps used to search for 9 in the sequence 1, 3, 4, 5, 6, 8, 9, 11 using
a) a linear search b) a binary search.
4. Describe an algorithm that inserts an integer x in the appropriate position into the list a 1,
a2, . . . , an of integers that are in increasing order.
5. Use the bubble sort to sort 3, 1, 5, 7, 4, showing the lists obtained at each step.
6. Consider the Linear search algorithm:
procedure linear search(x: integer, a1,a2,...,an: distinct integers)
i := 1
while (i ≤ n and x  ai )
i := i + 1
if i ≤ n then location := i
else location := 0
return location
Given the sequence a n: 3, 1, 5, 7, 4, 6. How many comparisons required for searching x = 7?

17
3.2 The Growth of Functions
1. Determine whether each of these functions is O(x).
a) f (x) = 10 b) f (x) = 3x + 7 c) f (x) = x2 + x + 1 d) f (x) = 5 log x
2. Determine whether each of these functions is O(x2).
a) f (x) = 17x + 11 b) f (x) = x2 + 1000 c) f (x) = x log x

x4
d) f  x   e) f  x   2 x f) ) f (x) = (x3 + 2x)/(2x + 1)
2
3. Find the least integer n such that f (x) is O(x n) for each of these functions.
a) f (x) = 2x3 + x2 log x b) f (x) = 3x3 + (log x)4
c) f (x) = (x4 + x2 + 1)/(x3 + 1) d) f (x) = (x4 + 5 log x)/(x4 + 1)
4. Determine whether x3 is O(g(x)) for each of these functions g(x).
a) g(x) = x2 b) g(x) = x3 c) g(x) = x2 + x3
d) g(x) = x2 + x4 e) g(x) = 3x f ) g(x) = x3/2

5. Arrange the functions n , 1000 log n, n log n, 2n!, 2n, 3n, and n2/1,000,000 in a list so
that each function is big-O of the next function.
6. Give as good a big-O estimate as possible for each of these functions.
a) (n2 + 8)(n + 1) b) (n log n + n2)(n3 + 2) c) (n! + 2n)(n3 + log(n2 + 1))

18
3.3 Complexity of Algorithms
1. Consider the algorithm:
procedure giaithuat(a1, a2, …, an : integers)
count:= 0
for i:= i to n do
if ai > 0 then count: = count + 1
print(count)
Give the best big-O complexity for the algorithm above.
2. Consider the algorithm:
procedure GT(n : positive integer)
F:=1
for i:= 1 to n do
F: = F * i
Print(F)
Give the best big-O complexity for the algorithm above.
3. Consider the algorithm:
procedure max(a ,a ,...,a : reals )
max:=a
for i:=2 to n
if max<a then max:=a
Give the best big-O complexity for the algorithm above.

19
3.4 The Integers and Division
1. Does 17 divide each of these numbers?
a) 68 b) 84 c) 357 d) 1001
2. What are the quotient and remainder when
a) 19 is divided by 7? b) −111 is divided by 11? c) 789 is divided by 23?
d) 1001 is divided by 13? e) 0 is divided by 19? f ) 3 is divided by 5?
3. Suppose that a and b are integers, a ≡ 4 (mod 13), and b ≡ 9 (mod 13). Find the integer c
with 0 ≤ c ≤ 12 such that
a) c ≡ 9a (mod 13). b) c ≡ 11b (mod 13). c) c ≡ a + b (mod 13).
d) c ≡ 2a + 3b (mod 13). e) c ≡ a2 + b2 (mod 13). f ) c ≡ a3 − b3 (mod 13).
4. Evaluate these quantities.
a) 13 mod 3 b) −97 mod 11 c) 155 mod 19 d) −221 mod 23
5. Find a div m and a mod m when
a) a = −111, m = 99. b) a = −9999, m = 101.
c) a = 10299, m = 999. d) a = 123456, m = 1001.
6. Decide whether each of these integers is congruent to 5 modulo 17.
a) 80 b) 103 c) −29 d) −122
7. Find each of these values.
a) (992 mod 32)3 mod 15 b) (34 mod 17)2 mod 11
c) (193 mod 23)2 mod 31 d) (893 mod 79)4 mod 26
8. Convert the decimal expansion of each of these integers to a binary expansion.
a) 23 b) 45 c) 241 d) 1025
9. Convert the binary expansion of each of these integers to a decimal expansion.
a) (1 1011)2 b) (10 1011 0101)2
c) (11 1011 1110)2 d) (111 1100 0001 1111)2

20
10. Convert the octal expansion of each of these integers to a binary expansion.
a) (572)8 b) (1604)8 c) (423)8 d) (2417)8
11. Convert each of the following expansions to decimal expansion.

a) (1021)3 b) (325)7 c) (A3)12 d) (401)5 e) (12B7)13

12. Convert 69 to

a) a binary expansion b) a base 6 expansion c) a base 9 expansion

11. Suppose a mod 3 = 2 and b mod 6 = 4, find ab mod 3.

21
3.5 Primes and Greatest Common Divisors
1. Determine whether each of these integers is prime.
a) 21 b) 29 c) 71 d) 97
e) 111 f ) 143 g) 93 h) 101
2. Find the prime factorization of each of these integers.
a) 39 b) 81 c) 101
d) 143 e) 289 f ) 899
3. Find the prime factorization of 10!
4. Which positive integers less than 12 are relatively prime to 12?
5. Which positive integers less than 30 are relatively prime to 30?
6. Find these values of the Euler φ-function.
a) φ(4) b) φ(10) c) φ(13)
7. What are the greatest common divisors of these pairs of integers?
a) 37 · 53 · 73, 211 · 35 · 59 b) 11 · 13 · 17, 29 · 37 · 55 · 73 c) 2331, 2317
d) 41 · 43 · 53, 41 · 43 · 53 e) 313 · 517, 212 · 721

22
3.6 Integers and Algorithms
1. Suppose pseudo-random numbers are produced by using: x n+1 = (3xn + 11) mod 13. If x3=
5, find x2 and x4.

2. Suppose pseudo-random numbers are produced by using: xn+1 = (2xn + 7) mod 9.

a) If x0 = 1, find x2 and x3 b) If x3 = 3, find x2 and x4.

3. Using the function f(x) = (x + 10) mod 26 to encrypt messages. Answer each of these
questions.

a) Encrypt the message STOP b) Decrypt the message LEI

4. Which memory locations are assigned by the hashing function h(k) = k mod 101 to the
records of insurance company customers with these Social Security Numbers?

a) 104578690 b) 432222187

5. Use the Euclidean algorithm to find

a) gcd(14, 28) b) gcd(8, 28) c) gcd(100, 101) d) gcd(28,35)

e) lcm(7, 28) f) lcm(12, 28) g) lcm(100, 101) h) lcm(28,35)

23
Chapter 4: Induction and Recursion
4.1 Mathematical Induction
n  n  1 2n  1
1. Let P (n) be the statement that 12  22  32  ...  n 2  for the positive
6
integer n.
a) What is the statement P (1)?
b) Show that P (1) is true, completing the basis step of the proof.
c) What is the inductive hypothesis?
d) What do you need to prove in the inductive step?
e) Complete the inductive step, identifying where you use the inductive hypothesis.

1 1 1 1
2. Let P (n) be the statement that 1    ...  2  2  , where n is an integer greater
4 9 n n
than 1.
a) What is the statement P (2)?
b) Show that P (2) is true, completing the basis step of the proof.
c) What is the inductive hypothesis?
d) What do you need to prove in the inductive step?
e) Complete the inductive step.
3. Prove the statement "6 divides n3 - n for all integers n ≥ 0".
4. Prove that 3n< n! if n is an integer greater than 6.
5. Prove that 2n > n2 if n is an integer greater than 4.
1 1 1
6. Prove that for every positive integer n, 1    ...   2 n 1  2 .
2 3 n
n
1
7. Prove that ln n   whenever n is a positive integer.
i 1 i

24
4.2 Strong Induction
1. Let P (n) be the statement that a postage of n cents can be formed using just 3-cent stamps
and 5-cent stamps. The parts of this exercise outline a strong induction proof that P(n) is true
for n ≥ 8.
a) Show that the statements P (8), P (9), and P (10) are true, completing the basis step of the
proof.
b) What is the inductive hypothesis of the proof?
c) What do you need to prove in the inductive step?
d) Complete the inductive step for k ≥ 10.
2. Let P (n) be the statement that a postage of n cents can be formed using just 4-cent stamps
and 7-cent stamps. The parts of this exercise outline a strong induction proof that P(n) is true
for n ≥ 18.
a) Show statements P(18), P(19), P(20), and P(21) are true, completing the basis step of the
proof.
b) What is the inductive hypothesis of the proof?
c) What do you need to prove in the inductive step?
d) Complete the inductive step for k ≥ 21.

25
4.3 Recursive Definitions and Structural Induction
1. Find f(1), f(2), f(3), and f(4) if f(n) is defined recursively by f(0) = 1 and for n = 0, 1, . . .
a) f (n + 1) = f (n) + 2 b) f (n + 1) = 3f (n)
c) f (n + 1) = 2f (n) d) f (n + 1) = f (n) 2 + f (n) + 1
2. Find f (2), f (3), f (4), and f (5) if f is defined recursively by f (0) = −1, f (1) = 2, and for
n= 1, 2, . . .
a) f (n + 1) = f (n) + 3f (n − 1) b) f (n + 1) = f (n) 2f (n − 1)
c) f (n + 1) = 3f (n)2 − 4f (n − 1)2 d) f (n + 1) = f (n − 1)/f (n)
3. Find f (2), f (3), f (4), and f (5) if f is defined recursively by f (0) = f (1) = 1 and for n = 1,
2, . . .
a) f (n + 1) = f (n) − f (n − 1) b) f (n + 1) = f (n)f (n − 1)
c) f (n + 1) = f (n)2 + f (n − 1)3 d) f (n + 1) = f (n)/f (n − 1)
4. Determine whether each of these proposed definitions is a valid recursive definition of a
function f from the set of nonnegative integers to the set of integers. If f is well defined, find
a formula for f(n) when n is a nonnegative integer and prove that your formula is valid.
a) f (0) = 0, f (n) = 2f (n − 2) for n ≥ 1
b) f (0) = 1, f (n) = f (n − 1) − 1 for n ≥ 1
c) f (0) = 2, f (1) = 3, f (n) = f (n − 1) − 1 for n ≥ 2
d) f (0) = 1, f (1) = 2, f (n) = 2f (n − 2) for n ≥ 2
e) f (0) = 1, f (n) = 3f (n − 1) if n is odd and n ≥ 1 and f (n) = 9f (n − 2) if n is even and n ≥ 2
5. Give a recursive definition of the sequence {an}, n = 1, 2, 3, . . . if
a) an = 6n b) an = 2n + 1 c) an = 10n d) an = 5
e) an = 4n − 2 f) an = 1 + (−1)n g) an = n(n + 1) h) an = n2
6. Let F be the function such that F(n) is the sum of the first n positive integers. Give a
recursive definition of F(n).
7. Give a recursive definition of each of these sets.

a) A = {2, 5, 8, 11, 14, …} b) B = {…, -5, -1, 3, 7, 10, …}

c) C = {3, 12, 48, 192, 768, …} d) D = {1, 2, 4, 7, 11, 16, …}


26
8. The reversal of a string is the string consisting of the symbols of the string in reverse
order. The reversal of the string w is denoted by wR. Find the reversal of the following bit
strings.

a) 0101 b) 1 1011 c) 1000 1001 0111

9. When does a string belong to the set A of bit strings defined recursively by

λ ∈ A, 0x1 ∈ A if x ∈ A, where λ is the empty string?

27
4.4 Recursive Algorithms
1. Give a recursive algorithm for computing nx whenever n is a positive integer and x is an
integer, using just addition.
2. Consider an recursive algorithm to compute the nth Fibonacci number:

procedure Fibo(n : positive integer)

if n = 1 return 1

else if n = 2 return 1

else return Fibo(n – 1) + Fibo(n – 2)

How many additions (+) are used to find Fibo(6) by the algorithm above?

3. Give a recursive algorithm for finding the sum of the first n odd positive integers.

4. Consider the following algorithm:

procedure tinh(a: real number; n: positive integer)

if n = 1 return a

else return atinh(a, n-1).

a) What is the output if inputs are: n = 4, a = 2.5? Explain your answer.

b) Show that the algorithm computes na using Mathematical Induction.

5. Consider the following algorithm:

procedure F(a1, a2, a3, ...,an: integers)

if n = 0 return 0

else return an + F(a1, a2, a3, ...,an-1)

Find

a) F(1,3,5) b) F(1,3,5) c) F(1,2,3,5,9)

28
Chapter 5-7: Counting
5.1 The Basics of Counting
1. How many different bit strings of length seven are there?
2. How many different license plates can be made if each plate contains a sequence of three
uppercase English letters followed by three digits (and no sequences of letters are prohibited,
even if they are obscene)?
3. Counting Functions: How many functions are there from a set with m elements to a set
with n elements?
4. Counting One-to-One Functions: How many one-to-one functions are there from a set
with m elements to one with n elements?
5. Counting bijection Functions: How many one-to-one functions are there from a set with
m elements to one with n elements?
6. Each user on a computer system has a password, which is six to eight characters long,
where each character is an uppercase letter or a digit. Each password must contain at least
one digit. How many possible passwords are there?
7. How many bit strings of length eight either start with a 1 bit or end with the two bits 00?
8. How many bit strings of length four do not have two consecutive 1s?
9. How many bit strings of length ten both begin and end with a 1?
10. How many positive integers between 5 and 31
a) are divisible by 3? b) are divisible by 4? c) are divisible by 3 and by 4?
11. How many positive integers between 50 and 100
a) are divisible by 7? b) are divisible by 11? c) are divisible by both 7 and 11?
12. How many positive integers less than 1000
a) are divisible by 7? b) are divisible by 7 but not by 11?
c) are divisible by both 7 and 11? d) are divisible by either 7 or 11?
e) are divisible by exactly one of 7 and 11? f ) are divisible by neither 7 nor 11?
g) have distinct digits? h) have distinct digits and are even?
13. How many positive integers between 100 and 999 inclusive
a) are divisible by 7? b) are odd?
29
c) have the same three decimal digits? d) are not divisible by 4?
e) are divisible by 3 or 4? f ) are not divisible by either 3 or 4?
g) are divisible by 3 but not by 4? h) are divisible by 3 and 4?
14. How many one-to-one functions are there from a set with five elements to sets with the
following number of elements?
a) 4 b) 5 c) 6 d) 7
15. How many bit strings of length seven either begin with two 0s or end with three 1s?
16. How many bit strings of length 10 either begin with three 0s or end with two 0s?
17. How many bit strings of length 8 begin with 11 or end with 00?
18. Let B be the set {a, b, c}. How many functions are there from B2 to B?
19. How may bit strings with length 10 that has exactly three 1s and end with 0?
20. A game consisting of flipping a coin ends when the player gets two heads in a row, two
tails in a row or flips the coin four times. In how many ways can the game end?

30
7.1 Recurrence Relations
1. a) Find a recurrence relation for the number of permutations of a set with n elements.
b) Use this recurrence relation to find the number of permutations of a set with n elements
using iteration.
2. a) Find a recurrence relation for the number of bit strings of length n that do not contain
three consecutive 0s.
b) What are the initial conditions?
c) How many bit strings of length seven do not contain
three consecutive 0s?
3. What is the solution of the recurrence relation an = an−1 + 2an−2 with a0 = 2 and a1 = 7?

31
7.3 Divide-and-Conquer Algorithms and recurrence
Relations
1. How many comparisons are needed for a binary search in a set of 64 elements?
2. Suppose that f(n) = f(n/3) + 1 when n is a positive integer divisible by 3, and f(1) = 1. Find
a) f(3) b) f(27) c) f(729)
3. Suppose that f(n) = 2f(n/2) + 3 when n is an even positive integer, and f(1) = 5. Find
a) f(2) b) f(8) c) f(64) d) f(1024).
4. Suppose that f(n) = f(n/5) + 3n when n is a positive integer divisible by 5, and f(1) = 4.
Find
a) f(5) b) f(125) c) f(3125)

32
Chapter 8: Relations
8.1 Relations and Their Properties
1. How many binary relations from A to B can be constructed?
2. How many relations are there on the set A?
3. How many relations are there on the set {1,2,3,4} that contain the pair (1,2) and (1,3)?
4. List the ordered pairs in the relation R from A = {0, 1, 2, 3, 4} to B = {0, 1, 2, 3}, where
(a, b) ∈ R if and only if
a) a = b b) a + b = 4 c) a > b d) a | b
e) gcd(a, b) = 1 f ) lcm(a, b) = 2
5. Let A = {1, 2, 3, 4, 5, 6}
a) List all the ordered pairs in the relation R = {(a, b) | a divides b} on A.
b) Display this relation graphically .
c) Display this relation in tabular form.
6. For each of these relations on the set {1, 2, 3, 4}, decide whether it is reflexive, whether it
is symmetric, whether it is antisymmetric, and whether it is transitive.
a) {(2, 2), (2, 3), (2, 4), (3, 2), (3, 3), (3, 4)}
b) {(1, 1), (1, 2), (2, 1), (2, 2), (3, 3), (4, 4)}
c) {(2, 4), (4, 2)}
d) {(1, 2), (2, 3), (3, 4)}
e) {(1, 1), (2, 2), (3, 3), (4, 4)}
f ) {(1, 3), (1, 4), (2, 3), (2, 4), (3, 1), (3, 4)}
7. Determine whether the relation R on the set of all people is reflexive, symmetric,
antisymmetric, and/or transitive, where (a, b) ∈ R if and only if
a) a is taller than b. b) a and b were born on the same day.
c) a has the same first name as b. d) a and b have a common grandparent

33
8. Determine whether the relation R on the set of all real numbers is reflexive, symmetric,
antisymmetric, and/or transitive, where (x, y) ∈ R if and only if
a) x + y = 0 b) x = ±y c) x − y is a rational number
d) xy ≥ 0 e ) xy = 0 g) xy > 1.
9. Determine whether the relation R on the set of all integers is reflexive, symmetric,
antisymmetric, and/or transitive, where (x, y) ∈ R if and only if
a) x ≠ y b) xy ≥ 1 c) x = y + 1 or x = y − 1
d) x ≡ y (mod 7) e) x is a multiple of y
Let R be a relation from a set A to a set B. The inverse relation from B to A, denoted by
R−1, is the set of ordered pairs {(b, a) | (a, b) ∈ R}. The complementary relation R is the
set of ordered pairs {(a, b) | (a, b) / ∈ R}.
10. Let R1 = {(1, 2), (2, 3), (3, 4)} and R2 = {(1, 1), (1, 2), (2, 1), (2, 2), (2, 3), (3, 1), (3, 2),
(3, 3), (3, 4)} be relations from {1, 2, 3} to {1, 2, 3, 4}. Find
a) R1 ∪ R2 b) R1 ∩ R2 c) R1 − R2

d) R-1 and R e) R1  R2

11. Let R be the relation {(1, 2), (1, 3), (2, 3), (2, 4), (3, 1)}, and let S be the relation {(2, 1),
(3, 1), (3, 2), (4, 2)}. Find S ◦ R
12. a) List the 16 different relations on the set {0, 1}
b) Which of the the relations are
a) reflexive? b) irreflexive? c) symmetric?
d) antisymmetric? e) asymmetric? f ) transitive?
13. Let R be the relation on the set {1, 2, 3, 4, 5} containing the ordered pairs (1, 1), (1, 2),
(1, 3), (2, 3), (2, 4), (3, 1), (3, 4), (3, 5), (4, 2), (4, 5), (5, 1), (5, 2), and (5, 4). Find
a) R2 b) R3 c) R4 d) R5

34
8.2 n-ary Relations and Their Applications

1. Which domains are primary keys for the n-ary relation displayed in Table 1, assuming that
no n-tuples will be added in the future?
2. Is the Cartesian product of the domain of major fields of study and the domain of GPAs a
composite key for the n-ary relation from Table 1, assuming that no n-tuples are ever added?
3. a) Find the records of computer science majors in the n-ary relation R shown in Table 1.
b) Find the records of students who have a grade point average above 3.5 in this database.
c) Find the records of computer science majors who have a GPA above 3.5.
4. What results when the projection P 1,3 is applied to the 4-tuples (2, 3, 0, 4), (Jane Doe,
234111001, Geography, 3.14), and (a1, a2, a3, a4)?
5. What relation results when the projection P 1,4 is applied to the relation in Table 1?
6. What is the table obtained when the projection P 2 is applied to the relation in Table 1?
7. What relation results when the join operator J 2 is used to combine the relation displayed in
Tables 5 and 6?

35
8.3 Representing Relations
1. Suppose that A = {1, 2, 3} and B = {1, 2}. Let R be the relation from A to B containing (a,
b) if a ∈ A, b ∈ B, and a > b. What is the matrix representing R?
2. Let A = {1, 2, 3} and B = {1, 2, 3, 4, 5}. Which ordered pairs are in the relation R
represented by the matrix

0 1 0 0 0
M R   1 0 1 1 0 
1 0 1 1 1
 

1 1 0
 
3. Suppose that the relation R on a set is represented by the matrix 1 1 1 . Is R
 
0 1 1
 
reflexive, symmetric, and/or antisymmetric?
4. Suppose that the relations R1 and R2 on a set A are represented by the matrices

1 0 1 1 0 1
 
M R1   1 0 0  and M R2   0 1 1  .What are the matrices representing R1 ∪ R2 ,
0 1 0 1 1 0
   
R1 ∩ R2 and S ◦R ?

5.

a) What are the ordered pairs in the relation R represented by the directed graph shown in the
Figure?

b) Determine whether the relations for the directed graphs shown in the Figure are reflexive,
symmetric, antisymmetric, and/or transitive.

36
6.

a) What are the ordered pairs in the relation R represented by the directed graph shown in the
Figure?

b) Determine whether the relations for the directed graphs shown in the Figure are reflexive,
symmetric, antisymmetric, and/or transitive.

7. Represent each of these relations on{1, 2, 3}with a matrix and a directed graphs

a) {(1, 1), (1, 2), (1, 3)}

b) {(1, 2), (2, 1), (2, 2), (3, 3)}

c) {(1, 1), (1, 2), (1, 3), (2, 2), (2, 3), (3, 3)}

d) {(1, 3), (3, 1)}

8. Represent each of these relations on{1, 2, 3}with a matrix and a directed graphs

a) {(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)}

b) {(1, 1), (1, 4), (2, 2), (3, 3), (4, 1)}

c) {(1, 2), (1, 3), (1, 4), (2, 1), (2, 3), (2, 4), (3, 1), (3, 2), (3, 4), (4, 1), (4, 2), (4, 3)}

d) {(2, 4), (3, 1), (3, 2), (3, 4)}

9. List the ordered pairs in the relations on {1, 2, 3} corresponding to these matrices (where
the rows and columns correspond to the integers listed in increasing order).

1 1 0 1 0 1 0 1
1 0 1 1 1 1 1
    0 1 0  1 0 1 0 
a) 0 1 0 b) 1 0 1 c)  d) 
    0 1 1 1 0 1 0 1
1 0 1 1 1 1
       
1 0 1 1 1 0 1 0

37
10. Let R1 and R2 be relations on a set A represented by the matrices

0 1 0 0 1 0
 
M R1   1 1 1  and M R2   0 1 1  .
1 0 0 1 1 1
   
Find the matrices that represent

a) R1  R2 b) R1  R2 c) R2 R1 d) R1  R2

e) R22 f) R13 g) R12 h) R14

11. Draw the directed graph that represents the relation {(a, a), (a, b), (b, c), (c, b), (c, d), (d,
a), (d, b)}

12. List the ordered pairs in the relations represented by the directed graphs

38
8.5 Equivalence Relations
1. Let R be the relation on the set of real numbers such that aRb if and only if a − b is an
integer. Is R an equivalence relation?
2. Let R be the relation on the set of integers such that aRb if and only if a = b or a = −b.
What is the equivalence class of an integer for the equivalence relation R?
3. What are the equivalence classes of 0 and 1 for congruence modulo 4?

4. List the ordered pairs in the equivalence relation R produced by the partition A1 = {1, 2,
3}, A2 = {4, 5}, and A3 = {6} of S = {1, 2, 3, 4, 5, 6}.

5. What are the sets in the partition of the integers arising from congruence modulo 4?

6. Which of these relations on {0, 1, 2, 3} are equivalence relations? Determine the


properties of an equivalence relation that the others lack.

a) {(0, 0), (1, 1), (2, 2), (3, 3)}

b) {(0, 0), (0, 2), (2, 0), (2, 2), (2, 3), (3, 2), (3, 3)}

c) {(0, 0), (1, 1), (1, 2), (2, 1), (2, 2), (3, 3)}

d) {(0, 0), (1, 1), (1, 3), (2, 2), (2, 3), (3, 1), (3, 2), (3, 3)}

e) {(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0), (2, 2), (3, 3)}

7. Which of these relations on the set of all people are equivalence relations? Determine the
properties of an equivalence relation that the others lack.

a) {(a, b) | a and b are the same age}

b) {(a, b) | a and b have the same parents}

c) {(a, b) | a and b share a common parent}

d) {(a, b) | a and b have met}

8. Which of these relations on the set of all functions from Z to Z are equivalence relations?
Determine the properties of an equivalence relation that the others lack.

a) {(f, g) | f (1) = g(1)} b) {(f, g) | f (0) = g(0) or f (1) = g(1)}

c) {(f, g) | f (x) − g(x) = 1 for all x ∈ Z} d) {(f, g) | for some C ∈ Z, for all x ∈ Z, f
(x) − g(x) = C}

39
9. Determine whether the relation with the directed graph shown is an equivalence relation

10. Determine whether the relations represented by these zero–one matrices are equivalence
relations

1 0 1 0 1 1 1 0
 1 1 1 0
  1 0 1  1 1 1 0 
a) 0 1 1 b)  c) 
  1 0 1 0 1 1 1 0
 1 1 1
     
0 1 0 1 0 0 0 1

11. Which of these collections of subsets are partitions of {1, 2, 3, 4, 5, 6}?


a) {1, 2},{2, 3, 4},{4, 5, 6} b) {1}, {2, 3, 6}, {4}, {5}
c) {2, 4, 6}, {1, 3, 5} d) {1, 4, 5}, {2, 6}
12. Let R={(1,1), (2,2), (3,3), (1,2), (2,1), (4,4), (4,5), (5,4), (5,5)} be a equivalence relation
on the set {1,2,3,4,5}. How many equivalence classes with respect to R?
13. List the ordered pairs in the equivalence relations produced by these partitions of {a, b, c,
d, e, f, g}.
a) {a, b}, {c, d}, {e, f, g} b) {a}, {b}, {c, d}, {e, f }, {g}
c) {a, b, c, d}, {e, f, g} d) {a, c, e, g}, {b, d}, {f }

40
Chapter 9: Graphs
9.1 Graphs and Graph Models
1. Determine whether the graph shown has directed or undirected edges, whether it has
multiple edges, and whether it has one or more loops

2. Construct a precedence graph for the following program:


S1: x := 0 S2: x := x + 1 S3: y := 2
S4: z := y S5: x := x + 2 S6: y := x + z S7: z := 4

41
9.2 Graph Terminology and Special Types of Graphs
1. find the number of vertices, the number of edges, and the degree of each vertex in the
given undirected graph. Identify all isolated and pendant vertices.

2. Find the sum of the degrees of the vertices of each graph in Exercises 1 and verify that it
equals twice the number of edges in the graph.
3. Can a simple graph exist with 15 vertices each of degree five?
4. determine the number of vertices and edges and find the in-degree and out-degree of each
vertex for the given directed multigraph

42
5. Draw these graphs.
a) K7 b) K1,8 c) K4,4
d) C7 e) W7 f ) Q4
6. Determine whether the graph is bipartite

43
7. For which values of n are these graphs bipartite?
a) Kn b) Cn c) Wn d) Qn
8. How many vertices and how many edges do these graphs have?
a) Kn b) Cn c) Wn d) Km,n e) Qn
9. Find the degree sequences for each of the graphs in Exercises 6.
10. Find the degree sequence of each of the following graphs.
a) K4 b) C4 c) W4 d) K2,3 e) Q3
11. How many edges does a graph have if its degree sequence is 4, 3, 3, 2, 2? Draw such a
graph.
12. How many edges does a graph have if its degree sequence is 5, 2, 2, 2, 2, 1? Draw such a
graph.
13. Determine whether each of these sequences is graphic. For those that are, draw a graph
having the given degree sequence.
a) 5, 4, 3, 2, 1, 0 b) 6, 5, 4, 3, 2, 1 c) 4, 4, 3, 2, 1
d) 3, 3, 3, 2, 2, 2 e) 3, 3, 2, 2, 2, 2 f ) 3, 2, 2, 1, 0

44
9.3 Representing Graphs and Graph Isomorphism
1. use an adjacency list to represent the given graph.

2. Represent the graph in Exercise 1 with an adjacency matrix.


3. Represent each of these graphs with an adjacency matrix.
a) K4 b) K1,4 c) K2,3 d) C4 e) W4 f ) Q3
4. Draw a graph with the given adjacency matrix

0 0 1 1
0 1 0 1 2 1 0
    0 1 0 
a) 1 0 1 b) 2 0 0 c) 
    1 1 0 1
0 1 0 0 2 2
     
1 1 1 0

45
5. Determine whether the given pair of graphs is isomorphic

6. Are the simple graphs with the following adjacency matrices isomorphic?

7. Determine whether the given pair of directed graphs are isomorphic.

46
47
9.4 Connectivity
1. Does each of these lists of vertices form a path in the following graph? Which paths are
simple? Which are circuits? What are the lengths of those that are paths?
a) a, e, b, c, b b) a, e, a, d, b, c, a c) e, b, a, d, b, e d) c, b, d, a, e, c

2. Does each of these lists of vertices form a path in the following graph? Which paths are
simple? Which are circuits? What are the lengths of those that are paths?
a) a, b, e, c, b b) a, d, a, d, a c) a, d, b, e, a d) a, b, e, c, b, d, a

3. Find the number of paths of length n between two different vertices in K 4 if n is


a) 2 b) 3 c) 4 d) 5
4. Find the number of paths between c and d in the graph of length
a) 2 b) 3 c) 4 d) 5 e) 6 f) 7

48
5. Find all the cut vertices of the given graph

49
9.5 Euler and Hamilton Paths
1. Determine whether the given graph has an Euler circuit. Construct such a circuit when one
exists.

2. Determine whether the directed graph shown has an Euler circuit. Construct an Euler
circuit if one exists.

50
3. For which values of n do these graphs have an Euler circuit?
a) Kn b) Cn c) Wn d) Qn
4. For which values of m and n does the complete bipartite graph Km,n have an
a) Euler circuit? b) Euler path?
5. Determine whether the given graph has a Hamilton circuit. If it does, find such a circuit.

51
9.6 Shortest-Path Problems
1. What is the length of a shortest path between a and z in the weighted graph shown in the
Figure?

2. Find a shortest path between a and z in the given weighted graph.

52
Chapter 10: Trees
10.1 Introduction to Trees
1. Which of these graphs are trees?

2. Which of these graphs are trees?

3. Construct a complete binary tree of height 4 and a complete 3-ary tree of height 3.
4. Which complete bipartite graphs K m,n, where m and n are positive integers, are trees?

5. How many edges does a tree with 10,000 vertices have?

6. How many vertices does a full 5-ary tree with 100 internal vertices have?

7. How many edges does a full binary tree with 1000 internal vertices have?

8. How many leaves does a full 3-ary tree with 100 vertices have?

53
10.2 Applications of Trees
1. Form a binary search tree for the words mathematics, physics, geography, zoology,
meteorology, geology, psychology and chemistry (using alphabetical order).
2. Use Huffman coding to encode the following symbols with the frequencies listed: A: 0.08,
B: 0.10, C: 0.12, D: 0.15, E: 0.20, F: 0.35. What is the average number of bits used to encode
a character?
3. Build a binary search tree for the words banana, peach, apple, pear, coconut, mango and
papaya using alphabetical order.
4. Build a binary search tree for the words oenology, phrenology, campanology, ornithology,
ichthyology, limnology, alchemy and astrology using alphabetical order.
5. How many comparisons are needed to locate or to add each of these words in the search
tree for Exercise 3, starting fresh each time?
a) pear b) banana c) kumquat d) orange
6. How many comparisons are needed to locate or to add each of the words in the search tree
for Exercise 4, starting fresh each time?
a) palmistry b) etymology c) paleontology d) glaciology
7. Which of these codes are prefix codes?
a) a: 11, e: 00, t: 10, s: 01
b) a: 0, e: 1, t: 01, s: 001
c) a: 101, e: 11, t: 001, s: 011, n: 010
d) a: 010, e: 11, t: 011, s: 1011, n: 1001, i: 10101
8. Construct the binary tree with prefix codes representing these coding schemes.
a) a: 11, e: 0, t: 101, s: 100
b) a: 1, e: 01, t: 001, s: 0001, n: 00001
c) a: 1010, e: 0, t: 11, s: 1011, n: 1001, i: 10001

54
9. What are the codes for a, e, i, k, o, p, and u if the coding scheme is represented by this
tree?

10. Given the coding scheme a: 001, b: 0001, e: 1, r: 0000, s: 0100, t: 011, x: 01010, find the
word represented by

a) 01110100011 b) 0001110000

c) 0100101010 d) 01100101010

11. Use Huffman coding to encode these symbols with given frequencies: a: 0.20, b: 0.10, c:
0.15, d: 0.25, e: 0.30. What is the average number of bits required to encode a character?

12. Use Huffman coding to encode these symbols with given frequencies: A: 0.10, B: 0.25,
C: 0.05, D: 0.15, E: 0.30, F: 0.07, G: 0.08. What is the average number of bits required to
encode a symbol?

13. Construct two different Huffman codes for these symbols and frequencies: t: 0.2, u: 0.3,
v: 0.2, w: 0.3.

55
10.3 Tree Traversal
1. What is the ordered rooted tree that represents the expression ((x + y)↑2) + ((x − 4)/3) ?

2. What is the prefix form for ((x + y) ↑ 2) + ((x − 4)/3) ?

3. What is the value of the prefix expression + − ∗ 2 3 5/↑ 2 3 4 ?

4. What is the postfix form of the expression ((x + y) ↑ 2) + ((x − 4)/3) ?

5. What is the value of the postfix expression 7 2 3 ∗ − 4 ↑ 9 3/+ ?

6. a) Represent the expression ((x + 2) ↑ 3) ∗ (y −(3 + x)) − 5 using a binary tree.

Write this expression in

b) prefix notation c) postfix notation d) infix notation

7. a) Represent the expressions (x + xy) + (x/y) and x + ((xy + x)/y) using binary trees.

Write these expressions in

b) prefix notation c) postfix notation d) infix notation

8. a) Represent the compound propositions ¬(p ∧ q) ↔ (¬p ∨ ¬q) and (¬p ∧ (q ↔ ¬p)) ∨ ¬q
using ordered rooted trees.

Write these expressions in

b) prefix notation c) postfix notation d) infix notation

9. a) Represent (A ∩ B) − (A ∪ (B − A)) using an ordered rooted tree.

Write this expression in

b) prefix notation c) postfix notation d) infix notation

10. Draw the ordered rooted tree corresponding to each of these arithmetic expressions written
in prefix notation. Then write each expression using infix notation.

a) + ∗ + − 5 3 2 1 4 b) ↑ + 2 3 − 5 1 c) ∗ / 9 3 + ∗ 2 4 − 7 6

11. What is the value of each of these prefix expressions?

a) − ∗ 2 / 8 4 3 b) ↑ − ∗ 3 3 ∗ 4 2 5

c) + − ↑ 3 2 ↑ 2 3 / 6 − 4 2 d) ∗ + 3 + 3 ↑ 3 + 3 3 3
56
12. What is the value of each of these postfix expressions?

a) 5 2 1 − − 3 1 4 ++ ∗ b) 9 3 / 5 + 7 2 − ∗ c) 3 2 ∗ 2 ↑ 5 3 − 8 4 / ∗ −

13. Determine the order in which a preorder traversal visits the vertices of the given ordered
rooted tree.

14. In which order are the vertices of the ordered rooted tree in Exercise 13 visited using an
inorder traversal?
15. In which order are the vertices of the ordered rooted tree in Exercise 13 visited using a
postorder traversal?

57
10.4 Spanning Trees
1. How many edges must be removed from a connected graph with n vertices and m edges to
produce a spanning tree?

2. Find a spanning tree for the graph shown by removing edges in simple circuits.

a.

b.

c.

d.

58
e.

f.

3. Find a spanning tree for each of these graphs.


59
a) K5 b) K4,4 c) K1,6
d) Q3 e) C5 f ) W5

4. Draw all the spanning trees of the given simple graphs.

a.

b.

c.

5. Use depth-first search and breadth-first search to produce a spanning tree for the given
simple graph. Choose a as the root of this spanning tree and assume that the vertices are ordered
alphabetically

a.

60
b.

c.

61
6. Use depth-first search and breadth-first search to find a spanning tree of each of these graphs.
a) W6 ,starting at the vertex of degree 6 b) K5

c) K3,4, starting at a vertex of degree 3 d) Q3

7. Use backtracking to solve the n-queens problem for these values of n.

a) n = 3 b) n = 5 c) n = 6

8. Use backtracking to find a subset, if it exists, of the set {27, 24, 19, 14, 11, 8} with sum

a) 20 b) 41 c) 60

62
10.4 Minimum Spanning Trees
1. The roads represented by this graph are all unpaved. The lengths of the roads between pairs
of towns are represented by edge weights. Which roads should be paved so that there is a path
of paved roads between each pair of towns so that a minimum road length is paved? (Note:
These towns are in Nevada.)

2. Use Prim’s algorithm and Kruskal’s algorithm to find a minimum spanning tree for the
given weighted graph

a.

63
b.

c.

64
65

You might also like