Build and check a binary search tree

8 steps · about 3 h 5 min · Intermediate

  1. Learn the binary-tree vocabulary (guide, Runestone Academy, 20 min)

    Defines nodes, depth, height and traversal before adding the search-order rule.

  2. Add the binary-search invariant (guide, Runestone Academy, 25 min)

    Derives dictionary operations from the ordering invariant and exposes their dependence on height.

  3. 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.

  4. Implement search and insertion (guide, Runestone Academy, 30 min)

    Provides a complete mapping-style implementation with parent and child links to study and simplify.

  5. 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.

  6. 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.

  7. 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.

  8. Validate the whole ordering invariant (interactive, GeeksforGeeks, 30 min)

    The exercise catches the common mistake of comparing a node only with its immediate children.