Write an algorithm to see if a tree is a BST.
Utilisateur anonyme
The above wont work, consider a tree that has a root value for 5, left is 4, right is 6, left of the left is 3 and right of the left is 6. This one should work (for integers): boolean isBST(Node root) { return isBST_helper(root, INT_MIN, INT_MAX); } boolean isBST_helper(Node root, int min, int max) { if (root == null) return true; return root.value >= min && root.value < max && isBST(root.left, min, root.value) && isBST(root.right, root.value+1, max); }