201k views
5 votes
if a maxheap has 100 elements in it, implemented using an array with an empty element at index 0, what is the index of the parent of the element whose index is 47?

User KickinMhl
by
7.0k points

1 Answer

5 votes

Answer: 23

Step-by-step explanation:

In a max heap implemented as an array, the parent of the element at index i is located at the index floor(i/2). Therefore, to find the index of the parent of the element at index 47 in a max heap with 100 elements implemented using an array with an empty element at index 0, we can simply use this formula:

parentIndex = floor(47/2) = 23

Note that in this case, the empty element at index 0 is ignored when calculating the parent index, since it is not considered part of the heap.

User Jau L
by
7.2k points