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.
What should be the values of X and Y so that the function works correctly?
(A) X = lDepth, Y = rDepth
(B) X = lDepth + 1, Y = rDepth + 1
(C) X = lDepth – 1, Y = rDepth -1
(D) None of the above
Explanation: If a tree is not empty, height of tree is
MAX(Height of Left Subtree, Height of Right Subtree) + 1
See program to Find the Maximum Depth or Height of a Tree for more details.