477 views
1 votes
1 votes
int A(struct node* node) 
    {
        if (node==NULL) 
            return 0;
        else
        {
   
              int lDepth = A(node->left);
              int rDepth = A(node->right);

              /* use the larger one */
              if (lDepth > rDepth) 
                    return(lDepth+1);
              else 
                   return(rDepth+1);
       }
    } 

1 Answer

0 votes
0 votes
At every node function call is made. It returns the number of levels in tree or height of tree if we consider root at level-1. Such questions can be answered by taking small tree and see what function returns.

Related questions

2 votes
2 votes
2 answers
1
radha gogia asked Jul 24, 2015
4,930 views
int fun(int x, int y) { if (y == 0) return 0; return (x + fun(x, y-1)); } int fun2(int a, int b) { if (b == 0) return 1; return fun(a, fun2(a, b-1)); }
0 votes
0 votes
0 answers
2
Rajesh Raj asked Dec 4, 2016
270 views
Anyone plz help in differentiating "consistency, inconsistency, valid,invalid,tautology, contradiction,arguments,fallacy" ?
0 votes
0 votes
2 answers
4
Desert_Warrior asked May 16, 2016
826 views
int foo( int a, int b) { int c = a-b; c = c&(0x80000000); return (!c)*a +(!!c)*b; }