Heaps & Priority Queues
![Question 41, GATE 2024: The array [82,101,90,11,111,75,33,131,44,93] is “heapified”. Which first three entries result? A 82,90,101; B 82,11,93; C 131,11,93; D 131,111,90. The original does not specify min-heap versus max-heap; the official answer uses the usual bottom-up max-heap interpretation.](../../assets/questions/CS-2024-S1-Q41-1.webp)
Answer & solution
Official answer: D
Step through it (13 steps)
Approach: Under the intended max-heap convention, every parent must be at least as large as its children. Build the heap bottom-up by sifting down internal nodes, using zero-based indices.
1. Start at index 4 (value 111), whose child is 93, so no change. At index 3, swap 11 with its larger child 131. Index 2 contains 90 above children 75 and 33 and needs no change.
2. At index 1, 101 has children 131 and 111. Swap with 131; 101 then sits at index 3 above 11 and 44.
3. At index 0, 82 must move below 131. At its new index 1, move it below 111; then at index 4 move it below 93.
4. The resulting array is [131,111,90,101,93,75,33,11,44,82]. Its first three entries are 131,111,90, matching D.
“Heap” alone also allows a min-heap, whose root would be 11, absent from all options. The question also does not name a particular construction algorithm. D is retained as the official intended answer, not as a uniquely forced result of the literal wording. Existing discrepancy CS-2024-S1-Q41-HEAP-TYPE remains open.