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...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Sec. 13.2 Balanced Trees 457PSSCAPA B B C(a)(b)Figure 13.7 Splay tree single rotation. This rotation takes place only whenthe node being splayed is a child of the root. Here, node S is promoted <strong>to</strong> theroot, rotating with node P. Because the value of S is less than the value of P,P must become S’s right child. The positions of subtrees A, B, <strong>and</strong> C are alteredas appropriate <strong>to</strong> maintain the BST property, but the contents of these subtreesremains unchanged. (a) The original tree with P as the parent. (b) The tree aftera rotation takes place. Performing a single rotation a second time will return thetree <strong>to</strong> its original shape. Equivalently, if (b) is the initial configuration of the tree(i.e., S is at the root <strong>and</strong> P is its right child), then (a) shows the result of a singlerotation <strong>to</strong> splay P <strong>to</strong> the root.GPDSASPGBCABCD(a)(b)Figure 13.8 Splay tree zigzag rotation. (a) The original tree with S, P, <strong>and</strong> Gin zigzag formation. (b) The tree after the rotation takes place. The positions ofsubtrees A, B, C, <strong>and</strong> D are altered as appropriate <strong>to</strong> maintain the BST property.

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

Saved successfully!

Ooh no, something went wrong!