Discrete Mathematics 2021

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

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

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

Discrete Mathematics
and Its Applications
Exercise Book

Trần Trọng Huỳnh - 2021

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.

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.

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

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

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.

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.

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)

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

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

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

14. 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)

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.

a) [¬p ∧ (p ∨ q)] → q b) [(p → q) ∧ (q → r)] → (p → 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.

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)


5
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)

9. 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)

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) ∃xP(x) b) ∀xP(x) c) ∃x¬P(x)

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

1.5 Rules of Inference


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

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.

2. Determine a proposition with the given truth table.

p q ?

0 0 0

0 1 0

1 0 1

1 1 0

3. Find the truth value of the following propositions:

Given that p = 1, q = 0, r = 1, t = 0

a)  p  q  r   t

b)  p xor q   r  t

Given that the proposition “p and q” is evaluated to 1

c)  p  q   p  q

Given that the proposition “if p then q” is evaluated to 0

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

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}

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

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

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

2.4 Sequences and Summations


1. 1. Find these terms of the sequence {an}, 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

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 1 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

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.

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

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

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

3.6 Integers and Algorithms


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

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

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

16
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)

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.

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

c) C = {3, 12, 48, 192, 768, …} d) D = {0, 101, 11011, …}


20
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?

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:

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,4,7) c) F(1,2,3,5,9)

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?

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?

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)

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

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

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.

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

5. Determine whether the given pair of graphs is isomorphic

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

7. Determine whether the given pair of directed graphs are 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

3. Find the number of paths of length n between two different vertices in K4 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

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

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.

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?

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

34
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 Km,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?

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) ?

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

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


41
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 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

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

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

You might also like