The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+12 votes
1.3k views

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

  1. $i-1$
  2. $\lfloor \frac{i}{2} \rfloor$
  3. $\lceil \frac{i}{2} \rceil$
  4. $\frac{(i+1)}{2}$
asked in DS by Veteran (59.5k points)
edited by | 1.3k views

2 Answers

+21 votes
Best answer
for node at index $i$

left $child(L)$ at $2$i

right $child(R)$ at $2i+1$

for node at index $i$

parent will be at floor $i/2$
answered by Boss (31.3k points)
edited by
+6
Ans is floor(i/2) ..

If index starts with 0 than Ceil(i/2)-1
+2 votes
ans b)
answered by Active (5.2k points)
0
ans is B.

just draw the heap and number the elements.


Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

37,111 questions
44,694 answers
127,232 comments
43,753 users