Which one of the following sequences when stored in an array at locations forms 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
Which one of the following sequences when stored in an array at locations forms a max-heap?
23, 17, 10, 6, 13, 14, 1, 5, 7, 12
23, 17, 14, 7, 13, 10, 1, 5, 6, 12
23, 17, 14, 6, 13, 10, 1, 5, 7, 15
23, 14, 17, 1, 10, 13, 16, 12, 7, 5
ANSWER
Option B — 23, 17, 14, 7, 13, 10, 1, 5, 6, 12 — is the only sequence satisfying the max-heap property.
Official answer: BSource: Official answer key, GATE 2023 CS (IIT Kanpur)
A max-heap stored 1-indexed in requires, for every node that has children, and (node 5 has only child index 10; nodes 6–10 are leaves since ).
Option A: node 3, , has child . Since , the property fails — reject.
Option B: check all internal nodes — ; ; ; ; . All pairs satisfy the property — B is a valid max-heap.
Option C: node 5, , has child . Since , the property fails — reject.
Option D: node 4, , has children . Since , the property fails — reject.
Only option B satisfies the max-heap property everywhere.
KEY IDEA
In a 1-indexed array max-heap, node 's children sit at and , and the heap property requires every parent's value to be greater than or equal to both of its children's values, everywhere in the array — checking this level by level (or bottom-up from the last internal node) is enough to rule options in or out.
WATCH OUT FOR
Treating the array as 0-indexed (children at ) instead of 1-indexed, which shifts every parent-child pair and can make a genuine violation look fine, or a valid heap look broken.
From the GATE 2023 CS paper. Every question of this paper · Download the full paper · All 26 Trees & heaps questions, with notes