function quickfindFirstK(list, left, right, k)
if right > left
select pivotIndex between left and right
pivotNewIndex := partition(list, left, right, pivotIndex)
if pivotNewIndex > k // new condition
quickfindFirstK(list, left, pivotNewIndex-1, k)
if pivotNewIndex < k
quickfindFirstK(list, pivotNewIndex+1, right, k)
function partition(list, left, right, pivotIndex)
pivotValue := list[pivotIndex]
swap list[pivotIndex] and list[right] // Move pivot to end
storeIndex := left
for i from left to right
if list[i] < pivotValue
swap list[storeIndex] and list[i]
increment storeIndex
swap list[right] and list[storeIndex] // Move pivot to its final place
return storeIndex
Top K algorithm
转载本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
Linux-top命令
爱看不看,随便!截图真费劲。
优先级 sed oracle -
Top(K)
topK问题
topK问题 -
海量数据求top K
文章目录一、大根堆/小根堆二、快排分割三、海量数据查重和topK的综合应用1. 题目1:数据的重复次数最大/最小的前K个/第K
算法 数据结构 c++ 小根堆 数据