AVL Trees
In order to have a worst case running time for insert and delete
operations to be O(log n), we must make it impossible for there
to be a very long path in the binary search tree. The first
balanced binary tree is the AVL tree, named after it's
inventors, AdelsonVelskii and Landis. A binary search tree is
an AVL tree iff each node in the tree satisfies the following
property:
The height of the left subtree can differ from the height of the
right subtree by at most 1.
Based on this property, we can show that the height of an AVL
tree is logarithmic with respect to the number of nodes stored
in the tree.
In particular, for an AVL tree of height H, we find that it must
contain at least F
H+3
1 nodes. (F
i
is the ith Fibonacci number.)
To prove this, notice that the number of nodes in an AVL tree
is the 1 plus the number of notes in the left subtree plus the
number of nodes in the right subtree. If we let S
H
represent the
minimum number of nodes in an AVL tree with height H, we
get the following recurrence relation:
S
H
= S
H1
+ S
H2
+ 1
We also know that S
0
=1 and S
1
=2. Now we can prove the
assertion above through induction.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentFor those of you who haven't seen induction yet, I won't "test"
on it in this class. I'll try to explain the major steps of induction
as best as I can, very briefly. Induction is used to prove that
some statement or formula is true for all positive integers.
Sometimes, it is difficult to prove a formula for all positive
integers outright though.
In these cases, it may be easier to prove that IF the formula is
true for an integer, say, 10 (we can call this k), then it MUST
BE true for the next integer 11 (this would be k+1).
Finally, if we can prove that, AND we can show that the
formula is true when you plug in 1 into it, it follows that the
formula is true for all positive integers.
Here's a simple example you can hopefully relate to (I
apologize to women who have small wardrobes!!!):
Assumptions: A female's wardrobe increases by 15% a year. A
male's wardrobe increases by 10% a year. At the age of 20, a
female has 50 pieces of clothing, while a male has 45.
We will prove: That for all years over 20 years of age, females
own more pieces of clothing than males.
It is true for age 20 based on the given information.
Assume it's true for age k, where k
This is the end of the preview.
Sign up
to
access the rest of the document.
 Spring '09
 Guha
 Computer Science, Binary Search

Click to edit the document details