Tree 2 - AVL Trees An AVL (Adelson-Velskii and Landis) tree...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
49 AVL Trees z An AVL (Adelson-Velskii and Landis) tree is a binary search tree with a balance condition. z An AVL tree is identical to a binary search tree, except that for every node in the tree, the height of the left and right subtrees can differ by at most 1. z With an AVL tree, all the tree operations can be performed in O (log n ) time, except insertion.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
50 Example •A bad binary tree. •Requiring balance at the root is not enough.
Background image of page 2
51 Example Two binary search trees. Only the left tree is AVL.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
52 Example Smallest AVL tree of height 9. Notice that the construction of the smallest AVL tree of height n is to use two smallest AVL sub-trees that are of n -1 and n -2 height.
Background image of page 4
53 Height of AVL Tree z The height of an empty tree is defined to be -1 z Height information is kept for each node (in the node structure). z The height of an AVL tree is at most roughly 1.44 log( n + 2) - .328, but in practice it is about log( n + 1) + 0.25 (although this has not been proven).
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
54 Observations z All the tree operations can be performed in O (log n ) time, except possibly insertion. z Insertion and deletion operations need to update the balancing information. z It is sometimes difficult since that inserting a node could violate the AVL tree property. z If this is the case, then the property has to be restored before the insertion step is considered over. z The property can be achieved through a rotation .
Background image of page 6
55 Single Rotation z A rotation involves only a few pointer changes, and changes the structure of the tree while preserving the search tree property.
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
56 Notes z
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 42

Tree 2 - AVL Trees An AVL (Adelson-Velskii and Landis) tree...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online