Homework problem L on Accelerated Binomial Heaps

Problem M

Assigned Oct 21+2, due Nov 4.

B-tree select.

This problem is designed to be helpful for review for the midterm. You may find it useful to work the exercise before the exam even though it is not due until afterwards.

We know how to find the median of a set of data elements or more generally select the k-th largest of them. We studied both a probabilistic method and deterministic method. They both work in Θ(n) time, expected time for the former, worst case time for the latter. Also, if the data are sorted in an array, you can select the k-th easily in Θ(1) time. What if the data are in a somewhat ordered structure such as a b-tree or red-black tree?

  1. (8 points) Suppose a b-tree stores in each node an additional number, s[x], which is the total number of keys in that node plus all it's children. Thus s[x] - n[x] is the total number in all the subtrees excluding the n[x] keys in x itself. Give a fast algorithm for finding the median key. Presumably, the extra information will help you produce a fast algorithm. Analyze it's complexity.

    Hint: Undoubtedly, you will find it easier to design and analyze the more general select k-th largest function and then apply it to median.

  2. (2 points) A trivial change has to be made in b-tree-create, namely to set s[x] = 0. Clearly an insertion can increment s[x] in each node you visit while going down to find a leaf to put the new key in. I think the least obvious adjustment is getting the appropriate s[x]'s right in b-tree-split-child. Explain how b-tree-split-child should be modified to get these numbers right.