{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Tree 2

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

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

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.

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

View Full Document
50 Example •A bad binary tree. •Requiring balance at the root is not enough.
51 Example Two binary search trees. Only the left tree is AVL.

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

View Full Document
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.
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).

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

View Full Document
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 .
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.

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

View Full Document
56 Notes z
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### 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
Ask a homework question - tutors are online