Application: AVL Trees and The Golden Ratio
Application: AVL Trees and The Golden Ratio
Application slides 5
1+ 5
2
= 1 + 1+
= 1.618
1
1+
. . .1
Binary trees
A binary tree is either
The empty binary tree, for which Ill write
A nonempty
binary tree
Another
nonempty
binary tree
size is 5
AVL trees
AVL trees are binary trees with the following restrictions.
The empty tree is an AVL tree
AVL
Not AVL
Not AVL
The question
We wish to access large amounts of data quickly.
Remember amount of information is proportional to
size of tree
Size
0
Smallest tree
12
5
5
where
1+ 5
=
2
n+1
1
1
1
Consider 5
5 ( )n+1 for n R and n 0.
10
size 6
0
1
minsize(h) dots
Typeset October 31, 2005
height
1
5
h+2 1 line
8
Size
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
Max height 0 1 2 2 3 3 3 4 4 4 4 4 5 5 5
Note that for s such that minsize(h 1) < s minsize(h)
maxheight(s) = h
h+2 1
1
s = h+2 1
5
h+2
5 (s
+
1)
=
log 5 (s + 1) = h + 2
log 5 (s + 1) 2 = h
So invert
1
5
10
Graphing maxheight
6
5
4
h3
2
1
0
maxheight(s) dots
10
s
12
14
16
18
20
11