0% found this document useful (0 votes)
79 views51 pages

Concept Review - Chapter 1-10

Uploaded by

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

Concept Review - Chapter 1-10

Uploaded by

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

Concept Review – chapter 1- LOGIC

 p  q (disjunction of p and q): the proposition “p or q,” which is true if and only
if at least one of p and q is (1) .
 p → q (p implies q): the proposition “if p, then q,” which is (2) if and only if p
is true and q is false.
 (3) is a compound proposition that is always true.
 ¬q → ¬p is logically (4) to p → q.
 ∀xP(x) is true if and only if P(x) is true for (5) x in the domain.
 The proposition p  q is (6) p → q.
 𝑝  𝑞  (7)
̅̅̅̅̅̅̅

Answer: (1) true (2) false (3) tautology (4) equivalent (5)
every/each/all (6) the negation of (7) 𝑝̅  𝑞̅

Multiple choice questions


1. Given the propositions:
p = “you drive at more than 80km/h”
q = “you get a speeding ticket”
Express the sentence into a logical expression.
“You get a speeding ticket if you drive at more than 80km/h”

a. qp
b. pq
c. qp
d. qp

Answer: p  q
Comment:
 “You get a speeding ticket if you drive at more than 80km/h”  q if p.
 p  q means “q if p”.

2. Given the propositions:


p = “this computer program is correct” and
q = “it does not produce error message during translation”.
Express the following sentence into a logical expression:
“A necessary condition for this computer program to be correct is that it does not
produce error message during translation”.
a. qp
b. pq
c. qp
d. qp

Answer: p  q
Comment:
 Read and try to find words such as “necessary”, “sufficient”, “if”, “only if”,
“if and only if”, …
 p  q means “q is necessary for p”.
 “A necessary condition for [A] is that [B]” means “[B] is necessary for [A]”.

3. Which proposition is logically equivalent to p  (r  q)?

a. pqr
b. (p v r)  q
c. pvrvq
d. None of these

Answer: None of these


Comment:
 Keep in your mind A  B  A  B
 (r  q)  r  q
 (r  q)  (r  q)  r  q (De Morgan’s law)
 p  (r  q)  p  (r  q)  (p)  (r  q)  p  (r  q).

4. Which of the following propositions is true? (x denotes a real number).

(i) x[(x  1)  (x2  1)]


(ii) x[(x  1)  (x2  1)]
(iii) x[(x  1)  (x2  1)]

Answer: (i)
Comment:
 A counter example for (ii) is x = -2.
 A counter example for (iii) is x = ½.
 No counter example for (i).
5. Let T(x, y) = “the student x takes the class y”, where x represents a student in a
university, and y represents a class.
Translate the logical expression into a sentence:
xyT(x,y)
a. Some students take some classes.
b. Every student takes at least one class.
c. There are some classes that every student takes.
d. Some students take every class.

Answer: b
Comment:
 x: every student/each student  options (a), (d) are not true.
 xyT(x, y)  yxT(x, y).

6. Which of the following is the negation of the proposition:


xy(M(x, y)  N(x, y))?

a. xy (N(x, y)  M(x, y))


b. xy (M(x, y)  N(x, y))
c. xy (N(x, y)  M(x, y))
d. xy (N(x, y)  M(x, y))

Answer: d
Comment:
 xP  x   xP  x 

 xP  x   xP  x 
 p q  pq
 xy  M  x, y   N  x, y    xy M  x, y   N  x, y  

 
 xy M  x, y   N  x, y  .
7. Given the premises:
(1) If I eat spicy foods, then I have strange dreams.
(2) I have strange dreams if there is thunder while I sleep.
(3) I did not have strange dreams.
Which conclusion can be drawn?

a. I did not eat spicy foods but there was thunder while I slept.
b. There was thunder while I slept.
c. I ate spicy foods.
d. I did not eat spicy foods and there wasn’t thunder while I slept.

Answer: d
Comment:
 (1) e  d
 (2) t  d
 (3) d
 Apply the rule below to (1)&(3) and to (2)&(3).

 We can conclude e and t.

8. Which proposition is equivalent to (p  q)  (p  q)?

(i) p
(ii) q
(iii) p
(iv) F

Answer:
Comment:
 Keep in your mind A  B  A B.
 p  q  (p)  q  p  q.
 p  q  (p)  q  p  q.
 (p  q)  (p  q)  (p  q)  (p  q)  p  (q  q)  p  (F)  p.

9. Let L(x, y) be the statement “x is a friend of y”, where the domain consists of all people.
Translate the statement “Anybody except one person is a friend of Leo”.

a. xL  x, Leo    y  x  L( y, Leo)


b. x  1 L( x, Leo) 

c. xL  x, Leo    y  x  L( y, Leo)


d. None of these.

Answer: a
Comment:
 Anybody () except one person () is a friend of Leo  options (b) and (c)
are not true.

10. Which of the following arguments is/are valid?


(i) Any hardworking student is good in class. Tram is good in class. Therefore, Tram
was working hard.
(ii) Anyone in class understands logics. Tram is a student in class. Therefore, Tram
understands logics.

a. (i)
b. (ii)
c. None
d. Both

Answer: (ii)
Comment:
 h  g  g  h.
 If we know that P(x) is true for every x, then we can conclude that P(x) is true
when x = c.

11.
(i) Any computer science major must take Discrete Mathematics. Anh is taking
Discrete Mathematics. Therefore, Anh is a computer science major.
(ii) Any student of FPT university lives in the dorm. Anh is living in a house.
Therefore, Anh is not a student of FPT university.

a. (i)
b. (ii)
c. None
d. Both

Answer: (ii)
Comment:
 h  g  g  h.
 (ii) is true due to the rule
Concept review – Chapter 2- SETS, FUNCTIONS, SUMS
 b  A means b is a/an (1) of the (2) A.
 If every element of S is also an element of T, we say S is a (3) of T.
 The (4) set, denoted by , is the set with (5) elements.
 A  B: the (6) of A and B.
 A ∩ B: the (7) of A and B.
 A − B (the difference of A and B): the set containing elements that are in A (8) in B.
 A ⊕ B (the symmetric difference of A and B): the set containing elements in (9) A
and B.
 A function from A to B maps (10) element of A to (11) element of B.
 If a function is both onto and one-to-one, it is called a (12) .
 If a function is a bijection, it has a/an (13) function. Then, it is called an invertible
function.
Answer: (1) element/member (2) set (3) subset (4) null/empty
(5) no (6) union (7) intersection (8) but not (9) exactly one
of (10) each (11) exactly one (12) bijection (13) inverse

Some multiple choice questions

1. Let U = {a, b, c, d, e, f, g, h} be the universal set. The bit string representing the set {a, c,
d, f, g} is ____.

a. 01001001
b. 11111100
c. 111111
d. 10110110

Answer: d
Comment:
 U has 8 elements  a bit string for a set has length 8  option (c) is not true.
 Bit string for A:
U a b c d e f g h
A a c d f g
Strings 1 0 1 1 0 1 1 0

2. Let A = {1, 2, 3, 4, 6}, and B = {3, 4, 7} be two sets in the universal set {1, 2, 3, 4, 5, 6,
7}. Find the bit string representing the set A  B.
a. 11111111
b. 1100111
c. 1111111
d. 1100011

Answer: b
Comment:
 U has 7 elements  a bit string for a set has length 7  option (a) is not true.
 A  B = (AB) – (AB) = {elements which are in A or in B, not both}.
 A  B = {1, 2, 6, 7}.

3. Let R be the set {(a, b) | a - 1 = b}, where a and b are in {-2, -1, 0, 1, 2}. How many
elements does R have? (or in other words, what is the cardinality of R?).

a. 4
b. 3
c. 2
d. 1

Answer: 4
Comment:
 R = {(-1, -2), (0, -1), (1, 0), (2, 1)}.
 Cardinality = number of elements of R.

4. The set A has n elements, B has n+1 elements. Assume that A  B has 42 elements. Find
n.

a. 6
b. 7
c. 21
d. 6 or -7
e. None of these

Answer: 6
Comment:
 A  B has n(n+1) = 42 elements  n = 6.
 Option (d) is impossible.
5. Given the sequence {an, n = 1, 2, …}: an = 1 + 3 + … + (2n-1).
Find a2019 – a2018.

a. 4037
b. 2019
c. 2018
d. 4038
e. None of these

Answer: 4037
Comment:
 a1 = 1, a2 = 1 + (21 – 1), a3 = 1 + 3 + (23 – 1), etc.
 an = the sum of n first odd positive integers
 a2019 = 1 + 3 + … + (22018 – 1) + (22019 – 1)
 a2018 = 1 + 3 + … + (22018 – 1)

6. Given the sequence {an, n = 1, 2, …}where an equals the number of 1 bits in the
binary format of n. Find a11.

a. 0
b. 1
c. 2
d. 3
e. 4

Answer: 3,
Comment:
 11 = (1011)2  three 1-bits  a11 = 3.

7. Which statement is FALSE?


a. A   = A
b. A  A = A
c. A  𝐴̅ = U, where U is the universal set.

Answer: A  A = A
Comment:
 AA=
8. Which rules are functions?

a. f : Z  R, f  x   1/  x 2  3

b. f : Z  Z , f  x   1/  x 2  3

c. f : Z  Z , f  x   1/  x 2  4 

d. f : Z  R, f  x   1/  x 2  4 

Answer: a
Comment:
 Option (b): f(1) = -1/3 is not in Z.
 Option (c), (d): f(2) = 1/0 (!), undefined.

9. Let N = {0, 1, 2, …} and f: N  N be the function f(x) = x2 – 2x + 1.


Which statement is true?
(i) f is onto
(ii) f is one-to-one.

a. (i)
b. (ii)
c. None
d. Both

Answer: d
Comment:
 f(x) = x2 – 2x + 1 = (x – 1)2
 f(0) = f(2) = 1  not 1-1.
 No x such that f(x) = 3  f is not onto.

𝑥 2 −3
10. Let f be the function defined by f(x) = floor( ).
3
Find f(1), f(2) and f(5) (or f({1, 2, 5})).

a. 0, 0, 7
b. -1, 0, 7
c. 0, 1, 8
d. -1, 0, 8
e. None of these.

Answer: -1, 0, 7
Comment:
 f(1) = floor(-2/3) = -1.
 f(2) = floor(1/3) = 0.
 f(5) = floor(22/3) = 7.

11. Find the composite function (fg)(x) = f(g(x)), where f(x) = x + 2018 and g(x) = x2018.

a. (x+2018)2018
b. x2018 + 2018
c. x2018(x+2018)
d. None of these

Answer: x2018 + 2018


Comment:
 g(x) = x2018.
 (fg)(x) = f(g(x)) = f(x2018).
 f(x) = x + 2018  f(x2018) = x2018 + 2018.

12. Given A = {1, 2}. Find A - P(A). (Recall that P(A) is the power set of A).

a. 
b. A
c. {}
d. None of these.

Answer: x2018 + 2018


Comment:
 A = {1, 2}
 Subsets of A: , {1}, {2}, {1, 2}
 P(A) = { , {1}, {2}, {1, 2} }
 A – P(A) = {1, 2}

13. Given A = {1, 2}, find AP(A).

a. A
b. 
c. {}
d. None of these
Answer: x2018 + 2018
Comment:
 A = {1, 2}
 Subsets of A: , {1}, {2}, {1, 2}
 P(A) = { , {1}, {2}, {1, 2} }
 AP(A) = { }.

14. How many elements does the set P({1, 2, 3, 4, 5, 6, 7, 8}) have?
a. 8
b. 16
c. 256
d. None of these

Answer: 256
Comment:
 P(A) has 2n elements if A has n elements.

2 3
15. Compute   i  j 
i  0 j 1

a. -1
b. -3
c. -9
d. -11
e. None of these.

Answer: -9
Comment:
  0  1   0  2    0  3  1  1  1  2   1  3   2  1   2  2    2  3  9
i  0, j from 1 to 3 i 1, j from 1 to 3 i 2, j from 1 to 3

10 20
16. Find the double sum   ij  .
i 1 j 1

a. 200
b. 231
c. 11550
d. 46200
e. None of these.

Answer: 11550
Comment:
10 20 10  20  10
 10
 20  21  
  ij    i j    i 1  2  ...  20   i i 1   2  

i 1 j 1 i 1  j 1  i 1

10
10 11
 210 i  210 1  2  ...  10   210   11550 .
i 1 2
Concept Review – Chapter 3 – ALGORITHMS & INTEGERS

 f(x) is (1) if f(x) is both O(g(x)) and (g(x))


 The linear search has (2) worst case time complexity.
 The binary search has (3) worst case time complexity.
 The bubble and insertion sorts have (4) worst case time complexity.
 If there is an integer c such that ac = b, we say a (5) b and write (6) .
 If a mod m = b mod m, we say a and b are (7) modulo m.
 gcd(a, b): (8) of two integers a, b.
 lcm(a, b): (9) of two integers a and b.
 If a and b are positive integers, then gcd(a, b)·lcm(a, b) = (10) .
 If gcd(a, b) = 1, then a and b are called (11) .
 If the function f(p) = (p + 13) mod 26 is used to encrypt a message, then (12) is used to
decrypt this encoded message.
 If a and b are integers and r = a mod b, then gcd(a, b) = (13) .
Answer: (1) (g(x)) (2) O(n) (3) O(logn) (4) O(n2) (5) divides
(6) a | b (7) congruent (8) greatest common divisor (9) least common
multiple (10) ab (11) relatively prime (12) f-1(p) = (p – 13) mod 26
(13) gcd(b, r)

Some multiple choice questions

1. Given f(x) = x2 and g(x) = 3x + 2018. Consider the statements:


(i) f(x) is O(g(x))
(ii) g(x) is O(f(x))

Which statement is TRUE?

a. (i)
b. (ii)
c. Both
d. None
Answer: (ii)
Comment:
 g(x) = 3x + 2018 ~ x is O(x2)
(√𝑥 8 +𝑥 4 +1 +1)(𝑙𝑜𝑔𝑥+3)
2. Find the least integer k such that is O(xk).
𝑥 2 +1
a. 1
b. 2
c. 3
d. 4
e. None of these
Answer: 3
Comment:
(√𝑥 8 +𝑥 4 +1 +1)(𝑙𝑜𝑔𝑥+3) (√𝑥 8 )(𝑙𝑜𝑔𝑥)
 ~ = x2logx.
𝑥 2 +1 𝑥2
 To easily estimate O-notation, keep in your mind the order: 1 < logx < x <
xlogx < x2 < x2logx < x3 < … < 2x < 3x … (for x large enough)
3. Which function is (xlogx)?
a. 2018x
b. x2/2018
c. 20182018
d. None of the others
Answer: x2/2018
Comment:
 x2/2018 ~ x2 is (xlogx).

4. Given f(x) = 3x2 + 12x + 2 and g(x) = x3


Which statement is True?
a. f(x) is O(g(x))
b. f(x) is (g(x))
c. f(x) is (g(x))
d. None of these
Answer: f(x) is O(g(x))
Comment:
 f(x) = 3x2 + 12x + 2 ~ x2
 g(x) = x3
5. Suppose a mod 4 = 3 and b mod 8 = 7, find ab mod 4.
a. 1
b. 2
c. 3
d. 21
e. 9
Answer: 1
Comment:
 b = 8k + 7  b = 4(2k) + 4 + 3  b mod 4 = 3
 ab mod 4 = ((a mod 4)(b mod 4)) mod 4 = (33) mod 4 = 9 mod 4 = 1.

6. Which of the following integers are congruent to 13 modulo 7?


a. -6
b. -1
c. 1
d. 7
e. None of these
Answer: -1
Comment:
 x congruent to 13 modulo 7  x  13 (mod 7)
 a  b (mod m)  m | (a – b )  (a – b)  m
 -6 – 13 = -19 7  option (a) is not true.
 -1 – 13 = -14  7  option (b) is true.
7. 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.
a. O(n)
b. O(logn)
c. O(1)
d. O(n2)
e. None of these
Answer: O(n)
Comment:
 Pay attention to “for loops” (or while loops).
 No “other loops” (for or while) inside the “for loop”.
8. Consider the algorithm:
procedure GT(a1, a2, …, an : integers)
count:= 0
for i:= 2 to n do
for j:= 1 to i-1 do
if ai = aj then count = count +1
print(count)
Give the best big-O complexity for the algorithm above.
a. O(n)
b. O(logn)
c. O(1)
d. O(n2)
e. None of these
Answer: O(n2)
Comment:
 Pay attention to “for loops” (or while loops).
 There is one “for loop” (via index j) inside the first for loop (via index i).
9. Find the base 7 expansion of 186
a. 354
b. 331
c. 413
d. 271
e. None of these
Answer: 354
Comment:
 (186) = (a3a2a1a0)7
 a0 = 186 mod 7 = 4  options b, c and d are not true.
 186 div 7 = 26
 a1 = 26 mod 7 = 5
 26 div 7 = 3
 a2 = 3 mod 7 = 3
 3 div 7 = 0  stop

10. Find the binary format of (2010)3.


a. 11110
b. 111010
c. 100111
d. 11100
e. None of these
Answer: 111010
Comment:
 (2010)3 = 58 = (111010)2
 (2011)3 = 233 + 032 + 131 + 130 = 58.

11. Suppose pseudo-random numbers are produced by using:


xn+1 = (3xn + 5) mod 7.
If x3 = 5, find x2 and x4.
a. x4 = 6, x2 = 3
b. x4 = 6, x2 = 0
c. x4 = 9, x2 = 3
d. x4 = 3, x2 = 5
e. None of these
Answer: x4 = 6, x2 = 0
Comment:
 You can test to find possible options.
 xn+1 = (3xn + 5) mod 7.
 Assume x2 = 3, it follows that x3 = (3x2 + 5) mod 7 = (33+5) mod 7 = 14 mod
7 = 0  options a, c are not true.
 x3 = 5  x4 = (3x3 + 5) mod 7 = 20 mod 7 = 6  option d is not true.

12. Use the function f(x) = (x + 17) mod 26 to encrypt the message CV.

a. CM
b. TM
c. FA
d. TV
e. None of these

Answer: TM
Comment:
 A = 0, B = 1, C = 2, …, V = 21, …, Z = 25.
 f(x) = (x + 17) mod 26
 f(C) = f(2) = 19 = T
 f(V) = f(21) = (21 + 17) mod 26 = 12 = M.

13. Suppose the password for a quiz has been encoded using the function f(p) = (p + 13)
mod 26.
If the result is SE, find the quiz password.
a. GP
b. FR
c. HR
d. DM
e. None of these
Answer: FR
Comment:
 f(p) = (p + 13) were used to encrypt the quiz password.
 We use f-1(p) = (p – 13) mod 26 to decrypt “SA” to obtain the password.
 SE = 18 4
 f-1(18) = (18 – 13) mod 26 = 5 = F
 f-1(4) = (4 – 13) mod 26 = -9 mod 26 = 17 = R.

14. Which pair of integers are relatively prime?


a. (17, 51)
b. (5, 24)
c. (11, 121)
d. (37, 111)
e. None of the others
Answer: (5, 24)
Comment:
 Two integers a and b are called relatively prime iff gcd(a, b) = 1.
 gcd(17, 51) = 3.
 gcd(11, 121) = 11.
 gcd(37, 111) = 37.
 gcd(5, 24) = 1.

15. If a, b are positive integers such that gcd(a, b) = 37 and ab = 111111, find lcm(a, b).
a. 4111107
b. 3003
c. 37
d. 1
e. None of the others
Answer:
Comment:
 gcd(a, b)lcm(a, b) = ab  lcm(a, b) = ab/gcd(a, b) = 111111/37 = 3003.

16. Consider the bubble sort algorithm:


bubblesort(a1, a2, ..., an: integers)
for i:= 1 to n-1
for j:= 1 to n-i
if aj+1 < aj then swap(aj, aj+1)

If the input is [3, 1, 4, 5, 2], what is the result after the second pass (i = 2)?

a. [1, 2, 3, 4, 5]
b. [1, 3, 2, 4, 5]
c. [2, 1, 3, 4, 5]
d. [1, 3, 2, 5, 4]
e. None of these
Answer: [1, 3, 2, 4, 5]
Comment:
 The initial list is [3, 1, 4, 5, 2].
 Some changes when i = 1: [3, 1, 4, 5, 2] (j = 1) [1, 3, 4, 5, 2] (j = 2) [1,
3, 4, 5, 2] (j = 3) [1, 3, 4, 5, 2] (j = 4) [1, 3, 4, 2, 5].
 After the 1st pass (i = 1), we have the list [1, 3, 4, 2, 5].
 Some changes when i = 2: [1, 3, 4, 2, 5] (j = 1) [1, 3, 4, 2, 5] (j = 2) [1,
3, 4, 2, 5] (j = 3) [1, 3, 2, 4, 5].
 After the 2nd pass (i = 2), we obtain the list [1, 3, 2, 4, 5].

17. 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 (≤ or ) required to locate the position of 5?
a. 7
b. 9
c. 11
d. 13
e. None of these
Answer: 7
Comment:
 n= 6, x = 5.
 i := 1  (1 ≤ 6 and 5  3 ) is true  i: = i +1 = 2.
 i := 2  (2 ≤ 6 and 5  1 ) is true  i: = i +1 = 3.
 i := 3  (3 ≤ 6 and 5  5 ) is FALSE  exit the while loop
 i = 3 ≤ 6  location = 3.
 Conclusion: 7 comparisons (≤, ).
Chapter 4 – Induction & Recursion
Review questions

1. Find a recursive definition for an = 1 + (-1)n, n = 0, 1, 2, ...

a. a0 = 2 and an = an-2, for n > 0.


b. a0 = 2, a1 = 0 and an = an-2, for n > 1.
c. a0 = 0, a1 = 2 and an = an-2, for n > 1.

Answer: b

Comment:

 an = 1 + (-1)n  a0 = 1 + (-1)0 = 2  option (c) is not true.


 From the definition given by option a, we cannot calculate a1  option (a) is not
true.
 Note that a0 = 2, a1 = 0, a2 = 2 = a0, a3 = 0 = a1, a4 = 2 = a2, etc.  an = an-2.

2. Find a recursive definition for the set of positive integers NOT divisible by 3.
a. 1S,
and xS  x+1S, x+2S.
b. 1S,
and xS  x+3S.
c. 1S, 2S,
and xS  x+3S.

Answer: c

Comment:

 Some positive integers not divisible by 3: 1, 2, 4, 5, 7, 8, …


 From the definition given by option (a): xS  x+2S  3S (!)  option (a)
is not true.
 We cannot generate the number 2 by applying the definition in option (b) 
option (b) is not true.

3. Study the set S of bit strings defined recursively by:


String 1 belongs to S
String 11x belongs to S if string x belongs to S.
Which statement is true?
(i) 11111S
(ii) 111111S
a. (i)
b. (ii)
c. Both
d. None

Answer: (i)

Comment:

 xS 
definition
 11xS. This means, add “11” before the string x you have.
 1S 
definition
 111S 
definition
 11111S 
definition
 1111111S 
definition
…

4. Let f(n) = f(n/3) + 2 and f(1) = 3, where n is divisible by 3.


Find f(27).
a. 9
b. 7
c. 5
d. 6
e. None of these.

Answer: 9

Comment:

 f(n) = f(n/3) + 2.
 f(3) = f(3/3) + 2 = f(1) + 2 = 5.
 f(9) = f(9/3) + 2 = f(3) + 2 = 7.
 f(27) = f(27/3) + 2 = f(9) + 2 = 9.

5. Find a recursive definition for the sequence f(n) = n, for n = 1, 2, 3, …


a. f(1) = 1, f(n) = n+ f(n-1) for n>1.
b. f(n) = f(n-1) +1 for all n ≥ 1.
c. f(1) = 1 and f(n) = f(n-1) +1 for all n > 1.
d. f(1) = 1, f(n) = n for all n>1.
e. None of the others.

Answer: c

Comment:

 Option (d), f(n) = n is not a recursive definition  not true.


 Option (b), no basis step, no one knows the value of f(1)  option (b) is not true.
 Option (a)  f(2) = 2 + f(1) = 3. But we want to define f(n) = n, the one that f(2)
= 2  option (a) is not true.
 f(n) = n  f(n-1) = n – 1  f(n) = f(n-1) + 1.

6. Consider the recursive algorithm:


procedure giaithuat(n : positive integer, a: real number)
if n = 1 then giaithuat(n,a): = a
else giaithuat(n, a) = giaithuat(n-1, a) + a
What is the output if n = 4, a = 2.5?

a. 8
b. 16
c. 10
d. None of these.

Answer: 10

Comment:

 giaithuat(1, 2.5) = 2.5 ( the case with n = 1)


 giaithuat(n, a) = giaithuat(n-1, a) + a if n > 1
 giaithuat(2, 2.5) = giaithuat(1, 2.5) + 2.5 = 2.5 + 2.5 = 5
 giaithuat(3, 2.5) = giaithuat(2, 2.5) + 2.5 = 5 + 2.5 = 7.5
 giaithuat(4, 2.5) = giaithuat(3, 2.5) + 2.5 = 7.5 + 2.5 = 10.

7. Consider the set A of bit strings defined recursively by

1A

if xA, then x11A

Which of the following strings is in A?

a. The empty string , the string with no symbols.


b. String 11
c. String 111
d. String 1111

Answer: string 111

Comment:

 xA  x11A.
 1A  111A
 111A  11111A
 etc.

8. To prove the statement " 6 divides n3 - n for all integers n ≥ 0", the mathematical induction
method is used as the following:
(1) The statement is true for n = 0.
(2) Suppose ____, the statement is true, that is, "6 divides k3 - k".
(3) We have, (k+1)3 - (k+1) = (k3 + 3k2 + 3k + 1) - (k + 1) = k3 - k + 3(k2 + k).

As 6 divides k3 - k (assumption, step 2) and 3(k2 + k) is a multiple of 6, we conclude that


(k+1)3 - (k+1) is also a multiple of 6.

(4) By induction, 6 divides n3 - n for all integers n ≥ 0.

Fill in the blank at step (2).

a. there exist an integer k ≥ 0.


b. for every integer k ≥ 0.
c. there are some integers k ≥ 0.

Answer: for every integer k ≥ 0

9. which statements are true? (n is any positive integer).

(i) 12 + 32 + 52 + ... + (2n-1)2 = n3

(ii) 1! + 2! + ... + n! = (n+1)! – 1

a. (i)
b. (ii)
c. None
d. Both

Answer: None

Comment:

 Examine (i) with n = 2: 12 + (22-1)2 = 23  10 = 8 (!)  option (i) is not true.


 Examine (ii) with n = 3: 1! + 2! + 3! = (3+1)! - 1  11 = 23 (!)  option (ii) is
not true.

9. Find f (2018) if f(n) = -f(n - 3) and f(0) = 1, f(1) = 4, f(2) = 6.

a. 1
b. 4
c. 6
d. -1
e. -4
f. -6

Answer: 6

Comment:

 f(n) = -f(n - 3)
 f(n-3) = -f(n-6)
 f(n) = -f(n - 3) = -(-f(n-6)) = f(n-6)
 f(2018) = f(2018 – 6) = f(2012)
 f(2012) = f(2012 – 6) = f(2006)
 f(2006) = f(2000) = … = f(8) = f(2) = 6.
 Note that 2018 mod 6 = 2.

10. Give a recursive definition of the set A = {…, -7, -4, -1, 2, 5, 8, …}.
Which of the following definitions is/are true?
(i) 2∈A; if x∈A then x+3∈A or x – 3∈A.
(ii) -1∈A; if x∈A then x + 3∈A or x – 3∈A.

a. (i)
b. (ii)
c. None
d. Both

Answer: Both

Comment:

 Start with basic element (2 or -1) other elements can be generated by adding or
subtracting by 3.
Concept Review – Chapter 5-7. COUNTING

1. How many different functions from {a, {a}, b, {a, b}} to {x, y, {z}, y}?
a. 34
b. 43
c. 12
d. Only one
e. 44
Answer: 34
Comment:
 {a, {a}, b, {a, b}} has 4 elements.
 {x, y, {z}, y} has 3 elements.

2. How many different one-to-one functions from {a, b, c} to {00, 01, 10, 11}?
a. 34
b. 43
c. 4·3·2
d. Only one

Answer: 4·3·2
Comment:
 3 steps to set up a function: (1) choose output for a, (2) choose output for b,
(3) choose output for c.
 “One-to-one” means the output values are different.
 Use product rule to count  4·3·2 one-to-one functions.

3. Suppose that a “word” is any string of seven letters of the alphabet, with repeated letters
allowed.
How many words begin with A or B and end with A or B?
a. 2.265
b. 4.265
c. 266
d. None of these
4. Suppose that a “word” is any string of seven letters of the alphabet, with repeated letters
allowed. How many words begin with a vowel or end with a vowel?
a. 5·266 + 5·266 - 25·265
b. 5·5·265
c. 2·5·265
d. 5·266 + 5·266
Answer: 5·266 + 5·266 - 25·265
Comment:
 Case 1: Vowel * * * * * *  5·266 words.
 Case 2: ******vowel  5·266 words.
 Case 3: vowel*****vowel  5·265·5 words.
 Note that case 1 includes case 3 and case 2 also includes case 3.
 Use inclusion-exclusion principle: case 1 + case 2 – case 3.

5. A club with 20 women and 17 men needs to choose three different members to be
president, vice president, and treasurer. In how many ways is this possible if women will
be chosen as president and vice president and a man as treasurer?
a. 20·19·17
b. 37·36·35
c. 20·17·16
d. None of these

Answer: 20·19·17
Comment:
 Three steps: (1) choose a woman as a president, (2) choose a woman as a vice
president, (3) choose a man as a treasurer.
 Use product rule  20·19·17 ways.

6. Find the number of subsets of {1, 2, 3, 4, 5, 6} that contain 3.


a. 26
b. 25
c. 5
d. None of these
Answer: 25
Comment:
 Six steps: (step 1) 2 ways (Y/N) to consider number 1, (step 2) 2 ways (Y/N)
to consider number 2, (step 3) one way (Y) to consider number 3, …, (step 6)
2 ways (Y/N) to consider number 6.
 Use product rule  25 ways to choose a subset of {1, 2, 3, 4, 5, 6} that
contain 3.
7. Suppose a restaurant serves a “special dinner” consisting of soup, salad, entree, dessert,
and beverage. The restaurant has five kinds of soup, three kinds of salad, ten entrees, five
desserts, and four beverages. How many different special dinners are possible? (Two
special dinners are different if they differ in at least one selection.)
a. 5·3·10·5·4
b. 5 + 3 + 10 + 5 + 4
c. 25
d. None of these
Answer: 5·3·10·5·4
Comment:
 Five steps to serve a “special dinner”: step 1 - soup (5 kinds), step 2 – salad (3
kinds), step 3 – entrée (10 entrées), step 4 – dessert (5 desserts), step 5 –
beverage (5 beverages).
 Use product rule  5·3·10·5·4 ways to serve.

8. A professor teaching a Discrete Math course gives a multiple choice quiz that has ten
questions, each with four possible responses: a, b, c, d. How many ways for a student to
complete the test? (Assume that no answers are left blank.)
a. 40
b. 104
c. 410
d. None of these
Answer: 410
Comment:
 Ten steps: step 1 – answer the 1st question (4 ways), step 2 – answer the 2nd
question (4 ways), …, step 10 – answer the 10th question (4 ways).
 Use product rule  410 ways complete the test.
9. How many integers between 100 and 1000 inclusive that are divisible by 7 or 13?
a. 208
b. 189
c. 188
d. None of these

Answer: 189
Comment:
 Case 1: integers in [100, 1000] that are divisible by 7 (128 such integers).
 Case 2: integers in [100, 1000] that are divisible by 13 (69 such integers).
 Case 3: integers in [100, 1000] that are divisible by both 7 and 13 (8 such
integers).
 Case 1 includes case 3 and case 2 also includes case 3.
 Use inclusion-exclusion principle (case 1 + case 2 – case 3)  Result = 128
+ 69 – 8.

10. Suppose f (n) = 4 f (n/2) if n is divisible by 2, and f (1) = 2. Find f (8).


a. 226
b. 128
c. 256
d. 64
e. None of these
Answer: 128
Comment:
 f(n) = 4f(n/2)
 f(2) = 4f(2/2) = 4f(1) = 8
 f(4) = 4f(4/2) = 4f(2) = 32
 f(8) = 4f(8/2) = 4f(4) = 128
 f is defined recursively.

11. You take a job that pays $55,000 annually. How much do you earn 15 years from now if
you receive a three percent raise each year?
a. 55,000·1.0315
b. 55,000·0.0315
c. 55,000·1.1315
d. 55,0001.03
e. None of these

Answer: 55,000·1.0315
Comment:
 Use the model Pn = Pn-1 + rPn-1 or Pn = (1+r)Pn-1.
 P1 = (1+r)P0, P2 = (1+r)P1 = (1+r)2P0
 P3 = (1+r)P2 = (1+r)3P0
 Pn = P0(1+r)n, where r = 3%, n = 15, P0 = $55,000.
Concept Review – Chapter 8 - Relations
 A binary relation from a set A to a set B is a (1) of (2) .
 A binary relation on a set A is a (3) of (4) .
 There are (5) different relations on a set with n elements.
 (a, b)  R means a (6) b.
 (a, b)  R if and only if (b, a)  (7) .
 (a, b)  R if and only if (a, b)  (8) .
 If R is a relation on the set A and for every element a in A, (a, a)  R, then R is called
(9) .
 If there are some element a in A such that (a, a)  R, then R is (10) .
 If there are some a, b, c in A such that aRb, bRc and (11) , then R is not transitive.
 A relation on a set A is called a/an (12) if it is reflexive, symmetric and transitive.

2
Answer: (1) subset (2) AB (3) subset (4) AA (5) 2n
(6) aRb (7) R-1 (8) R (9) reflexive (10) not irreflexive (11) a R c
(12) equivalence relation

Multiple choice questions

1. If R = {(a, b), (b, c), (c, c)}, how many ordered pairs are there in R2?
a. 1 b. 2 c. 3 d. 4 e. none of these
Answer: 3
Comment:
 R2 is RR.
 (a, b)R and (b, c)R  (a, c)R2, etc.
 R2 = {(a, c); (c, c); (b, c)}.
2. A company makes four kinds of products. Each product has a size code, a weight code,
and a shape code. The following table shows these codes:
Size Code Weight Code Shape Code
42 27 42
27 38 13
13 12 27
42 38 38
Which of the three codes is a primary key?
a. size code
b. weight code
c. shape code
d. No primary key
Answer: shape code

3. If X = (Fran Williams, 617885197, MTH 202, 248B West), find the projection P1,3(X).
a. (Fran Williams, MTH 202)
b. (617885197, 248B West)
c. (Fran Williams, 617885197)
d. None of these
Answer: (Fran Williams, MTH 202)
Comment:
 The projection P1,3(X) helps us to keep the 1st and 3rd components of X and
delete the other components in the 5-tuples X.

4. Suppose R = {(a, b), (b, b), (c, a)} and S = {(a, c), (b, c)} are relations on {a, b, c}.
Construct RS.
a. {(a, c); (b, c)}
b. {(a, a); (b, a)}
c. {(a, a); (b, a); (b, c)}
d. None of these

Answer: {(a, a); (b, a)}


Comment:
 If xSy, yRz, then x(RS)z.
 (a, c)S and (c, a)R  (a, a)( RS)

5. Let R = {(x, y) | x – y = 5 or y = x + 5} and S = {(x, y) | x – y = 5} be relations on the set


of integers. Which relation(s) is(are) symmetric?

a. R
b. S
c. None
d. Both

Answer: R
Comment:
 Consider the relation S: (8, 3)S (due to 8 – 3 = 5) but (3, 8) S (due to 3 – 8 
5)  S is not symmetric  not b, d.
 Consider R: you can see if (8, 3) R (due to 8 – 3 = 5 – the 1st condition) then (3,
8) R (due to 8 = 3 + 5 – the 2nd condition)
 If (x, y)R then x – y = 5 or y = x + 5  y = x + 5 or x – y = 5  y – x = 5 or x
= y + 5  (y, x) R  R is symmetric.

6. Given a matrix of a relation R

Consider the statements:


(i) R is anti-symmetric
(ii) R is reflexive
Which one is true?

a. (i)
b. (ii)
c. None
d. Both

Answer: Both
Comment:
 a[i, i] = 1 for every index i  R is reflexive.
 Cannot find i  j such that a[i, j] = 1 and a[j, i] = 1  R is anti-symmetric.

7. Given a matrix of a relation R


1 1 0 0
0 0 1 0 
MR  
0 0 1 1
 
1 1 1 1
Consider the statements:
(i) R is reflexive
(ii) R is antisymmetric
Which one is true?

a. (i)
b. (ii)
c. None
d. Both
Answer: None
Comment:
 a[2, 2] = 0 for every index i  R is not reflexive.
 a[4,3] = a[3,4]  not anti-symmetric.
1 1 1 0 
1 1 1 1 
8. If M R    , determine if R is (a) reflexive (b) symmetric (c) antisymmetric.
0 1 1 0 
 
1 0 0 1 

a. Yes, no, yes


b. Yes, no, no
c. No, yes, yes
d. No, no, yes
e. None of the others

Answer: Yes, no, no


Comment:
 a[i, i] = 1 for every index i  R is reflexive  not c, d.
 a[3,2] = a[2,3]  not anti-symmetric  not a.
 a[3,1]  a[1,3]  not symmetric.

9. Which of these binary relations on the set {1, 2, 3, 4} are equivalence relations?
R = {(1, 1), (1, 2), (2, 1), (2, 2), (3, 1), (1, 3), (4, 4)}
S = {(1, 1), (1, 2), (2, 1), (2, 2), (3, 3), (4, 4)}
a. S
b. R
c. Both
d. None

Answer: S
Comment:
 Check for reflexive property: (3, 3)R  R is not reflexive  R is not an
equivalence relation.
 S is reflexive, symmetric and transitive  S is an equivalence relation.

10. How many ordered pairs in the equivalence relation corresponding to the partition {a},
{b, d}, {c} of {a, b, c, d}?
a. 3
b. 4
c. 5
d. 6
e. None of the others

Answer: 6
Comment:
 {a}, {b, d}, {c} are classes of this equivalence relation.
 The relation must contain (a, a), (b, b), (c, c), (d, d) (due to reflexive property)
 The relation must contain (b, d), (d, b) (due to symmetry and b, d are in the
same class).

11. How many different binary relations from {a, b, c} to {1, 2}?

a. 6
b. 8
c. 9
d. 26
e. None of these

Answer: 26
Comment:
 Every binary relation from {a, b, c} to {1, 2} is a subset of {a, b, c}  {1, 2}.
 {a, b, c}  {1, 2} = {(a, 1), (a, 2), (b, 1), (b, 2), (c, 1), (c, 2)}.
 Count the ways to choose a subset of the set {(a, 1), (a, 2), (b, 1), (b, 2), (c, 1),
(c, 2)}.
 By product rule in basic counting techniques, there 222222 = 26 ways.

12. How many different binary relations on {a, b} that contains (a, b)?

a. 1
b. 8
c. 4
d. 16
e. None of these

Answer: 8
Comment:
 Every binary relation on the set {a, b} is a subset of {a, b}  {a, b}.
 {a, b}  {a, b} = {(a, a), (a, b), (b, a), (b, b)}.
 Count the ways to choose a subset of the set {(a, a), (a, b), (b, a), (b, b)}.
 The subset (binary relation) you choose must contain (a, b).
 By product rule in basic counting techniques, there 2122 = 8 ways.
Concept review – Chapter 9- GRAPHS
 A/an (1) graph is an undirected graph with no multiple edges or loops.
 Two vertices are called (2) if there is an edge between them.
 An edge is (3) with a vertex if the vertex is an endpoint of that edge.
 (4) of a vertex in an undirected graph is the number of edges incident with this
vertex with loops counted twice.
 A/an (5) is a path that does not contain an edge more than once.
 A/an (6) is a path of length n ≥ 1 that begins and ends at the same vertex.
 A/an (7) graph is the undirected graph with n vertices where each pair of vertices is
connected by an edge.
 Graph Km,n has (8) edges and (9) vertices.
 Graph Wn has (10) edges and (11) vertices.
 A matrix representing a graph using the adjacency of vertices is called (12) of the
graph.
 A matrix representing a graph using the incidence of edges and vertices is called (13)
of the graph.
 A graph with vertex set that can be partitioned into subsets V1 and V2 so that each edge
connects a vertex in V1 and a vertex in V2 is called a/an (14) graph.
 A circuit that contains every edge of a graph exactly once is called a/an (15) .
 A simple path in a graph that passes through each vertex exactly once is called a/an (16).
Answer: (1) simple (2) adjacent (3) incident (4) degree (5) simple path
(6) circuit (7) connected (8) m.n (9) m + n (10) 2n (11) n +1
(12) adjacency matrix (13) incidence matrix (14) bipartite (15) Euler
circuit (16) Hamilton path

Multiple choice questions

1. How many edges are there in an undirected graph with degree sequence 5, 5, 4, 3, 2,
1, 1, 1, 0?

a. 21
b. 20
c. 10
d. 11
e. No such a graph.

Answer: None
Comment:
The sum of degrees of all vertices in a undirected graph = 2*(the number
of edges)
 (5 + 5 + 4 + 3 + 2 + 1 + 1 + 1 + 0) = 2*(the number of edges)
2. Which degree sequence corresponds to a simple graph?

(i) 5, 4, 3, 2, 1
(ii) 5, 5, 4, 2, 1, 1
a. (i)
b. (ii)
c. None
d. Both

Answer: None
Comment:
 Study (i), 3 vertices of odd degrees  no such a graph.
 Two vertices of degree 5  each of other vertices (4 vertices) has at least
degree 2  (ii) is impossible to be a degree sequence of a simple graph (a
graph with no loop, no multiple edge).

3. Which graph corresponds to the following adjacency matrix?

a. K6
b. C6
c. W6
d. Q3
e. None of these
Answer: K6
Comment:
 An adjacency matrix has the size of nn, where n is the number of
vertices.
 The size of the matrix is 66  the graph has 6 vertices.
 Q3 has 8 vertices, W6 has 7 vertices.
 From the matrix, vertex 1 is adjacent to each of vertices {2, 3, 4, 5, 6} 
the matrix is not for C6.
4. How many 1-entries in the adjacency matrix of graph K3,5?

a. 15
b. 30
c. 8
d. None of these

Answer: 30
Comment:
 K3,5 is a complete bipartite graph with 8 vertices.
 K3,5 has 3*5 = 15 edges.
 Number of 1s = 2*number of edges.
 Adjacency matrix of K3,5 is
1 2 3 4 5 6 7 8
1 0 0 0 1 1 1 1 1
2 0 0 0 1 1 1 1 1 
3 0 0 0 1 1 1 1 1
 
4 1 1 1 0 0 0 0 0
5 1 1 1 0 0 0 0 0
 
6 1 1 1 0 0 0 0 0
7 1 1 1 0 0 0 0 0
 
8 1 1 1 0 0 0 0 0 

5. Cn is bipartite if and only if

a. n is an integer.
b. n is an even integer.
c. n is an odd integer.
d. No such n.
Answer: n is an even integer
Comment:
 Let use two colors to color every vertex of Cn.
 Try with C4, C5 to see a conclusion.

6. Are these two graphs isomorphic?


a. Two graphs are isomorphic.
b. Two graphs are not isomorphic. The first graph has a triangle, the second one has
no.
c. Yes, they have the same number of vertices and edges.
d. Two graphs are not isomorphic. Two graphs do not have the same shapes.

Answer: Two graphs are isomorphic


Comment:
 A bijection: d-6 e-5 g-1 f-2 c-3 a-7 b-4
 Try to find a “special thing” that one graph has but the other graph has not.
7. Consider the graph shown below.
(i) Does it have an Euler circuit?
(ii) Does it have an Euler path?

a. (i) Yes (ii) Yes


b. (i) Yes (ii) No
c. (i) No (ii) Yes
d. (i) No (ii) No

Answer: Yes – Yes


Comment:
 Every vertex of this graph has even degree  yes for (i).
 Yes for (i)  Yes for (ii)

8. Consider the graph shown below.


(i) Does it have a Hamilton circuit?
(ii) Does it have a Hamilton path?
a. (i) Yes (ii) Yes
b. (i) Yes (ii) No
c. (i) No (ii) Yes
d. (i) No (ii) No

Answer: No – Yes
Comment:
 Yes for (i)  Yes for (ii)
 A Hamilton path: h-i-d-e-a-c-b-g-k-l-m-j-f

9. Consider the graph shown below.


(i) Does it have a Hamilton circuit?
(ii) Does it have a Hamilton path?

a. (i) Yes (ii) Yes


b. (i) Yes (ii) No
c. (i) No (ii) Yes
d. (i) No (ii) No
10. Consider the graph shown below.
(i) Does it have an Euler circuit?
(ii) Does it have an Euler path?

a. (i) Yes (ii) Yes


b. (i) Yes (ii) No
c. (i) No (ii) Yes
d. (i) No (ii) No

Answer: No – No
Comment:
 Yes for (i)  Yes for (ii)
 No for (ii)  No for (i)
 If there is at least one vertex of odd degree  No for (i)
 The graph has 4 vertices of odd degree  No for (ii)

11. Find the length of an Euler circuit in the graph K9 or state that K9 has no an Euler
circuit.

a. 18
b. 9
c. 45
d. 36
e. K9 has no an Euler circuit.

Answer: 36
Comment:
 K9: a simple graph with 9 vertices of degree 8.
 EVERY VERTEX has EVEN DEGREE  K9 has an Euler circuit.
 The length of a path = number of edges.
 K9 has C92  36 edges.
 An Euler circuit is a circuit that passes through every edge exactly once 
An Euler circuit in K9 passes through 36 edges of K9, exactly once for
each.

12. Which graphs given by adjacency matrices below are bipartite?

G H
a. G
b. H
c. Both
d. None
Answer: H
Comment:
 Color each of 4 vertices of the graph, start form an arbitrary vertex (e.g.,
vertex 1).
 Use two colors (Red, Blue) (or two states 0, 1).
 Adjacent vertices  different colors/states.
 Check out the adjacency of vertices of the same color.
 Let consider the graph G:
vertex 1 2 3 4
Color/state Red Blue Red Blue
So, {2, 4} are vertices of the same color.
Let check out the adjacency of vertices 2 and 4  vertex 2 and vertex 4
are adjacent  G is NOT bipartite.

13. List all positive integers m and n such that Km,n has a Hamilton circuit.

a. m = n.
b. m = n > 1.
c. |m – n| = 1.
d. m and n are even.
e. None of these

Answer: m = n > 1
Comment:
 There is NO criteria to know whether a graph has a Hamilton circuit.

14. Find the length of an Euler circuit in the graph W7 or state that it has no an Euler
circuit.

a. 7
b. 8
c. 14
d. W7 has no an Euler circuit.

Answer: d
Comment:
 To have an Euler circuit, a graph must be connected and EVERY
VERTEX of this graph has EVEN DEGREE.
 A graph with at least one vertex of ODD DEGREE  has no an Euler
circuit.
 W7: a wheel with a center (degree 7) and 7 other vertices (degree 3).

15. How many cut vertices does the graph below have?

a. 0
b. 1
c. 2
d. 3
e. 4

Answer: 4
Comment:
 A vertex is called cut vertex if deleting this vertex makes a disconnected
graph.
 Cut vertices are b, c, e, i.

16. How many paths of length 2 from a to c in the graph below?

a. 3
b. 6
c. 9
d. 12

Answer: 6
Comment:
 Let A be the adjacency matrix of the given graph.
 To count the number of path of length 2, you have to compute A2.
 You can only do this: multiply <row a> of A by <column c> of A.

17. How many paths of length 3 from b to c?

a. 27
b. 9
c. 28
d. 32
e. None of these

Answer: 28
Comment:
 Let A be the adjacency matrix of the given graph.
 To count the number of path of length 3, you have to compute A3.
 To see the result, read the number at the (row b, column c)-entry.
 You can only do this: multiply <row b> of A2 (respectively, A) by
<column c> of A (respectively, A2).

18. Use Dijkstra's Algorithm to find the shortest path length from a to z in the following
weighted graph. How many vertices are not used?

a. 1
b. 2
c. 3
d. 4
e. None of these

Answer: 1
Comment:
 The shortest path is a-b-e-d-z and b is not used.
Concept review – Chapter 10 - TREES
 A tree is a connected undirected graph with no (1) .
 An m-ary tree is a tree with the property that every internal vertex has (2) children.
 A full m-ary tree is a tree with the property that every internal vertex has (3) children.
 A tree with n nodes has (4) edges.
 A full m-ary tree with i internal vertices has (5) nodes and (6) leaves.
 A code that has the property that the code of a character is never a prefix of the code of
another character is called a (7) .
 (8) is a listing of the vertices of an ordered rooted tree defined recursively - the root is
listed, followed by the first subtree, followed by the other subtrees in the order they occur
from left to right.
 (9) is the form of an expression obtained from a preorder traversal of the tree
representing this expression.
 (10) is the form of an expression obtained from a post-order traversal of the tree
representing this expression.

Answer: (1) simple circuit (2) exactly 2 (3) exactly m (4) n – 1 (5) mi + 1
(6) (mi + 1 – i) (7) prefix code (8) Preorder traversal (9) Prefix
notation/form (10) Postfix notation/form

Multiple choice questions

1. A full binary tree with 99 internal vertices has ____ edges.


a. 99
b. 198
c. 100
d. 199
e. 98

Answer: 198
Comment:
 Number of edges = number of nodes – 1 = n – 1.
 “Binary” means m = 2.
 Solve the system n = i + l (for every tree) and n = mi + 1 (for full m-ary
tree only) where n (l, i) stands for number of nodes (leaves, internal
nodes).

2. A full 5-ary tree with 45 leaves has ____ internal vertices.


a. 11
b. 12
c. 13
d. 14
e. None of these

Answer: 11
Comment:
 Solve the system n = i + l (for every tree) and n = mi + 1 (for full m-ary
tree only) where n (l, i) stands for number of nodes (leaves, internal
nodes).

3. Construct a binary search tree for the words: TIME, AND, TIDE, WAIT, FOR, NO,
MAN. How many comparisons are used to locate the word “MAN”?

a. 3
b. 4
c. 5
d. 6
e. None of these

Answer: 6
Comment:
 Start by adding the word “TIME” to the tree.
 The word “MAN” is also needed to compare to itself.

4. How many comparisons are used to locate the word “ending” in the binary search
tree for the words of the sentence “A bad beginning makes a bad ending”?

a. 2
b. 3
c. 4
d. 5
e. None of the others

Answer: 5
Comment:
 Start by adding the word “A” to the tree.
 The same position for the same word (A, bad).
 The word “ending” is also needed to compare to itself.

5. Which codes are prefix codes?


(i) A: 010 B: 101 C: 1101 D: 1011
(ii) A: 01 B: 111 C: 101 D: 1101

a. (i)
b. (ii)
c. None
d. Both

Answer: (ii)

Comment:

 Study the code scheme (i), 101 is for B and 101 is also a prefix of 1011,
the one is for D.

6. Which codes are prefix codes?


(i) A: 01 B: 101 C: 1101 D: 0011
(ii) A: 11 B: 1011 C: 1101 D: 1110
a. (i)
b. (ii)
c. None
d. Both

Answer: (i)
Comment:
 Study the code scheme (ii), 11 is for A and 11 is also a prefix of 1101, the
one is for C.

7. Consider the coding scheme: t: 001, e: 101, a: 11, n: 0111.


What is the message represented by 10111001?
a. tea
b. eat
c. net
d. an
e. None of these

Answer: eat
Comment:
 Start “reading” 10111001 from left to right
 101 is for e, 11 is for a, 001 is for t.

8. What is the code for the word “keep” if the coding scheme is represented by the
following tree?

a. 1000010011110
b. 1010001001111
c. 00100111101101
d. 110000100111110
e. None of these
Answer: 110000100111110 (d)
Comment:
 Start from the root to go to the leaf node.
 From the tree above, 1100 is for k, 001 is for e, 1110 is for p.

9. What is the average number of bit required to encode the word “nobody” using
Huffman coding algorithm?
a. 8/3
b. 2
c. 7/3
d. 2.5
e. None of these
Answer: 7/3
Comment:
 First, count the frequency of each character and list them in an increasing
order (n(1) b(1) d(1) y(1) o(2)).
 Construct a binary tree using Huffman algorithm.
10. What is the average number of bits required for each letter when using Huffman
coding algorithm to encode the word “success”?
a. 13/7
b. 15/7
c. 2
d. 16/7
e. None of these
Answer: 13/7
Comment:
 First, count the frequency of each character and list them in an increasing
order (u(1) e(1) c(2) s(3)).
 Construct a binary tree using Huffman algorithm.

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?
a. 3.15
b. 2.45
c. 2.25
d. 3.45
e. None of these
Answer: 2.25 bits/symbol
Comment:
 Always choose 2 trees of least weights from the forest.
 After constructing the binary tree for the given data, the number of bits for
each character is given as below: 2 bits for a, 3 bits for b, 3 bits for c, 2 bits
for d and 2 bits for e.
 Average number of bits for each character can be calculated as follow:
Ave = sum(number of bits of a character * frequency of this character) =
2*0.20 + 3*0.10 + 3*0.15 + 2*0.25 + 2*0.30 = 2.25.
12. Find the value of the expression + - 7 * 2 1 / 3 1
a. 4
b. 6
c. 8
d. 10
e. None of these

Answer: 8

Comment:
 An operator (+) is in the first position, it follows that the expression is in
prefix form.
 From right to left, find a triple in form <operator> <number 1>
<number 2> (for example, / 3 1) to compute <number 1> <operator>
<number 2>.

13. Find the value of the expression 5 4 - 3 6 3 /  7 - *.


a. 2
b. 4
c. 6
d. 8
e. None of these

Answer: 2

Comment:

 The expression is in postfix form, because the last symbol is an operator


(*).
 From left to right, find a triple in form <number 1> <number 2>
<operator> (for example, 5 4 - ) to compute <number 1> <operator>
<number 2>.

14. Find the postfix form of the infix expression (2*x + y)/(x – 3*y).

a. 2 x * y + x 3 y *- /
b. 2 *x y + x 3 /y * /
c. / + * 2 x y -x * 3 y
d. None of these

Answer: a

Comment:

 The expression includes only one /  option (b) is not true. In the postfix
form, the root node (an operator) is visited last. So, the last symbol is
always an operator (+, -, *, /, …)  option (c) is not true.
 In the expression (2*x + y)/(x – 3*y), the last operator is /, and therefore
the postfix form ends with /.
 The expression tree is shown as below

You might also like