Quiz Entry - updated: 2026.12.01
What are the running times of an AVL tree's operations, and where does each come from?
One restructuring is $O(1)$; find, insert and remove are all $O(\log n)$. Insert needs at most one restructuring after its search, while remove may need one per level on the way up, still $O(\log n)$ in total.
| Operation | Time | Why |
|---|---|---|
| one restructuring | $O(1)$ | a constant number of references change, in a linked tree |
find |
$O(\log n)$ | one root-to-leaf path, and the height is $O(\log n)$ |
insert |
$O(\log n)$ | search $O(\log n)$, walk back up $O(\log n)$, one restructuring $O(1)$ |
remove |
$O(\log n)$ | search $O(\log n)$, then up to one $O(1)$ restructuring per level |
Compare a plain binary search tree, where the same operations are $O(h)$ and $h$ can reach $n$. The AVL tree's extra work (storing a height or balance factor in each node, updating it on the way up, rotating) buys a worst-case guarantee: there is no input order that makes it slow.
Tip: "insert: one fix; remove: maybe one per level" is the asymmetry exam questions like to probe.
Go deeper:
MIT 6.006 — Binary Trees, Part 2: AVL (Erik Demaine) — rotations, the height bound and the $O(\log n)$ operations in one lecture.