n keys are hashed independently and uniformly into m slots. How do you find the probability that at least two keys share a slot, and how large must n be for this probability to pass 12 when m=365 (the birthday problem)?

Probability and statistics, Probability axioms and counting
Level L3 Intermediate. Length Medium. Nature Mat Mathematical.

What's being asked

Whether you use the complement rule and the product of conditional probabilities, and can turn it into the approximation n≈2mln⁡2.

Key idea

P(no collision)=∏i=0n−1(1−im)≈e−n(n−1)/(2m), so collisions become likely once n is of order m, not m.

Steps

  1. Use the complement: P(collision)=1−P(all keys in different slots). Counting the 'no collision' case is easier.
  2. Place the keys one at a time. The first key can go anywhere. The (i+1)th key must avoid the i slots already used, which has probability m−im=1−im.
  3. Multiply, since the placements are independent: P(none)=∏i=0n−1(1−im).
  4. Approximate with 1−x≈e−x for small x: P(none)≈exp⁡ ⁣(−∑i=0n−1im)=exp⁡ ⁣(−n(n−1)2m).
  5. Set P(collision)=12: n(n−1)2m≈ln⁡2, so n≈2mln⁡2≈1.18m. For m=365 this gives about 22.5, so n=23.
  6. Check numerically: the exact product for n=23 gives P(collision)=0.5073 (the approximation gives 0.5000). As a second example, 10 keys in 100 slots collide with probability 0.372, which is already large.

Common mistakes

How long your answer should be

Half a page; 3–4 minutes.

Read this

Previous in Probability and statistics: For a bivariate Gaussian (X,Y) with correlation ρ, show that I(X;Y)=−12ln⁡(1−ρ2). What is the value for ρ=0.8, and what happens as ρ→0 and ρ→1?
Next in Probability and statistics: Three independent jobs have exponential run times with rates λ1=1, λ2=2 and λ3=3 per hour. What is the distribution of the time until the first job finishes, and what is the probability that job 1 is the first to finish?