Overview

This chapter introduces binary search trees (BSTs), a fundamental data structure that supports all major dynamic-set operations—SEARCH, MINIMUM, MAXIMUM, PREDECESSOR, SUCCESSOR, INSERT, and DELETE—in time proportional to the tree's height. BSTs serve as both dictionaries and priority queues. The chapter covers the BST property, tree traversals, querying, insertion, deletion, and proves that a randomly built BST has expected height O(lg n).

Key Concepts

Algorithms and Techniques

Inorder Tree Walk

INORDER-TREE-WALK(x): If x ≠ NIL, recursively walk x.left, print x.key, then recursively walk x.right. Produces sorted output.

Searching

Minimum and Maximum