class Node: def __init__(self, data): self.data = data self.left = None self.right = None def get_height(root): if root is None: return 0 return max(get_height(root.left), get_height(root.right)) + 1 def is_tree_balanced(root): if root is None: return True lh = get_height(root.left) rh = get_height(root.right) if (abs(lh - rh) <= 1) and is_tree_balanced( root.left) is True and is_tree_balanced( root.right) is True: return True return False