AVL tree explained in plain terms means understanding what happens when a search tree refuses to tolerate even a little imbalance. The central question is whether stricter balance is worth the extra work it costs on every update, and the answer is that it depends entirely on how often you search versus how often you change the data.
An AVL tree is a self-balancing binary search tree in which the heights of any node’s two subtrees differ by at most one, a rule enforced after every insert and delete with rotations. It was the first self-balancing tree ever invented, published by Georgy Adelson-Velsky and Evgenii Landis in 1962, and it still offers the fastest searches of any balanced tree.
The trade is simple to state and easy to get wrong in practice: searches run faster because the tree is shorter, but inserts and deletes rotate more often to maintain that strict shape. This article explains how an AVL tree works, how it compares with its rivals, and when it is the right choice.
Key takeaways
- An AVL tree keeps sibling subtree heights within one of each other.
- Searches are faster than in a red-black tree because the tree is shorter.
- Inserts and deletes cost more, since balance is restored more often.
- Four rotation cases cover every imbalance an update can cause.
- AVL trees suit read-heavy workloads with rare updates.
What an AVL tree is
An AVL tree is a binary search tree with one extra number stored at each node, the balance factor, which is the height of the left subtree minus the height of the right subtree. A node is balanced when that factor is minus one, zero, or one, and the moment an update pushes any node’s factor to two or minus two, the tree repairs itself.
That single rule has a powerful consequence. Because no subtree can be more than one level taller than its sibling, the height of an AVL tree holding a million keys is at most about twenty, and usually a little less. A search therefore touches fewer nodes than in any competing balanced tree, which is the whole point of the design.
The cost of the rule is paid on updates. Where a red-black tree might accept a slightly lopsided shape and move on, an AVL tree stops and rotates, sometimes twice, to restore perfect poise. Our guide to B-trees describes a tree that trades height for width to suit disk storage, while the AVL tree is built purely for speed in memory.
How rotations restore balance
Every imbalance in an AVL tree falls into one of four cases, named for where the heavy side sits. A left-left case means the left subtree of a left child grew too tall, and a single right rotation fixes it. A right-right case is the mirror image, fixed by a single left rotation. These two are the easy ones, and they cover the cases where the new key landed on the outer edge of the heavy side.
The inner cases need two rotations each. In a left-right case, the new key sits in the right subtree of a left child, so the tree first rotates the child left, turning the problem into a left-left case, and then rotates the parent right. A right-left case does the same in reverse. Two rotations sound expensive, but each one only rewires a few pointers, so the repair is still constant work.
The repair always starts at the lowest unbalanced node and works upward. After an insert, the tree walks back up the search path, updating heights and checking balance factors, and the first node it finds out of balance is the one it fixes. One repair is enough, because a rotation at that node restores balance all the way to the root, which is a neat property that keeps inserts simple.
Deletion is more demanding, because removing a key can unbalance several nodes on the path back up. The tree may need a rotation at each level, so a delete can cost logarithmic rotations rather than the constant number an insert needs. This is the main reason AVL trees are recommended for data that changes rarely.

AVL tree versus red-black tree
The honest comparison between an AVL tree and a red-black tree comes down to one question: how often does the data change. If the answer is rarely, the AVL tree wins on search speed, and if the answer is constantly, the red-black tree wins on update cost. Most real workloads sit somewhere in between, which is why the choice is worth thinking about rather than assuming.
The table below sets out the main contrasts between the leading balanced trees.
| Aspect | AVL tree | Red-black tree | B-tree |
|---|---|---|---|
| Balance rule | Sibling heights differ by at most one | Longest path at most twice shortest | All leaves at the same depth |
| Search speed | Fastest, shortest tree | Slightly slower, taller tree | Logarithmic, disk-friendly |
| Rotations per insert | At most two, but more frequent | At most two, less frequent | Node splits instead |
| Rotations per delete | Up to logarithmic | At most three | Node merges instead |
| Best for | Read-heavy, rarely updated data | General ordered maps | Databases and file systems |
The practical result is that an AVL tree is the better pick for lookup tables, dictionaries, and indexes that are built once and read constantly, while a red-black tree is the safer default when updates are frequent or unpredictable.
Where AVL trees are used
Databases use AVL trees for in-memory indexes that change rarely. A table of reference data, a catalogue of product categories, or a set of configuration values may be loaded once and queried thousands of times a second, which is exactly the workload where an AVL tree earns its keep. Our guide to database indexing explains how such structures speed up queries, and our guide to in-memory computing covers the systems that hold them in RAM.
Operating systems have used AVL trees for memory management, because the kernel needs to find free memory regions quickly and the set of regions changes far less often than it is searched. Some kernels later moved to red-black trees as workloads grew more write-heavy, which is itself a useful lesson in how the choice follows the workload.
Compilers and interpreters use AVL trees for symbol tables in some designs, where identifiers are looked up constantly during parsing and code generation. A symbol table that is built in one pass and consulted in every later pass is a natural fit for the strictest balance available.
Network routers and switches have used AVL trees for routing tables, where the table updates when links change but lookups happen for every single packet. When a lookup runs millions of times a second, shaving even one level off the tree is worth paying for with costlier updates.
Strengths and limits
The greatest strength of an AVL tree is its search speed. No other balanced binary tree guarantees a shorter height, so no other one answers a lookup in fewer steps, and for a read-heavy workload that difference compounds across millions of queries into real time saved.
It is also a strength that the rules are simple to reason about. The balance factor is a single number, the four rotation cases are easy to enumerate, and the behaviour of the tree is easy to predict, which makes AVL trees a favourite teaching structure and a dependable building block.
The limits are real, though. Deletes can trigger a cascade of rotations, inserts rotate more often than in a red-black tree, and storing a height at every node costs a little memory. For data that changes constantly, those costs add up, and a red-black tree or a hash table will serve better.
AVL tree checklist
- Use an AVL tree when lookups vastly outnumber inserts and deletes.
- Store the balance factor or height at each node, never recompute it.
- Learn the four rotation cases before implementing one by hand.
- Repair from the lowest unbalanced node upward after an insert.
- Expect deletes to need more rotations than inserts.
- Prefer a red-black tree when updates are frequent or unpredictable.
- Prefer a hash table when ordering does not matter at all.
- Measure search speed on your real workload before committing.
- Consider a sorted array when the data never changes after loading.
Frequently asked questions
What is an AVL tree in simple terms?
It is a binary search tree that keeps the two sides of every node almost exactly equal in height, so searches are as short as possible.
Who invented the AVL tree?
Georgy Adelson-Velsky and Evgenii Landis, two Soviet mathematicians, published it in 1962, and it was the first self-balancing tree ever described.
What is a balance factor?
It is the height of a node’s left subtree minus the height of its right subtree, and a node is balanced when that number is minus one, zero, or one.
How is an AVL tree different from a red-black tree?
An AVL tree balances more strictly, so it searches faster but rotates more on updates, while a red-black tree balances loosely and updates more cheaply.
How fast is a search in an AVL tree?
Logarithmic in the number of keys, with the smallest constant of any balanced binary tree, because its height is minimal.
When should I not use an AVL tree?
When the data changes constantly, because deletes can trigger many rotations, and a red-black tree or hash table will serve better.
The bottom line
AVL tree explained in one line is this: keep every node’s two sides within one level of each other, and no search can ever take a long path.
It is the fastest searching balanced tree there is, and the right choice whenever the data is read far more often than it is changed.
This article is general information about how AVL trees work, not advice about choosing a data structure for a particular system.







