cos423: Theory of Algorithms handout #18
Michael Goldwasser
Princeton University Tuesday, March 31, 1998

Homework #6: Randomized Algorithms and Hashing
Due Date: Tuesday, April 7, 1998 (5:00pm)


Collaboration Policy


Work entirely on your own for all of these problems.

Reading


You should read Ch. 12.1-12.3 of CLR regarding hashing. You may review Chapter 13.4 of CLR, regarding the discussion of randomly built binary search trees.

Practice


Recall, these exercises are purely for your own practice. You need only turn in the official problems.

Problems


1.
CLR 12-5 (40 points)
Let ${\cal H} = \{h\}$ be a class of hash functions in which each h maps the universe U of keys to $\{0, 1, \ldots, m-1\}$. We say that ${\cal H}$ is k-universal if, for every fixed sequence of k distinct keys $\langle x_1, x_2, \ldots, x_k \rangle$ and for any h chosen at random from ${\cal H}$, the sequence $\langle h(x_1),
h(x_2), \ldots, h(x_k)\rangle$ is equally likely to be any of the mk sequences of length k with elements drawn from $\{0, 1, \ldots, m-1\}$.

2.
(60 points)
In class last week (and in Chapter 13.4 of the text), we saw that if you take a list of n items with distinct keys and insert them into a standard binary search tree using a random order, the expected height of the tree is $O(\lg n)$. We can use this idea to get yet another version of balanced trees. The difficulty, however, is that in a dynamic setting you cannot really assume that the items come in a random order, and you cannot afford to wait until all items arrive before building your data structure. In this problem, we will design a new method, which has expected $O(\lg n)$time for any operation in a sequence of Insert's, Delete's, and Search's.

Assume that every object x has two associated values, key[x] and priority[x]. We define a new data structure called a treap, which is a binary tree with objects stored at internal nodes, satisfying the following two properties. (we assume that keys are distinct, and that priorities are distinct)

In other words, this tree happens to be both a binary search tree on the keys, while at the same time a heap on the priorities (and hence the name treap = tree + heap).

We would like to maintain a treap dynamically through a sequence of calls to Insert, Delete, and Search, as defined below. In the following three parts, we will ask you how to implement each of these operations while maintaining the properties of a valid treap. For each operation, you should briefly justify the correctness of your implementation as well as the bound on its running time. In describing your implementations, you may feel free to refer to descriptions of basic operations on binary trees as described in Chapter 13 of the text.

Up until now, we have assumed that an object given to Insert arrives with both a key and a priority. If we want to maintain a set of objects for which only the key is defined, we are free to choose any values we want for priorities, and the above routines will be correct. For the remainder of the problem, we assume that when an object x with key[x] is inserted, we set the priority of that object uniformly at random to a real number in the range [0,1]. (The probability that two different objects choose the identical priority is equivalently zero.)

Extra Credit


This week, we will save the algebra for those who really want the work. Assuming uniform hashing we were able to bound, without too much trouble, the expected size of a particular bucket in a hashing scheme to be O(1). Of course, there will be some variance in the sizes of various buckets, and so it is not necessarily the case that the maximum sized bucket will be O(1).

Suppose that we have a hash table with n slots, with collisions resolved by chaining, and suppose that n keys are inserted into the table. Each key is equally likely to be hashed to each slot. Let M be the maximum number of keys in any slot after all the keys have been inserted. Your mission is to prove an $O(\lg n / \lg \lg n)$ upper bound on E[M], the expected value of M.


This document was generated using the LaTeX2HTML translator Version 97.1 (release) (July 13th, 1997)

Copyright © 1993, 1994, 1995, 1996, 1997, Nikos Drakos, Computer Based Learning Unit, University of Leeds.