Leftover questions could be used from review sheet

advertisement
EECS 560
Test 1 Review sheet
Spring 2014
Here are some questions from old exams to give you an idea of what may appear on test 1.
The set of problems is not intended to be all inclusive. That is, you are responsible for all
topics covered in class even if there is no question about that topic below.
1. Suppose you have a 5-ary tree of height k.
a. What is the maximum number of nodes in the tree?
b. What is the minimum number of nodes in the tree?
2. In the best case, what is the number of swaps made by selection sort on a list of length n?
3. In the best case, what is the complexity of selection sort on a list of length n?
4. If f(n) = O(g(n)) then, lim f(n)/g(n) is a. 0 b. a constant c. n d.  e. impossible to determine
n 
5. You are doing a binary search for 26 in the list below. Specify, in order, which elements of
the list are examined by the search. Assume the comparison operator is >
1 3 6 8 14 15 18 20 22 25 27 29 30
6. Describe the divide and conquer algorithm to solve the maximum subsequence sum
problem and state the recurrence relation for this algorithm.
7. Set up and solve the summation that, when solved, will determine the value of x when the
function below terminates. You may assume n is even.
x0
for i  2 to n step 2
for j  1 to i
xx+1
8. The following recursive algorithm is used to find the largest element in an array A containing n
elements. To make things simple, assume n = 3k.
1. Divide the list into thirds
2. Find the largest element in each third of the list
3. Return the largest of the three elements found in step 2
a. Given three numbers, how many comparisons are needed to find the largest of them?
b. Initially the list occupies positions 1 to n in an array. In terms of n, what is the left
endpoint of the second search interval?
c. Find and solve the recurrence relation for the number of comparisons performed by the
algorithm.
9. Find the average case complexity for a linear search for item x on a list of length n if the
probability x is in the first half of the list is ½, the probability it is on the second half is 1/3.
10. What is the smallest number of keys that when inserted in an appropriate order will force a
2-3-4 tree to have height 2? Give an example of such a list of keys.
11. What will be the height of the red-black tree corresponding to your answer to question 10?
12. What is the largest number of keys that can be inserted in an appropriate order into a 2-3-4
tree so that the height does not exceed 2?
13. Draw an AVL tree of height 4 with the minimum number of nodes.
14. Suppose you have an AVL tree T of height k with the minimum number of nodes. What
can be said about the left and right subtrees of the root of T?
15. What is the smallest number of keys that when inserted in an appropriate order will force
an AVL tree to have height 3? Give an example of such a list of keys and draw the tree.
16. Suppose you search a binary search tree for key k and end up in a leaf. Consider three
sets: A, the keys to the left of the search path; B, the keys on the search path; and C, the
keys to the right of the search path. Claim: if aA, bB, and cC, then a  b  c. Prove or
disprove the claim.
17. Consider the optimal binary search tree algorithm. Suppose you find out that the optimal
tree has key k as its root. If the tree contains a total of 20 nodes what keys are in the left
and right subtrees?
Other topics are: other algorithms for the maximum subsequence sum problem; selection and
insertion sort algorithms and their analysis; sequential and binary search algorithms; binary
search trees; optimal binary search trees; insertion and deletion for AVL trees, splay trees, and
2-3-4 trees; complexity of operations on the BST variations.
Download