Ans is floor(i/2) ..

If index starts with 0 than Ceil(i/2)-1

If index starts with 0 than Ceil(i/2)-1

Consider any 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 \leq n)$, the index of the parent is

- $i-1$
- $\lfloor \frac{i}{2} \rfloor$
- $\lceil \frac{i}{2} \rceil$
- $\frac{(i+1)}{2}$

Best answer

Search GATE Overflow