由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - Pick k lines from a large file randomly uniformly distributed
相关主题
一道概率题目一道概率题
问一道题careercup 上一道F 题
求教Careercup 150 上的一道题目一个经典的随机数的问题。求教。
请教一道careercup上面的概率题问一道google面试题
如果给随即函数rand[1,5] 如何产生rand[1,7]计算机菜鸟找工作, 求一些建议
请教一道题目Yelp 面经
rand5 -> rand7的解法?请教个弱题:random generator: from 1~5 to 1~7
请教一个math puzzle题非CS背景,除了刷题,知识性的东西怎么突击?
相关话题的讨论汇总
话题: lines话题: randomly话题: uniformly话题: line话题: file
进入JobHunting版参与讨论
1 (共1页)
t*****e
发帖数: 53
1
I know the solution:
read the first k lines from the file,
then repeat the following steps:
- read one line from the file
- with probability X, keep the new line, and randomly drop a line from the
previous selected k lines.
- with probability (1-X), drop the new line.
till all the lines of the lines are read
My questions is:
- What should be the value of X?
- How to give a strict math proof that this method gives a randomly
uniformly distributed k lines.
thanks alot for your help.
l********8
发帖数: 83
2
CareerCup 150题里有道要求从一串数字流里随机挑一个数。这个应该也是用一样的方
法吧。
a*******y
发帖数: 1040
3
wiki reservoir sampling
basically you have to have a random() function to generate from 1 to i where
i is the count of the line you have seen so far, if it fall between 1 and k
, you replace that one, otherwise, drop this one
1 (共1页)
进入JobHunting版参与讨论
相关主题
非CS背景,除了刷题,知识性的东西怎么突击?如果给随即函数rand[1,5] 如何产生rand[1,7]
明天去G家onsite LC刷了0.8遍请教一道题目
[合集] Re: 贡献两个智力题,攒RP ( QUALCOMM)rand5 -> rand7的解法?
[合集] 贡献两个智力题,攒RP ( QUALCOMM)请教一个math puzzle题
一道概率题目一道概率题
问一道题careercup 上一道F 题
求教Careercup 150 上的一道题目一个经典的随机数的问题。求教。
请教一道careercup上面的概率题问一道google面试题
相关话题的讨论汇总
话题: lines话题: randomly话题: uniformly话题: line话题: file