A max-heap is a heap where the value of each parent is greater than or equal to the value of its children. Which of the following is a max-heap?
A max-heap is a heap where the value of each parent is greater than or equal to the value of its children. Which of the following is a max-heap? Correct Answer <img alt="F1 Raju Shraddha 01.06.2021 D 8" src="//storage.googleapis.com/tb-img/production/21/06/F1_Raju_Shraddha_01.06.2021_D%208.png" style="width: 192px; height: 152px;">
The correct answer is option 2
CONCEPT:
A max-heap is a complete binary tree in which the value in each internal node is greater than or equal to the values in the children of that node.
Explanation:
Option 1: not a max heap
[ alt="F1 Raju Shraddha 01.06.2021 D 7" src="//storage.googleapis.com/tb-img/production/21/06/F1_Raju_Shraddha_01.06.2021_D%207.png" style="width: 157px; height: 210px;">
Since there is no right child for element 8. Hence it is not a complete binary tree. Therefore it is not a max heap
Option 2: max heap
[ alt="F1 Raju Shraddha 01.06.2021 D 8" src="//storage.googleapis.com/tb-img/production/21/06/F1_Raju_Shraddha_01.06.2021_D%208.png" style="width: 192px; height: 152px;">
Follow max heap properties
Option 3: not a max heap
[ alt="F1 Raju Shraddha 01.06.2021 D 9" src="//storage.googleapis.com/tb-img/production/21/06/F1_Raju_Shraddha_01.06.2021_D%209.png" style="width: 191px; height: 152px;">
Reason:
In a max heap, the keys of parent nodes are always greater than or equal to those of the children
but in this option, the child node 8 is greater than parent node 5.
Option 4: not a max heap
[ alt="F1 Raju Shraddha 01.06.2021 D 10" src="//storage.googleapis.com/tb-img/production/21/06/F1_Raju_Shraddha_01.06.2021_D%2010.png" style="width: 192px; height: 152px;">
Reason:
In a max heap, the keys of parent nodes are always greater than or equal to those of the children
but in this option child node, 10 is greater than parent node 8.