AVL tree
From Wikipedia, the free encyclopedia
In computer science, an
AVL tree
is a selfbalancing binary search tree, and
it is the first such data structure to be invented.
[1]
In an AVL tree, the heights
of the two child subtrees of any node differ by at most one; therefore, it is also
said to be heightbalanced. Lookup, insertion, and deletion all take O(log
n
)
time in both the average and worst cases, where n is the number of nodes in
the tree prior to the operation. Insertions and deletions may require the tree to
be rebalanced by one or more tree rotations.
The AVL tree is named after its two inventors, G.M. AdelsonVelsky and
E.M. Landis, who published it in their 1962 paper "An algorithm for the
organization of information."
The
balance factor
of a node is the height of its right subtree minus the
height of its left subtree and a node with balance factor 1, 0, or 1 is
considered balanced. A node with any other balance factor is considered
unbalanced and requires rebalancing the tree. The balance factor is either
stored directly at each node or computed from the heights of the subtrees.
AVL trees are often compared with redblack trees because they support the
same set of operations and because redblack trees also take O(log
n
) time for
the basic operations. AVL trees perform better than redblack trees for
lookupintensive applications.
[2]
The AVL tree balancing algorithm appears
in many computer science curricula.
Operations
The basic operations of an AVL tree generally involve carrying out the same actions as would be carried out on an
unbalanced binary search tree, but preceded or followed by one or more operations called tree rotations, which help to
restore the height balance of the subtrees.
Insertion
Insertion into an AVL tree may be carried out by inserting the given value into the tree as if it were an unbalanced binary
search tree, and then retracing one's steps toward the root updating the balance factor of the nodes.
If the balance factor becomes 1, 0, or 1 then the tree is still in AVL form, and no rotations are necessary.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
This is the end of the preview.
Sign up
to
access the rest of the document.
 Fall '09
 Lee
 Binary Search, Splay tree, Redblack tree, Selfbalancing binary search tree, balance factor

Click to edit the document details