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 $i-1$ $\lfloor \frac{i}{2} \rfloor$ $\lceil \frac{i}{2} \rceil$ $\frac{(i+1)}{2}$ DS gatecse-2001 data-structures binary-heap easy + – Kathleen asked Sep 14, 2014 • edited Jan 2, 2018 by kenzou Kathleen 5.0k views answer comment Share Follow See all 0 reply Please log in or register to add a comment.
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$ Pooja Palod answered Sep 10, 2015 • edited May 5, 2019 by Naveen Kumar 3 Pooja Palod comment Share Follow See all 4 Comments See all 4 4 Comments reply papesh commented Aug 23, 2016 i moved by papesh Oct 8, 2016 reply Follow Share Ans is floor(i/2) .. If index starts with 0 than Ceil(i/2)-1 18 votes 18 votes harypotter0 commented Nov 1, 2020 reply Follow Share @papesh What would be the left child and right child if index starts with 0? 0 votes 0 votes Pascua commented Dec 21, 2020 reply Follow Share left child: 2i+1 right child: 2i+2 3 votes 3 votes himanshud2611 commented Aug 1, 2023 reply Follow Share simple intuition to check whether floor or ceil value – it depends on the type of indexing. indexing from 1 gives floor i/2 whereas indexing from 0 gives ceil i/2, to ensure this just draw a binary tree of whatever no of nodes and verify! 0 votes 0 votes Please log in or register to add a comment.
4 votes 4 votes ans b) Aditi Dan answered Dec 21, 2014 Aditi Dan comment Share Follow See 1 comment See all 1 1 comment reply jayendra commented Dec 31, 2014 reply Follow Share ans is B. just draw the heap and number the elements. 0 votes 0 votes Please log in or register to add a comment.