public static int findHeight(Tree root) {
int leftHeight, rightHeight;
if (root == null) {
return 0;
}
leftHeight = 1 + findHeight(root.left);
rightHeight = 1 + findHeight(root.right);
return leftHeight > rightHeight ? leftHeight : rightHeight;
}
My confusion here is for the variables leftHeight and rightHeight. What exactly is being added for the recursive call on this line?
leftHeight = 1 + findHeight(root.left);
findHeight(root.left) does not return any value at that point so what addition will take place there? Or does it sum up the leftHeight for each recursive call? If so, how does that work?