Thursday 3 November 2011

Discuss all cases of deletion in AVL tree and give pseudo code to handle in each case separately.

Solution
► Case 1 
1.  If the node from where the node has been deleted had balance 0 and after deleting the node the new balance has become 1 or 21 Correct the balance of the node
► Case 2 
2.  If the node from where the node has been deleted had balance 1 or 21 and after deleting the node balance has become zero Correct the balance of the node and also check its parent nodes till root to see whether their balance is violating the AVL tree condition or not if so then these nodes will also fall in one of these
cases take action appropriately.
► Case 3
3.  If the node from where the node has been deleted had balance 1 or 21 and its other sub tree (may be right or left) was balanced. Apply single left or right rotation and adjust the balance values for
nodes.
► Case 4
4.  If the node from where the node has been deleted had balance 1 or 21 and its other sub tree (may be right or left) was unbalanced (due to sub tree attached with inner child node) Apply double rotation and adjust the balance values for nodes.
► Case 5 
5.  If the node from where the node has been deleted had balance 1 or 21 and its other sub tree (may be right or left) was unbalanced (due to sub tree attached with outer child node) Apply single rotation and adjust the balance values for nodes.

No comments:

Post a Comment