771 views
1 1 vote
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 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.
Position:
Show:

Related questions

2 2 votes
2 answers 2 answers
5.6k
5.6k views
radha gogia asked Jul 24, 2015
5,632 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 0 votes
0 0 answers
486
486 views
Rajesh Raj asked Dec 4, 2016
486 views
Anyone plz help in differentiating "consistency, inconsistency, valid,invalid,tautology, contradiction,arguments,fallacy" ?
22 22 votes
3 answers 3 answers
11.1k
11.1k views
pC asked Jul 27, 2016
11,051 views
Cache 1Direct Mapping 17 tag 10 block5 word Cache 2Set Assosicative 2- way associative 1895Cache 3Associative Cache 27 5 Calculate Hit Latenncy in Each of Three Cache...
1 1 vote
2 2 answers
1.2k
1.2k views
Desert_Warrior asked May 16, 2016
1,188 views
int foo( int a, int b) { int c = a-b; c = c&(0x80000000); return (!c)*a +(!!c)*b; }