This post is completed by 3 users
|
Add to List |
Find the Maximum Depth OR Height of a Binary Tree
Objective: Given a binary tree, find the height of it
Input: A Binary Tree
Output: Height of a binary tree
Example:
Approach:
Recursion:
- Get the height of left sub tree, say leftHeight
- Get the height of right sub tree, say rightHeight
- Take the Max(leftHeight, rightHeight) and add 1 for the root and return
- Call recursively.
Time Complexity : O(n)
Code:
Height of the Tree is 7
Also Read: