boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - find 5 smallest number in a billion number list
相关主题
Find the first k smallest numbers in an array.
大量数据里面找top 100
问一个常见面试题,求讲解
Sort a list in which each number is at a distance k from its actual position
An interview question of finding the median in a moving window.
Google phone interview
算法--找一个unsorted array的largest and second largest 最
a very difficult interview question
n个点,找出离原点最近的100个点
问道面试题
相关话题的讨论汇总
话题: smallest话题: number话题: list话题: find话题: heap
进入JobHunting版参与讨论
1 (共1页)
g****e
发帖数: 172
1
how?
w****f
发帖数: 684
2
min-heap with only 5 element,
or top-k selection?
v****c
发帖数: 29
3
一共就5个数,怎么搞都行
by the way, 应该是max heap

【在 w****f 的大作中提到】
: min-heap with only 5 element,
: or top-k selection?

w****f
发帖数: 684
4
Yes, it should be max-heap.

【在 v****c 的大作中提到】
: 一共就5个数,怎么搞都行
: by the way, 应该是max heap

f*******n
发帖数: 12623
5
Find k smallest numbers in a list of size n:
* Use max-heap of size k, iterate through list
O(n log k)
* Turn entire list into min-heap, then pop k times
O(n + k log n)
* Use worst-case linear-time selection algorithm to find the value of the k'
th smallest element, then partition the list with this value, and take the
first k elements
O(n)
h*******e
发帖数: 225
6
It is only asking for the five smallest numbers. Forget about min-heap and
linear time selection algorithm. The constant factor is so small that by
just keeping five ints and do comparisons directly you would probably yield
a faster program than all the algorithms you listed here.

k'

【在 f*******n 的大作中提到】
: Find k smallest numbers in a list of size n:
: * Use max-heap of size k, iterate through list
: O(n log k)
: * Turn entire list into min-heap, then pop k times
: O(n + k log n)
: * Use worst-case linear-time selection algorithm to find the value of the k'
: th smallest element, then partition the list with this value, and take the
: first k elements
: O(n)

1 (共1页)
进入JobHunting版参与讨论
相关主题
问道面试题
发个一直没有见过满意答案的题吧
今天面试问题:有一个整数数组,如何find kth smallest element,如果数据是dynamic
问一道题(3)
当数据很大时,如果做BFS、DFS?
amazon question
careercup书上一个老题
这两道题(CareerCup 150)的答案是不是有问题啊?
find subset that sum up to given number
O(lgk)解法Find the k-th Smallest in Two Sorted Arrays
相关话题的讨论汇总
话题: smallest话题: number话题: list话题: find话题: heap