You are viewing a single comment's thread. Return to all 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
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
Seems like cookies are disabled on this browser, please enable them to open this website
Trees: Is This a Binary Search Tree?
You are viewing a single comment's thread. Return to all 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
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