Consider an array representation of an n element binary heap where the elements are stored from index 1 to index n of the array. For the element stored at index i of the array (i < = n), the index of the parent is:
Consider an array representation of an n element binary heap where the elements are stored from index 1 to index n of the array. For the element stored at index i of the array (i < = n), the index of the parent is: Correct Answer floor (i / 2)
The correct answer is "option 3".
CONCEPT:
The binary heap is a complete binary tree with heap properties.
Binary heap is either max. heap (root value > all key values) or min. heap. (root value < all key values).
EXPLANATION:
Binary heap elements can be represented using an array with index value i (i < = n),
Parent node of element will be at index: floor (i / 2)
Left Child node will be at index: 2 * i
Right child node will be at index: 2 * i + 1
Hence, the index of the parent is floor (i / 2).
মোঃ আরিফুল ইসলাম
Feb 20, 2025