0

I have a specific question about min-max heap related problem in Java.

If you have inputs in this order:

71, 8, 41, 100, 60

Would the tree look like the following?

                   8
           100           41
       70       60

What about after deleteMin and deleteMax?

I am trying to understand what would happen if the max node is somehow smaller than some of the min nodes... If you can help me by explaining it with a tree that would be great :)

nbro
  • 15,395
  • 32
  • 113
  • 196

1 Answers1

-2

The process of creating the min heap of this inputs is this:

        71
      8    41
  100  60

And then it looks like this:

     8
  71  41
100 60

And at last, it looks like this:

      8
  60    41
100  71

At this time, every non-leaf node, its value is greater than that of its children's. So, after you delete the min value, the root of the min-heap above would be deleted, and result is this:

     41
  60    100
71

And if you delete the max value, that would be the last element that is deleted. then the result would be this:

     8
  60    41
71

I hope this would help you to understand Heap.

SilentKnight
  • 13,761
  • 19
  • 49
  • 78
  • 1
    I am sorry but is that a min. heap? I thought that is different from Min-Max heap... – Thank you for your help Mar 31 '15 at 02:49
  • 2
    There is actually another type of heap: min-max heap which involves both min and max heaps... – Thank you for your help Mar 31 '15 at 03:06
  • @SilentKnight There exists really a _min-max heap_ data structure. [Here](https://en.wikipedia.org/wiki/Min-max_heap)'s the Wikipedia's related page, which isn't complete. However, you can check the original paper in the references of that same article. – nbro Mar 12 '17 at 16:38