由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - The time complexity on finding the kth largest element in a
相关主题
partition array problemfind elements in an array that sum up to a given number
array a1,a2,... ,an, b1,b2,..., bnFind the intersection of two sorted arrays【扩展】
请问G一题Given an array of N integers from range [0, N] and one is missing. Find the missing number.
MS a0, a1, ..., b0, b1... 问题finding the majority element in an array?
问道算法题关于quicksort的两种实现方法
find Kth Largest Element 有没有更简化的解法Find the Kth smallest element in 2 sorted
求教一个onsite面试题目果家OA, 关于数组中S[K]的最大长度,要求O(N)时间与空间
一个算法题:Selecting median of three sorted arrays请教一道题目
相关话题的讨论汇总
话题: array话题: sa话题: element话题: largest话题: kth
进入JobHunting版参与讨论
1 (共1页)
r****o
发帖数: 1950
1
【 以下文字转载自 InterviewHackers 俱乐部 】
发信人: roufoo (五经勤向窗前读), 信区: InterviewHackers
标 题: The time complexity on finding the kth largest element in a
发信站: BBS 未名空间站 (Tue Jun 1 22:42:09 2010, 美东)
We can use the partition() in qsort. Each time, we can partition the array
into two parts, array_a and array_b. Let the number of elements in array_a
and array_b be sa and sb, respectively.
If sa is smaller than k, then find the (k-sa)th largest element in array_b;
If sa is larger than or equal to k, then find
g*****a
发帖数: 1457
2
the worst case is that every round of recursion, sb is 1.
the O(n) = n + ( n-1) + (n-2)... + k = O(n^2)
g*****a
发帖数: 1457
3
why not just use max heap or loser tree
1 (共1页)
进入JobHunting版参与讨论
相关主题
请教一道题目问道算法题
向各位大侠请教几道面试题的思路find Kth Largest Element 有没有更简化的解法
Quick sort为什么需要logN的memory?求教一个onsite面试题目
Find the first k smallest numbers in an array.一个算法题:Selecting median of three sorted arrays
partition array problemfind elements in an array that sum up to a given number
array a1,a2,... ,an, b1,b2,..., bnFind the intersection of two sorted arrays【扩展】
请问G一题Given an array of N integers from range [0, N] and one is missing. Find the missing number.
MS a0, a1, ..., b0, b1... 问题finding the majority element in an array?
相关话题的讨论汇总
话题: array话题: sa话题: element话题: largest话题: kth