Similar questions 4 more →
Heaps & Priority Queues
![Question 37, GATE 2004: Insert 32,15,20,30,12,25,16 one at a time into an empty binary max-heap, using upward restoration after each insertion. Which resulting heap is obtained? The four source diagrams are encoded below as level-order arrays (root first, left-to-right at each level).
Options:
(A) [32,30,25,15,12,20,16]
(B) [32,25,30,12,15,20,16]
(C) [32,30,25,15,12,16,20]
(D) [32,25,30,12,15,16,20]](../../assets/questions/CS-2004-Q37-1.webp)
Answer & solution
Answer: A (no official key was published)
Step through it (11 steps)
1. Insert32,15,20, then 30 bubbles above 15, giving[32,30,20,15]. Insert12 unchanged.
2. Insert25 bubbles above 20, giving[32,30,25,15,12,20];16 remains under 25. Final level order is 32,30,25,15,12,20,16, diagram A.
3. Teaching check: Insertion order matters: the final heap need not be the one obtained by bottom-up heapifying the array or sorting its values. Inserting 30 swaps it above 15; inserting 25 swaps it above 20. All remaining parent-child inequalities already hold.