Created
September 18, 2018 18:17
-
-
Save nihal-singh/4bb13daae3cd247531e557eb502b13c3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Pseudo code to check whether a binary tree is Binary Search Tree or not | |
bool checkBST(Node* root,int min,int max){ | |
if(root == NULL)return true; | |
if(root->data > min && root->data < max && checkBST(root->left,min,root->data) && checkBST(root->right,root->data,max)) | |
return true; | |
else return false; | |
} | |
isBST(Node* root){ | |
return checkBST(root, INT_MIN, INT_MAX); | |
} | |
//##We can also do the Inorder traversal of the binary search tree as the Inorder traversal of BST is sorted and thus can Find BST. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment