In many of websites i have seen that hieght of tree is calculated as
int height(Node node)
{
if (node == null)
return 0;
else
{
int lDepth = height(node.left);
int rDepth = height(node.right);
if (lDepth > rDepth)
return (lDepth + 1);
else
return (rDepth + 1);
}
}But i have seen that hieght of empty tree is -1 and root node has height 0 ;
So why people use "root==null" return 0 ;
and not -1;
I am confused a lot .
What will be the hieght of empty tree ? and depth of binary tree ?