Discrete Mathematics 2021
Discrete Mathematics 2021
Discrete Mathematics 2021
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.
e) If you bought the lottery ticket, then you won the million dollar jackpot.
f) It is hot if and only if it is not raining.
a) ¬p b) p ∨ q c) p → q
d) p ∧ q e) p ↔ q f ) ¬p → ¬q
g) ¬p ∧ ¬q h) ¬p ∨ (p ∧ q)
p : It is below freezing.
q : It is snowing.
Write these propositions using p and q and logical connectives (including negations).
2
c) It is not below freezing and it is not snowing.
Write these propositions using p and q and logical connectives (including negations).
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.
a) 2 + 2 = 4 if and only if 1 + 1 = 2.
b) 1 + 1 = 2 if and only if 2 + 3 = 4.
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.
3
9. Write each of these statements in the form “if p, then q”
c) A sufficient condition for the warranty to be good is that you bought the computer less
than a year ago.
e) You can access the website only if you pay a subscription fee.
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
a) p ∧ ¬p b) p ∨ ¬p c) (p ∨ ¬q) → q d) (p ∨ q) → (p ∧ q)
12. 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
d) if (x + 1 = 2) XOR (x + 2 = 3) then x := x + 1
13. Find the bitwise OR, bitwise AND, and bitwise XOR of each of these pairs of bit strings.
4
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)
2. Show that each of these conditional statements is a tautology by using truth tables.
2. Let P(x) be the statement “the word x contains the letter a.” What are these truth values?
3. Let Q(x, y) denote the statement “x is the capital of y”. What are these truth values?
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
7. Let P(x) be the statement “x = x2”. If the domain consists of the integers, what are these
truth values?
8. Let Q(x) be the statement “x + 1 > 2x.” If the domain consists of all integers, what are
these truth values?
9. Determine the truth value of each of these statements if the domain for all variables
consists of all integers.
10. Suppose that the domain of the propositional function P(x) consists of the integers 0, 1
and 4. Write out each of these propositions using disjunctions, conjunctions, and negations.
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.
d) A convertible car is fun to drive. Isaac's car is not a convertible. Therefore, Isaac's car is
not fun to drive.
6
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.
p q ?
0 0 0
0 1 0
1 0 1
1 1 0
Given that p = 1, q = 0, r = 1, t = 0
a) p q r t
b) p xor q r t
c) p q p q
d) p p q
7
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(∅))
8
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
9
2.3 Functions
1. Study the following rules:
(i) f: Z → R; f(x) = 1/(2x-1)
(ii) f: R → R; f(x) = 1/(2x-1)
Which rule describes a function?
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
n2 4
3. Find these values
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
10
x
a) f (x) = 1 b) f (x) = 2x + 1 c) f x
5
9. Determine whether the following function is invertible
(i) F: R → R, F(x) = |x|
(ii) G: Z → Z, G(x)= 5x
(iii) H: R →R, H(x) = 2x-3
a) a0 b) a1 c) a4 d) a5
3. Find the first five terms of the sequence defined by each of these recurrence relations and
initial conditions.
4. Find the solution to each of these recurrence relations and initial conditions.
k 1 j 2 2i 3 j ij
2
a) b) c) d)
k 1 j 1 i 0 j 1 i 1 j 2
1
a) j j
b) j 2
c) 2
jS jS jS
11
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 an: 3, 1, 5, 7, 4, 6. How many comparisons required for searching x = 7?
12
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(xn) 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))
13
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 time complexity for the algorithm above.
2. Consider the algorithm:
procedure F(n : positive integer)
F:=1
for i:= 1 to n do:
F: = F * i
Print(F)
Give the best big-O time complexity for the algorithm above.
3. Consider the algorithm:
procedure max(a1 ,a2 ,...,an : reals )
max:=a1
for i:=2 to n
if max<ai then max:=ai
Give the best big-O time complexity for the algorithm above.
14
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 ≡ 11+2b (mod 13). c) c ≡ a + 2b (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 = 19. b) a = −999, m = 101.
c) a = 1299, m = 17. d) a = 1456, m = 101.
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
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
15
11. Convert each of the following expansions to decimal expansion.
12. Convert 69 to
16
3. Using the function f(x) = (x + 10) mod 26 to encrypt messages. Answer each of these
questions.
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
17
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
18
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.
19
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.
9. When does a string belong to the set A of bit strings defined recursively by
21
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:
if n = 1 return 1
else if n = 2 return 1
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.
if n = 1 return a
if n = 0 return 0
Find
22
Chapter 5-7: Counting
5.1 The Basics of Counting
1. How many different bit strings of length seven are there?
2. How many positive integers less than 100 are divisible by 3 or 7?
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. How many license plates can be made using either two letters followed by three digits or
three letters followed by two digits?
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?
13. How many positive integers between 100 and 999 inclusive
a) are divisible by 7? b) are odd?
c) have the same three decimal digits? d) are not divisible by 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
23
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?
24
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
25
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
26
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
27
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
28
9.3 Representing Graphs and Graph Isomorphism
1. use an adjacency list to represent the given graph.
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
29
6. Are the simple graphs with the following adjacency matrices isomorphic?
30
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
31
5. Find all the cut vertices of the given graph
2. Determine whether the directed graph shown has an Euler circuit. Construct an Euler
circuit if one exists.
32
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.
33
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?
34
Chapter 10: Trees
10.1 Introduction to Trees
1. 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 Km,n, where m and n are positive integers, are trees?
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?
35
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
36
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.
37
10.3 Tree Traversal
1. What is the ordered rooted tree that represents the expression ((x + y)↑2) + ((x − 4)/3) ?
7. a) Represent the expressions (x + xy) + (x/y) and x + ((xy + x)/y) using binary trees.
8. a) Represent the compound propositions ¬(p ∧ q) ↔ (¬p ∨ ¬q) and (¬p ∧ (q ↔ ¬p)) ∨ ¬q
using ordered rooted trees.
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
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
38
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?
39
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.
40
e.
f.
a.
b.
c.
5. Use depth-first search and breadth-first search to produce a spanning tree for the given
simple graph. Choose vertex a as the root of this spanning tree and assume that the vertices
are ordered alphabetically
a.
42
b.
c.
43
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
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
44
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.
b.
45
c.
46