01-04-2012, 10:32 PM
AVL tree, It must satisfie the 2 conditions. I got the first one but I have problem in the 2nd condition. Can you explain in detail with examples?
.
For a tree to be an AVL, there are two conditions:
1) It must be a BST
2) For every node, height of left subtree and right subtree can differ by at most 1. In otherwords, balance factor of every node must be 0, 1 or -1. Balance factor = (height of left subtree) - (height of right subtree).
If during insertion, some node doesn't satisfy 2nd condition, then we have to rotate it and there are 4 cases of rotation.
Case I: If new node is inserted in the left subtree of the left child of a, perform single right rotation.
Case II: If new node is inserted in the right subtree of the left child of a. perform left-right double rotation.
Case III: If new node is inserted in the left subtree of the right child of a. perform right-left double rotation.
Case IV: If new node is inserted in the right subtree of the right child of a, perform single left rotation.
All these cases are discussed with the help of examples in handouts.
Now where specifically, you are facing problem in understanding?
Do some practice on the examples given in handouts or book, send me your effort at cs301@vu.edu.pk and point out the exact area where you are facing problem.
.
For a tree to be an AVL, there are two conditions:
1) It must be a BST
2) For every node, height of left subtree and right subtree can differ by at most 1. In otherwords, balance factor of every node must be 0, 1 or -1. Balance factor = (height of left subtree) - (height of right subtree).
If during insertion, some node doesn't satisfy 2nd condition, then we have to rotate it and there are 4 cases of rotation.
Case I: If new node is inserted in the left subtree of the left child of a, perform single right rotation.
Case II: If new node is inserted in the right subtree of the left child of a. perform left-right double rotation.
Case III: If new node is inserted in the left subtree of the right child of a. perform right-left double rotation.
Case IV: If new node is inserted in the right subtree of the right child of a, perform single left rotation.
All these cases are discussed with the help of examples in handouts.
Now where specifically, you are facing problem in understanding?
Do some practice on the examples given in handouts or book, send me your effort at cs301@vu.edu.pk and point out the exact area where you are facing problem.
0300-9520262
Get solution in 24 hour |cpmputer & internet
mileys81:[SIZE="4"][SIZE="3"]....[/SIZE][/SIZE]
