edited by
525 views
0 votes
0 votes

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

edited by

Please log in or register to answer this question.

Related questions

1 votes
1 votes
2 answers
1
CHïntän ÞäTël asked Dec 10, 2018
978 views
four vertices {A,B,C,D} is given which has only vertex D as a leaf total number of binary tree are possible when every binary tree has four node!
0 votes
0 votes
1 answer
2
0 votes
0 votes
1 answer
3