avl-tree-animation and trversals and balancing

Anandkumar105685 7 views 20 slides Oct 27, 2025
Slide 1
Slide 1 of 20
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20

About This Presentation

AVL Tree animation


Slide Content

AVL Tree Example:
• Insert 14, 17, 11, 7, 53, 4, 13 into an empty AVL tree
14
1711
7 53
4

AVL Tree Example:
• Insert 14, 17, 11, 7, 53, 4, 13 into an empty AVL tree
14
177
4 5311
13

AVL Tree Example:
• Now insert 12
14
177
4 5311
13
12

AVL Tree Example:
• Now insert 12
14
177
4 5311
12
13

AVL Tree Example:
• Now the AVL tree is balanced.
14
177
4 5312
1311

AVL Tree Example:
• Now insert 8
14
177
4 5312
1311
8

AVL Tree Example:
• Now insert 8
14
177
4 5311
128
13

AVL Tree Example:
• Now the AVL tree is balanced.
14
17
7
4
53
11
12
8 13

AVL Tree Example:
• Now remove 53
14
17
7
4
53
11
12
8 13

AVL Tree Example:
• Now remove 53, unbalanced
14
17
7
4
11
12
8 13

AVL Tree Example:
• Balanced! Remove 11
14
17
7
4
11
128
13

AVL Tree Example:
• Remove 11, replace it with the largest in its left branch
14
17
7
4
8
12
13

AVL Tree Example:
• Remove 8, unbalanced
14
17
4
7
12
13

AVL Tree Example:
• Remove 8, unbalanced
14
17
4
7
12
13

AVL Tree Example:
• Balanced!!
14
17
4
7
12
13

In Class Exercises
•Build an AVL tree with the following values:
15, 20, 24, 10, 13, 7, 30, 36, 25

15
15, 20, 24, 10, 13, 7, 30, 36, 25
20
24
15
20
24
10
13
15
20
24
13
10
13
20
24
1510

13
20
24
1510
15, 20, 24, 10, 13, 7, 30, 36, 25
7
13
20
2415
10
7
30
3613
20
3015
10
7
3624

13
20
3015
10
7
3624
15, 20, 24, 10, 13, 7, 30, 36, 25
25
13
20
30
15
10
7
36
24
25
13
24
36
20
10
7
25
30
15

Remove 24 and 20 from the AVL tree.
13
24
36
20
10
7
25
30
15
13
20
36
15
10
7
25
30
13
15
36
10
7
25
30
13
30
36
10
7
25
15
Tags