Consider program
int foo(struct node *tree)
{
if(tree==0)
return 0;
int lh=ht(tree->left);
int rh=ht(tree->right);
int ld=foo(tree->left);
int rd=foo(tree->right);
return max(lh+rh+1,max(ld,rd));
}
int ht(struct node*node)
{
if(node==null)
return o;
return 1+max(ht(node->left),ht(node->right));
}
The value returned by foo when a pointer to the root of a binary tree is passed as its argument is
- Number of leaf nodes in the tree
- Difference in the number of nodes in left and right
- Depth of the tree
- Diameter (maximum number of nodes on the longest path between two leaf nodes) of tree
How d could be correct ......it would be correct only when we consider nodes between leaf nodes including leaf nodes itself