edited by
14,042 views
30 30 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$

3 Answers

8 8 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:
Position:
Show:

Related questions

26 26 votes
3 3 answers
16.8k
16.8k views
admin asked Feb 15, 2023
16,764 views
Let $A$ be a priority queue for maintaining a set of elements. Suppose $A$ is implemented using a max-heap data structure. The operation $\text{EXTRACT-MAX} (A)$ extracts...
40 40 votes
6 6 answers
27.0k
27.0k views
admin asked Feb 15, 2023
26,982 views
Let $\textsf{SLLdel}$ be a function that deletes a node in a singly-linked list given a pointer to the node and a pointer to the head of the list. Similarly, let $\textsf...
33 33 votes
6 6 answers
18.9k
18.9k views
admin asked Feb 15, 2023
18,853 views
Consider the $\text{C}$ function $\text{foo}$ and the binary tree shown.typedef struct node { int val; struct node *left, *right; } node; int foo(node *p) { int retval; i...
23 23 votes
4 4 answers
15.8k
15.8k views
admin asked Feb 15, 2023
15,792 views
Consider a sequence $a$ of elements $a_{0}=1, a_{1}=5, a_{2}=7, a_{3}=8, a_{4}=9$, and $a_{5}=2$. The following operations are performed on a stack $S$ and a queue $Q,$ b...