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.

![Question 59, GATE 2009: Which zero-based array is a binary max-heap? A[25, 12, 16, 13, 10, 8, 14]; B[25, 14, 13, 16, 10, 8, 12]; C[25, 14, 16, 13, 10, 8, 12]; D[25, 14, 12, 13, 10, 8, 16].](../../../assets/questions/CS-2009-Q59-1.webp)
![Question 59, GATE 2009: Which zero-based array is a binary max-heap? A[25, 12, 16, 13, 10, 8, 14]; B[25, 14, 13, 16, 10, 8, 12]; C[25, 14, 16, 13, 10, 8, 12]; D[25, 14, 12, 13, 10, 8, 16].](../../../assets/questions/CS-2009-Q59-2.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-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)
![Question 14(a), GATE 1991: The complete binary tree has level-order array [1,5,18,7,13,25,20,11,9,15,17,27]. Its edges are 1→(5,18), 5→(7,13), 18→(25,20), 7→(11,9), 13→(15,17), and 25→(27,left only). Identify the data structure.](../../../assets/questions/CS-1991-Q63-1.webp)
![Question 14(a), GATE 1991: The complete binary tree has level-order array [1,5,18,7,13,25,20,11,9,15,17,27]. Its edges are 1→(5,18), 5→(7,13), 18→(25,20), 7→(11,9), 13→(15,17), and 25→(27,left only). Identify the data structure.](../../../assets/questions/CS-1991-Q63-2.webp)
![Question 14(a), GATE 1991: The complete binary tree has level-order array [1,5,18,7,13,25,20,11,9,15,17,27]. Its edges are 1→(5,18), 5→(7,13), 18→(25,20), 7→(11,9), 13→(15,17), and 25→(27,left only). Identify the data structure.](../../../assets/questions/CS-1991-Q63-3.webp)