Trees: Is This a Binary Search Tree?

  • + 2 comments

    Here is the Logic

    The Inorder Traversal of the Binary Search Tree gives you the sorted array. i.e

    if tree is something like this

    image Source :wiki

    then its Inorder Traversal would be

    A, B, C, D, E, F, G, H, I.

    and now I have checked if the i th element is greater than its previous (i-1)th element

    if the loop is over then return true else there is a violation and the tree isnt BST so return false