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

Introduction

Named after inventors Adelson-Velsky and Landi in 1962, 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, 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 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 that: 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.