38 38 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}$ Data Structures gatecse-2001 data-structures binary-heap easy + – Kathleen 9.6k views answer comment Share Follow Print See all 2 Comments 2 2 Comments reply js__ commented Nov 5, 2025 reply Follow flag 1 / \ 2 3 a. (i-1) , 3-1 = 2 ❌c. taking ceil (2/2) = 1, ceil(3/2) = 2 ❌b. taking floor(2/2) = 1, floor(3/2) = 1 ✔d. (i+1)/2 , for i = (3+1)/2 = 2 ❌ 1 1 replyShare jacknroll commented Dec 23, 2025 reply Follow flag all binary heap are cbt 1 1 replyShare Please log in or register to add a comment.
Best answer 53 53 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 5 Comments 5 5 Comments reply Show 2 previous comments Pascua commented Dec 21, 2020 reply Follow flag left child: 2i+1 right child: 2i+2 3 3 replyShare himanshud2611 commented Aug 1, 2023 reply Follow flag 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 0 replyShare Kishori_ commented Jul 17 reply Follow flag If we start the index for "0" then the parent index will be : ceil(i/2) - 1 0 0 replyShare Please log in or register to add a comment.
6 6 votes ans b) Aditi Dan answered Dec 21, 2014 Aditi Dan comment Share Follow See all 3 Comments 3 3 Comments reply jayendra commented Dec 31, 2014 reply Follow flag ans is B. just draw the heap and number the elements. 0 0 replyShare vxi lin commented Oct 2, 2025 reply Follow flag Strange, why is this chosen as wrong answer despite b being the correct opiton 3 3 replyShare J_Last commented Nov 30, 2025 reply Follow flag maybe not explained thats why 1 1 replyShare Please log in or register to add a comment.