Let be an odd number greater than . Consider a binary minheap with elements stored in an array whose index starts from .
Which of the following indices of do/does NOT correspond to any leaf node of the minheap?
View worked solution
Answer: B;C
In a 1-indexed binary heap of size , a node at index is a leaf node if and only if it has no children.
The left child of a node at index is located at index . Therefore, node is a leaf node if:
Since is given to be an odd number, we can write for some integer . Substituting this into the inequality:
Since , the leaf nodes are located at indices:
Thus, the indices corresponding to leaf nodes are from to . The indices corresponding to non-leaf (internal) nodes are from to .
Let's evaluate each option:
- Option A: is the first leaf node.
- Option B: is the last non-leaf node. Hence, it is not a leaf node.
- Option C: is less than , so it is a non-leaf node. Hence, it is not a leaf node.
- Option D: 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.
