edited by
4,915 views
25 votes
25 votes

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}$
edited by

2 Answers

Best answer
33 votes
33 votes
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$

Correct Answer: $B$
edited by
Answer:

Related questions

22 votes
22 votes
7 answers
1
Kathleen asked Sep 14, 2014
24,128 views
What is the minimum number of stacks of size $n$ required to implement a queue of size $n$?OneTwoThreeFour
25 votes
25 votes
2 answers
2
Kathleen asked Sep 14, 2014
10,420 views
Which of the following requires a device driver?RegisterCacheMain memoryDisk
37 votes
37 votes
3 answers
3
Kathleen asked Sep 14, 2014
12,507 views
Where does the swap space reside?RAMDiskROMOn-chip cache
36 votes
36 votes
2 answers
4
Kathleen asked Sep 14, 2014
12,523 views
The process of assigning load addresses to the various parts of the program and adjusting the code and the data in the program to reflect the assigned addresses is called...