Trees: Is This a Binary Search Tree?

  • + 2 comments

    Hi, I can't see why my solution is wrong, it looks pretty similar. If anyone has an idea...

    def check_binary_search_tree_(root):
        if (root is None):
            return True
        elif (root.left is None) and (root.right is None):
            return -float('inf')<root.data<float('inf')
        elif (root.left is None):
            return (root.right.data>root.data) and check_binary_search_tree_(root.right)
        elif (root.right is None):
            return (root.left.data<root.data) and check_binary_search_tree_(root.left)
        else:
            return (root.left.data<root.data) and (root.right.data>root.data) and check_binary_search_tree_(root.right) and check_binary_search_tree_(root.left)