Apex › Storage & databases

Treap — the randomized BST

A binary search tree that stays balanced by accident, not by rules. Every node gets a random priority, and the tree maintains BST order on keys plus heap order on priorities at once — which, for random priorities, is a balanced tree with no rotations to track. Add keys (even a sorted run that would ruin a plain BST) and watch it stay shallow; because priorities come from a key hash, the shape depends only on the key set, not insertion order.

More in Storage & databases