For this binary heap Is this a minheap or a maxheap Why Is i

For this binary heap: Is this a minheap or a maxheap? Why? Is it complete? Is it full? Which element is deleted from the heap and how does that happen?

Solution

1) In a min heap, the keys of parent nodes are less than or equal to those of the children and the lowest key is in the root node.
It is minheap as value of child nodes is greater than parent node value at each node.

2)A complete binary tree is the binary tree in which every level except possibly the last level is completely filled and all nodes
are as left as possible. So, it is a Complete Binary tree.

3)a binary tree is full binary tree if each node has exactly two children and all leaf nodes are at the same level.Since all leaf nodes are not at the same level , this is not a
full binary heap.

4)The root element is basically swapped with the last element of the heap i.e. 18 and now min heap property is maintained in the heap.
a) 18 goes to the root position and 4 is taken out. Now, min heap property i.e.the keys of parent nodes are less than or equal to those of the children.
and so, the adjusments has to me made. between the child 6 and 9 , 6 is smaller so 6 is swapped with 18.
          
b) again 18 is greater than both the child 12 and 13. so, MIN heap property is again maintained. since 12 is smaller than 18, 12 will be
swapped with 18.

c)again 18 is greater than 14 and 16. So 14 and 18 gets swapped.

4)5 will be added to left child of 17. But since now the heap doesn\'t follow min heap property. 5 is swapped with 17. Again 5 is swapped with 9 , because 5 is smaller than 9. So, 9 will come down.      
          

 For this binary heap: Is this a minheap or a maxheap? Why? Is it complete? Is it full? Which element is deleted from the heap and how does that happen?Solution

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site