Given parent array representation of a tree, construct the tree using this parent array. In this parent array representation, a node would be constructed with values taken from indices of this array. For element parent[i], a node would be constructed with value 'i'. And parent node for this constructed node with value 'i' would be node with value parent[i]. If parent[i] is -1, then we make the node with value 'i' as the root of the tree. For example, for the parent array {3, 5, 0, -1, 5, 3, 0} - parent[0] is 3 and also parent[5] is 3, therefore node with value 3 would be parent node for nodes with values 0 and 5. Similarly, parent[1]=parent[4]=5, therefore node with value 5 would be parent node for nodes with values 1 and 4. Then parent[2]=parent[6]=0 implies that node with value 0 would be parant node for nodes with values 2 and 6. Here, parent[3] is -1 therefore, node 3 would be the root node for this tree.

The complete constructed tree for parent array {3, 5, 0, -1, 5, 3, 0} would look like following:

For parent array {-1, 0, 1, 5, 1, 0}, constructed binary tree would be :