• edited by
46,829 views
103 103 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$.

  1. $5$
  2. $6$
  3. $7$
  4. $10$

13 Answers

Best answer
142 142 votes

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$

• edited by
65 65 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

1 flag:
✌ Low quality (i.kshitij “Wrong answer”)
10 10 votes

Ans: D (10)

9 9 votes
tell me if this approach is right or wrong
chances of collision of first element =0
chances of collision of 2nd element is 1/20

chances of collision of 3rd element is 2/20
.
.
.
.
and so on
we have to insert elements till our probability doesnt exceed 0.5 and the moment it exceeds 0.5 we take that nth number as our answer
probability = 0+1/20+2/20+3/20+4/20+...... so on till our value doesnt exceed 0.5
we can see for 5 elements our probability becomes => (0+1/20+2/20+3/20+4/20) which is equal to 0.5
now when we include 6 th element our probabilty will become 0.5+5/20 which is greater than 0.5 so 6 should be answer
8 8 votes
After the 10th insertion, probability of collision of new key hashed= 10/20= 0.5

After 11th insertion, probability of collision of new key hashed= 11/20 > 0.5

We are asked after which insertion, probability of collision of new key hashed exceeds 0.5. So it should be 11.
3 3 votes
Very Simple Question:

When first key is inserted : probability of collision: 0

When Second key is inserted : probability of collision: 1/20 , because there is only one place at which collision is possible out of 20 places

When Third key is inserted : probability of collision: 2/20... and so on.

Answer is :10
Answer:
Position:
Show:

Related questions

60 60 votes
4 answers 4 answers
25.0k
25.0k views
Arjun asked Feb 12, 2020
25,028 views
Consider a double hashing scheme in which the primary hash function is $h_1(k)= k \text{ mod } 23$, and the secondary hash function is $h_2(k)=1+(k \text{ mod } 19)$. Ass...
52 52 votes
11 answers 11 answers
24.8k
24.8k views
Ishrat Jahan asked Oct 29, 2014
24,825 views
Suppose you are given an implementation of a queue of integers. The operations that can be performed on the queue are:$\text{isEmpty (Q)}$ — returns true if the queue is ...
258 258 votes
18 answers 18 answers
61.6k
61.6k views
Ishrat Jahan asked Oct 29, 2014
61,553 views
When searching for the key value $60$ in a binary search tree, nodes containing the key values $10, 20, 40, 50, 70, 80, 90$ are traversed, not necessarily in the order gi...
61 61 votes
6 answers 6 answers
23.6k
23.6k views
Ishrat Jahan asked Oct 30, 2014
23,638 views
Consider a selection of the form $\sigma_{A\leq 100} (r)$, where $r$ is a relation with $1000$ tuples. Assume that the attribute values for $A$ among the tuples are unifo...