This post is completed by 4 users

  • 1
Add to List
Beginner

36. Find the Maximum Depth OR Height of a Binary Tree

Objective: Given a binary tree, find the height of it

Example:

Tree Height - Example

Approach: Recursion

  1. Get the height of the left sub-tree, say left height
  2. Get the height of the right sub tree, say rightHeight
  3. Take the Max(leftHeight, rightHeight)  and add 1 for the root, and return
  4. Call recursively.

Time Complexity : O(n)

get Height of a tree - Recursion

 
Height of the Tree is 7