Hello,
i found two codes for finding out the height of the tree
(this is what creating confusion for me which one is correct)
1.
int height( BinaryTree Node t) {
if t is a null tree
return -1;
hl = height( left subtree of t);
hr = height( right subtree of t);
h = 1 + maximum of hl and hr;
return h;
}
2. int height(BST_t *root) {
if(root == NULL)
return 0;
return 1+ max( height ( root->left ), height( root->right ) );
}
for the above codes
if i have only one node in the list one function displays
height as -1 and other displays 0
(i am in confusion which one is right)
if my tree is 40 and 20 with 40 as root node
then 1 displays 1 and other displays 2.
Please can some one help me out what actually the height of the Tree is and how to find it.