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 in index i of the array (i < =n), the index of the parent is
A
ceiling (i/2)
No worries! We‘ve got your back. Try BYJU‘S free classes today!
B
floor (i/2)
Right on! Give the BNAT exam to get a 100% scholarship for BYJUS courses
C
ceiling ((i + 2)/2)
No worries! We‘ve got your back. Try BYJU‘S free classes today!
D
floor ((i - 2)/2)
No worries! We‘ve got your back. Try BYJU‘S free classes today!
Open in App
Solution
The correct option is B floor (i/2) If array index is starting from '1' then for any node whose index 'i' its left child at index 2i and right child at index 2i + 1 and its parent index at ⌊i2⌋.