码迷,mamicode.com
首页 > 其他好文 > 详细

CC150 20.6

时间:2014-12-11 10:32:53      阅读:136      评论:0      收藏:0      [点我收藏+]

标签:interview

20.6 Describe an algorithm to find the largest 1 million numbers in 1 billion numbers. Assume that the computer memory can hold all one billion numbers.

// can hold all numbers.
// Cheating!

// Do we know the max or min?
// Consider using bitmap

// If 1 billion numbers also spread a lot.
// 1. Hash-split into K smaller pieces. Just % n. Thinking about how to handle negative numbers.
// Dealing with the small files.
// Maintain a min heap with 1 million. (so said)

// Random select K as pivok.
// Track numbers bigger than K.
// If # > 1m, pivot right, to find 1m
// else, pivot left, (1m - #)


CC150 20.6

标签:interview

原文地址:http://7371901.blog.51cto.com/7361901/1588570

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!