Skip to content
Official PYQ · 2026

GATE CS 2026 Set 1 Q13 — Searching, Sorting, Hashing

Explain with AI

Let nn be an odd number greater than 100100. Consider a binary minheap with nn elements stored in an array PP whose index starts from 11.

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

Select all correct options
View worked solution

Answer: B;C

In a 1-indexed binary heap of size nn, a node at index ii is a leaf node if and only if it has no children.

The left child of a node at index ii is located at index 2i2i. Therefore, node ii is a leaf node if:

2i>n  ⟹  i>n22i > n \implies i > \frac{n}{2}

Since nn is given to be an odd number, we can write n=2k+1n = 2k + 1 for some integer kk. Substituting this into the inequality:

i>2k+12  ⟹  i≥k+1i > \frac{2k+1}{2} \implies i \ge k + 1

Since k=n−12k = \frac{n-1}{2}, the leaf nodes are located at indices:

i≥n−12+1  ⟹  i≥n+12i \ge \frac{n-1}{2} + 1 \implies i \ge \frac{n+1}{2}

Thus, the indices corresponding to leaf nodes are from n+12\frac{n+1}{2} to nn. The indices corresponding to non-leaf (internal) nodes are from 11 to n−12\frac{n-1}{2}.

Let's evaluate each option:

  • Option A: n+12\frac{n+1}{2} is the first leaf node.
  • Option B: n−12\frac{n-1}{2} is the last non-leaf node. Hence, it is not a leaf node.
  • Option C: n−32\frac{n-3}{2} is less than n−12\frac{n-1}{2}, so it is a non-leaf node. Hence, it is not a leaf node.
  • Option D: nn is the last element of the heap, which is a leaf node.

Therefore, the indices that do NOT correspond to any leaf node are B and C.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Searching, Sorting, Hashing questions