views:

317

answers:

1

I've been stuck on a question for a while and was wondering if anyone can point me in the right direction:

suppose binary heaps are represented using a pointer-based tree representation instead of an array. consider the problem of merging binary heap LHS with RHS. assume both heaps are full complete trees, containing (2^L) - 1 and (2^R) -1 nodes, respectively. Give two O(log N) algorithms to merge the two heaps if L = R and if |L - R| = 1

note: this is a homework problem, i just need to be pointed in the right direction

+4  A: 

Hint for L=R: pretend you've just removed the root. Let me know if you need more.

outis
Thank you so much! I get it now!
This is a good hint. What I can't figure out is, what is the prof. getting at with the |L-R| = 1? Seems like the algorithm that is the result of your hint would work in that case as well.
PeterAllenWebb
Think about the properties of an array-based heap, and how the algorithm hinted at would violate some of these properties if |L-R|=1. Actually, it's not just array-based heaps; think about the shape property.
outis