Today i am doing a problem on Binary Trees during which I found a structure of BSTree which is satisfying property : "Every node has smaller value on its left child and greater value on its right child". But it is not a BST ( in my opinion ) because root has smaller value than one of its grand child.Please Explain me all this .
Binary tree :
7
/ \
4 10
/ \
2 8
Tell me is this BST or Not ? Explain .
A more correct definition of a BST can be found here:
- 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 or equal to the node's key.
- Both the left and right subtrees must also be binary search trees.
So, although your tree satisfies the specific case of every node having a smaller value to its left and a larger value to its right, it does not satisfy the more general case involving the left and right subtrees, and is therefore not a BST.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With