Você está na página 1de 18

Splay Trees

Sean Lyn
April 3, 2008
What is it?
• A binary tree structure that is very similar to other trees
but with additional properties.
• Has the potential for speeds faster than O(logn).
• Its bounds are amortized – even though individual
operations may be expensive, any sequence of
operations is guaranteed to behave as though each
operation had logarithmic behavior.
• Self adjusting.
Differences
• Balanced trees require an extra piece of balancing
information.
• Balanced trees have expensive insertion and deletion.
• Splay trees take advantage of the 90-10 rule.
Splaying
• Splaying is the process of rotating the most currently
used node to the root.
• Two types of trees: Bottom Up and Top Down.
Bottom Up Splay Trees
• Three Cases: Zig, Zig-Zag, and Zig-Zig
• Zig occurs when X is a non-root and P is the root. In this
case we rotate X to the root.
• Zig-Zag occurs when X has a parent P and a
grandparent G where X is a right child and P is a left
child or vice versa.
• Zig-Zig occurs when X and its parent P are both left or
right children.
Zig
• Single rotation involving X and P
Zig-Zag
• Double rotation similar to an AVL tree.
First we rotate X and P, then X and G to
bring X to the root.
Zig-Zig
• Uses a double rotation by first rotating P
and G then rotating X and P
Zig-Zig
Splay Tree Operations
• A splay operation is performed after every access to a
node.
• Find – splay the tree after finding it
• DeleteMin is simple, perform FindMin which will bring it
to the top then the right child becomes the new root.
• Removal – Access the node which makes it the root then
delete it which gives two trees. Find the max of the left
tree and that is the new root.
Deletion on 6
Top Down Splay Trees
• Works by starting at the top and working down to
produce a similar result.
• All of the nodes lower than the target are put into one
tree and all of the nodes greater than the target are put
into another tree then it is recombined.
Top Down Splaying
Top Down Splaying
Top Down Splaying
Conclusion
• Are Splay Trees better to use? The
answer has no been resolved completely.
• They situationally perform better than
other balanced trees, usually determined
by the access patterns.
Questions
1. What is one unique property of a splay
tree?
2. What are the three cases for rotating a
node to the root?
Sources
• Weiss, Mark. Data Structures and Problem
Solving Using Java. Boston: Pearson
Education, Inc, 2006.

Você também pode gostar