Which of the following indices of do/does NOT correspond to any leaf node of the minheap?
["B","C"]
Step-by-Step Solution
Insight: In a complete binary tree with nodes, the leaf nodes are exactly those at indices to . The internal nodes are $1$ to . We just need to check which options fall in the internal node range.
Exam route:
- Identify the range of leaf indices for a heap of size : from to .
- Since is odd, let . The internal nodes are $1$ to , and leaves are to .
- Evaluate each option:
- (Leaf)
- (Internal)
- (Internal)
- (Leaf)
- The question asks for indices that do NOT correspond to leaf nodes, which are the internal nodes.
- These are and .
Learning route:
- A binary heap is a complete binary tree.
- The array representation maps the tree level by level.
- For an array of size , the parent of node is .
- A node is a leaf if it has no children, i.e., .
- Thus, internal nodes are .
- For odd , .
- So internal nodes are .
- Option A is , which is , so it's a leaf.
- Option B is , which is , so it's an internal node.
- Option C is , which is , so it's an internal node.
- Option D is , which is the last element, always a leaf.
- Therefore, B and C do not correspond to leaf nodes.