Find whether Binary tree is a Binary Search Tree

Property: A binary tree is a Binary Search Tree when all elements to the left is lesser than the current node and the ones to the right are greater than that node.

  • Simplest way to understand is when you print a left node, root and right node, you should get a sorted list based on property of BST.
  • In other words, traversing in the order Left, Root, Right is called Inorder traversal.
  • Inorder traversal visits each element in a tree exactly once and hence takes O(n) time, where ’n’ is the number of elements.

  • Hence, if Inorder traversal of a Binary tree produces a sorted list, the tree is said to be a Binary Search Tree.