Consider an array representation an n element binary heap where the elements are stored from index 1 to index n of the array. For the element stored at…
Consider an array representation 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 :
Show answerHide answer
Correct answer: (C) floor (i/2)
Explanation
In a binary heap stored in an array from index 1 to n, the children of index i are at 2i and 2i + 1, so the parent of the element at index i is at floor(i/2).