Skip to content

Instantly share code, notes, and snippets.

@nihal-singh
Created September 18, 2018 18:17
Show Gist options
  • Save nihal-singh/4bb13daae3cd247531e557eb502b13c3 to your computer and use it in GitHub Desktop.
Save nihal-singh/4bb13daae3cd247531e557eb502b13c3 to your computer and use it in GitHub Desktop.
//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