• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

Data Structures | Tree Traversals | Question 1

Following function is supposed to calculate the maximum depth or height of a Binary tree -- the number of nodes along the longest path from the root node down to the farthest leaf node. C
int maxDepth(struct node* node)
   if (node==NULL)
       return 0;
       /* compute the depth of each subtree */
       int lDepth = maxDepth(node->left);
       int rDepth = maxDepth(node->right);
       /* use the larger one */
       if (lDepth > rDepth)
           return X;
       else return Y;
What should be the values of X and Y so that the function works correctly?


X = lDepth, Y = rDepth


X = lDepth + 1, Y = rDepth + 1


X = lDepth - 1, Y = rDepth -1


None of the above


Please comment below if you find anything wrong in the above post
Feeling lost in the world of random DSA topics, wasting time without progress? It's time for a change! Join our DSA course, where we'll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 geeks!

Last Updated :
Share your thoughts in the comments