advertisement

Assignment 3 35 points Assume that we have a hash table structured as a vector of lists, resolving collisions by sequential search of buckets, as in the generic hash table template THashTable<Key,Data,Hash> distributed in the file thashtbl.h. Without making any assumptions on the hash function used, show the following, where n is the number of items in the table and b is the number of buckets (or slots) in the table implementation. Key terms: hashing, Bernoulli trials, binomial distribution. 1. Let e(k) denote the expected number of buckets of size k. Show that e(k) = bp(k). 2. Let p(k) denote the probability a given bucket has exactly k items. Show that the expected bucket size is n X kp(k) = k=0 n . b Now assume that we have a hash table structured as a vector of lists, as above, and we have an actual instance of a table. 3. Let b(k) denote the actual number of buckets of size k. Show that the size of the table is X kb(k). n= k≥0 4. What is the smallest safe upper index for the sum in the formula above? Explain your answer. Finally, assume that we have assigned keys to buckets randomly, so that each key has a uniformly likely probability of being assigned to a bucket. (This is called “simple uniform hashing” in the textbook - see page 259.) 5. Show that the probability that a given bucket is empty is µ p(0) = b−1 b ¶n . 6. Let 0 ≤ k ≤ n. Show that the probability that a given bucket has size k is p(k) = µ ¶µ ¶k µ ¶ n 1 b − 1 n−k . k b b 1 2 7. Using the formulas above, show that the bucket size distribution {e(k)} satisfies the recursive calculation: µ ¶ b−1 n e(0) = b initial condition b µ ¶µ ¶ n−k+1 1 e(k) = e(k − 1) for k = 1 . . . n. k b−1 e(k) = 0 for k > n. Assemble your solution paper as follows: • For each question, repeat the question on the paper, and then provide your solution. • Take some time to get your math typeset correctly. • Convert to a pdf document and turn that document in via Blackboard under “Assignment 3”.