Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSE 3358 NOTE SET 13 Data Structures and Algorithms.

Similar presentations


Presentation on theme: "CSE 3358 NOTE SET 13 Data Structures and Algorithms."— Presentation transcript:

1 CSE 3358 NOTE SET 13 Data Structures and Algorithms

2 Tree Balancing - AVL  Self-balancing binary search tree  The height of the left and right subtrees of every node differ by at most one  Based on Balance Factor – the height of the right subtree minus the height of the left subtree.  For AVL tree, all balance factors must be +1, 0, -1 0 0 +1 0 +1 0 0 0

3 AVL - Operations  Searching – close to O(lg n)  Insert – may have to update balance property all the way up the tree because it could cause a violation of the AVL property 5 1 2 3 47 8 Insert 6.

4 4 Cases  For a particular node, there are 4 possible insertion places. NNNN Case 1Case 2Case 3Case 4 Case 1 and Case 4 – Single Rotation Case 2 and Case 3 – Double Rotation

5 AVL Case 1 P Q AB C Original Tree Insert node in Subtree A P Q A B C Single Rotation: Rotate Q about P P Q A BC 1 2

6 AVL Case 4 Original Tree Insert node in Subtree c Single Rotation: Rotate P about Q Q P BC 1 2 A Q P B C A Q P B C A

7 Example : 3,2,1,4,5,6,7

8

9

10

11 ?


Download ppt "CSE 3358 NOTE SET 13 Data Structures and Algorithms."

Similar presentations


Ads by Google