avatar
一个算法问题# JobHunting - 待字闺中
w*f
1
有一个文件含1000000000个(user, login-timing,...)
要求登陆时间前1000名,以及median。请问那种算法最好?
avatar
s*n
2
根据userid hash分配到k台机器。每台机器上统计,排序。
然后k-way合并(用heap),得到总排名的前1000和median
avatar
w*f
3
谢谢,swan。
这种算法好像对占memory较多,有无更好的算法?
avatar
z*8
4
求前1000个用 maxheap就行了, 求median就只能那么做

【在 w****f 的大作中提到】
: 谢谢,swan。
: 这种算法好像对占memory较多,有无更好的算法?

avatar
s*n
5
求median必须要排序,可以用external sort
avatar
d*n
6
+1
好像1 billion 的数据不是都load 到memory.
是不是要把user 放进bst 或者hash里面,只保留最早时间?
1 billion user, 多少unique names?

【在 z*********8 的大作中提到】
: 求前1000个用 maxheap就行了, 求median就只能那么做
avatar
w*f
7
It's 1 billion user, and only 1 million unique userid.
"求median必须要排序,可以用external sort". What's external sort?
Does the below work?
1.) take first 1001, use 501th as the initial median values of login-
timing.
2.) read next one and shift the median to fit the new one.
3.) repeat step 2 till the end.
(But this one only give the values of timing, not the associated useid)
avatar
w*x
8
1. 把文件切成2^n个大小相同的小文件, 每两个可以装入内存
2. 两两载入内存, 对每个pair做median merge, 2 个 file merge成一个大小相同的
file
3. 如此merge下去, 直到所有的file浓缩成一个file, 取这个file的median, 不过这题
因该允许取得非精确median
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。