Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Summer B 2017
Final Exam
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
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.
(b) For the result of question (a), delete the maximum value and draw the updated heap.
1 2
3 4
R(0)
1 2 3 4
1 0 1 0 0
2 0 0 0 1
3 0 0 0 0
4 1 0 1 0
R(1)
1 2 3 4
1 0 1 0 0
2 0 0 0 1
3 0 0 0 0
4 1 1 1 0
R(2)
1 2 3 4
1 0 1 0 1
2 0 0 0 1
3 0 0 0 0
4 1 1 1 1
R(3)
1 2 3 4
1 0 1 0 1
2 0 0 0 1
3 0 0 0 0
4 1 1 1 1
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.
ABDEC
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
vertex a. Fill out the table as you learned in the class.
a 5 c
7 1 3
1
b 3 d 6 e
V a b c d e
a 0a 7a 5a 1a
b 2d 1a
c 2d 6c 8c
d 1a
e 7d
6 trips
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.
Once it found the value it must delete that value and replace for the bottom right element in the
array.
Once it switched the values it much verify it is still max heap and replace values if necessary.