FACTOID # 35: Looking for Czech and Slovak men? Half are in factories.
 
 Home   Encyclopedia   Statistics   Countries A-Z   Flags   Maps   Education   Forum   FAQ   About 
 
 
 
WHAT'S NEW
RECENT ARTICLES
More Recent Articles »
 

SEARCH ALL

FACTS & STATISTICS    Advanced view

Search encyclopedia, statistics and forums:

 

 

(* = Graphable)

 

 


Encyclopedia > AVL tree
An example of an unbalanced non-AVL tree
An example of an unbalanced non-AVL tree

In computer science, an AVL tree is a self-balancing binary search tree, and the first such data structure to be invented[citation needed]. In an AVL tree the heights of the two child subtrees of any node differ by at most one, therefore it is also called height-balanced. Lookup, insertion, and deletion all take O(log n) time in both the average and worst cases. Additions and deletions may require the tree to be rebalanced by one or more tree rotations. Image File history File links Unbalanced_binary_tree. ... Image File history File links Unbalanced_binary_tree. ... Computer science, or computing science, is the study of the theoretical foundations of information and computation and their implementation and application in computer systems. ... In computing, a self-balancing binary search tree or height-balanced binary search tree is a binary search tree that attempts to keep its height, or the number of levels of nodes beneath the root, as small as possible at all times, automatically. ... The height of a node in a tree is defined as length of the path to its furthest child. ... A child node or descendant node is a node in a tree data structure that is linked to by a parent node. ... A height-balanced tree is a tree data structure which keeps its children similar in height to within some defined limit. ... For other uses, see Big O. In computational complexity theory, big O notation is often used to describe how the size of the input data affects an algorithms usage of computational resources (usually running time or memory). ... Please also consider changing this to a more descriptive stub notice. ...


The AVL tree is named after its two inventors, G.M. Adelson-Velsky and E.M. Landis, who published it in their 1962 paper "An algorithm for the organization of information." Georgii Maximovich Adelson-Velsky (Russian: Георгий Максимович Адельсон-Вельский, sometimes transliterated as Adelson-Velskii), (19??— ) is a Russian mathematician and... Yevgeniy Mikhailovich Landis (E.M. Landis, Russian Евгений Михайлович Ландис) ( ? – ? ) is a Russian mathematician. ...


The balance factor of a node is the height of its right subtree minus the height of its left subtree. 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 red-black trees because they support the same set of operations and because red-black trees also take O(log n) time for the basic operations. AVL trees perform better than red-black trees for lookup-intensive applications.[1] The AVL tree balancing algorithm appears in many computer science curricula. A red-black tree is a type of self-balancing binary search tree, a data structure used in computer science. ... For other uses, see Big O. In computational complexity theory, big O notation is often used to describe how the size of the input data affects an algorithms usage of computational resources (usually running time or memory). ...

The same tree after being height-balanced
The same tree after being height-balanced

Contents

Image File history File links No higher resolution available. ... Image File history File links No higher resolution available. ...

Explanation

Binary search trees operate under a divide and conquer algorithm approach to data management. Because of the nature of the structure, in the average case, for any node in the tree there are about as many nodes to the left of the current node as there are nodes to the right of the current node. In the average case, the number of nodes in a tree of size n that need be traversed to find a particular node is approximately lg(n). A binary search tree of size 9 and depth 3, with root 8 and leaves 1, 4, 7 and 13. ... In computer science, divide and conquer (D&C) is an important algorithm design paradigm. ...


For a binary search tree to be optimal, elements should be arranged as compactly as possible, so that each time a left-right choice is made in a descent down the tree, maximum possible number of nodes are eliminated from the outstanding path. A binary search tree of size 9 and depth 3, with root 8 and leaves 1, 4, 7 and 13. ...


In the worst-case situations of a binary search tree, all the nodes still have to be reached to find a particular node (e.g. the parent node only has one child, and it only has one child, and that child only has one child... all the way down to the last child who doesn't have any children). Which gives a worst-case scenario for binary search trees is that the number of nodes traversed to find a particular node in a tree of size n is n (i.e. all the nodes need be traversed).


An AVL tree solves this problem by putting additional restrictions on the binary search tree -- For all nodes in the tree, the height of the left subtree and the height of the right subtree differ by at most one. This restriction prevents the worst case scenarios of binary search trees, and ensures that at most (3 / 2) * lg(n) nodes be visited. A simple example unordered tree In computer science, a tree is a widely-used data structure that emulates a tree structure with a set of linked nodes. ... A simple example unordered tree In computer science, a tree is a widely-used data structure that emulates a tree structure with a set of linked nodes. ...


Operations

The basic operations of an AVL tree generally involve carrying out the same algorithms as would be carried out on an unbalanced binary search tree, but preceded or followed by one or more of the so-called "AVL rotations." A binary search tree of size 9 and depth 3, with root 8 and leaves 1, 4, 7 and 13. ...


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.[citation needed]


If the balance factor becomes -1, 0, or 1 then the tree is still in AVL form, and no rotations are necessary.


If the balance factor becomes 2 or -2 then the tree rooted at this node is unbalanced, and a tree rotation is needed. At most a single or double rotation will be needed to balance the tree.[citation needed] Please also consider changing this to a more descriptive stub notice. ...


Only the nodes traversed from the insertion point to the root of the tree need be checked, and rotations are a constant operation, and because the height is limited to O(log(n)), the execution time for an insertion is O(log(n)).


Deletion

If the node is a leaf, remove it. If the node is not a leaf, replace it with either the largest in its left subtree or the smallest in its right subtree, and remove that node. Thus the node that is removed has at most one child. After deletion retrace the path back up the tree to the root, adjusting the balance factors as needed.


The retracing can stop if the balance factor becomes -1 or 1 indicating that the height of that subtree has remained unchanged. If the balance factor becomes 0 then the height of the subtree has decreased by one and the retracing needs to continue. If the balance factor becomes -2 or 2 then the subtree is unbalanced and needs to be rotated to fix it. If the rotation leaves the subtree's balance factor at 0 then the retracing towards the root must continue since the height of this subtree has decreased by one. This is in contrast to an insertion where a rotation resulting in a balance factor of 0 indicated that the subtree's height has remained unchanged.


The time required is O(h) for lookup plus O(h) rotations on the way back to the root; so the operation can be completed in O(log n) time.


Lookup

Lookup in an AVL tree is performed exactly as in an unbalanced binary search tree, except because of the height-balancing of the tree, a lookup takes O(log n) time. No special provisions need to be taken, and the tree's structure is not modified by lookups. (This is in contrast to splay tree lookups, which do modify their tree's structure.) A splay tree is a self-balancing binary search tree with the additional unusual property that recently accessed elements are quick to access again. ...


If each node additionally records the size of its subtree (including itself and its descendants), then the nodes can be retrieved by index in O(log n) time as well.


Once a node has been found in a balanced tree, the next or previous node can be obtained in amortized constant time. (In a few cases, about 2*log(n) links will need to be traversed. In most cases, only a single link need be traversed. On the average, about two links need to be traversed.)[citation needed] In computer science, especially analysis of algorithms, amortized analysis refers to finding the average running time per operation over a worst-case sequence of operations. ...


Comparison to other structures

Both AVL trees and red-black trees are self-balancing binary search trees, so they are very similar mathematically. The operations to balance the trees are different, but both occur in constant time. The real difference between the two is the limiting height. For a tree of size n:

  • an AVL tree's height is limited to 1.44 * lg(n)
  • a red-black tree's height is limited to 2 * lg(n)

So while both insertions, deletions, and lookups in both types of trees would be O(log(n)), an AVL tree is shorter in the worst case, so will generally require less time for each of those operations.


See also

Please also consider changing this to a more descriptive stub notice. ... A splay tree is a self-balancing binary search tree with the additional unusual property that recently accessed elements are quick to access again. ... A red-black tree is a type of self-balancing binary search tree, a data structure used in computer science, typically used to implement associative arrays. ... B-trees are tree data structures that are most commonly found in databases and filesystem implementations. ... In computer science a T-tree is a type of tree data structure that is used by main-memory databases, such as, supposedly, TimesTen. ...

References

  • G. Adelson-Velskii and E.M. Landis, "An algorithm for the organization of information." Doklady Akademii Nauk SSSR, 146:263–266, 1962 (Russian). English translation by Myron J. Ricci in Soviet Math. Doklady, 3:1259–1263, 1962.
  • Donald Knuth. The Art of Computer Programming, Volume 3: Sorting and Searching, Third Edition. Addison-Wesley, 1997. ISBN 0-201-89685-0. Pages 458–475 of section 6.2.3: Balanced Trees. Note that Knuth calls AVL trees simply "balanced trees".
  1. ^ Pfaff, Ben (June 2004). Performance Analysis of BSTs in System Software (PDF). Stanford University.

The English language is a West Germanic language that originates in England. ... Donald Ervin Knuth ( or Ka-NOOTH[1], Chinese: [2]) (b. ... “Stanford” redirects here. ...

External links



 
 

COMMENTARY     


Share your thoughts, questions and commentary here
Your name
Your comments

Want to know more?
Search encyclopedia, statistics and forums:

 


Lesson Plans | Student Area | Student FAQ | Reviews | Press Releases |  Feeds | Contact
The Wikipedia article included on this page is licensed under the GFDL.
Images may be subject to relevant owners' copyright.
All other elements are (c) copyright NationMaster.com 2003-5. All Rights Reserved.
Usage implies agreement with terms, 1022, m