AVL Tree is a type of self-balancing Binary Search Tree. It is named after its inventor Adelson-Velsky and Landis.
It’s a Binary Search Tree with the following properties:
The height of the left and right subtrees of any node in the tree can differ by at most 1.
The AVL Tree is designed to maintain balance so that the height of the tree remains logarithmic with respect to the number of the nodes in the tree. This allows operations such as insertion, deletion and searching to be performed in O(log n) time.
z z x
/ \ / \ / \
y T4 Left Rotate (y) x T4 Right Rotate(z) y z
/ \ - - - - - - - - -> / \ - - - - - - - -> / \ / \
T1 x y T3 T1 T2 T3 T4
/ \ / \
T2 T3 T1 T2
z z x
/ \ / \ / \
T1 y Right Rotate (y) T1 x Left Rotate(z) z y
/ \ - - - - - - - - -> / \ - - - - - - - -> / \ / \
x T4 T2 y T1 T2 T3 T4
/ \ / \
T2 T3 T3 T4