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, 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 of the tree the heights of 's children can differ by at most .
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 time, where “h” is the height of Binary Search Tree.
The worst-case time complexity is , 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 .
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.