Following function is supposed to calculate the maximum depth or height of a…

Following function is supposed to calculate the maximum depth or height of a Binary tree —( root is at level 1)

int maxDepth (struct node* node)

{

    if (node==NULL)

        return 0;

    else

    {

        /* 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?

  1. A.

    X = lDepth, Y = rDepth

  2. B.

    X = lDepth + 1, Y = rDepth + 1

  3. C.

    X = lDepth – 1, Y = rDepth -1

  4. D.

    None of the above

Attempted by 494 students.

Sign up free to check your answer

Sign up free

Explore the full course: Isro

Loading lesson…