What is an AVL Tree?

This lesson has 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

Introduction

In 1962, AVL was named after the inventors, Adelson-Velsky and Landi. They claimed that AVL trees are: “An algorithm for the organization of information." They are binary search trees such that 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, then steps are taken to rebalance 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 the 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 or list. However, in the best case, 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 70+ hands-on prep courses.