Question:

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: Jul 7, 2026
  • 𝑛+ 1 2
  • π‘›βˆ’1 2
  • π‘›βˆ’3 2
  • 𝑛
Show Solution
collegedunia
Verified By Collegedunia

The Correct Option is B, C

Solution and Explanation

We have a binary min-heap with n elements (n odd, n > 100) stored in array P with 1-based indexing. We need to identify which given index does NOT correspond to a leaf node.

Step 1: Recall the leaf-node rule for a 1-indexed binary heap.

In a binary heap stored in an array with indices starting at 1, the parent of the node at index i is at \(\lfloor i/2 \rfloor\), so a node at index i is an internal node (has at least one child) if and only if \(2i \le n\), i.e., \(i \le \lfloor n/2 \rfloor\). Consequently, a node is a leaf if and only if \(i \gt \lfloor n/2 \rfloor\).

Step 2: Simplify \(\lfloor n/2 \rfloor\) for odd n.

Since n is odd, \(n = 2k+1\) for some integer k, so \(\lfloor n/2 \rfloor = k = \dfrac{n-1}{2}\). So leaf indices are exactly those with \(i \gt \dfrac{n-1}{2}\), and internal-node indices satisfy \(i \le \dfrac{n-1}{2}\).

Step 3: Test each option against this boundary.

Option (A): \(i = \dfrac{n+1}{2} = \dfrac{n-1}{2} + 1\). This is strictly greater than \(\dfrac{n-1}{2}\), so it IS a leaf.

Option (B): \(i = \dfrac{n-1}{2}\). This exactly equals the internal-node boundary \(\dfrac{n-1}{2}\), so it is an internal node, NOT a leaf.

Option (C): \(i = \dfrac{n-3}{2} = \dfrac{n-1}{2} - 1\). This is strictly less than \(\dfrac{n-1}{2}\), so it is also an internal node, NOT a leaf.

Option (D): \(i = n\), the very last index, which always satisfies \(n \gt \dfrac{n-1}{2}\) for n > 1, so it IS a leaf.

Step 4: Conclude.

The indices that do NOT correspond to a leaf node are \(\dfrac{n-1}{2}\) (option B) and \(\dfrac{n-3}{2}\) (option C).

\[ \boxed{\text{Options B and C}} \]
Was this answer helpful?
0
0

Top GATE CS Computer Science and IT Engineering Questions

View More Questions

Top GATE CS Trees Questions