in DS retagged by
13,584 views
23 votes
23 votes

Consider a binary max-heap implemented using an array.
Which one of the following array represents a binary max-heap?

  1. $\left\{25,12,16,13,10,8,14\right\}$    
  2. $\left\{25,14,13,16,10,8,12\right\}$
  3. $\left\{25,14,16,13,10,8,12\right\}$
  4. $\left\{25,14,12,13,10,8,16\right\}$
in DS retagged by
13.6k views

3 Answers

15 votes
15 votes
Best answer

Answer : (C)

The binary max-Heap looks like this :

Max-heap

 

edited by
18 votes
18 votes
Taking the given array as level order traversal, we can build binary tree.

(A)  13 comes as child of 12, which is not allowed in a binary max-heap

(B) 16 comes as child of 14 violating max-heap property

(C) is a valid binary max-heap as all children are smaller than their parent

(D) 16 comes as child of 12, violating max-heap property
by
0 votes
0 votes

option c is right

Answer:

Related questions