简体   繁体   English

在O(K)时间中找到大小为N的最大堆中最大K个数的算法?

[英]Algorithm for finding the largest K numbers in a max heap of size N in O(K) time?

The O(K * logK) algorithm for finding the largest K numbers in a max heap of size N is well known. 在大小为N的最大堆中找到最大K个数的O(K * logK)算法是众所周知的。 I heard about that there is an O(K) algorithm for solving this problem. 我听说有一个O(K)算法可以解决此问题。 I do not find the literature on this. 我找不到有关此的文献。 Could anyone give any pointers on this? 有人可以对此提出任何建议吗? Thanks! 谢谢!

I finally find the paper that describes the algorithm. 我终于找到描述该算法的论文。 There is a similar question on Quora . 关于Quora也有类似的问题。

The paper, " An Optimal Algorithm for Selection in a Min-Heap ", by GN Frederickson, describes the algorithm. GN Frederickson的论文“ 用于最小堆中的最优选择算法 ”描述了该算法。 The following is the abstract: 以下是摘要:

An O(k)-time algorithm is presented for selecting the kth smallest element in a binary min-heap of size n⪢k. 提出了一种O(k)时间算法,用于选择大小为n⪢k的二进制最小堆中的第k个最小元素。 The approach uses recursively defined data structures that impose a hierarchical grouping on certain elements in the heap. 该方法使用递归定义的数据结构,该数据结构对堆中的某些元素施加了分层分组。 The result establishes a further example of a partial order for which the kth smallest element can be determined in time proportional to the information theory lower bound. 结果建立了偏序的另一个示例,对于该偏阶,可以在时间上确定与信息理论下限成比例的第k个最小元素。 Two applications, to a resource allocation problem and to the enumeration of the k smallest spanning trees, are identified. 确定了两个应用程序,分别用于资源分配问题和k个最小生成树的枚举。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM