Similar questions 4 more →
Heaps & Priority Queues
![Question 76, GATE 2006: A ternary max-heap is stored level-by-level, left-to-right, in a zero-based array. Root is a[0]; children of i are 3i+1,3i+2,3i+3. Insert by appending then moving upward until the parent is at least as large. Which array is a valid heap?
Options:
(A) [1,3,5,6,8,9]
(B) [9,6,3,1,8,5]
(C) [9,3,6,8,5,1]
(D) [9,5,6,8,3,1]](../../assets/questions/CS-2006-Q76-1.webp)
![Question 76, GATE 2006: A ternary max-heap is stored level-by-level, left-to-right, in a zero-based array. Root is a[0]; children of i are 3i+1,3i+2,3i+3. Insert by appending then moving upward until the parent is at least as large. Which array is a valid heap?
Options:
(A) [1,3,5,6,8,9]
(B) [9,6,3,1,8,5]
(C) [9,3,6,8,5,1]
(D) [9,5,6,8,3,1]](../../assets/questions/CS-2006-Q76-2.webp)
Answer & solution
Answer: D (no official key was published)
1. In a zero-based ternary heap, children of i are 3i+1,3i+2,3i+3. For D=[9,5,6,8,3,1], root 9 dominates 5,6,8 and node 5 dominates children 3,1.
2. A fails at the root; B has parent 6 with child 8; C has parent 3 with child 5. Only D is a valid max-heap.
3. Teaching check: Heap order is a parent-child condition, not full sorting. For six entries only root 0 and node 1 have children; checking these is sufficient. Option D’s 8 may exceed node 1’s 5 because they are siblings, so that comparison imposes no restriction.