15 votes

Consider a binary max-heap implemented using an array.

Which one of the following array represents a binary max-heap?

- $\left\{25,12,16,13,10,8,14\right\}$
- $\left\{25,14,13,16,10,8,12\right\}$
- $\left\{25,14,16,13,10,8,12\right\}$
- $\left\{25,14,12,13,10,8,16\right\}$

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

(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