l*z
3 楼
具体说说。。
f*n
7 楼
This is not good. It has worst-case O(n^2)
What they were asking for is WORST-CASE O(n).
http://en.wikipedia.org/wiki/Selection_algorithm#Linear_general
是O
【在 d*******e 的大作中提到】![](/moin_static193/solenoid/img/up.png)
: 方法和quicksort差不多。
: 在quicksort里,选择一个pivot value,完成partition,这时候有大于pivot value和
: 小于pivot value的两个序列,都需要递归的用quick sort排序。
: 如果要求第k大的数,只要判断一下该数在哪个序列里,然后对那一个序列再找第k'个
: 数就可以了。
: 该方法平均时间成本是O(n),如果选pivot时增加一些限制,可以保证最坏时间成本是O
: (n)。
What they were asking for is WORST-CASE O(n).
http://en.wikipedia.org/wiki/Selection_algorithm#Linear_general
是O
【在 d*******e 的大作中提到】
![](/moin_static193/solenoid/img/up.png)
: 方法和quicksort差不多。
: 在quicksort里,选择一个pivot value,完成partition,这时候有大于pivot value和
: 小于pivot value的两个序列,都需要递归的用quick sort排序。
: 如果要求第k大的数,只要判断一下该数在哪个序列里,然后对那一个序列再找第k'个
: 数就可以了。
: 该方法平均时间成本是O(n),如果选pivot时增加一些限制,可以保证最坏时间成本是O
: (n)。
l*z
8 楼
这个答案好。看来还真不是那么简单的。
【在 f*******n 的大作中提到】![](/moin_static193/solenoid/img/up.png)
: This is not good. It has worst-case O(n^2)
: What they were asking for is WORST-CASE O(n).
: http://en.wikipedia.org/wiki/Selection_algorithm#Linear_general
:
: 是O
【在 f*******n 的大作中提到】
![](/moin_static193/solenoid/img/up.png)
: This is not good. It has worst-case O(n^2)
: What they were asking for is WORST-CASE O(n).
: http://en.wikipedia.org/wiki/Selection_algorithm#Linear_general
:
: 是O
d*x
10 楼
but this is practically good.
The worst case O(N) method has a very large hidden constant factor which
makes it not practical at all.
value和
'个
【在 f*******n 的大作中提到】![](/moin_static193/solenoid/img/up.png)
: This is not good. It has worst-case O(n^2)
: What they were asking for is WORST-CASE O(n).
: http://en.wikipedia.org/wiki/Selection_algorithm#Linear_general
:
: 是O
The worst case O(N) method has a very large hidden constant factor which
makes it not practical at all.
value和
'个
【在 f*******n 的大作中提到】
![](/moin_static193/solenoid/img/up.png)
: This is not good. It has worst-case O(n^2)
: What they were asking for is WORST-CASE O(n).
: http://en.wikipedia.org/wiki/Selection_algorithm#Linear_general
:
: 是O
a*n
12 楼
用selection algorithm排完序再取median应该满足要求吧...
a*m
13 楼
这俩是一回事吧。
【在 f*******n 的大作中提到】![](/moin_static193/solenoid/img/up.png)
: This is not good. It has worst-case O(n^2)
: What they were asking for is WORST-CASE O(n).
: http://en.wikipedia.org/wiki/Selection_algorithm#Linear_general
:
: 是O
【在 f*******n 的大作中提到】
![](/moin_static193/solenoid/img/up.png)
: This is not good. It has worst-case O(n^2)
: What they were asking for is WORST-CASE O(n).
: http://en.wikipedia.org/wiki/Selection_algorithm#Linear_general
:
: 是O
相关阅读
请帮忙看看这些面试问题应该怎么回答?(假设题)5万闲职和8万忙的工作,选哪个?请教resume distribution网站火急!! palantir的programming challengeCS本科入学率13年曲线[zt] (转载)再问一下target bonus的问题给LeetCode推荐一道题Modified Minimum Path Sum请问H1 transfer求bless,拿到offer发100个包子帮俺算算我的年薪是多少急问这个bonus条款是什么意思啊?海量数据处理的题目看来写bug free的code只是基本要求找工作select2perform上面C++测试挺头疼的[合集] H4可以在H1 approved后就递还是必须等10/1生效了才能递?电话面试一般多久能有消息?学院 VS 实用你们电话面试都是 手机+蓝牙耳机吗?factual vs facebook