Tools
Other Compiler Courses
Splay(x,S) | Reorganize S such that x is in the root or, if x is not in S, the root is either ... |
Member(x,S) | Splay(x,S). If x is in S, x is now the root. |
Min(S); Max(S) | Member(-Inf,S); Member(+Inf,S). |
Join(S,S') | (assuming all the members of S are smaller than those of S'.) Max(S), set right(S) = S', i.e., make S' the right subtree of S, or Min(S'), set left(S') = S. |
Split(x,S,S',S'') | Splay(x,S), S' = left(S)+S and S''=right(S), or, S' = left(S) and S'' = S+right(S), depending on S<=x or S>x. |
Insert(x,S) | Split(x,S,S',S'') to get S' and S''. Make x the root and set left(x) = S' and right(x) = S''. |
A node is inserted as is done in a regular binary search tree, after the insertion the node is splayed to the top of the tree. | |
Delete(x,S) | Splay(x,S), Join(left(S), right(S)) |
Find node; Find max of left subtree. It will have no right child, so make the right subtree the new right child. | |
Predecessor(x,S) | Splay(x,S), Max(left(S)) |
Successor(x,S) | Splay(x,S), Min(right(S)) |