GATE / CS ARCHIVE

GATE CSE 1997 / QUESTION 12(c)

Probability of the first collision

Discrete Mathematics · Probability & Random Variables · Full GATE CSE 1997 paper

GATE 1997, Q12(c) 2 marks · Descriptive
Report issue

Probability & Random Variables

Question 12(c), GATE 1997: A hash table has n≥1 buckets, uses external chaining, and is initially empty. K distinct keys are inserted. Each key hashes uniformly to one of the n buckets. Under the standard additional assumption that different keys hash independently, find the probability that the first collision occurs on insertion K.
Question 12(c), GATE 1997: A hash table has n≥1 buckets, uses external chaining, and is initially empty. K distinct keys are inserted. Each key hashes uniformly to one of the n buckets. Under the standard additional assumption that different keys hash independently, find the probability that the first collision occurs on insertion K.
Tap to enlarge
Answer & solution

Answer: [n! / ((n−K+1)! n^(K−1))]·(K−1)/n for 2≤K≤n+1; 0 otherwise. (no official key was published)

The event consists of two parts: the first K−1 insertions are collision-free, and the Kth key hits one of their occupied buckets. Given the first part, there are exactly K−1 occupied buckets, so the conditional probability of the second part is (K−1)/n.

For 2≤K≤n+1, the requested probability is therefore

[n(n−1)…(n−K+2)/nK−1]·(K−1)/n
= n!(K−1) / ((n−K+1)! nK).

The upper endpoint n+1 is legitimate: the first n keys could fill all n buckets without a collision, after which the next key certainly collides. Its probability is n!/nn. For K=1 the event is impossible because an empty table has no occupied bucket. For K>n+1, a first collision must already have happened, so the probability is also zero.

As a check, write pj for the probability of no collision after j insertions. Then P(first at K)=pK−1−p_K. Summing from K=2 to n+1 telescopes to p1−pn+1=1, as required. For n=2 the probabilities are 1/2 at K=2 and 1/2 at K=3. These arguments all use independent uniform bucket choices; the source's uniform marginals alone do not determine the distribution of the first collision.

Original paper, page 7