wiz-icon
MyQuestionIcon
MyQuestionIcon
1
You visited us 1 times! Enjoying our articles? Unlock Full Access!
Question

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)/2)
No worries! We‘ve got your back. Try BYJU‘S free classes today!
C
floor (i/2)
Right on! Give the BNAT exam to get a 100% scholarship for BYJUS courses
D
ceiling ((i + 2)/2)
No worries! We‘ve got your back. Try BYJU‘S free classes today!
Open in App
Solution

The correct option is C 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

flag
Suggest Corrections
thumbs-up
0
similar_icon
Similar questions
View More
Join BYJU'S Learning Program
Join BYJU'S Learning Program
CrossIcon