In: Computer Science
a.) Lets first define structure of each node in binary tree:-
node {
int data;
node *left, *right;
}
where variable 'data' will store the actual data in a node and pointer variables, 'left' and 'right' will store the address of left and right child respectively.
Now, lets define the structure of binary tree,
For an element at index 'i' its right child will be 'i+4', where 'i' will be multiple of 4. For example 'i' can have values,
0, 4, 8, 12, 16, 20, .... and so on.
Special case:-
When last index of array is not a multiple of 4, then.
In worst case, we have to travers all right nodes and then all left nodes from the last right node. Element that we are searching for will be present in the last leaf node, and index of this node will be the last highest index which is not multiple of 4.
Maximum number of nodes which will be required to access is
MAX((last_index/4 + last_index%4), (last_index/4 + 2)) + 1.
T(n) = O(n).
where 'n' is the size of array.
Tree will look something like this, Missing nodes are NULL in this given binary tree .
Node A16 is the special case node.