Data Structures19 sections · 729 units
Open in Course

BST Property

The ordering invariant

A Binary Search Tree maintains a simple invariant: for every node with value vv:

  • All values in the left subtree are less than vv
  • All values in the right subtree are greater than vv

Note: this applies to entire subtrees, not just immediate children.

If node 10 has left child 5, then 5's entire subtree must contain only values less than 10. This property enables binary search. To find value xx:

1.1. Compare xx with current node's value

2.2. If equal, found it

3.3. If xx is smaller, search left subtree

4.4. If xx is larger, search right subtree Each comparison eliminates half the remaining tree (in the balanced case).