Skip to content

Check if Binary Tree is Balanced #2719

Closed
@iccowan

Description

@iccowan

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions