Treap Data Structure | Data Structures Interview | Skill-Lync Resources
Hard Data Structures Advanced Structures

What is a Treap and how does it combine BST and heap properties?

Answer

A Treap is a randomized BST where each node has a key (BST property) and a random priority (heap property). Keys maintain BST ordering; priorities maintain max-heap ordering with parents having higher priority than children. This random structure provides expected O(log n) height without explicit balancing. Operations use tree rotations to maintain heap property after BST operations. Treaps support split and merge operations naturally, useful for implementing rope data structures.

Master These Concepts with IIT Certification
IIT Certified

Master These Concepts with IIT Certification

175+ hours of industry projects. Get placed at Bosch, Tata Motors, L&T and 500+ companies.

Relevant for Roles

Algorithm Developer Software Engineer Competitive Programmer