1.用天平(只能比较,不能称重)从一堆小球中找出其中唯一一个较轻的,使用x 次天平,最多可以从y 个小球中找出较轻的那个,求y 与x 的关系式。
2.有一个很大很大的输入流,大到没有存储器可以将其存储下来,而且只输入一次,如何从这个输入流中随机取得m 个记录。
3.大量的URL 字符串,如何从中去除重复的,优化时间空间复杂度
HANDWRITING:
1、y = 2^x
2、蓄水池抽样
3、先用hash,将这些字符串分到不同的文件中,再在这些文件里找重复的
关于蓄水池抽样:http://blog.csdn.net/hackbuteer1/article/details/7971328
ANSWER
FROM:http://blog.csdn.net/v_july_v/article/details/6870251
1、x=1, y=3: if a=b, c is the lighter, else the lighter is the lighter...do this recursively. so y=3^x;
2、That is, keep total number count N. If N<=m, just keep it.
For N>m, generate a random number R=rand(N) in [0, N), replace a[R] with new number if R falls in [0, m).
3、Use hash map if there is enough memory.
If there is no enough memory, use hash to put urls to bins, and do it until we can fit the bin into memory.