What is an AVL Tree?

This lesson is a brief introduction to AVL trees, why they are used, and what makes them more efficient than regular binary search trees

We'll cover the following


Named after inventors Adelson-Velsky and Landi, the AVL tree was invented in 1962. They claimed that AVL trees are “An algorithm for the organization of information”. They are Binary Search Trees in which for every internal node vv of the tree TT the heights of vv's children can differ by at most 11.

To put it simply, for each node, the height of the left and right subtrees in an AVL tree can differ at most by one, or the tree is balanced.

If at any point their difference becomes more than one, steps are taken to re-balance the tree.

Time Complexity

In the case of binary search trees, the time complexity of all three basic operations- Insertion, Deletion, and Search, take O(h)O(h) time, where “h” is the height of Binary Search Tree.

The worst-case time complexity is O(n)O(n), for skewed BSTs, where “n” is the number of nodes in the tree. This is the same as an array. However, in the best-case scenario, when the tree is completely balanced, the time complexity for basic operations is O(log(n))O(log(n)).

AVL trees are essentially BSTs in the best-case.

The following diagram is an example of a valid AVL Tree:

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.