CS 361: Test #2

This is a take-home test; return it to me (hardcopy or email) by Friday, May 12, 5pm. The test is open book, open notes. You may not talk about any of the questions with anyone except me and the TA. There are four questions of equal weight.



Problem 1. If you use a hash table for a compiler (to store the symbol table), successful searches are the rule. Thus we may want to improve the behavior of successful search and ignore unsuccessful search. The choice at each collision to bounce over the existing item or to dislodge it and send it bouncing away was made in ordered hashing on the basis of key values; but we could instead make that choice on the basis of the length of resulting probe sequences so as to minimize the length of probe sequences.

Design a simple scheme that uses this idea. How expensive can an insertion become? Does the scheme affect the handling of deletions? Does the scheme reduce the worst-case number of probes needed in successful search? (The scheme appears to reduce the average number of probes for successful search by up to 50\% for heavily loaded tables.)


Problem 2. Design a linked implementation of the standard binary heap; the heap retains its properties about heap ordering and about having all leaves on 1 or 2 adjacent levels, with the second level packed to the left. Show how to implement insert and deletemin. Discuss whether melding is now possible.

Problem 3. Suppose you want a priority queue that allows you to carry out efficiently (in logarithmic time) both deletemin and deletemax. Using standard structures discussed in class, present two different designs for such a minmax priority queue. (If you would rather design a new structure, that is fine, but probably a lot more work.)

Problem 4. We want to be able to search for an item given its key (regular dicitionary), but also want to be able to find the k-th element in the ordering when given k as an input as well as answer queries of the form "how many elements are there that have a key smaller than x?" We can do both of these in logarithmic time by adding one extra field to each node of a (balanced) binary search tree. What would you store in this field and how would you use it?