Why it matters

Treaps are simple randomized balanced BSTs. Foundation for persistent structures.

Advertisement

The architecture

Each node: key + random priority.

BST on keys.

Max-heap on priorities.

Rotations maintain.

Treap structureNodekey + priorityBST on keyscompareMax-heap prioritiesrotate to restoreRandomization gives expected balance without strict maintenance
Treap.
Advertisement

How it works end to end

Random priorities on insert.

Rotations when priority violates heap.

Expected height O(log n).