- 10. AVL Trees
Balanced Trees [Ottman/Widmayer, Kap. 5.2-5.2.1, Cormen et al, Kap. Problem 13-3]
166
10. AVL Trees Balanced Trees [Ottman/Widmayer, Kap. 5.2-5.2.1, - - PowerPoint PPT Presentation
10. AVL Trees Balanced Trees [Ottman/Widmayer, Kap. 5.2-5.2.1, Cormen et al, Kap. Problem 13-3] 166 Objective Searching, insertion and removal of a key in a tree generated from n keys inserted in random order takes expected number of steps O
166
167
168
169
170
171
172
173
174
!
1 √ 5(φi − ˆ
√ 5 2
√ 5 2
def
[∗]
175
h ⊆ Ω(1.618h)
5The perfectly balanced tree has a height of ⌈log2 n + 1⌉
176
177
+1 p p n
−1 p p n
178
+1 p p n
−1 p p n
179
180
pp +1 pp p p
pp pp −1 p p
6If p is a right son: symmetric cases with exchange of +1 and −1
181
pp −1 p
182
y x
pp −2 p −1 h h − 1 h − 1 h + 2 h
x y
pp p h h − 1 h − 1 h + 1 h + 1
7p right son: ⇒ bal(pp) = bal(p) = +1, left rotation
183
z x y
pp −2 p +1 h −1/ + 1 h − 1 h − 1 h − 2 h − 2 h − 1 h − 1 h + 2 h
y x z
pp 0/ − 1 +1/0 h − 1 h − 1 h − 2 h − 2 h − 1 h − 1 h + 1
8p right son ⇒ bal(pp) = +1, bal(p) = −1, double rotation right left
184
185
p n h = 0, 1, 2
− →
p h = 0, 1, 2
186
p n k
− →
p k
187
188
189
y
pp +1
x
p
z
q
1 2 3 4
h − 1 h − 1 h + 1 h + 1
z
−1
y
+1
x 1 2 3 4
h − 1 h − 1 h + 1 h + 1
9(b).3.1: bal(pp) = −1, bal(q) = −1, Right rotation
190
y
pp +1
x
p
z
q +1
1 2 3 4
h − 1 h − 1 h h + 1
z
r
y x 1 2 3 4
h − 1 h − 1 h h + 1
10(b).3.2: bal(pp) = −1, bal(q) = +1, Right rotation+upout
191
y
pp +1
x
p
z
q −1
w 1 2 3 4 5
h − 1 h − 1 h
w
r
y x z 1 2 3 4 5
h − 1 h − 1 h
11(b).3.3: bal(pp) = −1, bal(q) = −1, left-right rotation + upout
192
193