IAE Academy

GATE 2026 CS1 Q.23: solution and answer

GATE 2026 · CS1Q.23 · 1 mark · MSQ

Let be an odd number greater than 100. Consider a binary minheap with elements stored in an array whose index starts from 1.

Which of the following indices of do/does NOT correspond to any leaf node of the minheap?

  1. (A)

  2. (B)

  3. (C)

  4. (D)

See the question in the paper

Answer and solution

ANSWER

The indices that do NOT correspond to any leaf node are (B) and (C) .

Official answer: B, CSource: Official answer key, GATE 2026 CS1 (IIT Guwahati)

  1. Rule: in a 1-indexed array-stored binary heap of n nodes, node i has children at 2i and 2i+1. Node i is internal iff 2i <= n, i.e., i <= floor(n/2); node i is a leaf iff i > floor(n/2).

  2. Since n is odd, floor(n/2) = (n-1)/2. So internal (non-leaf) indices run from 1 to (n-1)/2, and leaf indices run from (n-1)/2 + 1 = (n+1)/2 up to n.

  3. Option (A) (n+1)/2 equals floor(n/2) + 1, the very first leaf index, so it IS a leaf: it is NOT one of the required answers.

  4. Option (B) (n-1)/2 equals floor(n/2) exactly, the last internal node, so it is NOT a leaf: this IS one of the required answers.

  5. Option (C) (n-3)/2 equals floor(n/2) - 1, strictly inside the internal range, so it is NOT a leaf: this IS one of the required answers.

  6. Option (D) n is the last stored element; its would-be children 2n and 2n+1 both exceed n, so it has no children and IS a leaf: it is NOT one of the required answers.

  7. Sanity check with n = 101: floor(101/2) = 50, so leaves are indices 51 through 101. (A) 51 is a leaf. (B) 50 is internal (not a leaf). (C) 49 is internal (not a leaf). (D) 101 is a leaf. This confirms that (B) and (C) are exactly the indices that do NOT correspond to a leaf node.

KEY IDEA

In a 1-indexed array representation of an -node binary heap, node is internal iff (its children still lie within ), and node is a leaf iff . For odd , , so the last internal index is and the first leaf index is .

WATCH OUT FOR

Confusing the leaf-boundary index (the first leaf) with the last internal node. Since is itself the LAST internal node (not a leaf), and is the FIRST leaf, it is easy to mislabel option (A), , as non-leaf, or to mislabel (B), , as a leaf, by an off-by-one slip in the floor computation.

From the GATE 2026 CS1 paper. Every question of this paper · Download the full paper · All 26 Trees & heaps questions, with notes

More Trees & heaps questions