in DS edited by
21,868 views
49 votes
49 votes

Consider a hash table with $100$ slots. Collisions are resolved using chaining. Assuming simple uniform hashing, what is the probability that the first $3$ slots are unfilled after the first $3$ insertions?

  1. $(97 \times 97 \times 97) / 100^3$
  2. $(99 \times 98 \times 97) / 100^3$
  3. $(97 \times 96 \times 95) / 100^3$
  4. $(97 \times 96 \times 95 / (3! \times 100^3)$
in DS edited by
21.9k views

4 Comments

can someone share the answer we get, using linear probing?
0
0

I think 

C(97,3) / C(100,3)

@Arjun sir please confirm once

2
2
0
0

3 Answers

122 votes
122 votes
Best answer
We have $100$ slots each of which are picked with equal probability by the hash function (since hashing is uniform). So, to avoid first $3$ slots, the hash function has to pick from the remaining $97$ slots. And repetition is allowed, since chaining is used- meaning a list of elements are stored in a slot and not a single element.

So, required probability $= \frac{97}{100} \times  \frac{97}{100} \times  \frac{97}{100}$

$= (97 \times 97 \times 97)/100^3$

Correct Answer: $A$
edited by
by

13 Comments

Sir, here if we use another hashing technique like Linear probing then ans will be c ?
0
0
Linear probing won't give c. It is slightly more trickier :)
5
5
edited by
if liner probing then what will be the ans ?@ arjun sir

is it 97*96*95/(100*99*98)
0
0
for liner probing it is complex . every time slot can picked up with equal probability. total 100^3 .

but then linear probing is method applied . in 1st go we can choose any 97 , but if we choose the last slot then for 2nd time we can choose 96 slots . if not then we can chhose 97 slots . likewise we have to split according to the condition .
9
9
hey pranay .. i didnt get your point .. pls explain again... and where my approach is wrong ?
0
0

total outcome : 1st time we can choose 100 slots * for 2nd time it we can choose 100 slots (if collision occur linear probing will handle ) * 3rd time 100 slot  = 100^3 .

Desire outcome : in 1st go we can choose any 97 , but if we choose the last slot then for 2nd time we can choose 96 slots + if not then we can choose 97 + 2nd time 97  if last slots are empty + if not 96 way only last one slot is full +and if 95 ways if last two slot is full + as goes for 3rd go  .

then  Desire outcome / total outcome = Something / 100^3 .

Your approach would be right if they include one condition that no collision occur also .

11
11
ohk ohk i got it.. i missed out  thank you :)
1
1

@Arjun sir if we take "linear probing" shouldnt the answer be :(95/100 *94/100 *93/100) + (97/100*96/100*95/100)+ (96*100*95/100*94/100)

0
0
We are doing "probability". Your answer is > 1.

Answer for linear probing is not simple here- we have to consider the cases separately - that is first one going to 99 and 100 are special cases, and so on. It is no longer a simple objective question which can be asked for GATE.
9
9
Sorry sir i did not notice the greater than 1 part.

sir just out of curiosity

if there are 2 more collisions in 99 after a no is entered in 99,then that case is getting cancelled because the third no will enter in 0. Sir will then the possible solution be by blocking 99 and 100 ? if so then

(95/100 *94/100 *93/100)

similarly sir if there are 2 more collisions in 100 after a no is entered in 100,then that case is getting cancelled because the second and third no will enter in 0 and 1. Sir will then the only possible solution is by blocking 100? if so then (96*100*95/100*94/100)

and rest of the cases

(97/100*96/100*95/100)
2
2
yes, just that you have to do it more formally.
4
4
okay got it sir.
1
1
How to solve this using reverse probability?
0
0
21 votes
21 votes
for the first insertion we have (4-100) 97 slots out of 100 slots for the second insertion also we have (4-100) 97 slots out of 100 because here chaining is used to resolve collision it means 2nd element may also get the slot where the first element already have and 3rd  insertion also have  (4-100) 97 slots out of 100 slots it means 3rd element may also get the slot  first and second elements already have. it is just like repetitions.  so answer should be       97/100 * 97/100 * 97/100

1 comment

@Murali

Completely satisfied by ur approach.

Nice explanation thank you. !

0
0
7 votes
7 votes

Simple Uniform hashing function is a hypothetical hashing function that evenly distributes items into the slots of a hash table. Moreover, each item to be hashed has an equal probability of being placed into a slot, regardless of the other elements already placed. (Source: https://en.wikipedia.org/wiki/SUHA_%28computer_science%29).

Probability that the first 3 slots are unfilled after the first 3 insertions = 
                (probability that first item doesn't go in any of the first 3 slots)*
                (probability that second item doesn't go in any of the first 3 slots)*
                (probability that third item doesn't go in any of the first 3 slots)

                 = (97/100) * (97/100) * (97/100) 

1 comment

Answer:

Related questions