Write an algorithm to check whether whether a binary tree (pointer to its root) is a binary search tree?
A binary search tree is a binary tree data having the following properties: The left subtree of a node contains only nodes with keys less than the node’s key. The right subtree of a node contains only nodes with keys greater than the node’s key. Both the left and right subtrees must also be binary search trees. The algorithm is based on In-Order Traversal.
Time Complexity: \( O(n) \). < Alternate Solution > (When space is a constraint) : Here, we traverse down the tree recursively from root and check whether the value at the current node is between the minimum and maximum value. When the left subtree is accessed we check the node value with the minimum one and for the right subtree with the maximum one. public boolean isBinarySearchTree(Node root){ |