online advertising
Processing math: 100%

Friday, November 20, 2015

Algorithms: Design and Analysis, Part 1 - Problem Set 6 - Question 1

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[ni=1Xi]=ni=1E[Xi]=ni=11m=nm.

No comments:

Post a Comment