Balanced Search Trees
Implement a self-balancing binary search tree and a B-tree, prove why their height stays logarithmic, and test their invariants against a reference ordered map.
3 objectives 6 steps about 140 min
Check what you know
The lessons are coming later. The knowledge check is ready now.
This skill page is a public outline. Its lessons and knowledge check appear here as subject-matter experts approve them.
Learning objectives
- Implement AVL insertion and deletion with single and double rotations, keeping stored heights up to date, and check the balance and ordering invariants after every operation.
- Derive the O(log n) height bound of an AVL tree from the minimum number of nodes at each height, and map red-black color rules onto 2-3-4 tree nodes to explain the red-black height bound.
- Implement B-tree search and insertion that splits full nodes on the way down for a chosen minimum degree, and relate node size to the number of nodes a lookup reads.
Lesson plan
6 steps, about 140 min · 0 of 5 lessons available so far
- Why Height Is the Whole Game Concept · 20 min · coming later
- Four Rotation Cases, Traced by Hand Worked example · 25 min · coming later
- Lab: An AVL Map with Invariant Checks Lab · 30 min · coming later
- Red-Black Trees as 2-3-4 Trees in Disguise Concept · 20 min · coming later
- Lab: B-Tree Search and Split-on-the-Way-Down Insert Lab · 30 min · coming later
- Check: Balanced Tree Mechanics Knowledge check · 6 questions
Practise it
Implement an AVL-backed ordered map (insert, delete, floor, ceiling, in-order iteration) with a check_invariants() method, run it after every step of 10,000 Hypothesis-generated operations compared with a bisect-based sorted-list model, and record the maximum height against the 1.44 log2(n + 2) bound; then implement B-tree search and insert for minimum degrees 2, 16 and 128 and report height and nodes read per lookup over one million keys.
References
Hard prerequisites
Unlocks
Nothing depends on this skill yet.
On these roadmaps
Progress and evidence for this skill are shared across all of them.