concept

Treap

A Treap (Tree + Heap) is a randomized binary search tree data structure that combines properties of a binary search tree (BST) and a heap. Each node contains a key (for BST ordering) and a priority (for heap ordering), with the tree maintaining BST order by key and heap order by priority, typically using random priorities to ensure balanced structure. It provides average-case O(log n) time complexity for insertion, deletion, and search operations, making it efficient for dynamic sets.

Also known as: Randomized BST, Cartesian Tree, Treap Tree, Randomized Search Tree, BST-Heap Hybrid
🧊Why learn Treap?

Developers should learn Treaps when implementing data structures that require efficient dynamic operations like insertion and deletion while maintaining sorted order, such as in priority queues, interval trees, or order statistic trees. They are particularly useful in competitive programming and algorithm design due to their simplicity and probabilistic guarantees, offering a practical alternative to more complex balanced trees like AVL or Red-Black trees without requiring explicit balancing rotations.

Compare Treap

Learning Resources

Related Tools

Alternatives to Treap