Let π be an odd number greater than 100. Consider a binary minheap with nβ¦
2026
Let π be an odd number greater than 100. Consider a binary minheap with n 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?
- A.
n+1/2
- B.
n-1/2
- C.
n-3/2
- D.
n
Attempted by 14 students.
Show answer & explanation
Correct answer: B, C
In a binary heap with n elements using 1-based indexing, the parent of node i is floor(i/2). A node i has children if 2*i <= n. Therefore, nodes with indices from 1 to floor(n/2) are internal nodes (non-leaves), and nodes with indices from floor(n/2)+1 to n are leaf nodes. Since n is odd, floor(n/2) equals (n-1)/2. Thus, any index less than or equal to (n-1)/2 does not correspond to a leaf node.