Dark Mode

22,773 views

54 votes

Consider a hash function that distributes keys uniformly. The hash table size is $20$. After hashing of how many keys will the probability that any new key hashed collides with an existing one exceed $0.5$.

- $5$
- $6$
- $7$
- $10$

edited
Sep 1, 2021
by Nirmalya Pratap 1

11

98 votes

Best answer

The question is a bit ambiguous.

After hashing of how many keys, will the probability that any new key hashed collides with an existing one exceed 0.5.

Here, 'new key hashed' is the ambiguity. It can mean the probability of a collision in the next 'hash', or the probability of a collision in any of the hashes of the 'new keys' starting from the first insertion. For the first case answer must be $10$ to get probability equal to $0.5$, and so $11$ must be the answer for probability $> 0.5$. Thus we can conclude from given choices, it is the second case.

So, we need to find $n$ such that after $n$ hashes, probability of collision (in any of the $n$ hashes) $> 0.5$.

Probability that there will be a collision after $n$ hashes (a collision happened in at least one of those $n$ hashes) $= 1 - $Probability that there was no collision in the first $n$ hashes

$= 1 - 1. \frac{19}{20} . \frac{18}{20} \dots \frac{20-n+1}{20}$.

So, we need,

$0.5 < 1 - 1. \frac{19}{20} . \frac{18}{20} \dots \frac{20-n+1}{20}$.

$\implies \frac{19}{20} . \frac{18}{20} \dots \frac{20-n+1}{20} < 0.5$.

For $n=5$, we get, $0.5814$ and for $n=6$, we get $0.43605$. So, answer should be $n = 6$.

Correct Answer: $B$

2

45 votes

He has asked "**after how many insertion" or in which insertion probability will be >= 0.5**

**So after 10 keys has been inserted probability of collision will be 0.5 **

**We can simply think like this :there are 20 slots out of which 10 are full. So there is half probability of collision. if there were less than 10 values prob. of collision would never exceed 1/2 rather it would decrease.**

So answer less than 10 is not possible at all

**Correct answer is (D) only.**

Also probability in 'k' th insertion is (k-1)/20

(k-1)/20 >=0.5

which gives k>=11

means in 11 th insertion we get required prob . OR **after inserting 10 values prob will exceed 0.5**

**It is important to note that **

Also probability in k ^th insertion is (k-1)/20

*It means the probability of collision at k^th insertion ,it is not the probability of first collision at **k^th insertion like in this question https://gateoverflow.in/2272/gate1997-12 c part :)*

0

8 votes

I think answer is **(D).**

- These three links are supporting your answer and are logical too.

https://www.geeksforgeeks.org/gate-gate-it-2007-question-28/

https://prepinsta.com/questions-hash-tables-sapient-razorfish/

- But below given link is supporting answer selected as best answer and giving the same explanation as above.

https://gatecse.in/w/images/4/4c/Hashng.pdf

0

Isn't this same as "The probability of collision on the (i+1)th insertion exceeding 0.5?

https://gateoverflow.in/2272/gate1997-12

Part C. Here we considered the probabilities of no collisions till i insertions in the solution. Why didn't we consider it here?

0