Suppose we are given keys, hash table slots, and two simple uniform hash functions and Further suppose our hashing scheme uses for the odd keys and for the even keys. What is the expected number of keys in a slot?
View worked solution
Answer: B
Under the simple uniform hashing assumption, each key is equally likely to hash to any of the slots, independent of where other keys have hashed.
Let the total number of keys be divided into:
- odd keys, which are hashed using
- even keys, which are hashed using
where .
Let be the random variable representing the total number of keys in a specific slot (where ). We can express as the sum of two components:
where:
- is the number of odd keys hashing to slot .
- is the number of even keys hashing to slot .
By the definition of simple uniform hashing:
- Each of the odd keys has a probability of of hashing to slot . Thus, the expected number of odd keys in slot is:
- Each of the even keys has a probability of of hashing to slot . Thus, the expected number of even keys in slot is:
Using the linearity of expectation, the expected total number of keys in slot is:
Thus, the expected number of keys in any slot is .
Free practice · Your answers on this page are not saved.
