01Smaller to the left, bigger to the right
A binary search tree (BST) is a binary tree in which, for every vertex:
- every key in its left subtree is smaller than its key,
- every key in its right subtree is bigger,
- and both subtrees are binary search trees themselves.
Keys only need to be comparable: numbers, strings, dates. The lecture’s node has the pointers left, right and parent and the key value; depending on the task you can drop parent or add more fields.
Look at 17 in the figure: 16 hangs to its left and 19 to its right, and the whole subtree of 17 still sits inside the “< 20” region. Thanks to this rule, every operation in this lesson walks one path from the root downward, so it costs O(h), where h is the height of the tree.