Why it matters

BST is foundation for sorted maps. Understanding shapes all balanced trees.

Advertisement

The architecture

Node: key + left + right.

Search: compare + descend.

Insert: descend to leaf.

Delete: 3 cases.

BST operationsNodekey + left + rightSearchdescend by compareInsert / Deleteleaf ops or replaceUnbalanced BST degenerates to O(n); balanced variants (AVL, RB) guarantee O(log n)
BST.
Advertisement

How it works end to end

Balanced: O(log n).

Unbalanced worst: O(n).

Delete: leaf, one child, two children (in-order successor).