Data Structures19 sections · 729 units
Open in Course

Implicit Treaps

Position-based keys

Implicit treaps don't store explicit keys. Instead, the "key" is the position in the in-order traversal, computed on the fly from subtree sizes.

Each node stores sizesize = number of nodes in its subtree. The position of a node is the count of nodes before it in in-order.

This approach enables array-like operations:

  • Insert at position ii
  • Delete at position ii
  • Reverse a range [l,r][l, r]
  • Cyclic shift

All in O(logn)O(\log n) expected time. Implicit treaps are like super-powered dynamic arrays.