Suppose our hash table has slots. Under the simple uniform hashing assumption, what is the expected number of distinct elements that needs to be inserted into the table so that all of the slots are occupied by at least one element?
This problem is a part of the Hash Crash Series
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
Relevant wiki: Coupon Collector Problem
Assume that we have a total of n slots, of which m − 1 distinct slots are occupied. Then let's first compute the number of additional elements that need to be inserted so that m distinct slots are occupied. Clearly, the probability that a newly inserted element occupies a previously unoccupied slot is p succ ( m ) = n n − m + 1 . Hence we need p succ ( m ) 1 = n − m + 1 n additional element, in expectation, for the required transition. As a result, total number of elements N required, in expectation to fill up the entire Hash table is N = m = 1 ∑ n n − m + 1 n = n H n , where H n is the n th harmonic number, which may be readily computed.