Similar questions 4 more →
Heaps & Priority Queues
![Question 12, GATE 2023: Which 1-indexed array is a max-heap? A [23,17,10,6,13,14,1,5,7,12]; B [23,17,14,7,13,10,1,5,6,12]; C [23,17,14,6,13,10,1,5,7,15]; D [23,14,17,1,10,13,16,12,7,5].](../../assets/questions/CS-2023-Q12-1.webp)
Answer & solution
Official answer: B
In a one-indexed max-heap, A[i] must be at least both A[2i] and A[2i+1] when those children exist. B satisfies all parent-child inequalities: 23≥17, 14; 17≥7, 13; 14≥10, 1; 7≥5, 6; 13≥12. A fails at 10<14, C at 6<7 and 13<15, and D at 1<12. Answer B.
Teaching detail. A heap is only partially ordered: parent keys dominate child keys, but siblings need not be sorted and the array need not be globally descending. There are only five possible parent positions in this ten-element array. For A, index 3 contains 10 and child index 6 contains 14. For C, parent index 4 contains 6 but child 9 contains 7. For D, parent 4 contains 1 but child 8 contains 12. One violation suffices to reject a candidate; every edge must pass to accept B.