You are on page 1of 11

CST 370 Design and Analysis of Algorithms

Summer B 2017
Final Exam (Makeup)

Name: Faiga Revah

Four-digits ID: 7070

Test time is 2 hours and 30 minutes.


Note that there are 10 problems in the exam.
This is a closed book exam. You cant 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-writ-
ten.
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 con-
suming to type in a Word file, 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 midterm Zoom session and turn
on the video. We will record the video. However, turn off the audio on
your computer.
If you have a question during the exam, please use "Chat" in Zoom. I will
answer.
When you finish the exam, submit your Word file (and PDF file) on the
iLearn. But keep the Word file well in case we need it.
Use your time wiselymake sure to answer the questions you know first.
Read the questions carefully.

CST370 Page ! 1 of 11
! Final (Summer B)
1. (3 points) (a) Is this an AVL tree? (Yes/ No)

(b) Is this a max heap? (Yes/ No)

(c) Is this a 2-3 tree? (Yes/ No)

CST370 Page ! 2 of 11
! Final (Summer B)
2. (3 points) Consider an AVL tree as below. Add the following nodes to the tree. You should
present each step clearly.

10, 11, 8, 9

7
2

CST370 Page ! 3 of 11
! Final (Summer B)
3. (3 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 ! 4 of 11
! Final (Summer B)
4. (2 points) Draw a sample 2-3 tree of height 2 with the largest number of key values. In your
answer, the tree should have integer values such as 10, 20, 30, etc. Note that a tree with only one
node (= root node) has the height zero.

5. (4 points) (a) Construct a max heap for the list 7, 5, 6, 10, 4, and 3. You should assume that the
numbers are given in that order and use the bottom-up approach covered in the class. For the
problem, you dont need to describe the intermediate results. A final result is good enough.

(b) For the result of question (a), delete the maximum value and draw the updated heap.

(c) For the result of the question (b), insert a node with the value 8 and draw the updated heap.
See above

CST370 Page ! 5 of 11
! Final (Summer B)
6. (3 points) Apply the Warshalls 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 11
! Final (Summer B)
7. (3 points) Assume that you are going to solve the MST (Minimum Spanning Tree) problem
using the Prims 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 11
! Final (Summer B)
8. (3 points) Assume that you are going to solve the single-source shortest-paths problem using
the Dijkstras algorithm for the following graph. For the problem, you should start from the ver-
tex a. Fill out the table as you learned in the class.

5
a c

7 1 3
1
3 6
b d e
!

V a b c d e
a 0a 7a 5a 1a inf.
D 4d 2d 1a 7d
C 4d 2d 5c
4d 5c

CST370 Page ! 8 of 11
! Final (Summer B)
5c

CST370 Page ! 9 of 11
! Final (Summer B)
9. (3 points) Two missionaries and two cannibals must cross a river. Their boat can only hold two
people. If present, missionaries cannot be outnumbered by cannibals. How can all four get across
the river with the fewest crossings? Note that we covered this puzzle in the class. But at that time,
we solved the puzzle of six persons. But this problem is about 4 persons, and you have to present
the minimum number of crossings. And also, you should draw a diagram to explain your an-
swer clearly. If the instructor cant under your diagram, you will not get the full credits. If its not
possible for the four persons to cross the river, indicate it clearly.

There are five minimum crossings.

CST370 Page ! 10 of 11
! Final (Summer B)
10. (3 points) Suppose you have a max heap. Design an efficient algorithm to find and delete an
arbitrary element of a value v in the max heap. After that, you have to present the time efficiency
of each operation (= find and delete). You should write your answer in English step-by-step so
that the instructor can understand your idea clearly.

//Algorithm SearchAndDelete(int x, int heapSize)


//input: an integer x to find in heap[1heapSize]
Int i = 1
Bool notFound = true
while(notFound)
{
if(heap[i] == x)
{
heap[i] = heap[heapSize]; //take the last element, and heapify
heapSize;
heapify();
notFound = false;
}
i++;
}

Time efficiency of find= O(n)


Time efficiency of search = O(log n)

CST370 Page ! 11 of 11
! Final (Summer B)

You might also like