Explain the concept of Splay Trees and their advantages in search operations.

Instruction: Discuss the structure of Splay Trees and how their self-adjusting property can benefit search operations.

Context: Assess self-adjustment, rotations and the distinction between amortized performance and worst-case cost for a single operation.

Updated

Official Answer

A splay tree is a self-adjusting binary search tree. After an access, rotations move the accessed node toward the root; a failed search commonly splays the last visited node. Zig, zig-zig and zig-zag steps preserve the search-tree ordering.

Standard operations have O(log n) amortized cost: the bound concerns total work over a sequence, not a promise that every operation is logarithmic. A single operation can take O(n), and the tree need not remain height-balanced.

Moving an accessed key to the root makes an immediate repeat access cheap and can exploit locality in the workload. It avoids storing balance factors, but even a search changes the structure, which complicates concurrent access. Workloads requiring a strict per-operation latency bound may favor a height-balanced tree instead.

Source

Sleator and Tarjan: Self-Adjusting Binary Search Trees.

Related Questions