Khan.randRange(0, 11) ["parent", "left child", "right child", "left sibling", "right sibling"] Khan.randRange(0, 4) completeFIB.genAnswer(node, randrel)

WARNING! Read the conditions for the problems in this set very carefully! The type of relation and node can change from problem to problem.

For a complete binary tree with nodes labeled as in the figure above, what is the relation[randrel] of the node labeled node? Type in the node number of the relation[randrel], or if one does not exist, then type NONE.

ANS

To find the parent of node R, calculate \lfloor (R - 1)/2 \rfloor. If R = 0, then it has no parent.

To find the left child of node R, calculate 2R + 1. If 2R + 1 \geq N, then R has no left child.

To find the right child of node R, calculate 2R + 2. If 2R + 2 \geq N, then R has no right child.

To find the left sibling of node R, calculate R - 1 if R is even and not 0. If R is odd or is 0, then it has no left sibling.

To find the right sibling of node R, calculate R + 1 if R is odd, and R + 1 < N. If these conditions are not met, then R has no right sibling.