Splay Tree

1/0
1.0x

Splay Tree

O(log n)Space: O(n)

Pseudocode

1procedure splay(node, value)
2 if node is null or node.value = value
3 return node
4 if value < node.value (left subtree)
5 zig-zig: rotate right twice
6 zig-zag: rotate left child, then right
7 zig: rotate right once
8 else (right subtree)
9 zig-zig: rotate left twice
10 zig-zag: rotate right child, then left
11 zig: rotate left once
12procedure insert(root, value)
13 BST insert, then splay the new node to root