Problem:
Suppose we use a hash function h to hash n distinct keys into an array T of length m. Assuming simple uniform hashing, that is, with each key mapped independently and uniformly to a random bucket --- what is the expected number of keys that get mapped to the first bucket? More precisely, what is the expected cardinality of the set {k:h(k)=1}.
Solution:
Intuitively, that would be nm, let formalize and prove this fact.
Denote Xi as the indicator random variable such that if the ith element get hashed to first bucket, then Xi=1, otherwise Xi=0.
E[Xi]=1×P(Xi=1)+0×P(Xi=0)=P(Xi=1)=1m.
Therefore, by linearity of expectation, we have E[S]=E[n∑i=1Xi]=n∑i=1E[Xi]=n∑i=11m=nm.
Suppose we use a hash function h to hash n distinct keys into an array T of length m. Assuming simple uniform hashing, that is, with each key mapped independently and uniformly to a random bucket --- what is the expected number of keys that get mapped to the first bucket? More precisely, what is the expected cardinality of the set {k:h(k)=1}.
Solution:
Intuitively, that would be nm, let formalize and prove this fact.
Denote Xi as the indicator random variable such that if the ith element get hashed to first bucket, then Xi=1, otherwise Xi=0.
E[Xi]=1×P(Xi=1)+0×P(Xi=0)=P(Xi=1)=1m.
Therefore, by linearity of expectation, we have E[S]=E[n∑i=1Xi]=n∑i=1E[Xi]=n∑i=11m=nm.
No comments:
Post a Comment