Write a C function to find the height or depth of a tree.
Solution : The height can be found out recursively by calculating height of left sub tree tree and right sub tree.Height of tree would be the maximum of height of left subtree and height of right subtree + 1.
int heightofTree(struct node *root) { int lheight,rheight; if(root==NULL) return 0; if(root->left) lheight = heightofTree(root->left); if(root->right) rheight = heightofTree(root->right); return(max(lheight,rheight)+1); }