算法导论(第三版)参考答案:思考题5.1,思考题5.2
Problem 5.1 (Probabilstic counting)
With a b -bit counter, we can ordinarily only count up to
2b−1 . With R. Morris’s probabilistic counting, we can count up to a much larger value at the expense of some loss of precision.We let a counter value of i represent that a count of ni for i=0,1,…,2b−1 , where the ni form an increasing sequence of nonnegative values. We assume that the initial value of the counter is 0 , representing a count of
n0=0 . TheINCREMENT
operation works on a counter containing the value i in a probabilistic manner. If i=2b−1 , then the operation reports an overflow error. Otherwise, theINCREMENT
operation increases the counter by 1 with probability 1/(ni+1−ni) , and it leaves the counter unchanged with probability 1−1/(ni+1−ni) .If we select ni=i for all i≥0 , then the counter is an ordinary one. More interesting situations arise if we select, say, ni=2i−1 for i>0 or ni=Fi (the ith Fibonacci number - see Section 3.2).
For this problem, assume that n2