You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Check if Binary Tree is Balanced
Given the root of a binary tree, check and see if the tree is balanced. A binary tree is balanced if for every node in the tree, the height of the left and the right sub-trees differ by at most 1. This can be done in both an iterative and recursive fashion.
Solution
Iterate through every node in the tree in a post-order traversal, calculating the height of each sub-tree for each node
Compare the heights of the left and right sub-trees for each node in the tree and if any are greater than 1, return false, else, return true
The text was updated successfully, but these errors were encountered:
Check if Binary Tree is Balanced
Given the root of a binary tree, check and see if the tree is balanced. A binary tree is balanced if for every node in the tree, the height of the left and the right sub-trees differ by at most 1. This can be done in both an iterative and recursive fashion.
Solution
The text was updated successfully, but these errors were encountered: