
Homework 4, due Thurs, Feb 16, 2006
February 9, 2006
To be done in groups.
•CLRS 5-1, probabilistic counting.
•CLRS C.2-7, pairwise independence. (Solve the problem for n= 3 for partial credit.)
•(From Mitzenmacher and Upfal.) Suppose we have a sequence of items passing by one at a time. We
want to maintain a sample of one item with the property that it is uniformly distributed over all the
items that we have seen at each step. Moreover, we want to accomplish this without knowing the total
number of items or storing all of the items that we see.
Consider the following algorithm, which stores just one item in memory at all times. When the first
item appears, it is stored in the memory. When the kth item appears, it replaces the item in memory
with probability 1/k.Prove that this algorithm solves the problem.
1