The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
+14 votes

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?



(C)    .   


asked in DS by Veteran (96.1k points)
edited by | 1.3k views
please edit the options..!

2 Answers

+20 votes
Best answer

in option (A) - it is not a max heap because it is not Almost Complete Binary Tree .

in option (C) - it is complete binary tree but not follow the max heap property i.e. the values of parent nodes always greater then child nodes

and  there node of value $5$ is less then on e of its children.

in option (D) - similar to above (C) option explanation here node of value $2$ is less then to the value $4$ .

correct option is (B) that is satisfy both properties and all of the max heap .

answered by (327 points) 1 flag:
✌ Edit necessary (Rajesh Panwar)

edited by
Without filling previous level completely we can not go to next level in heap, that is why a is wrong as it is not following the heap structure property.

in option (A) - it is not a max heap because it is not complete binary tree 
                     @ASHU2015 correct this line
it is not a max heap because it is not Almost Complete Binary tree. Because Heap Must Be Complete binary tree or almost complete binary tree.

+5 votes
heap is complete binary tree . so it is filled from top to bottom. left to right. option b is correct.

in option a even if all parents are greater , it does not follow heap structure
answered by Boss (11.1k points)

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
49,535 questions
54,117 answers
71,028 users