Merging two perfect binary heaps?

I got stuck in the question for a while and wondered if anyone could point me in the right direction:

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

This is a domestic problem, I just need to point in the right direction.

+6
java merge data-structures binary-heap
source share
1 answer

Hint for L = R: Pretend you just deleted the root. Let me know if you need more.

+5
source share

All Articles