Probability & Random Variables


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.