1

I have a (min) Leftist Heap as show below:

               1
            /     \
            8      6
          /   \   /  \
         10   12 14   16
                 /\   /
               18 20  22

And I am asked to show the result of inserting 21. My understanding of leftist heaps is that inserting is just a merge of a single node, in which case, 21 should get compared to each right parent until it reaches the NULL child of 16, and should just automatically get placed in there. Am I wrong? Should it go somewhere else?

Rekson
  • 1,293
  • 3
  • 12
  • 13
  • Is there a typo that the left node relative to 1 is 8 and the right node is 6? – Vlad from Moscow Nov 04 '13 at 22:46
  • The left child of 1 is 8 and the right child of 1 is 6. Is there something wrong with that? Its a leftist minheap, it follows the appropriate rules – Rekson Nov 04 '13 at 22:54
  • Well, 1 is the only node in the graph where its left child is the largest node. The other nodes have their largest child on the right. – Sean Nov 04 '13 at 23:00

1 Answers1

0

I have no idea why the commenters were so concerned with with node ordering. Maybe they didn't know what a leftist heap even was?

Turns out the answer is that is does become the right child of 16, but because the NPL of 6 becomes 2, which is greater than the left tree's NPL of 1, you have to swap the 8 and 6 tree locations.

Rekson
  • 1,293
  • 3
  • 12
  • 13