You are on page 1of 6

1.

(5 points) Draw a binary search tree with 9 nodes labeled 10, 15, 20, 23, 25, 30, 35, 39, 42 in such a way that
the preorder traversals of the tree yield the following lists:

30, 20, 10, 15, 25, 23, 39, 35, 42

If you can’t completely draw a binary search tree with the given information, explain why.

2. (5 points) Add 80 to the following heap. After adding the node, show intermediate diagrams (if any) that
make it a heap again
6. (15 points) Consider an AVL tree as below.

(a) Add a vertex with the value 15 to the above AVL tree. If there is a rotation, you should present it
clearly.

Answer: No rotation, see picture for tree answer


(b) To your solution of the question (a), add a vertex with the value 20. If there is a rotation, you should
present it clearly.

Answer: Left rotation, see picture for tree answer


(c) To your solution of the above question (b), add a vertex with the value 14. If there is a rotation, you
should present it clearly.
Answer: No rotation, see picture for tree answer
7. (5 points) Construct a heap for the list 1, 8, 6, 5, 3, 7, 4. You should assume that the numbers are given in that
order and use the bottom-up approach.
8. (10 points) Assume that you are constructing a heap with five nodes 10, 20, 30, 40, and 50. But you don’t
know the input order of the numbers. Draw all possible different heaps with the five nodes that satisfy the
requirement of a heap.

9. (10 points) Is the following tree a binary tree? If so, is it a binary search tree?

Answer:

It is a binary tree as each node has at most 2 children.


It is NOT binary search tree as the binary tree is not sorted, as nodes that are greater then root node 10 are not at
the right subtree of node 10.

10. (5 points) Assume a binary tree with six vertices such as v1, v2, v3, v4, v5, and v6. Determine the maximum
number of edges possible in the tree.

|E| = |V|-1 = 6-1 = 5

11. (5 points) The preorder traversal sequence of a binary search tree is 30, 20, 10, 15, 25, 23, 39, 35, 42. Which
one of the following is the postorder traversal sequence of the same tree? Explain your answer.

(c) 10, 20, 15, 23, 25, 35, 42, 39, 30


(ci) 15, 10, 25, 23, 20, 42, 35, 39, 30
(cii) 15, 20, 10, 23, 25, 42, 35, 39, 30
(ciii) 15, 10, 23, 25, 20, 35, 42, 39, 30
Answer: d. Postorder = left-right-root. => first two nodes would be 15(right) and 10(last left subtree root). Last
nodes would be last left node of right subtree (35), right node of right subtree (42), root of right subtree(39), tree
root (30).

12. Consider True/false:


13. (5 points) Construct an AVL tree for the list C, S, U, M, B, G, O. Insert each letter successively starting with
the empty tree. Use alphabetical order when inserting a letter. Your answer should present the rotation operations
(if necessary) for each letter insertion.

You might also like