Tree/balanced_tree_check library

🌳 Balanced Tree Checker

Checks if a binary tree is height-balanced. A tree is height-balanced if the heights of the left and right subtrees of every node differ by at most one.

Time complexity: O(n) where n is the number of nodes Space complexity: O(h) where h is the height of the tree (worst case O(n))

Example:

final root = BinaryTreeNode<int>(10);
root.left = BinaryTreeNode<int>(5);
root.right = BinaryTreeNode<int>(15);
root.left!.left = BinaryTreeNode<int>(3);
final isBalanced = isBalancedTree(root);
// isBalanced: true

Functions

isBalancedTree<T>(BinaryTreeNode<T>? root) → bool