GATE / CS ARCHIVE

GATE CSE 1997 / QUESTION 12(b)

Probability of collision-free insertion

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

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

Probability & Random Variables

Question 12(b), 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 none of the K insertions causes a collision.
Question 12(b), 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 none of the K insertions causes a collision.
Tap to enlarge
Answer & solution

Answer: n! / ((n−K)! n^K) for 0≤K≤n; 0 for K>n. (no official key was published)

After j collision-free insertions, exactly j buckets are occupied. Conditional on that event, the next independently hashed key must choose one of the n−j empty buckets, which has probability (n−j)/n. Multiplying from j=0 through K−1 gives

P(no collision in K insertions)
= 1·(n−1)/n·(n−2)/n·…·(n−K+1)/n
= n! / ((n−K)! nK), for 0≤K≤n.

For K>n the probability is zero by the pigeonhole principle. Do not extend the factorial formula to a negative factorial. At K=0, the empty product is 1; at K=1, no collision is possible and the result is also 1. For n=3,K=2 it is 2/3, because only the second key can cause the first collision.

An equivalent counting argument considers nK equally likely ordered bucket-choice sequences. Collision-free choices are injective assignments of the K ordered keys to the n buckets, numbering n(n−1)…(n−K+1). The keys are distinct, but that does not make their bucket values distinct automatically.

This derivation needs independent uniform hashing, not just equal marginal bucket probabilities. Under the correlated scheme that sends every key to one common randomly chosen bucket, the probability is already zero at K=2 despite uniform marginals. That source-model limitation is stated explicitly rather than hidden in the multiplication.

Original paper, page 7