Height of Binary Tree
1) If node is null then return 0.
2) Else we call the recursive function, height for left and right subtree and choose their maximum.
3) We also add 1 to the result which indicates height of root of the tree.
2) Else we call the recursive function, height for left and right subtree and choose their maximum.
3) We also add 1 to the result which indicates height of root of the tree.
int height(struct Node* root)
{
if(root==0)
return 0;
else
return 1+max(height(root->right),height(root->left));
}
{
if(root==0)
return 0;
else
return 1+max(height(root->right),height(root->left));
}
Comments
Post a Comment