简体   繁体   English

如何在O(k)时间内实现一个算法来合并两个堆,其中n = 2 ^ k个元素?

[英]How to implement an algorithm to merge two heaps with n=2^k number of elements in O (k) time?

However, I don't even know what this problem means. 但是,我甚至不知道这个问题意味着什么。

This only takes a minimum time of O (n) to just merge the two sorted arrays, I don't know how to merge in O (k) time. 这只需要O(n)的最小时间来合并两个排序的数组,我不知道如何在O(k)时间内合并。

This is a total of three problems associated with it: 这是与之相关的三个问题:

The purpose of this problem is to explore the possibility of building a standard heap efficiently in a top-down manner. 此问题的目的是探索以自上而下的方式有效构建标准堆的可能性。

  1. Give a high level description of an algorithm that merges two standard heaps which each contain exactly n = 2^k elements. 给出一个算法的高级描述,该算法合并两个标准堆,每个堆包含n = 2 ^ k个元素。 The algorithm should run in O(k)time. 该算法应在O(k)时间内运行。

  2. Using the subroutine as specified in part 1, give a recursive or iterative algorithm that builds a heap of 2^n elements. 使用第1部分中指定的子例程,给出一个递归或迭代算法,构建一个2 ^ n个元素的堆。

  3. Write down an equation for the running time of the algorithm specified in part 2, solve it. 记下第2部分中指定的算法运行时间的等式,求解它。

You can use the Binomial_heap or Leftist heaps . 您可以使用Binomial_heapLeftist堆

When n=2^k they all have merge operation in O(k) time. 当n = 2 ^ k时,它们都在O(k)时间内具有合并操作。

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

相关问题 使用堆在O(N log K)时间中找到前K个元素 - Find the top K elements in O(N log K) time using heaps 如何在 O(k log n) 时间内搜索 n 个元素中的 k 个元素? - How do search k elements of n elements in O(k log n) time? 在 O(n log n) 时间内生成具有 n 个长度和 k 个反转的数组的算法? - Algorithm to generate an array with n length and k number of inversions in O(n log n) time? 如何获得基于O(n log k)-时间比较的算法对k-multiset进行排序? - How to get a O(n log k)-time comparison-based algorithm to sort k-multiset? 算法的渐近分析:如何将k个新元素插入到时间大小为n的排序列表中(k log k + n) - Asymptotic Analysis of Algorithms:how to insert k new elements into a sorted list of size n in time O(k log k + n) 在O(n log n)时间内找到特殊点k的算法 - Algorithm to find special point k in O(n log n) time 如何对具有n个元素的数组进行排序,其中k个元素在O(n + k log k)中不合适? - How to sort an array with n elements in which k elements are out of place in O(n + k log k)? 在O(nk)时间复杂度中合并k个排序大小为n的数组 - Merge k sorted arrays of size n in O(nk) time complexity 算法K路合并。 这个解决方案是O(n log k)吗? - Algorithm K-Way Merge. Would this solution be O(n log k)? 在O(n)时间内遍历LinkedList并删除k个元素 - walking through a LinkedList and deleting k elements, in O(n) time
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM