01Chapter 1: Quick review: the binary search tree invariantThis chapter refreshes the one rule that every balanced tree in this tutorial must keep. AVL and red-black trees add extra rules for shape. The ordering rule underneath stays the same, and every later repair, rotation and test builds on it.6 min read
02Chapter 2: Why balance matters: height controls costThis chapter assumes you can read basic Python and that you already know how binary search tree (BST) search, insertion and deletion work. It also assumes you are comfortable with recursion, the terms root, leaf, subtree and height, and Big-O notation, including the difference between O(log n) and O7 min read
03Chapter 3: Rotations: changing shape without breaking orderThis chapter assumes you can read Python and follow recursive code. It also assumes you know the binary search tree (BST) ordering rule: for every node, all keys in its left subtree are smaller and all keys in its right subtree are larger. You should know that the height of a tree is the number of n6 min read
04Chapter 4: AVL trees: heights that differ by at most oneThis chapter defines the AVL invariant, shows how to store and read it, and says what it does and doesn't promise. It assumes you can read Python and know the binary search tree (BST) ordering rule. It also assumes you know what a subtree's height is, that you have seen left and right rotations, and6 min read
05Chapter 5: AVL insertion and the four imbalance casesThis chapter assumes you can read recursive Python and can do plain binary search tree (BST) insertion. It also assumes you know what an AVL tree guarantees: at every node, the heights of the left and right subtrees differ by at most one. You should already have met left and right rotations. The cod6 min read
06Chapter 6: AVL deletion and rebalancing on the way upThis chapter assumes you have read the earlier chapters on rotations, the AVL invariant, and AVL insertion. You should know the balance factor (height of left subtree minus height of right subtree), the rotate_left and rotate_right helpers, and the rebalance function. You should also be comfor5 min read
07Chapter 7: Why AVL trees have logarithmic heightThis chapter assumes you have read the earlier chapters on the AVL invariant and on insertion and deletion. You should be comfortable with recurrences, mathematical induction at a basic level, and logarithms. Height here follows the chapter code: an empty tree has height 0 and a single node has heig7 min read
08Chapter 8: Red-black trees: the color rulesThis chapter assumes you can read Python and know binary search tree (BST) search and insertion. It also assumes you know the rotations from earlier in this tutorial, and that you are comfortable with root, leaf, subtree and height. It covers the rules a red-black tree must satisfy, how to check the6 min read
09Chapter 9: Red-black insertion: recolor or rotateThis chapter assumes you know binary search tree insertion, the left and right rotations from the earlier chapter, and the five red-black properties. You should also be comfortable reading Python classes that use parent pointers.6 min read
10Chapter 10: Red-black deletion and the double-black problemThis chapter assumes you know the five red-black properties, left and right rotations, and the insertion fixup that looks at the uncle's color. It covers deletion, which is the hardest red-black operation. Deletion can break the equal-black-count rule in a way insertion never does.5 min read
11Chapter 11: Why red-black trees have logarithmic heightThis chapter assumes you know the five red-black properties from the earlier chapter, basic binary search tree operations, recursion, and Big-O notation. It proves that a red-black tree with n keys has height at most 2·log₂(n+1). That bound is what guarantees O(log n) search, insertion, and deletion6 min read
12Chapter 12: AVL or red-black: choosing between themThis chapter assumes you have read the earlier chapters on rotations, AVL insertion and deletion, and the red-black properties and fixups. You should be comfortable with O(log n) reasoning and with reading short Python programs. Both tree types guarantee O(log n) search, insertion and deletion. The 6 min read
13Chapter 13: Checking invariants in testsA balanced tree can return correct answers and still be broken. Lookups succeed while the tree quietly drifts into a shape that costs O(n) per operation. This chapter shows how to write validators that check the structural rules directly, and how to drive them with randomized tests.6 min read