We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Is This a Binary Search Tree?
Is This a Binary Search Tree?
Sort by
recency
|
899 Discussions
|
Please Login in order to post a comment
Some of the tests are wrong. The following tree is binary search. But it says that it's not. Thank u for wasting my time :( data 3 data left 2 data right 6 data 2 data left 1 data right 4 data 1 data 4 data 6 data left 5 data right 7 data 5 data 7
include
bool isBSTUtil(Node* node, int min, int max) { if (node == nullptr) return true; if (node->data <= min || node->data >= max) return false; return isBSTUtil(node->left, min, node->data) && isBSTUtil(node->right, node->data, max); }
bool checkBST(Node* root) { return isBSTUtil(root, INT_MIN, INT_MAX); }