Presentation is loading. Please wait.

Presentation is loading. Please wait.

AVL Trees (Adelson – Velskii – Landis) AVL tree: 20 30 187 1625 5 1719.

Similar presentations


Presentation on theme: "AVL Trees (Adelson – Velskii – Landis) AVL tree: 20 30 187 1625 5 1719."— Presentation transcript:

1 AVL Trees (Adelson – Velskii – Landis) AVL tree:

2 AVL Trees Not AVL tree:

3 AVL Tree Rotations Single rotations: insert 14, 15, 16, 13, 12, 11, First insert 14 and 15: Now insert 16.

4 AVL Tree Rotations Single rotations: Inserting 16 causes AVL violation: Need to rotate. 16

5 AVL Tree Rotations Single rotations: Inserting 16 causes AVL violation: Need to rotate. 16

6 AVL Tree Rotations Single rotations: Rotation type: 16

7 AVL Tree Rotations Single rotations: Rotation restores AVL balance: 16

8 AVL Tree Rotations Single rotations: Now insert 13 and 12: AVL violation - need to rotate.

9 AVL Tree Rotations Single rotations: Rotation type:

10 AVL Tree Rotations Single rotations: Now insert

11 AVL Tree Rotations Single rotations: AVL violation – need to rotate

12 AVL Tree Rotations Single rotations: Rotation type:

13 AVL Tree Rotations Single rotations: Now insert 10.

14 AVL Tree Rotations Single rotations: AVL violation – need to rotate

15 AVL Tree Rotations Single rotations: Rotation type:

16 AVL Tree Rotations Single rotations: AVL balance restored.

17 AVL Tree Rotations Double rotations: insert 1, 2, 3, 4, 5, 7, 6, 9, 8 First insert 1 and 2:

18 AVL Tree Rotations Double rotations: AVL violation - rotate

19 AVL Tree Rotations Double rotations: Rotation type:

20 AVL Tree Rotations Double rotations: Now insert 3. AVL balance restored:

21 AVL Tree Rotations Double rotations: AVL violation – rotate:

22 AVL Tree Rotations Double rotations: Rotation type:

23 AVL Tree Rotations Double rotations: AVL balance restored: Now insert 4.

24 AVL Tree Rotations Double rotations: AVL violation - rotate

25 AVL Tree Rotations Double rotations: Rotation type:

26 AVL Tree Rotations Double rotations: Now insert 5.

27 AVL Tree Rotations Double rotations: AVL violation – rotate. 5

28 AVL Tree Rotations Single rotations: Rotation type:

29 AVL Tree Rotations Single rotations: AVL balance restored: Now insert 7.

30 AVL Tree Rotations Single rotations: AVL violation – rotate. 7

31 AVL Tree Rotations Single rotations: Rotation type:

32 AVL Tree Rotations Double rotations: AVL balance restored. Now insert 6.

33 AVL Tree Rotations Double rotations: AVL violation - rotate. 6

34 AVL Tree Rotations Double rotations: Rotation type: 6

35 AVL Tree Rotations Double rotations: AVL balance restored. Now insert 9 and 8. 5

36 AVL Tree Rotations Double rotations: AVL violation - rotate

37 AVL Tree Rotations Double rotations: Rotation type: 9 8 5

38 AVL Tree Rotations Final tree: Tree is almost perfectly balanced 5 97


Download ppt "AVL Trees (Adelson – Velskii – Landis) AVL tree: 20 30 187 1625 5 1719."

Similar presentations


Ads by Google