119k views
1 vote
Consider a node R of a complete binary tree whose value is stored in position i of an array representation for the tree. If R has a right child, where will the right child's position be in the array?

a. 2∗i+1
b. 2∗i+2
c. i+1
d. None of the above

User Aeon
by
8.0k points

1 Answer

1 vote

Final answer:

In a complete binary tree represented as an array, the right child of a node at position i is located at position 2*i+2, assuming the array is zero-indexed.

Step-by-step explanation:

If you consider a node R of a complete binary tree whose value is stored in position i of an array representation for the tree, and R has a right child, the right child's position in the array will be 2*i+2. In a complete binary tree represented as an array, the left child of a node at position i is at position 2*i+1, while the right child is at position 2*i+2. This is under the assumption that the indexing of the array starts at 0. Therefore, if the node at position i has a right child, that child would indeed be located at position 2*i+2 of the array.

User Manoel Stilpen
by
7.8k points