Is This a Binary Search Tree?

  • + 0 comments
    def check_binary_search_tree_(root):
        # create helper function
        def check(root, min_value, max_value):
            # base case
            if root is None:
                return True
            
            # general case
            if root.data < min_value or root.data > max_value:
                return False
            
            return check(root.left, min_value, root.data - 1) and check(root.right, root.data + 1, max_value)
        
        return check(root, 0, 10000)