# What Is AVL Tree Data Structure?

//

Angela Bailey

An AVL tree is a self-balancing binary search tree data structure that maintains a balanced height by performing rotations when necessary. It is named after its inventors, Georgy Adelson-Velsky and Evgenii Landis. AVL trees are widely used in computer science and are particularly useful for applications where efficient searching and insertion operations are required.

## Properties of an AVL Tree

An AVL tree has the following properties:

• Balance Factor: Each node in an AVL tree stores an additional attribute called the balance factor. The balance factor of a node is the difference between the heights of its left and right subtrees. It can be either -1, 0, or 1.
• Height-Balanced: An AVL tree is height-balanced if for every node, the balance factor is either -1, 0, or 1.

## Insertion Operation in an AVL Tree

When a new element is inserted into an AVL tree, it may cause an imbalance in the tree’s height. To maintain the balance factor property, rotations are performed to restore the balance. There are four types of rotations:

### Left-Left Rotation

If a node’s left child has a greater height than its right child and the newly inserted element is in the left subtree of this left child, a left-left rotation is performed.

### Right-Right Rotation

If a node’s right child has a greater height than its left child and the newly inserted element is in the right subtree of this right child, a right-right rotation is performed.

### Left-Right Rotation

If a node’s left child has a greater height than its right child and the newly inserted element is in the right subtree of this left child, a left-right rotation is performed.

### Right-Left Rotation

If a node’s right child has a greater height than its left child and the newly inserted element is in the left subtree of this right child, a right-left rotation is performed.

## Time Complexity

The time complexity of searching, insertion, and deletion operations in an AVL tree is O(log n), where n is the number of elements in the tree. This makes AVL trees efficient for applications that require frequent searching and insertion operations.

## Conclusion

An AVL tree is a self-balancing binary search tree that maintains a balanced height by performing rotations when necessary. It provides efficient searching and insertion operations with a time complexity of O(log n). Understanding AVL trees can be beneficial when working on applications that require maintaining sorted data efficiently.