Trees: Is This a Binary Search Tree?

  • + 0 comments
    #A tree is a binary tree if its inorder traversal is sorted
    a = []
    def checkBST(root):
            if not root : return True
            def inorder(root):
                    if root.left :
                            inorder(root.left)
                    a.append(root.data)
                    if root.right:
                            inorder(root.right)
            inorder(root)
            return a==sorted(list(set(a)))