Build and check a binary search tree
8 steps · about 3 h 5 min · Intermediate
- Learn the binary-tree vocabulary (guide, Runestone Academy, 20 min)
Defines nodes, depth, height and traversal before adding the search-order rule.
- Add the binary-search invariant (guide, Runestone Academy, 25 min)
Derives dictionary operations from the ordering invariant and exposes their dependence on height.
- Watch tree shape change (interactive, University of San Francisco, 25 min)
Shows why insertion order can create a shallow tree or a costly chain with the same keys.
- Implement search and insertion (guide, Runestone Academy, 30 min)
Provides a complete mapping-style implementation with parent and child links to study and simplify.
- Work through the deletion cases (guide, Cornell University, 25 min)
Separates leaf, one-child and two-child deletion so each link change can be tested independently.
- Expose traversal as an iterator (reference, Python Software Foundation, 10 min)
Turns an inorder walk into a small public interface that can be checked against sorted input.
- Reason recursively about tree operations (guide, Cornell University, 20 min)
Connects the recursive structure of a tree to the induction used to justify its operations.
- Validate the whole ordering invariant (interactive, GeeksforGeeks, 30 min)
The exercise catches the common mistake of comparing a node only with its immediate children.