Consider this question:- Efficiently picking a random element from a chained hash table?
And consider it's first answer. It suggests a method to select a key in a uniformly random fashion. That, however, is unclear to me. The first step would take a probability of 1/m
(i.e randomly selecting a bucket from m buckets)
And the second step can be divided into two steps:
1) If k<=p
, then p is returned.
2) If k>p
then the loop again runs.
This is done until p is returned.
So the probability of a key being selected is :
(1/m)[(k1/L)+((L-k1)/L)[(1/m)[(k2/L)+((L-k2)/L)[(1/m)[(k3/L)+((L-k3)/L)[......and so on.
Now how can this be equal to 1/n
?
This is a form of rejection-sampling.
L / size-within-b0 = L/2
) as one from b1, because the bucket is uniformly selected; but the number of elements to sample from differ.