Professional Documents
Culture Documents
Summer B 2017
Final Exam (Makeup)
CST370 Page ! 1 of 11
! Final (Summer B)
1. (3 points) (a) Is this an AVL 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.
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.
CST370 Page ! 11 of 11
! Final (Summer B)