con you provide me pseudo code of this question with explain
How to solve this question
The question says to find out whether a given binary tree is balanced or not. A non-empty binary tree T is balanced if:
- Left subtree of T is balanced
- Right subtree of T is balanced
- The difference between heights of left subtree and right subtree is not more than 1.
Also, an empty tree is balanced.
Algorithm:
- Get the height of left and right subtrees.
- Return true if difference between heights is not more than 1 and left and right subtrees are balanced, otherwise return false.
you can also optimize this approach further.