Problem on Probability -- Hash Table & Collisions

Click For Summary
The discussion revolves around calculating probabilities related to a hash table with external chaining for collision resolution. For part (a), the probability that bucket number 1 remains empty after K insertions is correctly identified as (n-1/n)^K. In part (b), the probability of no collisions during K insertions is expressed as the product of decreasing probabilities for each insertion. For part (c), the probability that the first collision occurs at the Kth insertion is clarified to involve the probability of the Kth element colliding with one of the previously filled slots, leading to the correct formulation of (1 × (1/(n-1)) × ... × (1/(n-(K-2))) × (K-1/n). The final consensus confirms the adjustments needed for accurate probability calculations.
22990atinesh
Messages
143
Reaction score
1

Homework Statement


Consider a hash table with ##n## buckets, where external (overflow) chaining is used to resolve collisions. The hash function is such that the probability that a key value is hashed to a particular bucket is ##\frac{1}{n}##. The hash table is initially empty and ##K## distinct values are inserted in the table

(a) What is the probability that bucket number 1 is empty after the the ##K^{th}## insertion ?
(b) What is the probability that no collision has occurred in any of the ##K## insertions ?
(c) What is the probability that the first collision occurs at the ##K^{th}## insertions ?

Homework Equations

The Attempt at a Solution


Probability that a key value is hashed to the first bucket = ##\frac{1}{n}##
Probability that a key value is doesn't hashed to the first bucket = ##1 - \frac{1}{n}## = ##\frac{n-1}{n}##

(a) Probability that bucket number 1 is empty after the the ##K^{th}## insertion = ##(\frac{n-1}{n})^k##
(b) Probability that no collision has occurred in any of the ##K## insertions = ##1 \times \frac{1}{n-1} \times \frac{1}{n-2} \times ... \times \frac{1}{n-(k-1)}##
(c) Probability that the first collision occurs at the ##K^{th}## insertions = ##1 \times \frac{1}{n-1} \times \frac{1}{n-2} \times ... \times \frac{1}{n-(k-2)} \times \frac{1}{k-1}##

are my above ans correct or I've done some mistake. Please share
 
Physics news on Phys.org
Where does the last factor at (c) come from?
Everything else looks right.
 
mfb said:
Where does the last factor at (c) come from?
Everything else looks right.

Probability that no collision has occurred in any of the ##K-1## insertions P(K-1)= ##1 \times \frac{1}{n-1} \times \frac{1}{n-2} \times ... \times \frac{1}{n-(k-2)}##
Probability that the first collision occurs at the ##K^{th}## insertions = ## P(K-1) \times## Probability of collision of ##K^{th}## element
As K-1 slots are filled, first collision will occur if ##K^{th}## element will get into these slot, It'll do it with probability = ##\frac{1}{k-1}##
Hence
Probability that the first collision occurs at the ##K^{th}## insertions = ##1 \times \frac{1}{n-1} \times \frac{1}{n-2} \times ... \times \frac{1}{n-(k-2)} \times \frac{1}{k-1}##
 
22990atinesh said:
As K-1 slots are filled, first collision will occur if ##K^{th}## element will get into these slot, It'll do it with probability = ##\frac{1}{k-1}##
No it does not.
If 2 out of 100 slots are filled, then the next element won't go to a filled slot with a probability of 1/(3-1)=1/2.
 
mfb said:
No it does not.
If 2 out of 100 slots are filled, then the next element won't go to a filled slot with a probability of 1/(3-1)=1/2.

Would it be ##\frac{k}{n}## in place of ##\frac{1}{k-1}## in (c)
 
Nearly. The numerator should be k-1.
 
  • Like
Likes 22990atinesh
mfb said:
Nearly. The numerator should be k-1.
Oops little mistake, you are right. ##\frac{k-1}{n}## is right.
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 13 ·
Replies
13
Views
4K
  • · Replies 4 ·
Replies
4
Views
3K
Replies
2
Views
1K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 29 ·
Replies
29
Views
4K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 21 ·
Replies
21
Views
1K
  • · Replies 7 ·
Replies
7
Views
3K