Q. Program to find the maximum depth or height of a treeExplanationIn 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, Height of left subtree is 2. The maximum height of the given binary tree is (4 + 1) = 5 denoted by white dotted line. Algorithm
SolutionPythonOutput: Maximum height of given binary tree: 5 COutput: Maximum height of given binary tree: 5 JAVAOutput: Maximum height of given binary tree: 5 C#Output: Maximum height of given binary tree: 5 PHPOutput: Maximum height of given binary tree: 5
Next TopicPrograms List
