469 views
0 votes
0 votes

Below is my approach to solving this question, can anyone please explain if I am doing it the right way?

Let X = #free slots
since, m =7 and n = 3

So,  $4 \leqslant x\leqslant 6$

Now, P(x=4) => Probability that all three keys map to different locations = $(7*6*5)/7^3$

Similarly P(x=5) => Probability that 2 keys map to different slots and the third key collides with any of the previously filled slots = $(7*6*2)/7^3$
similarly for P(x=6) => Probability that all three maps to the same slot = $(7*1*1)/7^3$

Now for expectation, E(X) = $\sum_{}^{}$PiXi

So, E(X) = $4* (7*6*5)/7^3 + 5 * (7*6*2)/7^3 + 6 * (7*1*1)/7^3$ = 3.795 $\approx$ 3.8

But the answer given in the test series is 4.408, I am not getting why is my approach wrong, can anyone explain, please!

 



I am providing a screenshot of their solution below – 

1 Answer

0 votes
0 votes
Independently , each key has $1/m$ probability of hashing into the first slot   so probability for being empty of first slot is $1-1/m$ thus the Probability that  no  key hashes into the first slot is $(1-1/m)^{n}$.

Now Let $X_{i}$ be the event (or just break it into bernouli RV) that slot $i$ is Empty. Since  $X_{i}$ =1 When slot  ${i}$ is Empty and  is $0$ other wise,

$E[X_{i}]=Pr(X_{i} =1)$ is the Probability of slot $i$ being Empty.

Now Expected  Number of Empty Slots

 $E[\sum X_{i}]=\sum E[X_{i}]*P_{i}$

$E[X_{1}] =(1-1/m)^n$ which will same for all slots  

then it will be $m(1-1/m)^n$

Related questions

5.9k
views
2 answers
3 votes
Smriti012 asked Feb 3, 2017
5,898 views
Given a hash table with n keys and m slots, with the simple uniform hashing assumption (each key is equally likely to be hashed into each slot). Collisions are ... ?(b) What is the expected number of slots that end up not being empty?
8.1k
views
6 answers
12 votes
radha gogia asked Jul 20, 2015
8,148 views
Consider a hash table with $m$ slots that uses chaining for collision resolution. The table is initially empty. What is the probability that after 4 keys are inserted that at least ... $3m^{–1}$