AVL TreeAVL Tree is invented by GM Adelson  Velsky and EM Landis in 1962. The tree is named AVL in honour of its inventors. AVL Tree can be defined as height balanced binary search tree in which each node is associated with a balance factor which is calculated by subtracting the height of its right subtree from that of its left subtree. Tree is said to be balanced if balance factor of each node is in between 1 to 1, otherwise, the tree will be unbalanced and need to be balanced. Balance Factor (k) = height (left(k))  height (right(k))If balance factor of any node is 1, it means that the left subtree is one level higher than the right subtree. If balance factor of any node is 0, it means that the left subtree and right subtree contain equal height. If balance factor of any node is 1, it means that the left subtree is one level lower than the right subtree. An AVL tree is given in the following figure. We can see that, balance factor associated with each node is in between 1 and +1. therefore, it is an example of AVL tree. Complexity
Operations on AVL treeDue to the fact that, AVL tree is also a binary search tree therefore, all the operations are performed in the same way as they are performed in a binary search tree. Searching and traversing do not lead to the violation in property of AVL tree. However, insertion and deletion are the operations which can violate this property and therefore, they need to be revisited.
Why AVL Tree ?AVL tree controls the height of the binary search tree by not letting it to be skewed. The time taken for all operations in a binary search tree of height h is O(h). However, it can be extended to O(n) if the BST becomes skewed (i.e. worst case). By limiting this height to log n, AVL tree imposes an upper bound on each operation to be O(log n) where n is the number of nodes.
Next TopicB Tree
