AVL Insertion
Explore AVL tree insertion and understand how to maintain balance through rotations in four distinct cases. Learn key concepts like nodes involved in imbalances and the process to rebalance an AVL tree efficiently with O(log n) time complexity.
We'll cover the following...
We'll cover the following...
Introduction
Insertion in AVL trees is done the same way that BST insertion is done. However, when a node is inserted into a BST, it usually becomes unbalanced, i.e., the tree has a node that has a left-right subtree height difference greater than 1. So, AVL trees have to be rebalanced after insertion unlike BSTs. To rebalance the tree, you need to perform a ‘rotation’. But before going deep, let’s look at AVL tree rebalancing case-by-case.
Look at the terms that you will be using while rebalancing the tree:
- Node U – An unbalanced node