发信人: justcome (ANewOne), 信区: JobHunting
标 题: 问一道google面试题
发信站: BBS 未名空间站 (Mon Oct 6 17:54:07 2008), 转信
没有看懂答案是什么意思?能不能给解释一下
3. you need read a lot of records, you don't know how many records here
before you complete it. After you read all those records, you need select
one record randomly.In another words, every record has same chance to be
selected. The memory is limited, that means you cannot store all those
records at one time.
Changing your random number pick dynamically. Add a weight (1/n) to nth
new number, add a weight (n-1)/n to the random number you picked from (1 to
n-1) numbers. This can guaranteer the randomess without knowing how many
number ahead.
1. P(1)=1; 2. P(2)=1/2, P(1)=1*1/2; 3. P(3)=1/3, P(1)=P(2)=2/3*1/2=1/3…
Monday, October 6, 2008
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment