{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# avl4 - Advanced Tree Structures AVL Trees(4 Introduction In...

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

Introduction In CS2 you were introduced to binary search trees (BSTs). Recall that one of the problems with general BSTs is that the tree may be unbalanced and thus skewed to the right or left. The more heavily skewed the tree, the further in general, you will get from the logarithmic time bound on searching in the tree. Therefore, it becomes a potentially important task to be able to balance the search tree. You were introduced to a global balancing algorithm known as the DSW algorithm (named for its developer’s Day and later improved by Stout and Warren). Algorithm’s such as the DSW algorithm perform balancing (or rebalancing actually) on the entire tree, thus algorithm’s of this type are known as global balancing algorithms. Global balancing algorithms are fairly costly, particularly when the search tree is already fairly well balanced. As an alternative, algorithms which adjust the balance of the search tree on a local basis; that is, they do not consider the entire tree but restrict their rebalancing to a subtree, have been developed as more efficient techniques for such well balanced search trees. In CS2 you were introduced to the AVL tree which is a search tree variant that self-balances at the local level. In this course, we will examine many other advanced tree structures each with particular properties regarding balance, restricting the height growth, specifying insertion points, etc. Most of these advanced tree structures will be geared toward searching operations in one form or another, rather than simple data representation. We’ll start our foray into advanced tree structures with a quick review of BSTs, the DSW algorithm, and AVL trees. I hope that the first sections of this set of notes will be a review, if not, be sure to understand carefully what the DSW algorithm is accomplishing and how it goes about doing so as well as understanding the concept of the rotation in both the DSW algorithm as well as how it is used in AVL trees. Binary Search Trees The property that turns a binary tree into a binary search tree is that for every node x , in the tree, the values of all the items in the left subtree of x are smaller than the item in x and the values of all the items in the right subtree of x are larger than the item in x . Notice that this implies that every item in the tree is part of a total ordering. Using this definition and considering the two trees shown in Figure 1, the tree on the left is a BST while the tree on the right is not a BST. AVL Trees - 1 Advanced Tree Structures – AVL Trees (4)

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

View Full Document
(b) Figure 1 – (a) A BST, (b) Not a BST (nodes 2 and 6 are in error) Recall that inserting a new node into a BST essentially involves a search for that node which will direct you to the correct location at which it is to be inserted as a new leaf node. Note that it is not possible to insert a new internal node in a BST. Deletion of a node in a BST is trivial if the node to be deleted is a leaf node. Deletion of an internal node is also trivial if the node to be deleted has only a single child.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 20

avl4 - Advanced Tree Structures AVL Trees(4 Introduction In...

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

View Full Document
Ask a homework question - tutors are online