What is the location of a parent node for any arbitary node i?

Category: QuestionsWhat is the location of a parent node for any arbitary node i?
Editor">Editor Staff asked 4 weeks ago

What is the location of a parent node for any arbitary node i?
 
(a) (i/2) position
 
(b) (i+1)/ position
 
(c) floor(i/2) position
 
(d) ceil(i/2) position
 
The above asked question is from Binary Heap topic in chapter Heap of Data Structures & Algorithms I
 
This question was posed to me by my school teacher while I was bunking the class.

1 Answers
Editor">Editor Staff answered 4 weeks ago

Right choice is (c) floor(i/2) position
 
The best I can explain: For any node child nodes are located at either 2*i, 2*i +1 So the parent node could be found by taking the floor of the half of child node.