Quiz Entry - updated: 2026.12.01
When would you choose an AVL tree, and when a splay tree?
Choose AVL when every single operation must be fast ($O(\log n)$ worst case) and reads dominate. Choose splay when the access pattern is skewed or local, memory per node matters, and an occasional slow operation is acceptable.
| AVL tree | Splay tree | |
|---|---|---|
| Guarantee | $O(\log n)$ worst case per operation | $O(\log n)$ amortised; one operation can be $O(n)$ |
| Extra data per node | height or balance factor | none |
| Rotates on | insert and remove, only when unbalanced | every operation, including find |
| Skewed access (a few hot keys) | no benefit | hot keys stay near the root |
| Concurrent reads | reads do not modify the tree | every read writes, so readers must be serialised |
Two practical notes:
- Because a splay tree changes on every read, it is awkward with several threads reading at once and with read-only or persistent data, where an AVL tree is unaffected.
- Many standard libraries choose a third option, the red-black tree (Java's
TreeMap, typical C++std::map). Its balance rule is looser than AVL's (height up to about $2 \log_2 n$), so updates need fewer rotations, at the price of slightly longer searches.
Go deeper:
Red-black tree — the balanced tree most libraries use, compared with AVL trees.
java.util.TreeMap — Java's sorted map, documented as a red-black tree with guaranteed $\log n$ operations.