Check for BST(CPP_BST)

In the video’s code to check for bst, shouldn’t we consider the case when height of left subtree is equal to the height of right subtree?

Hi Divyam,
I believe you are confusing a Balanced BST with a normal BST. There is no constraint on the height of a BST. A skew tree can be a BST as well as complete tree.
There are only three conditions that you need to check to see if a given tree is a BST or not.

  1. Its left subtree is a BST.
  2. Its right subtree is a BST
  3. The root node element should be greater than maximum of left subtree and less than minimum of right subtree.

Even if right subtree and left subtree do not have same height or large height differences , it doesn’t matter.

1 Like