This page is the module index for binary search tree.
Start with BST operations, then study traversals and balanced search trees.
trees/bst.py— insert, search, delete, and in-order walk. O(h) per operation for height h.trees/traversals.py— preorder, postorder, and level order in O(n) time.trees/llrb.py— left-leaning red-black tree withrankandselectin O(log n).
Industry
A working engineer reaches for a B-tree when keys must answer equality and
range comparisons. PostgreSQL's index documentation says CREATE INDEX
builds a B-tree by default, and that a B-tree handles <, <=, =, >=,
and >. The binary search tree in this lesson is that comparison walk in
memory. Sorted insertion makes its height linear, which is why the
left-leaning red-black tree keeps the height logarithmic.