Redirected
edited by
1,621 views
0 votes
0 votes

Consider an 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. $\text{floor} ((i+1)/2)$
  2. $\text{ceiling} ((i+1)/2)$
  3. $\text{floor} (i/2)$
  4. $\text{ceiling} (i/2)$
edited by

1 Answer

2 votes
2 votes

Consider a binary heap of n elements in which elements are stored in array from index 1 to n

Parent of any element at index i is calculated as $\lfloor{\frac{i}{2}}\rfloor$

For ex. Index of parent of 2(its index is 8) =$\lfloor{\frac{8}{2}}\rfloor=4$

Index of parent of 3(its index is 7) =$\lfloor{\frac{7}{2}}\rfloor=3$

Hence option 3) is correct

Answer:

Related questions

1 votes
1 votes
2 answers
1
Arjun asked Nov 5, 2017
3,067 views
Which speed up could be achieved according to Amdahl's Law for infinte number of processes if $5\%$ of a program is sequential and the remaining part is ideally parallel?...
0 votes
0 votes
1 answer
2
Arjun asked Nov 5, 2017
2,519 views
Which of the given wireless technologies used in IoT, consumes the least amount of power?ZigbeeBluetoothWi-FiGSM/CDMA
0 votes
0 votes
2 answers
3
Arjun asked Nov 5, 2017
4,592 views
Which of the following is not a Clustering method?K-Means methodSelf Organizing feature map methodK- nearest neighbor methodAgglomerative method