Adobe Interview Question
Computer Scientistsint height(struct node* node)
{
if (node==NULL)
return 0;
else
{
/* compute the height of each subtree */
int lheight = height(node->left);
int rheight = height(node->right);
if (lheight > rheight)
return(lheight+1);
else return(rheight+1);
}
}
you can't reconstruct a tree with 100% certainty if you are given preorder and postorder, consider a tree that has left only or right only sub-trees then you can have the same preorder and postorder for two different trees.
- Vir Pratap Uttam May 04, 2015