419 views
0 votes
0 votes
An array X of n distinct integers is interpreted as a complete binary tree.The index of first element of array is 0.index of parent of element X[i] is

(i-2)/2

(i/2)-1

2 Answers

Best answer
0 votes
0 votes

if index of first element of array is 0 then left child of ith element will be at 2*i+1 and right child at 2(i+1)

so index of parent of element X[i] is ⌈i2⌉−1

otherwise take one example and verify it

selected by
0 votes
0 votes
i think answer should be (i/2) -1

we should take upper bound of (i/2)

Related questions

0 votes
0 votes
1 answer
1
0 votes
0 votes
1 answer
3