retagged by
449 views
1 votes
1 votes
  1. Design an algorithm to construct one heap that contains all the elements of two given heaps of sizes n and m, respectively. The heaps are given in a linked-list representation ( each node has links to its two children). The running time of the algorithm should be O(log(m + n)) in the worst case
retagged by

1 Answer

0 votes
0 votes
We take the last element of one of the heaps and add it to the root and connect the two heaps to it. Now apply heapify on the resulting tree which takes O(log(m+n)) (in the worst case) to settle the root to its correct position.

Related questions

638
views
0 answers
0 votes
manvi_agarwal asked Sep 10, 2018
638 views
https://gateoverflow.in/?qa=blob&qa_blobid=17275535249024428371
720
views
0 answers
0 votes
Shiv Gaur asked Aug 20, 2018
720 views
How traversal in a heap takes place? Consider a min heap , I think we cannot traverse it like a binary tree ......For Example if we have to print all elements ... overall takes O(N) time ? Whether same is for search as well Plz explain...
1.6k
views
0 answers
0 votes
Shubhanshu asked Oct 18, 2017
1,599 views
In a binary min heap with n elements, the 7th smallest element can be found in _____ ?Answer given is O(logn) and solution:-Delete the 1st smallest ... heap will be changed after performing these operation.any better solution than this???