Hash Crash Finals

Computer Science Level pending

Suppose our hash table has 1 0 3 10^3 slots. Under the simple uniform hashing assumption, what is the minimum number of distinct elements that needs to be inserted to ensure that the probability of a hash collision is at least 1 2 \dfrac{1}{2} ?


This problem is a part of the Hash Crash Series


The answer is 38.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

2 solutions

Christopher Boo
Jul 9, 2016

The probability that there are no collision after n n insertions is Q n = 1000 × 999 × × ( 1000 n + 1 ) 100 0 n Q_n = \frac{1000\times 999 \times \dots \times (1000-n+1)}{1000^n} . Hence the probability that there exist a collision is P n = 1 Q n P_n = 1 - Q_n . The problem wants us to find n n such that P n 0.5 Q n 0.5 P_n \geq 0.5 \rightarrow Q_n \leq 0.5 . Iterate through all n n to find such answer.

1
2
3
4
5
6
Q = 1.00
for i in range(1000):
    Q = val * (1000-i) / 1000
    if val < 0.5:
        print i+1
        break

Abhishek Sinha
Jul 10, 2016

Also on the Brilliant wikis: birthday problem

Agnishom Chattopadhyay - 4 years, 11 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...