Tree/validate_bst library

🌳 Binary Search Tree Validator

Validates if a binary tree is a valid Binary Search Tree (BST). A BST has the property that for every node, all values in the left subtree are less than the node's value, and all values in the right subtree are greater than the node's value.

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);
root.left!.right = BinaryTreeNode<int>(7);
final isValid = validateBST(root);
// isValid: true

Functions

validateBST<T extends Comparable>(BinaryTreeNode<T>? root) → bool