Consider a heap containing n elements, where n > 100 and n is odd. Assuming 1-based indexing, which of the following cannot be the index of a leaf node in the heap?
Correct Answer :
(n−1)/2
Solution :
The correct answer is (n−1)/2.
To understand why this is correct, let us analyze the properties of a binary heap represented as an array with 1-based indexing. For any node at index in a heap containing elements:
- The left child of the node is located at index .
- The right child of the node is located at index .
- A node is a leaf node if it has no children, which means its left child index exceeds the total number of elements in the heap: .
- Conversely, a node is an internal (non-leaf) node if it has at least one child, which means:
Let us now test the index given in the correct option, which is:
To determine if this node can be a leaf, we calculate the index of its left child:Since we are given that , it is clear that:
This means the index of the left child, , is a valid position within the heap. In fact, since is odd, the node at index also has a right child at index . Because the node at index has children, it must be an internal node and cannot be a leaf node in the heap.Access expert-curated educational resources and study materials—completely free.
Create, conduct, and manage professional online assessments with Mindyard. Perfect for teachers and institutes.
Copyright © 2026 Mindyard. All Rights Reserved.