edited by
6,538 views
14 votes
14 votes

Which one of the following sequences when stored in an array at locations $A[1], \ldots, A[10]$ forms a max-heap?

  1. $23,17,10,6,13,14,1,5,7,12$
  2. $23,17,14,7,13,10,1,5,6,12$
  3. $23,17,14,6,13,10,1,5,7,15$
  4. $23,14,17,1,10,13,16,12,7,5$
edited by

3 Answers

4 votes
4 votes
  • Option (A) is wrong here because node $14$ comes after node $10$
  • Option (B) is a correct representation of the max heap.
  • Option (C) is wrong here because node $15$ comes after node $13$.
  • Option (D) is wrong here because node $12$  comes after node $1$.

Note: Here we insert the given value one by one and check whether the value at root node $\geq$ to its children as a max heap, also it should be a complete binary tree. 

The max heap representation of option (B) is as follows:

Ref: some max heap insertion questions from the previous year:

edited by
Answer:

Related questions