AVL Trees

Is an AVL Tree a Type of Binary Tree?

Yes: an AVL tree is a binary search tree with an extra balance rule. Learn what makes a tree binary, what the AVL rule adds, and how the two differ.

On this page
  1. Short answer
  2. What makes a tree binary
  3. What a binary search tree adds
  4. What the AVL rule adds
  5. A binary tree that is not an AVL tree
  6. Why the extra rule matters
  7. Summary

Short answer

Yes. An AVL tree is a binary tree. More precisely, it is a binary search tree that also follows a balance rule, so it is a special case of both a binary search tree and a binary tree.

What makes a tree binary

A binary tree is a rooted tree in which each node has at most two children, usually called the left child and the right child. A node with no children is a leaf. The shape can vary a lot, as long as no node has more than two children.

What a binary search tree adds

A binary search tree is a binary tree with an ordering rule. For any node, every key in its left subtree is smaller than the node’s key, and every key in its right subtree is larger. This rule lets a search discard one whole side of the tree at each step.

What the AVL rule adds

An AVL tree is a binary search tree with one more condition. For each node, the balance factor is the height of the right subtree minus the height of the left subtree. In an AVL tree, that value is -1, 0, or +1 for every node. A binary search tree that meets the ordering rule but breaks the balance condition is not an AVL tree.

A binary tree that is not an AVL tree

Insert 10, 20, and 30, in that order, into an ordinary binary search tree. The result is a binary tree, since each node has at most one child. It is also a binary search tree, because each new key is larger than the last and sits in the right subtree.

The root, 10, has a balance factor of +2. Its right side is two levels tall and its left side is empty. That breaks the AVL rule. An AVL tree would rotate the tree so that 20 becomes the root, with 10 on the left and 30 on the right.

Why the extra rule matters

A plain binary search tree is only fast when it happens to stay bushy. In the worst case, as in the example above, it becomes a chain, and search takes O(n) time. The balance rule keeps the height close to log n, so an AVL tree gives O(log n) worst-case time for search, insertion, and deletion.

Summary

An AVL tree is a binary tree and a binary search tree, with the added requirement that the balance factor of every node is -1, 0, or +1. Every AVL tree is a binary tree, but not every binary tree is an AVL tree.

The complete guide to avl trees

AVL Trees in Data Structures
Read the guide

Keep exploring

Guides from other topics

All topics →