Search decisions
At each node, equality finishes the search. A smaller target moves left; a larger target moves right.
For every node, all values in the left subtree are smaller and all values in the right subtree are larger. This rule determines every search, insertion, deletion, predecessor, and successor path.
Example tree loaded. Choose an operation.
if node is a leaf:
remove it
else if node has one child:
replace it with that child
else:
copy the inorder successor
delete that successor
from the right subtreeAt each node, equality finishes the search. A smaller target moves left; a larger target moves right.
The predecessor is the greatest smaller key. The successor is the smallest larger key. They may be found in a subtree or among ancestors.
Deleting a node with two children uses the minimum node in its right subtree, called the inorder successor.
Inserting already sorted values can create a chain. The BST remains valid, but its height and operation time become linear.
| Traversal | Order | Typical use |
|---|---|---|
| Inorder | Left, Root, Right | Read BST values in sorted order. |
| Preorder | Root, Left, Right | Serialize or copy tree structure. |
| Postorder | Left, Right, Root | Delete or evaluate subtrees first. |
| Level order | Breadth by breadth | Inspect the tree one level at a time. |