Exam 1
Exam 1
INSTRUCTOR: HOA VU
Instructions
• This exam is open book, open notes. You are allowed to use any resource including books,
notes, and lecture notes. No collaboration. No internet or any electronic device.
• Manage your time wisely. You have 75 minutes to complete the exam. Do not get stuck on
one problem for too long.
• There are 3 parts. For part 1, circle the correct answer answer on the multiple choice
ZipGrade sheet. For parts 2 and 3 write your answer on the blank papers provided.
Figure 1. Figure 1
Recall the definition of quotient and remainder of a division. For integers a, b, if a = bq+r
where 0 ≤ r ≤ b − 1, then q is the quotient and r is the remainder when a is divided by
b. Note that r must be between 0 and b − 1. For example, if a = 7 and b = 5, then q = 1
and r = 2 since 7 = 5 × 1 + 2. When a = −7 and b = 5, then q = −2 and r = 3 since
−7 = 5 × (−2) + 3.
(5) (2 pts) Consider the directed acyclic graph in Figure 1. What is the length of the shortest
path from s to d modulo 5?
(a) 0
(b) 1
(c) 2
(d) 3
(e) 4
(6) (2 pts) Consider the directed acyclic graph in Figure 1. What is the length of the shortest
path from s to e modulo 5?
(a) 0
(b) 1
(c) 2
(d) 3
(e) 4
(7) (2 pts) Consider the directed acyclic graph in Figure 1. What is the length of the longest
path from s to c modulo 5?
(a) 0
(b) 1
(c) 2
(d) 3
(e) 4
(8) (2 pts) Consider the directed acyclic graph in Figure 1. What is the length of the longest
path from s to d modulo 5?
(a) 0
(b) 1
(c) 2
(d) 3
(e) 4
(9) (2 pts) It is not possible to compute the product of two n × n matrices using fewer than
Θ(n3 ) operations.
(a) True
(b) False
CS 660, EXAM 1 3
(10) (4 pts) Consider two strings A[1 . . . n] and B[1 . . . m] where A[n] = B[m]. Let ed[i, j]
be the edit distance between A[1 . . . i] and B[1 . . . j]. Suppose that ed[n − 1, m] = 90,
ed[n, m − 1] = 101, ed[n − 1, m − 1] = 88. What is the value of ed[n, m]?
(a) 91
(b) 102
(c) 99
(d) 100
(e) None of the above.
(11) (4 pts) Consider an n × n board with some given dark squares. Starting at the top left,
at each step you can move down or to the right without crossing a dark square. Your goal
is to count the number of paths from the top left to the bottom right. For example, the
number of paths for the board below is 3 ((down, down, right, right), (down, right, down,
right), (down, right, right, down)).
How many paths are there for the board below modulo 5?
(a) 0
(b) 1
(c) 2
(d) 3
(e) 4
(12) (2 pts) Consider the AVL tree in Figure 2. After inserting 150, what is the parent of 100?
(a) 150
(b) 50
(c) 200
(d) 20
(e) None of the above.
(13) (2 pts) Consider the AVL tree in Figure 2. After deleting 40, what is the parent of 100?
(a) 50
(b) 20
(c) 200
(d) 10
(e) None of the above.
(14) (2 pts) Consider the graph in Figure 3. What is the weight of the minimum spanning tree
modulo 5?
(a) 0
4 INSTRUCTOR: HOA VU
(b) 1
(c) 2
(d) 3
(e) 4
(15) (2 pts) The edge cb must be in some minimum spanning tree of the graph in Figure 3.
(a) True
(b) False
after performing swaps. Your algorithm should run in O(m log n + n log n) time. Consider
using a data structure that we covered in class. Justify the running time. If you come
up with an algorithm that is correct using the above observation but does not run in the
required time, you will receive partial credit.