804 views

Which of the following is a valid heap?

1. $a$
2. $b$
3. $c$
4. $d$

all option are false

Option A is violated max heap property because 8 is greater than his root.
Option B  is violated max heap property because 8 is greater than his root.
Option C is violated max heap property because 7 is greater than his root.
Option D is violated max heap property because 9,10,8,7 elements are greater than his root.

OPTION (B) This is only tree which follows the property of max heap.

In binary search tree root is greater than left Subtree and less than right subTree but in heap there are two cases

Case1:Max heap:Root is maximum in this if not then we have to heapify

Case 2:Min heap:Root is minimum in this if not then we have to do heapify

A) no because of 4

B) yes

C) no because of 1

D) same as c

So option b

### 1 comment

Option A and B are same
A , D , C are invalid

As there are child>parent case

A: 8>4

C: 7>1

D: 10>3

only B is valid heap... parents>children

### 1 comment

This is the case of a max heap. in min heap parent < child

1 vote