Skip to content

Check if Binary Tree is Balanced #2719

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
iccowan opened this issue Oct 24, 2021 · 1 comment · Fixed by #2732
Closed

Check if Binary Tree is Balanced #2719

iccowan opened this issue Oct 24, 2021 · 1 comment · Fixed by #2732
Assignees

Comments

@iccowan
Copy link
Contributor

iccowan commented Oct 24, 2021

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

  1. Iterate through every node in the tree in a post-order traversal, calculating the height of each sub-tree for each node
  2. 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
@iccowan
Copy link
Contributor Author

iccowan commented Oct 24, 2021

Please assign this to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant