Presentation is loading. Please wait.

Presentation is loading. Please wait.

Draft for an AVL tree insertion visualization with multiple levels of engagement T-106.6200 Special Course in Software Techniques: Directions for Future.

Similar presentations


Presentation on theme: "Draft for an AVL tree insertion visualization with multiple levels of engagement T-106.6200 Special Course in Software Techniques: Directions for Future."— Presentation transcript:

1 Draft for an AVL tree insertion visualization with multiple levels of engagement
T Special Course in Software Techniques: Directions for Future Research in Algorithm Visualization Lasse Hakulinen A V

2 AVL tree insertion Mode 1: Animation

3 The AVL tree is now balaced Insert the next key (5) to the AVL tree
Input: 5 2 3 9 10 4 1 Balance factor = height of left subtree – height of right subtree 5

4 Insert the next key (2) to the AVL tree The AVL tree is now balaced
Input: 5 2 3 9 10 4 1 5 1 2

5 Insert the next key (0) to the AVL tree
The tree is unbalanced: The balance factor of node with key ”5” is 2. Do a single rotation right. Insert the next key (0) to the AVL tree Input: 5 2 3 9 10 4 1 5 2 1 2 1

6 The AVL tree is now balaced
The tree is unbalanced: The balance factor of the node with key ”5” is 2. Do a single rotation right. Input: 5 2 3 9 10 4 1 5 1 2

7 Mode 2: User defined input
AVL tree insertion Mode 2: User defined input

8 The AVL tree is now balaced
Insert a key Input key: 12 Insert Insert random key 12

9 The AVL tree is now balaced
Insert a key The AVL tree is now balaced Input key: 100 Insert Insert random key 12 -1 100

10 The tree is unbalanced: The balance factor of node with key ”12” is -2.
Do a right-left double rotation Insert a key Input key: Insert Insert random key 12 -1 -2 TODO: Smooth animation of the rotation 1 100 13

11 The AVL tree is now balaced
Input key: Insert Insert random key 13 12 100

12 Mode 3: Challenge yourself
AVL tree insertion Mode 3: Challenge yourself

13 Task 1: Insert a key so that the node ”21” will be the new root
The tree is unbalanced: The balance factor of node with key ”5” is -2. Do a single left rotation Input key: 30 Insert Insert random key 5 -1 -2 TODO: Smooth animation of the rotation 3 21 -1 -1 11 28 30

14 Task correct! Input key: Insert Insert random key 21 5 28 -1 30 3 11

15 Task 2: Insert a key so that the node ”11” will be the new root
The tree is unbalanced: The balance factor of node with key ”5” is -2. Do a double right-left rotation Task 2: Insert a key so that the node ”11” will be the new root Input key: 7 Insert Insert random key 5 -1 -2 TODO: Smooth animation of the rotation 3 21 1 1 11 28 7

16 Task correct! Input key: Insert Insert random key 11 5 21 -1 28 3 7

17 Task 3: Insert maximum of 3 keys so that the right child of root's left child (highlighted) has a key ”16”. The tree is unbalanced: The balance factor of node with key ”20” is 2. Do a double left-right rotation Input key: 16 Insert Insert random key 20 1 2 TODO: Smooth animation of the rotation -1 9 27 -1 3 14 16

18 Task 3: Insert maximum of 3 keys so that the right child of root's left child (highlighted) has a key ”16”. Input key: Insert Insert random key 14 1 9 20 3 16 27

19 Let's try again...

20 Task 3: Insert maximum of 3 keys so that the right child of root's left child (highlighted) has a key ”16”. Input key: 30 Insert Insert random key 20 1 -1 9 27 3 14 30

21 Task 3: Insert maximum of 3 keys so that the right child of root's left child (highlighted) has a key ”16”. Input key: 16 Insert Insert random key 20 -1 9 27 3 14 30 16

22 Task 3: Insert maximum of 3 keys so that the right child of root's left child (highlighted) has a key ”16”. Input key: 17 Insert Insert random key 20 1 -1 -1 9 27 -1 3 14 30 16 17

23 Task 3: Insert maximum of 3 keys so that the right child of root's left child (highlighted) has a key ”16”. The tree is unbalanced: The balance factor of node with key ”14” is -2. Do a single left rotation Input key: 17 Insert Insert random key 20 2 TODO: Smooth animation of the rotation -2 -1 9 27 -2 3 14 30 -1 16 17

24 Task 3: Insert maximum of 3 keys so that the right child of root's left child (highlighted) has a key ”16”. Task correct! Input key: Insert Insert random key 1 20 -1 -1 9 27 3 16 30 14 17


Download ppt "Draft for an AVL tree insertion visualization with multiple levels of engagement T-106.6200 Special Course in Software Techniques: Directions for Future."

Similar presentations


Ads by Google