Trees & Ordered Maps
Binary Search Trees (BSTs) and balanced search structures maintain keys in sorted order, supporting dynamic predecessor, successor, range queries, and ceiling operations. Red-Black trees and 2-3 trees guarantee O(log N) height by enforcing structural balance invariants.
Key Invariants & Rules
- In a BST, all keys in node.left are strictly less than (or <= duplicate rule) node.key, and node.right keys are strictly greater.
- In-order traversal of a valid BST visits keys in strictly monotonic ascending order.
- BST ceiling search branches left when node.key >= target, saving the node as candidate, else branches right.
- A 2-3 tree maintains all leaves at the exact same depth; 3-nodes hold 2 keys and 3 children.
- Red-Black trees represent 2-3 trees using binary nodes with red left links.
Must-Know Algorithms
Finds smallest key >= target by candidate tracking during downward search.
Lazy traversal using an explicit stack of left-spine ancestors.
Translates 3-nodes into equivalent 2-node clusters with red binding edges.
Learning Path (11 Lessons)
Self-Check & Concept Review
1. What is the ceiling of key X in a Binary Search Tree?
2. How does a lazy BST iterator achieve O(1) amortized time per next() call?
3. In an Array-backed BST with soft deletion (tombstones), what happens when a deleted key is re-inserted?
4. What structural invariant does a 2-3 tree maintain to prevent skewing?
5. What does a red link represent in a Left-Leaning Red-Black (LLRB) tree?