Open In App

Data Structures | Heap | Question 2

A max-heap is a heap where the value of each parent is greater than or equal to the values of its children. Which of the following is a max-heap? (GATE CS 2011) .

 


(A)

A

(B)



B

(C)

C

(D)

D


Answer: (B)
Explanation:

(A) The provided tree is not a complete tree. 
(B) The tree is a max-heap, as the root element is greater than all of its children elements.

(C) In the given tree, the Left root value 5 is smaller than 8, which is not following the constraints.
(D) In the given tree, the root value 5 is smaller than 8, which dissatisfies the condition.

Hence (B) is the correct Option. 

Quiz of this Question
Please comment below if you find anything wrong in the above post

Article Tags :