An implicit treap represents a sequence by the inorder traversal of a treap, without storing explicit positional search keys. Each node stores its subtree size. If the left subtree has size , the root has local index ; smaller indices descend left, while larger indices descend right after subtracting .
An empty tree has size zero; splitting it at zero returns two empty trees. A split at returns the first entries and the remainder. If , split the left subtree and attach its returned suffix as the root's new left child. Otherwise split the right subtree at and attach its returned prefix as the root's new right child. Recompute sizes on the return path. A merge assumes that every entry of its first operand precedes every entry of its second; choose the higher-priority root and recursively merge the adjoining inner subtrees.
Both operations preserve inorder traversal order and heap order on priorities. They permit insertion, deletion or moving a contiguous segment through a few splits and merges. Independent identically distributed continuous random priorities give the underlying randomized search-tree balance and expected logarithmic operation cost; a particular tree can still be tall.[ref]
Randomized Search Trees by Raimund Seidel and Cecilia R. Aragon. section 2, treap invariants and split/join; positional-size variant derived here
Articles by others on the same topic
There are currently no matching articles.