Java program to find the maximum depth or height of a tree
In this program, we need to find out the maximum height of the binary tree. The height of the binary tree can be defined as the number of nodes between root and a leaf. Maximum height will be the number of levels between root and deepest leaf. To solve this problem, we traverse through the left subtree and calculate the height of the left subtree. Again, calculate the height of the right subtree by traversing through it. Maximum height will be maximum of the height of the left subtree and right subtree.
In the above binary tree,
a. findHeight() will determine the maximum height of the binary tree:
Maximum height of given binary tree: 5