LOGBOOK

HELP

Quiz Entry - updated: 2026.11.26

What is a binary search tree, and which ordering property must it satisfy?

A binary search tree is a binary tree that stores key-value pairs in its internal nodes such that, for every node v, all keys in v's left subtree are ≤ key(v) and all keys in its right subtree are ≥ key(v).

Formally: if u is anywhere in the left subtree of v and w anywhere in the right subtree, then

$$\text{key}(u) \le \text{key}(v) \le \text{key}(w).$$

It is the binary-search idea turned into a tree. Binary search on 0 1 3 4 5 7 8 9 11 14 16 18 19 always compares with 8 first, then with either 3 or 14, and so on; store those comparison points as linked nodes and you get a binary tree with 8 at the root. The root plays the role of the middle element: everything smaller is on its left, everything larger on its right, and each subtree repeats the pattern. So a search can decide at every node which half to discard, without needing an array.

The rule concerns whole subtrees, not just the direct children. In the tree with root 6, children 2 and 9, 2's children 1 and 4, and 9's left child 8, it is not enough that 4 ≥ 2: 4 must also be ≤ 6, because it sits in 6's left subtree.

This is the opposite emphasis of a heap. A heap orders each parent against its children vertically and leaves left and right unordered; a binary search tree orders left against right and that is exactly what makes searching possible.

The binary search tree 6 with children 2 and 9, keys 1, 4 and 8 below, external nodes drawn as squares

* Smaller keys to the left, larger to the right, at every node; squares are external nodes. *

Go deeper:

From Quiz: ADS / Binary Search Trees | Updated: Nov 26, 2026