SECOND MIDTERM (with SOLUTIONS)
ANSWER: TRUE, by information-theoretic arguments, there must be at least n leaves in the comparison tree. This tree has height at least lgn.
REMARKS: Of course, lgn is very far from the truth, since we can use other arguments to prove a lower bound of n-1. Roughly, any computation that do not look at every input number cannot guarantee to find the answer. This actually gives you a lower boundn/2 comparisons. How can you improve this to n-1?
(b)
``In a certain TRUE/FALSE question, you get 5 points for correct
answer, 0 points for not attempting the question
and -3 points for an incorrect guess.
Suppose you have NO clue what the answer might be.
It is a good idea to toss a coin and answer TRUE
if head, and answer FALSE if tail.''
ANSWER: TRUE. Your expected value is (-3)(1/2)+(5)(1/2) which is equal to 1. This is better than the 0 points you would get if you do not attempt to answer the question.
|
REMARK: of course, our definition of s(N) has simply combined the range transformation and domain transformation into one step.
(b)
Prove the best upper bound you can for the following recurrence:
|
ANSWER: For a preliminary investigation of this recurrence, if you look at the term ``40 T(n/6)'' alone, Master theorem would tell you that T(n) = W(nlog6(40)). Note that log6(40) is between 2 and 3.
Let us guess that T(n) £ C na for some a that we will determine. Then, by applying real induction, we have
|
|
|
|
REMARK: Let a = a0 be the unique solution to the equation g(a) = 1. The above argument shows that we can choose a to be a0+e for any e > 0. But, can you choose a = a0? Well, case (0) of the Master theorem will suggest that you modify the induction hypothesis to
|
|
ANSWER: We choose height h = 10 because it would be impossible to enumerate or draw the AVL tree. You need to work out the general principle. But we had already seen this principle in our lectures and notes. It is closely related to the Fibonacci sequence.
Here is the answer: Let N(h) be the smallest number of nodes in an AVL tree of height h. Thus, N(0) = 1 and N(1) = 2. For h ³ 1, we have N(h+1) = 1+N(h)+N(h-1). Thus, N(2) = 1+2+1 = 4, which you can verify directly. Continuing,
|
REMARK: you get no credit if you simply show me the number "232". How do I know that you have not gotten this number by magic, or worst? ALWAYS SHOW YOUR WORKING SOMEWHERE.
(b)
Show an AVL tree of height 4, and a single deletion of a node
in this tree that will result in 2 rotations.
ANSWER: Construct a tree of height 4 with N(4) = 12 nodes. Note that N(4) is the minimum number in part (a). It is not necessary to use this minimum number, but it is the simplest example. Let u be the root of this tree, and uL and uR be its two children. Let the heights of uL and uR be 3 and 2, respectively. There is a leaf x below uR of depth 2. Delete x. This will cause a double rotation below uR. Then, you need one further rotation (either single or double, depending on the heights of the children of uL.)
REMARKS: I intended the 2 rotations to be either a ßingle rotation" or a "double rotation". Since I did not specify that "double rotation" counts as öne rotation", I gave you the benefit of the doubt. If you only use a height 3 tree, which some of you did, you cannot achieve the desire effect.
ANSWER: Each non-leaf must have at least a children, except the root can have only 2 children. Hence the number of nodes at level l = 0, 1, 2, 3, 4, ¼ (respectively) is at least
|
|
REMARKS. You get partial credit if you do not know how to put the summation in closed form. The most frequent error is not remembering that the root may have only 2 children - but you can get most of the credit even in this case.
(b)
In our homework, we discussed a method for splitting and
merging (``fusion of'') nodes in an (a,b)-tree to achieve
an utilization ratio of a/b that is more than 2/3.
Generalize the arguments to achieve a ratio of m/(m+1) for
any integer m. You must state the needed inequalities on a and b.
ANSWER: You need to ensure that a ³ m+1. Then, when you need to merge or split, you can be assured of at least a-1 ³ m siblings in which to borrow (if you are short) or share (if you are long) your keys.
In case of merging, your current node has a-1 keys. We may assume that the other m siblings has a keys each. We can combine all these a(m+1)-1 keys and split them into m new nodes. This requires
|
ANSWER: Let W be the sample space and S the event space. The first mistake is to assume W = {1,2 ,¼, 6}. In our case, we can think of each sample point as the ENTIRE history of the rolls of your dice. Let i1, i2,¼ be the result of the first, second, etc, roll. For instance, if you stop after step 2, this means you rolled (i1,i2) where i1 is unrestricted (i1 = 1 ,¼, 6) and i2 = 1. If you stop after step 3, this means you rolled (i1,i2,i3) where i1 is unrestricted, i2 ³ 2 and i3 £ 2. And so on. Then
|
|
Now, you need to define T. This is a random variable, which means T is a function from W to real numbers:
|
|
(b)
Compute the expected value of T.
ANSWER: The expected value of T is
|
|