Final Exam Summer A 19 Complete
Final Exam Summer A 19 Complete
Final Exam Summer A 19 Complete
Summer A 2019
Final Exam
2. (2 points) (a) Based on our class’s definition, this is a graph. (True/False) Yes
Based on the theorem, determine the time efficiency of the following formula T(n).
5. (2 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.
(a) Assuming the worst case occurs, what is the minimum number of balls you have to choose to
get a matching pair? Here, a matching pair means that there must be one large ball and one
small ball of the same color in the jar C. But the color itself of the pair is not important. Present
just the number of balls. You don’t need to explain your answer.
(b) Assuming the best case occurs, what is the minimum number of balls you have to choose to
get three matching pairs of each color (= black, red, green)? In other words, you should have
one pair of large and small black balls, one pair of large and small red balls, and one pair of large
and small green balls. Present just the number of balls. You don’t need to explain your
answer.
6 balls
(c) Assuming the worst case occurs, what is the minimum number of balls you have to choose to
get three matching pairs of each color (= black, red, green)? In other words, you should have
one pair of large and small black balls, one pair of large and small red balls, and one pair of large
and small green balls. Present just the number of balls. You don’t need to explain your
answer.
17
Note that the problem is asking to draw only one binary tree. If you can’t completely draw a
binary tree with the given information, explain why.
8. (2 points) (a) Remove the max value from the following heap.
1 2
3 4
a 5 c
4 2 3
2
b 1 d 6 e
V a b c d e
a 0a
(a) Describe the basic idea of your decrease-and-conquer (or divide-and-conquer) algorithm in
English.
Subtract n until n = 1. Return two and multiply the return by two and return again until the
algorithm has multiplied 2n
(b) Based on the basic idea of (a), write a pseudocode of your algorithm. If you want, you can
write your algorithm in C++ code.
Int twoPower(int n)
{
If(n == 1)
{
Return 2;
{
Else
{
Return 2 * twoPower(n -1);
}
}