User:Cdb273/Treap
Analysis Of Operations
[edit]The expected time for find, insert and delete operations on a treap is . In order to prove this, consider the following lemma:
For an element of rank , it holds that:
and can be thought of as the expected number of right and left turns, respectively in order to find starting at the root of the treap. This lemma has the implication that the depth of each element is . The proof of this lemma is as follows:
Define:
- (items less than or equal to x), and
- (items greater than or equal to x)
If is the set of values that are ancestors of , then:
- , and
Thus,
Aragon and Seidel[1] make use of Mulmuley Games in order to show that and .
Searching in a Treap
[edit]Consider searching for the key , not already in the treap, whose rank in the set is . Let be the key in the treap whose rank is , . The probability that is on the search path for is .
Expected length of the search path (for all ):
It follows that the expected time to find elements in the treap is .
Insertions and Deletions in a Treap
[edit]The cost of finding where to insert must be paid, and once found, it must be removed by the use of tree rotations. For insertion, the element is inserted as a leaf, and rotated upward to the correct position in the treap. For delection, it is rotated down to a leaf position, and removed. The number of rotations is equal to:
- , where is the right spine of the left subtree of , and is the left spine of the right subtree of
Again, through the use of Mulmuley Games, Aragon and Seidel show that , .
Therefore, , and the total cost of an insertion or deletion is .
Splitting and Merging a Treap
[edit]These operations, as described above, involve a single insertion or deletion, and are thus expected to run in time.
References
[edit]- ^ Aragon, Cecilia R.; Seidel, Raimund (1989), "Randomized Search Trees", Proc. 30th Symp. Foundations of Computer Science (FOCS 1989), Washington, D.C.: IEEE Computer Society Press, pp. 540–545, doi:10.1109/SFCS.1989.63531, ISBN 0-8186-1982-1