822 views
4 votes
4 votes

Suppose we used a hash function H(n) to hash ‘n’ distinct elements (keys) into an array T of length ‘m’.
What is the expected number of colliding pairs of elements, if we used simple uniform hashing?

2 Answers

Best answer
6 votes
6 votes
$\begin{align*} & \text{Let } X_k \text{ is a random variable and it is defined as follows :} \\ & X_k = \begin{cases} & 1 \quad \text{ if collision occurs at kth insertion}\\ & 0 \quad \text{ if collision does not occur at kth insertion}\\ \end{cases} \\ \\ &\text{before the {k}th insertion (k - 1) elements will be there in the hash array} \\ &\Rightarrow P(X_k = 1) = \frac{k-1}{m} \\ &\Rightarrow E(X_k) = P(X_k = 1) \\ &\text{By linearity of expectation} \\ &E = \sum E(X_k) \\ &E = \sum P(X_k = 1) \\ &E = \sum_{x=0}^{n-1} \frac{x}{m} \\ &E = \frac{1}{m}.\frac{(n-1).n}{2} \\ \end{align*}$
selected by

Related questions

0 votes
0 votes
0 answers
2
chandra sai asked Nov 18, 2017
231 views
0 votes
0 votes
1 answer
3
tishhaagrawal asked Dec 16, 2023
351 views
Below is my approach to solving this question, can anyone please explain if I am doing it the right way?Let X = #free slotssince, m =7 and n = 3So, $4 \leqslant x\leqsla...
0 votes
0 votes
1 answer
4
Ray Tomlinson asked Aug 9, 2023
506 views
Numerical Answer Type Que?(please Try to give some ahortcut trick also or important concept is there to solve that question )