private static bool BruteForce(BinaryTreeNode <int> root) { if (root == null) { return(true); } foreach (BinaryTreeNode <int> node in BinaryTree.InOrderTraversal(root.Left)) { if (node.Data > root.Data) { return(false); } } foreach (BinaryTreeNode <int> node in BinaryTree.InOrderTraversal(root.Right)) { if (node.Data < root.Data) { return(false); } } return(SatisfiesBST.BruteForce(root.Left) && SatisfiesBST.BruteForce(root.Right)); }
private static bool Recursive(BinaryTreeNode <int> root, int minValue = int.MinValue, int maxValue = int.MaxValue) { if (root == null) { return(true); } if (root.Data < minValue || root.Data > maxValue) { return(false); } return(SatisfiesBST.Recursive(root.Left, minValue, root.Data) && SatisfiesBST.Recursive(root.Right, root.Data, maxValue)); }
private static bool Recursive(BinaryTreeNode <int> root) { return(SatisfiesBST.Recursive(root, int.MinValue, int.MaxValue)); }