Finding if a Binary Tree is a Binary Search Tree [duplicate]
This question already has an answer here: How do you validate a binary search tree? 30 answers Today I had an interview where I was asked to write a program which takes a Binary Tree and returns true if it is also a Binary Search Tree otherwise false. My Approach1: Perform an in-order traversal and store the elements in O(n) time. Now scan through the array/list of elements and check if element at i th index is greater than element at (i+1) th index. If such a condition is encountered, return false and break out of the loop. (This takes O(n) time). At the end return true. But this gentleman