由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - Find the first k smallest numbers in an array.
相关主题
find 5 smallest number in a billion number listAmazon电面(经),也求个祝福。。
The time complexity on finding the kth largest element in a今天又被recuiter 鄙视了,大家来教育下我吧。
find kth smallest key in BST with O(lgn)how do you find x number of items in an array sum up to K?
已知sum 在unsorted set中找两个数 线性复杂度也问一个算法题
问个算法题8bloomberg onsite 。
O(lgk)解法Find the k-th Smallest in Two Sorted Arrays哪位大写给说说 何时用 merge sort, 何时用 quick sort, 何时 heap sort
几种linked List (array) merge 的复杂度(附个人体会)Google phone interview
Find the Kth smallest element in 2 sorted题都感觉做对了,面试的人也满意,为什么二面过后还是直接悲剧呢……顺便上P面经
相关话题的讨论汇总
话题: find话题: array话题: smallest话题: numbers话题: first
进入JobHunting版参与讨论
1 (共1页)
s********e
发帖数: 83
1
Find the first k smallest numbers in an array.
是不是先找到K+1大的值,然后遍历整个array,凡是<这个值,就加到结果里面
h******3
发帖数: 351
2
I think the idea is correct.
Also, think about special cases such as the array length is less than K.
b******v
发帖数: 1493
3
就是用qsort的思想,找到第k小的元素,并partition
时间复杂度平均是O(n)

【在 s********e 的大作中提到】
: Find the first k smallest numbers in an array.
: 是不是先找到K+1大的值,然后遍历整个array,凡是<这个值,就加到结果里面

r****o
发帖数: 1950
4
I think so.
The book <> said this method has time complexity O(N
log2K).
It seems incorrect and should be O(N).

【在 b******v 的大作中提到】
: 就是用qsort的思想,找到第k小的元素,并partition
: 时间复杂度平均是O(n)

r*****l
发帖数: 216
5
也可以建一个有k个元素的最大堆,每次检查堆里最大的那个根元素和当前元素的大小
,总是keep当前最小的k个
时间复杂度也是O(N)
空间多了一个k-heap
r****c
发帖数: 2585
6

this is N logk
In order to find in O(N), you need to find the kth number in O(N) which is a
simple extension of finding median in O(N)

【在 r*****l 的大作中提到】
: 也可以建一个有k个元素的最大堆,每次检查堆里最大的那个根元素和当前元素的大小
: ,总是keep当前最小的k个
: 时间复杂度也是O(N)
: 空间多了一个k-heap

f*********5
发帖数: 576
7
when u consider k as a constant,they just assume that this is O(N)

is a

【在 r****c 的大作中提到】
:
: this is N logk
: In order to find in O(N), you need to find the kth number in O(N) which is a
: simple extension of finding median in O(N)

g*****a
发帖数: 1457
8
use max heap or looser tree.
both big O are N*lg(k)
1 (共1页)
进入JobHunting版参与讨论
相关主题
题都感觉做对了,面试的人也满意,为什么二面过后还是直接悲剧呢……顺便上P面经问个算法题8
Extension problem of finding intersection of two sorted arrayO(lgk)解法Find the k-th Smallest in Two Sorted Arrays
T家电面一般有几轮? [UPDATE面经]几种linked List (array) merge 的复杂度(附个人体会)
heap sort的缺点是什么?和quick sort比Find the Kth smallest element in 2 sorted
find 5 smallest number in a billion number listAmazon电面(经),也求个祝福。。
The time complexity on finding the kth largest element in a今天又被recuiter 鄙视了,大家来教育下我吧。
find kth smallest key in BST with O(lgn)how do you find x number of items in an array sum up to K?
已知sum 在unsorted set中找两个数 线性复杂度也问一个算法题
相关话题的讨论汇总
话题: find话题: array话题: smallest话题: numbers话题: first