LOGBOOK

HELP

Quiz Entry - updated: 2026.12.01

How does a binary search tree compare with a search table (a sorted array searched by binary search)?

Both find a key in $O(\log n)$ when the tree is balanced, but the search table pays $O(n)$ for every insert and remove because elements must be shifted, while the tree only pays $O(h)$. The tree's weakness is that h can grow to n.

Operation Search table (sorted array) Binary search tree
find $O(\log n)$ $O(h)$
insert $O(n)$: shift to make room $O(h)$: expand an external node
remove $O(n)$: shift to close the gap $O(h)$
Ordered traversal trivial (the array is sorted) inorder traversal, $O(n)$
Worst case of h — $n$ (degenerate chain)

A search table is the better choice when the data rarely changes: it guarantees $O(\log n)$ lookups and reads fast from contiguous memory. A growable array also has costs a table hides: it keeps spare capacity in reserve (unused memory, much like the free slots of a hash table at a 75% load factor), and inserting near the front shifts almost everything. As soon as keys are inserted and removed often, the shifting dominates, and a tree, ideally a balanced one, wins.

From Quiz: ADS / Binary Search Trees | Updated: Dec 01, 2026