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 :)
The process of creating the min heap of this inputs is this:
And then it looks like this:
And at last, it looks like this:
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:
And if you delete the max value, that would be the last element that is deleted. then the result would be this:
I hope this would help you to understand Heap.