/
AVL Trees AVL Trees
K08 Δομές Δεδομένων και Τεχνικές Προγραμματισμού Κώστας Χατζηκοκολάκης
1
AVL Trees AVL Trees K08 - - PowerPoint PPT Presentation
AVL Trees AVL Trees K08 / 1 Balanced trees Balanced trees O ( h ) We saw that most of the algorithms in BSTs
/
1
/
/
/
4
/
5
/
6
/
7
/
8
/
9
/
10
/
2 h
2 k−2
2 k−2 2 k
11
/
12
/
−
13
/
/ −
14
/
\ − / −
15
/
− − − − − \
16
/
− / − − / − − − − −
17
/
// / −
18
/
\\ \\ \ − −
19
/
// \\ \ − − − /
20
/
\\ − − −
21
/
/
23
/
24
/
r x \ \\ T
1
T
2
h h h h T
1
T
2
h h x r − − T ree height h+3 T ree height h+2 T
3
New node T
3
New node
25
/
26
/
r x / \\ T
1
T
2
h h-1
h h T
1
h w r One of T
2 or T 3 has the new node and height h
T ree height h+3 T ree height h+2 w − x T
4
h-1
h h T
4
T
3
T
2
T
3
27
/
/
29
/
r x / // T
2
T
3
h h h T
2
T
3
h h x r T ree height h+3 T ree height h+2 − − New node T
1
h T
1
30
/
r x \ // T
1
h h T
1
h w r One of T
2 or T 3 has the new node and height h
T ree height h+3 T ree height h+2 w − x T
4
h T
4
h-1
h T
3
T
2
h-1
h T
3
T
2
31
/
32
/
32
/
32
/
32
/
32
/
32
/
32
/
33
/
r \\ Deleted node T
2
r Height reduced T
3
x h-1 h-1 h \ T
1
T
3
h h-1 h-1 − − x T
2
T
2
T
1
34
/
35
/
r \\ Deleted node T
2
T
2
r Height unchanged T
3
x h-1 h h − T
1
T
3
h h h-1 \ / x T
1
36
/
37
/
r \\ Deleted node T
2
r Height reduced T
4
x h-1 h-1
h-2 h-1 / T
1
T
4
h-1 h-1
h-2 h-1 − w T
3
T
2
w x T
3
T
1
38
/
39
/
39
/
39
/
/
/
in C++. 2nd edition. Section 10.2