Mcdermott 6014 Final Summer B 17
Mcdermott 6014 Final Summer B 17
Mcdermott 6014 Final Summer B 17
Summer B 2017
Final Exam
No. Tree may be complete, but the child nodes are not left-justified.
Yes. All of the leaves are at the same level, and all nodes have only 1 or 2 values.
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
Adding 10 to the tree:
Adding 8 to tree:
Adding 9 to tree:
5. (4 points) (a) Construct a max heap for the list 9, 5, 6, 10, 4, 8, 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.
(c) For the result of the question (b), insert a node with the value 7 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 1 0 1 1
3 0 0 0 0
4 1 1 1 0
R(3):
1 2 3 4
1 1 1 1 1
2 1 1 1 1
3 0 0 0 0
4 1 1 1 1
R(4):
1 2 3 4
1 1 1 1 1
2 1 1 1 1
3 0 0 0 0
4 1 1 1 1
Using Prim's algorithm, we start at a and we continue to choose the edge with the lowest value
connected to all nodes reached so far, until all nodes have been visited. Given this, the sequence
the vertices are visited is:
{a, b, d, c, e}
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 inf
d 3d 1c 1a 6d
c 3d 1c 3c
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.