Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Final Exam Summer A 19 Complete

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 9

CST 370 Design and Analysis of Algorithms

Summer A 2019
Final Exam

Name: Sean Figel

Four-digits ID: 0507

 Test time is 2 hours and 30 minutes.


 Note that there are 12 problems in the final exam.
 This is a closed book exam. You can’t use a calculator during the
exam. However, as a reference during the exam, you can prepare “two
pages (= total of 4 sides)” cheat sheet. The cheat sheet can be typed or
hand-written.
 If possible, enter your answers directly into the Word file to increase the
readability of your answers. However, if it is too difficult or time
consuming to type in a Word file, please write down your answer on
paper. Then, take a picture and insert the picture into the Word file.
 During the exam, you must sign into the Zoom session and turn on the
video and turn off the audio. We will record the whole zoom session.
 If you have a question during the exam, please use "Chat" in Zoom. I will
answer as soon as possible.
 When you finish the exam, submit your Word file (and an optional PDF
file) on the iLearn. But keep the Word file well in case we need it.
 Use your time wisely—make sure to answer the questions you know first.
 Read the questions carefully.

CST370 Page 1 of 9 Final Exam


1. (1 point) Assume that Dr. Byun assigned a programming project which requires the time
complexity of O(n2). If your program’s basic operation runs (n*logn + 2*n + 75) times, can you
say that your program meets the project requirement? (Yes/No). Yes

2. (2 points) (a) Based on our class’s definition, this is a graph. (True/False) Yes

(b) This is an AVL tree. (True/False) No

(c) This is a max heap. (True/False) No

3. (1 point) Consider the following master theorem:


T(n) = aT(n/b) + f (n) where f(n)  (nd), d  0

Master Theorem: If a < bd, T(n)  (nd)


If a = bd, T(n)  (nd log n)
If a > bd, T(n)  (nlogba )

Based on the theorem, determine the time efficiency of the following formula T(n).

(a) T(n) = 2 * T(n/2) + n2

(b) T(n) = 4 * T(n/2) + 5n

CST370 Page 2 of 9 Final Exam


4. (3 points) Solve the following recurrence relation using the backward substitution as we
learned in the class. In the problem, you should present the intermediate steps and time
complexity of the recurrence relation.

M(n) = 2 * M(n − 1) + 2, for n > 0 // recurrence relation

M(1) = 2 // initial condition

5. (2 points) Draw all possible AVL trees with 4 nodes of the key values 10, 15, 20, and 25 that
satisfy the balance requirement of AVL trees.

CST370 Page 3 of 9 Final Exam


6. (3 points) Suppose you have three jars, A, B, and C, in a room. Jar A has 5 large black balls, 3
large red balls, and 2 large green balls. Jar B has 4 small black balls, 3 small red balls, and 2
small green balls. Jar C is empty. Thus, there are total 19 balls. Now, you will pick a few balls
from the jar A in the dark and place them in the jar C. After that, you will pick a few balls from
the jar B in the dark and place them in the jar C. Note that the color of the selected balls at the jars
A and B can not be confirmed because the surroundings are dark. Also, the numbers of balls
selected from the jars A and B need not always be the same. Once you're done, you can turn on
the lights in the room and see the balls in the jar C.

(a) Assuming the worst case occurs, what is the minimum number of balls you have to choose to
get a matching pair? Here, a matching pair means that there must be one large ball and one
small ball of the same color in the jar C. But the color itself of the pair is not important. Present
just the number of balls. You don’t need to explain your answer.

9 balls need to be pulled, 8 from Jar B and 1 from Jar A.

(b) Assuming the best case occurs, what is the minimum number of balls you have to choose to
get three matching pairs of each color (= black, red, green)? In other words, you should have
one pair of large and small black balls, one pair of large and small red balls, and one pair of large
and small green balls. Present just the number of balls. You don’t need to explain your
answer.

6 balls

(c) Assuming the worst case occurs, what is the minimum number of balls you have to choose to
get three matching pairs of each color (= black, red, green)? In other words, you should have
one pair of large and small black balls, one pair of large and small red balls, and one pair of large
and small green balls. Present just the number of balls. You don’t need to explain your
answer.

17

CST370 Page 4 of 9 Final Exam


7. (2 points) Draw a binary tree with ten nodes labeled 0, 1, 2, ..., 9 in such a way that the inorder
and preorder traversals of the tree yield the following lists:
6, 7, 9, 4, 8, 1, 5, 0, 2, 3 (inorder)
5, 4, 7, 6, 9, 1, 8, 2, 0, 3 (preorder).

Note that the problem is asking to draw only one binary tree. If you can’t completely draw a
binary tree with the given information, explain why.

8. (2 points) (a) Remove the max value from the following heap.

(b) Add 55 to the following heap.

CST370 Page 5 of 9 Final Exam


9. (2 points) Apply the Warshall’s algorithm to get the transitive closure of the digraph defined by
the following graph. Present R(0), R(1), R(2), R(3), and R(4) as we discussed in the class.

1 2

3 4

CST370 Page 6 of 9 Final Exam


10. (3 points) Assume that you are going to solve the MST (Minimum Spanning Tree) problem
using the Prim’s algorithm for the following graph. Draw the final MST. For the problem, you
have to start from the vertex a. You must also provide the sequence of vertices to be added to the
"visited" set as we covered in the class.

CST370 Page 7 of 9 Final Exam


11. (3 points) Assume that you are going to solve the single-source shortest-paths problem using
the Dijkstra’s algorithm for the following graph. For the problem, you should start from the
vertex a. Fill out the table as you learned in the class.

a 5 c

4 2 3
2

b 1 d 6 e

V a b c d e
a 0a

CST370 Page 8 of 9 Final Exam


12. (3 points) Assume that you want to calculate 2n where n is a positive integer using a
decrease-and-conquer (or divide-and-conquer) algorithm. For example, if the algorithm
receives an input value 3 for n, it should return 8 (= 23). As another example, if the algorithm
receives an input value 1, it should return 2 (= 21).

(a) Describe the basic idea of your decrease-and-conquer (or divide-and-conquer) algorithm in
English.
Subtract n until n = 1. Return two and multiply the return by two and return again until the
algorithm has multiplied 2n

(b) Based on the basic idea of (a), write a pseudocode of your algorithm. If you want, you can
write your algorithm in C++ code.

Int twoPower(int n)
{
If(n == 1)
{
Return 2;
{
Else
{
Return 2 * twoPower(n -1);
}
}

CST370 Page 9 of 9 Final Exam

You might also like