**REF.**- Daniel D Sleator and Robert E. Tarjan. Self-adjusting binary search
trees.
*Journal of the ACM*, Volume 32, Number 3, pp. 652-686, 1985. **REF.**- Robert E. Tarjan. Amortized computational complexity.
*SIAM Journal on Algebraic and Discrete Methods*, Volume 6, Number 2, pp. 306-318, 1985.

- These are binary search trees which are self-adjusting in
the following way:
Every time we access a node of the tree, whether for retrieval or insertion or deletion, we perform radical surgery on the tree, resulting in the newly accessed node becoming the root of the modified tree. This surgery will ensure that nodes that are frequently accessed will never drift too far away from the root whereas inactive nodes will get pushed away farther from the root.

- Amortized complexity
- Splay trees can become highly unbalanced so that a single access to a node of the tree can be quite expensive.
- However, over a long sequence of accesses, the few expensive cases are averaged in with many inexpensive cases to obtain good performance.

- Does not need heights or balance factors as in AVL trees and colours as in Red-Black trees.
- The surgery on the tree is done using
**rotations**, also called as splaying steps. There are six different splaying steps.- 1.
- Zig Rotation (Right Rotation)
- 2.
- Zag Rotation (Left Rotation)
- 3.
- Zig-Zag (Zig followed by Zag)
- 4.
- Zag-Zig (Zag followed by Zig)
- 5.
- Zig-Zig
- 6.
- Zag-Zag

- Consider the path going from the root down to the accessed node.
- Each time we move left going down this path, we say we ``zig'' and each time we move right, we say we ``zag.''

- Zig Rotation and Zag Rotation
- Note that a zig rotation is the same as a right rotation whereas the zag step is the left rotation.
- See Figure 4.17.

- Zig-Zag
- This is the same as a double rotation in an AVL tree. Note that the target element is lifted up by two levels.
- See Figure 4.18.

- Zag-Zig
- This is also the same as a double rotation in an AVL tree.
- Here again, the target element is lifted up by two levels.
- See Figure 4.19.

- Zig-Zig and Zag-Zag
- See Figure 4.22 for an example

- The above scheme of splaying is called
**bottom-up**splaying. - In
**top-down**splaying, we start from the root and as we locate the target element and move down, we splay as we go. This is more efficient.