This is the fourth article on binary tree operations. For other topics on binary tree, please refer to:
- Binary Tree Operations(I)
- Binary Tree Operations(II)
- Binary Tree Operations(III) - Convert a Binary Tree to Down-Right Representation
The problem is: given a binary tree, how to determine if it is a Binary Search Tree(BST) or not? A binary search tree is a binary tree data structure which has 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.