12.07.2015 Views

A Practical Introduction to Data Structures and Algorithm Analysis

A Practical Introduction to Data Structures and Algorithm Analysis

A Practical Introduction to Data Structures and Algorithm Analysis

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Sec. 13.2 Balanced Trees 455SXDYAYXSBCABCD(a)(b)Figure 13.6 A double rotation in an AVL tree. This operation occurs when theexcess node (in subtree B) is in the right child of the left child of the unbalancednode labeled S. By rearranging the nodes as shown, we preserve the BST property,as well as re-balance the tree <strong>to</strong> preserve the AVL tree balance property. The casewhere the excess node is in the left child of the right child of S is h<strong>and</strong>led in thesame way.found <strong>to</strong> be unbalanced. Deletion is similar; however consideration for unbalancednodes must begin at the level of the deletemin operation.Example 13.3 In Figure 13.4 (b), the bot<strong>to</strong>m-most unbalanced node hasvalue 7. The excess node (with value 5) is in the right subtree of the leftchild of 7, so we have an example of Case 2. This requires a double rotation<strong>to</strong> fix. After the rotation, 5 becomes the left child of 24, 2 becomes the leftchild of 5, <strong>and</strong> 7 becomes the right child of 5.13.2.2 The Splay TreeLike the AVL tree, the splay tree is not actually a data structure per se but rather isa collection of rules for improving the performance of a BST. These rules governmodifications made <strong>to</strong> the BST whenever a search, insert, or delete operation isperformed. Their purpose is <strong>to</strong> provide guarantees on the time required by a seriesof operations, thereby avoiding the worst-case linear time behavior of st<strong>and</strong>ardBST operations. No single operation in the splay tree is guaranteed <strong>to</strong> be efficient.Instead, the splay tree access rules guarantee that a series of m operations will take

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!