Question:hard

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?

Show Hint

For a 1-indexed binary heap with n nodes, indices from 1 to floor(n/2) are internal nodes and indices greater than floor(n/2) are leaves; since n is odd, floor(n/2) = (n-1)/2.
Updated On: Aug 3, 2026
  • \(\frac{n+1}{2}\)
  • \(\frac{n-1}{2}\)
  • \(\frac{n-3}{2}\)
  • \(n\)
Show Solution

The Correct Option is B, C

Solution and Explanation

Instead of working with the general formula directly, let's pick a concrete odd value of n greater than 100, say \(n = 101\), compute the actual leaf boundary, and then generalize the pattern to confirm the answer.

Step 1: Find the last internal (non-leaf) node for \(n = 101\).

For a 1-indexed heap, the last internal node index is \(\lfloor n/2 \rfloor = \lfloor 101/2 \rfloor = 50\). So indices \(1\) through \(50\) are internal nodes (have children), and indices \(51\) through \(101\) are leaves.

Step 2: Evaluate each option numerically at \(n=101\).

Option A: \(\dfrac{n+1}{2} = \dfrac{102}{2} = 51\). Since \(51 \gt 50\), this is a leaf.

Option B: \(\dfrac{n-1}{2} = \dfrac{100}{2} = 50\). Since \(50 \le 50\), this is an internal node, not a leaf.

Option C: \(\dfrac{n-3}{2} = \dfrac{98}{2} = 49\). Since \(49 \le 50\), this is also an internal node, not a leaf.

Option D: \(n = 101\), the last node in the array, which is always a leaf.

Step 3: Confirm the pattern holds for any odd \(n \gt 100\).

Because \(n\) is odd, \(\lfloor n/2 \rfloor = \dfrac{n-1}{2}\) always. Option B always lands exactly on this boundary (internal), and option C is always one less (also internal), while options A and D always fall strictly beyond it (leaves). This numeric check with \(n=101\) matches the general algebraic argument.

Step 4: State the final result.

The indices that do NOT correspond to any leaf node are those given by options B (\(\frac{n-1}{2}\)) and C (\(\frac{n-3}{2}\)).

Was this answer helpful?
0

Top Questions on Trees


Questions Asked in GATE CS exam