由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - Quick selection for k unsorted arrays
相关主题
优步面试,哎。。。请问两道题
facebook 电面M大小的数组中选出前N个元素 (如果M和N都很大)
自己设计的一道面试题一道小题
问一个merge k sorted array的问题TopK nearest points为啥用heap不用selection sort?
fb + google 电面面经找2个sorted array中的第K小的元素,有O(lgn)方法吗?
刷题刷到没自信了一个算法题:Selecting median of three sorted arrays
问道算法题Quick Sort的partition问题
找median有O(N)的算法吗?find median for k sorted arrays
相关话题的讨论汇总
话题: arrays话题: quick话题: unsorted话题: selection话题: log
进入JobHunting版参与讨论
1 (共1页)
d**0
发帖数: 124
1
请教一个题目: k个unsorted arrays,假设都是n个元素。怎么样快速求出median?
不能把所有的array拼到一起再做quick selection。
我用类似quick selection的方法使用同一个pivot element在k个arrays里quick
select,再求 方法应该是这样,但是复杂度分析不出来。一个naive的bound是o(kn),但是这样就和拼
到一起做quick select一样。最后猜了一个o(nlogk)但是自己也不是很信服。
请大牛指教,谢谢!
l******e
发帖数: 149
2
you don't need to physically 把所有的array拼到一起再做quick selection, but
logically.
O(kn)
f*******n
发帖数: 12623
3
可以 O(k*log(n)^2)
Binary search in the first array for the index closest to the median. At
each step, binary search in the other (k-1) arrays for the current value in
the first array. Then add the indexes to see if we are before or after the
median. At the end, we are down to one element and we also know the index in
the other arrays. The answer is in one of these.
The bigger binary search is log(n), at each step, we need to do (k-1) * log(
n), so multiplied together we get O(k*log(n)^2)
d**0
发帖数: 124
4
这k个arrays是unsorted的啊 你的做法是认为他sorted吧

in
in
log(

【在 f*******n 的大作中提到】
: 可以 O(k*log(n)^2)
: Binary search in the first array for the index closest to the median. At
: each step, binary search in the other (k-1) arrays for the current value in
: the first array. Then add the indexes to see if we are before or after the
: median. At the end, we are down to one element and we also know the index in
: the other arrays. The answer is in one of these.
: The bigger binary search is log(n), at each step, we need to do (k-1) * log(
: n), so multiplied together we get O(k*log(n)^2)

1 (共1页)
进入JobHunting版参与讨论
相关主题
find median for k sorted arraysfb + google 电面面经
CC150 18.6 quick select刷题刷到没自信了
top k 用 heap 还是quick selection?问道算法题
问个面试题找median有O(N)的算法吗?
优步面试,哎。。。请问两道题
facebook 电面M大小的数组中选出前N个元素 (如果M和N都很大)
自己设计的一道面试题一道小题
问一个merge k sorted array的问题TopK nearest points为啥用heap不用selection sort?
相关话题的讨论汇总
话题: arrays话题: quick话题: unsorted话题: selection话题: log