Submitted by jjadmin on Wed, 06/08/2016 - 19:46
Problem
Given a binary tree, find out if it is a binary search tree or not.
Approach 1ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd
-
You can traverse the tree in in-order way, and see if the elements are assending.
-
You may either put the elements into an array and see if the array is sorted in assending way,
-
or while traversing see if the current element is always greater than or equal to previous element.
-
return false is current data is less than previously printed data.
-
may use a static variable to hold the last printed value.
-
Complete solution can be found @ http://javajee.com/solution-checking-if-a-binary-tree-is-a-binary-search....