7,937 views

2 Answers

Best answer
13 votes
13 votes
Probability of a hash to a given slot $=\frac{1}{m}$ since hashing is uniform. (Also whatever be the probing, all elements are stored in the array only)

Expected number of collisions (assuming $n \leq m)$

$=1\times \text{Probability of collision in first insertion}\\
+1\times \text{Probability of collision in second insertion}\\
\ldots\\
+1\times \text{Probability of collision in $n^{th}$ insertion}\\
= 1*0 + 1*\frac{1}{m} + 1* \frac{2}{m} + 1* \frac{3}{m} + \ldots + 1* \frac{n-1}{m}\\
= \frac{n^2-n}{2m}$
edited by
4 votes
4 votes
Nice question @Pranjal.

Since there are m slots the probability of inserting a key into a specific slot is 1/m

Probability to place two keys in a particular slot is 1/m* 1/m

As there are m slots probability of colliding two keys is m*1/m*1/m =1/m

Just now we solve for only 2 keys. There are n keys.

First key can be collided with n-1 keys

Second key can be collided with n-2 keys..

total number of combinations = n(n-1)/2

Expected number of collisions = n(n-1)/2m

Related questions

0 votes
0 votes
0 answers
1
0 votes
0 votes
0 answers
3
0 votes
0 votes
0 answers
4