This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: CMPSC 130A: Winter 2011 Programming Assignment 2 Assigned: Feb 17, 2011 Due: Mar 1, 2011 (11:59 PM) Your second programming assignment is to implement the splay trees . Recall that splay trees are balanced search trees in which no explicit balance condition is maintained; instead, a simple restructuring heuristic is used after each access. Splaying Specifically, whenever a node x is accessed (either by search, or insert, or delete), the following splay operation is repeated at x until it becomes the root. In the following, p ( x ) denotes the parent of node x . • Case 1 : if p ( x ) is the root, rotate the edge between x and p ( x ); and terminate. • Case 2 : [Two Single Rotations] if p ( x ) is not the root and x and p ( x ) are both left or both right children, first rotate the edge joining p ( x ) with x ’s grandparent g ( x ), and then rotate the edge joining x with p ( x ). • Case 3 : [Double Rotation] if p ( x ) is not the root and x is a left child and p ( x ) is a right child, or vice versa, then rotate the edge joining x with p ( x ) and then rotate the edge joining x with its new parent....
View Full Document
- Fall '11
- Splay tree, 20 pts, 60 pts