Consider any array representation of an element binary heap where the elements are stored from index to index of the array. For the element stored at index of the array , the index of the parent is
View worked solution
Answer: B
In a standard 1-based array representation of a binary heap, the elements are mapped as follows:
- The root of the heap is stored at index .
- For any node at index ():
- Its left child is located at index (if ).
- Its right child is located at index (if ).
To find the parent of a node at index (where ), we reverse this relationship:
- If the node is a left child, its index is , so its parent is at index .
- If the node is a right child, its index is , so its parent is at index .
Combining both cases using the floor function, the parent of the node at index is always located at index:
Example:
- For the node at index , its parent is at .
- For the node at index , its parent is at .
Therefore, the correct option is B.
Free practice · Your answers on this page are not saved.
