1

This is a somewhat homework question and somewhat not. In my homework I had to demonstrate how to merge two Heaps of the same size and estimate it's time complexity. While I was searching for this I read about skew Heaps and the Fibonacci Heap.

My question is, can you combine two heaps of separate sizes to one heap? With all the examples I found online I couldn't get a straight answer from it.

Thanks everyone.

Pradeep Simha
  • 17,683
  • 18
  • 56
  • 107
  • 1
    Did you check this thread? http://stackoverflow.com/questions/1595333/merge-heaps-algorithm – Amit Feb 19 '13 at 04:28
  • I'm sorry. I didn't see that thread. Will check now, thank you. –  Feb 19 '13 at 14:58

1 Answers1

0

Take an array of size M+N : where M is the size of first array and N is the size of second array. Now insert all the elements into that array and hepify it. Time complexity would be O((m+n)log(m+n)){as each hepify operation takes log(m+n) and we have m+n elements} + the complexity of the insert operation: Theta(m)+Theta(n) + O((m+n)log(m+n))

TruthTeller
  • 186
  • 2
  • 9