• +91 9723535972
  • info@interviewmaterial.com

Data structure Interview Questions and Answers

Question - Write a recursive C function to calculate the height of a binary tree.

Answer -

int countHeight(struct node* t)  
{  
    int l,r;  
    if(!t)  
        return 0;  
    if((!(t->left)) && (!(t->right)))  
        return 0;  
    l=countHeight(t->left);  
    r=countHeight(t->right);  
    return (1+((l>r)?l:r));  
}         

Comment(S)

Show all Coment

Leave a Comment




NCERT Solutions

 

Share your email for latest updates

Name:
Email:

Our partners