0% found this document useful (0 votes)
85 views123 pages

Treaps - 26014

The document discusses treaps, which are a combination of binary search trees and heaps. A treap stores a key-priority pair (Bi, Hi) for each node, preserves the BST property on keys and the heap property on priorities. Treaps can be constructed by inserting nodes one by one, where each insertion restructures the tree to preserve the heap property on priorities. Common operations like search, insert and delete can be supported in logarithmic time by taking advantage of the tree's self-balancing properties.

Uploaded by

Fabio Francisco
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
85 views123 pages

Treaps - 26014

The document discusses treaps, which are a combination of binary search trees and heaps. A treap stores a key-priority pair (Bi, Hi) for each node, preserves the BST property on keys and the heap property on priorities. Treaps can be constructed by inserting nodes one by one, where each insertion restructures the tree to preserve the heap property on priorities. Common operations like search, insert and delete can be supported in logarithmic time by taking advantage of the tree's self-balancing properties.

Uploaded by

Fabio Francisco
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 123

Motivation

Structure
Operations
Implicit Treaps

Treaps

CSEN 1038

German University in Cairo

CSEN 1038 Treaps 1 / 91


Motivation
Structure
Operations
Implicit Treaps

Recall Binary Search Trees and Binary Heaps.


What operations they can support?
What is the (worst-case) complexity?

General-purpose programming languages (such as C++ and Java)


usually support maps and sets.
depends on a Self-Balanced Binary Search Tree (SBBST)
– Java uses a Red-Black tree.
provides a limited set of functions.
– typically to use it as a map or a set.

CSEN 1038 Treaps 2 / 91


Motivation
Structure
Operations
Implicit Treaps

Recall Binary Search Trees and Binary Heaps.


What operations they can support?
What is the (worst-case) complexity?

General-purpose programming languages (such as C++ and Java)


usually support maps and sets.
depends on a Self-Balanced Binary Search Tree (SBBST)
– Java uses a Red-Black tree.
provides a limited set of functions.
– typically to use it as a map or a set.

CSEN 1038 Treaps 2 / 91


Motivation
Structure
Operations
Implicit Treaps

Recall Binary Search Trees and Binary Heaps.


What operations they can support?
What is the (worst-case) complexity?

General-purpose programming languages (such as C++ and Java)


usually support maps and sets.
depends on a Self-Balanced Binary Search Tree (SBBST)
– Java uses a Red-Black tree.
provides a limited set of functions.
– typically to use it as a map or a set.

CSEN 1038 Treaps 2 / 91


Motivation
Structure
Operations
Implicit Treaps

Recall Binary Search Trees and Binary Heaps.


What operations they can support?
What is the (worst-case) complexity?

General-purpose programming languages (such as C++ and Java)


usually support maps and sets.
depends on a Self-Balanced Binary Search Tree (SBBST)
– Java uses a Red-Black tree.
provides a limited set of functions.
– typically to use it as a map or a set.

CSEN 1038 Treaps 2 / 91


Motivation
Structure
Operations
Implicit Treaps

Recall Binary Search Trees and Binary Heaps.


What operations they can support?
What is the (worst-case) complexity?

General-purpose programming languages (such as C++ and Java)


usually support maps and sets.
depends on a Self-Balanced Binary Search Tree (SBBST)
– Java uses a Red-Black tree.
provides a limited set of functions.
– typically to use it as a map or a set.

CSEN 1038 Treaps 2 / 91


Motivation
Structure
Operations
Implicit Treaps

Recall Binary Search Trees and Binary Heaps.


What operations they can support?
What is the (worst-case) complexity?

General-purpose programming languages (such as C++ and Java)


usually support maps and sets.
depends on a Self-Balanced Binary Search Tree (SBBST)
– Java uses a Red-Black tree.
provides a limited set of functions.
– typically to use it as a map or a set.

CSEN 1038 Treaps 2 / 91


Motivation
Structure
Operations
Implicit Treaps

Recall Binary Search Trees and Binary Heaps.


What operations they can support?
What is the (worst-case) complexity?

General-purpose programming languages (such as C++ and Java)


usually support maps and sets.
depends on a Self-Balanced Binary Search Tree (SBBST)
– Java uses a Red-Black tree.
provides a limited set of functions.
– typically to use it as a map or a set.

CSEN 1038 Treaps 2 / 91


Motivation
Structure
Operations
Implicit Treaps

Recall Binary Search Trees and Binary Heaps.


What operations they can support?
What is the (worst-case) complexity?

General-purpose programming languages (such as C++ and Java)


usually support maps and sets.
depends on a Self-Balanced Binary Search Tree (SBBST)
– Java uses a Red-Black tree.
provides a limited set of functions.
– typically to use it as a map or a set.

CSEN 1038 Treaps 2 / 91


Motivation
Structure
Operations
Implicit Treaps

However, we cannot modify the built-in implementation to support


more functions.
Finding the k th smallest element in a set.
Find the subtree size of a specific node in a BST.

We need to implement our own SBBST!

CSEN 1038 Treaps 3 / 91


Motivation
Structure
Operations
Implicit Treaps

However, we cannot modify the built-in implementation to support


more functions.
Finding the k th smallest element in a set.
Find the subtree size of a specific node in a BST.

We need to implement our own SBBST!

CSEN 1038 Treaps 3 / 91


Motivation
Structure
Operations
Implicit Treaps

Treaps

A combination of a Binary Search Tree and a Heap.


every node stores a pair (Bi , Hi ).
preserves the BST property on Bi values.
preserves the Heap property on Hi values.
Bi values are the keys and Hi values are the priorities.

CSEN 1038 Treaps 4 / 91


Motivation
Structure
Operations
Implicit Treaps

Treaps

A combination of a Binary Search Tree and a Heap.


every node stores a pair (Bi , Hi ).
preserves the BST property on Bi values.
preserves the Heap property on Hi values.
Bi values are the keys and Hi values are the priorities.

CSEN 1038 Treaps 4 / 91


Motivation
Structure
Operations
Implicit Treaps

Treaps

A combination of a Binary Search Tree and a Heap.


every node stores a pair (Bi , Hi ).
preserves the BST property on Bi values.
preserves the Heap property on Hi values.
Bi values are the keys and Hi values are the priorities.

CSEN 1038 Treaps 4 / 91


Motivation
Structure
Operations
Implicit Treaps

Treaps

A combination of a Binary Search Tree and a Heap.


every node stores a pair (Bi , Hi ).
preserves the BST property on Bi values.
preserves the Heap property on Hi values.
Bi values are the keys and Hi values are the priorities.

CSEN 1038 Treaps 4 / 91


Motivation
Structure
Operations
Implicit Treaps

Treaps

A combination of a Binary Search Tree and a Heap.


every node stores a pair (Bi , Hi ).
preserves the BST property on Bi values.
preserves the Heap property on Hi values.
Bi values are the keys and Hi values are the priorities.

CSEN 1038 Treaps 4 / 91


Motivation
Structure
Operations
Implicit Treaps

Construction

CSEN 1038 Treaps 5 / 91


Motivation
Structure
Operations
Implicit Treaps

Construction

CSEN 1038 Treaps 6 / 91


Motivation
Structure
Operations
Implicit Treaps

Construction

CSEN 1038 Treaps 7 / 91


Motivation
Structure
Operations
Implicit Treaps

Construction

CSEN 1038 Treaps 8 / 91


Motivation
Structure
Operations
Implicit Treaps

Construction

CSEN 1038 Treaps 9 / 91


Motivation
Structure
Operations
Implicit Treaps

Construction

CSEN 1038 Treaps 10 / 91


Motivation
Structure
Operations
Implicit Treaps

Construction

CSEN 1038 Treaps 11 / 91


Motivation
Structure
Operations
Implicit Treaps

Construction

CSEN 1038 Treaps 12 / 91


Motivation
Structure
Operations
Implicit Treaps

Construction

CSEN 1038 Treaps 13 / 91


Motivation
Structure
Operations
Implicit Treaps

Construction

CSEN 1038 Treaps 14 / 91


Motivation
Structure
Operations
Implicit Treaps

Construction

CSEN 1038 Treaps 15 / 91


Motivation
Structure
Operations
Implicit Treaps

Construction

CSEN 1038 Treaps 16 / 91


Motivation
Structure
Operations
Implicit Treaps

Construction

CSEN 1038 Treaps 17 / 91


Motivation
Structure
Operations
Implicit Treaps

Treaps

If Hi values (i.e. the priorities) are unique, then there is a


unique structure for the treap.
If we assigned random priorities to the keys, the result treap
will non-degenerate with O(log n) height, approximately.
Randomized binary search tree!

CSEN 1038 Treaps 18 / 91


Motivation
Structure
Operations
Implicit Treaps

Treaps

If Hi values (i.e. the priorities) are unique, then there is a


unique structure for the treap.
If we assigned random priorities to the keys, the result treap
will non-degenerate with O(log n) height, approximately.
Randomized binary search tree!

CSEN 1038 Treaps 18 / 91


Motivation
Structure
Operations
Implicit Treaps

Treaps

If Hi values (i.e. the priorities) are unique, then there is a


unique structure for the treap.
If we assigned random priorities to the keys, the result treap
will non-degenerate with O(log n) height, approximately.
Randomized binary search tree!

CSEN 1038 Treaps 18 / 91


Motivation
Structure
Operations
Implicit Treaps

Auxiliary Operations

The main operations of the treap is based on two important


auxiliary operations:
split(T , x): split the subtree T into two subtrees Tl and Tr :
Tl contains all keys smaller than or equal to x.
Tr contains all keys greater than x.
merge(Tl , Tr ): merge the subtrees Tl and Tr into one tree.
All keys in Tl are less than all keys in Tr .

What is the complexity of these operations?

CSEN 1038 Treaps 19 / 91


Motivation
Structure
Operations
Implicit Treaps

Auxiliary Operations

The main operations of the treap is based on two important


auxiliary operations:
split(T , x): split the subtree T into two subtrees Tl and Tr :
Tl contains all keys smaller than or equal to x.
Tr contains all keys greater than x.
merge(Tl , Tr ): merge the subtrees Tl and Tr into one tree.
All keys in Tl are less than all keys in Tr .

What is the complexity of these operations?

CSEN 1038 Treaps 19 / 91


Motivation
Structure
Operations
Implicit Treaps

Auxiliary Operations

The main operations of the treap is based on two important


auxiliary operations:
split(T , x): split the subtree T into two subtrees Tl and Tr :
Tl contains all keys smaller than or equal to x.
Tr contains all keys greater than x.
merge(Tl , Tr ): merge the subtrees Tl and Tr into one tree.
All keys in Tl are less than all keys in Tr .

What is the complexity of these operations?

CSEN 1038 Treaps 19 / 91


Motivation
Structure
Operations
Implicit Treaps

Auxiliary Operations

The main operations of the treap is based on two important


auxiliary operations:
split(T , x): split the subtree T into two subtrees Tl and Tr :
Tl contains all keys smaller than or equal to x.
Tr contains all keys greater than x.
merge(Tl , Tr ): merge the subtrees Tl and Tr into one tree.
All keys in Tl are less than all keys in Tr .

What is the complexity of these operations?

CSEN 1038 Treaps 19 / 91


Motivation
Structure
Operations
Implicit Treaps

Split Operation
split(Treap, 6)

CSEN 1038 Treaps 20 / 91


Motivation
Structure
Operations
Implicit Treaps

Split Operation
split(Treap, 6)

CSEN 1038 Treaps 21 / 91


Motivation
Structure
Operations
Implicit Treaps

Split Operation
split(Treap, 6)

CSEN 1038 Treaps 22 / 91


Motivation
Structure
Operations
Implicit Treaps

Split Operation
split(Treap, 6)

CSEN 1038 Treaps 23 / 91


Motivation
Structure
Operations
Implicit Treaps

Split Operation
split(Treap, 6)

CSEN 1038 Treaps 24 / 91


Motivation
Structure
Operations
Implicit Treaps

Split Operation
split(Treap, 6)

CSEN 1038 Treaps 25 / 91


Motivation
Structure
Operations
Implicit Treaps

Split Operation
split(Treap, 6)

CSEN 1038 Treaps 26 / 91


Motivation
Structure
Operations
Implicit Treaps

Split Operation
split(Treap, 6)

CSEN 1038 Treaps 27 / 91


Motivation
Structure
Operations
Implicit Treaps

Split Operation
split(Treap, 6)

CSEN 1038 Treaps 28 / 91


Motivation
Structure
Operations
Implicit Treaps

Split Operation
split(Treap, 6)

CSEN 1038 Treaps 29 / 91


Motivation
Structure
Operations
Implicit Treaps

Split Operation
split(Treap, 6)

CSEN 1038 Treaps 30 / 91


Motivation
Structure
Operations
Implicit Treaps

Split Operation
split(Treap, 6)

CSEN 1038 Treaps 31 / 91


Motivation
Structure
Operations
Implicit Treaps

Split Operation
split(Treap, 6)

CSEN 1038 Treaps 32 / 91


Motivation
Structure
Operations
Implicit Treaps

Split Operation
split(Treap, 6)

CSEN 1038 Treaps 33 / 91


Motivation
Structure
Operations
Implicit Treaps

Split Operation
split(Treap, 6)

CSEN 1038 Treaps 34 / 91


Motivation
Structure
Operations
Implicit Treaps

Split Operation
split(Treap, 6)

CSEN 1038 Treaps 35 / 91


Motivation
Structure
Operations
Implicit Treaps

Split Operation
split(Treap, 6)

CSEN 1038 Treaps 36 / 91


Motivation
Structure
Operations
Implicit Treaps

Split Operation
split(Treap, 6)

CSEN 1038 Treaps 37 / 91


Motivation
Structure
Operations
Implicit Treaps

Merge Operation
merge(L, R)

CSEN 1038 Treaps 38 / 91


Motivation
Structure
Operations
Implicit Treaps

Merge Operation
merge(L, R)

CSEN 1038 Treaps 39 / 91


Motivation
Structure
Operations
Implicit Treaps

Merge Operation
merge(L, R)

CSEN 1038 Treaps 40 / 91


Motivation
Structure
Operations
Implicit Treaps

Merge Operation
merge(L, R)

CSEN 1038 Treaps 41 / 91


Motivation
Structure
Operations
Implicit Treaps

Merge Operation
merge(L, R)

CSEN 1038 Treaps 42 / 91


Motivation
Structure
Operations
Implicit Treaps

Merge Operation
merge(L, R)

CSEN 1038 Treaps 43 / 91


Motivation
Structure
Operations
Implicit Treaps

Merge Operation
merge(L, R)

CSEN 1038 Treaps 44 / 91


Motivation
Structure
Operations
Implicit Treaps

Merge Operation
merge(L, R)

CSEN 1038 Treaps 45 / 91


Motivation
Structure
Operations
Implicit Treaps

Merge Operation
merge(L, R)

CSEN 1038 Treaps 46 / 91


Motivation
Structure
Operations
Implicit Treaps

Merge Operation
merge(L, R)

CSEN 1038 Treaps 47 / 91


Motivation
Structure
Operations
Implicit Treaps

Merge Operation
merge(L, R)

CSEN 1038 Treaps 48 / 91


Motivation
Structure
Operations
Implicit Treaps

Merge Operation
merge(L, R)

CSEN 1038 Treaps 49 / 91


Motivation
Structure
Operations
Implicit Treaps

Merge Operation
merge(L, R)

CSEN 1038 Treaps 50 / 91


Motivation
Structure
Operations
Implicit Treaps

Merge Operation
merge(L, R)

CSEN 1038 Treaps 51 / 91


Motivation
Structure
Operations
Implicit Treaps

Merge Operation
merge(L, R)

CSEN 1038 Treaps 52 / 91


Motivation
Structure
Operations
Implicit Treaps

Merge Operation
merge(L, R)

CSEN 1038 Treaps 53 / 91


Motivation
Structure
Operations
Implicit Treaps

Merge Operation
merge(L, R)

CSEN 1038 Treaps 54 / 91


Motivation
Structure
Operations
Implicit Treaps

Merge Operation
merge(L, R)

CSEN 1038 Treaps 55 / 91


Motivation
Structure
Operations
Implicit Treaps

Merge Operation
merge(L, R)

CSEN 1038 Treaps 56 / 91


Motivation
Structure
Operations
Implicit Treaps

Main Operations

Basically, we want to support some common operations:


search, insertion, deletion of a key.
However, we can support more interesting operations:
the subtree size of a key.
the sum of values in the subtree a key.
k th smallest key in the tree.

How can we build a treap using these operations?


How can we build a treap in linear time?

CSEN 1038 Treaps 57 / 91


Motivation
Structure
Operations
Implicit Treaps

Main Operations

Basically, we want to support some common operations:


search, insertion, deletion of a key.
However, we can support more interesting operations:
the subtree size of a key.
the sum of values in the subtree a key.
k th smallest key in the tree.

How can we build a treap using these operations?


How can we build a treap in linear time?

CSEN 1038 Treaps 57 / 91


Motivation
Structure
Operations
Implicit Treaps

Main Operations

Basically, we want to support some common operations:


search, insertion, deletion of a key.
However, we can support more interesting operations:
the subtree size of a key.
the sum of values in the subtree a key.
k th smallest key in the tree.

How can we build a treap using these operations?


How can we build a treap in linear time?

CSEN 1038 Treaps 57 / 91


Motivation
Structure
Operations
Implicit Treaps

Main Operations

Basically, we want to support some common operations:


search, insertion, deletion of a key.
However, we can support more interesting operations:
the subtree size of a key.
the sum of values in the subtree a key.
k th smallest key in the tree.

How can we build a treap using these operations?


How can we build a treap in linear time?

CSEN 1038 Treaps 57 / 91


Motivation
Structure
Operations
Implicit Treaps

Main Operations

Basically, we want to support some common operations:


search, insertion, deletion of a key.
However, we can support more interesting operations:
the subtree size of a key.
the sum of values in the subtree a key.
k th smallest key in the tree.

How can we build a treap using these operations?


How can we build a treap in linear time?

CSEN 1038 Treaps 57 / 91


Motivation
Structure
Operations
Implicit Treaps

Main Operations

Basically, we want to support some common operations:


search, insertion, deletion of a key.
However, we can support more interesting operations:
the subtree size of a key.
the sum of values in the subtree a key.
k th smallest key in the tree.

How can we build a treap using these operations?


How can we build a treap in linear time?

CSEN 1038 Treaps 57 / 91


Motivation
Structure
Operations
Implicit Treaps

Main Operations

Basically, we want to support some common operations:


search, insertion, deletion of a key.
However, we can support more interesting operations:
the subtree size of a key.
the sum of values in the subtree a key.
k th smallest key in the tree.

How can we build a treap using these operations?


How can we build a treap in linear time?

CSEN 1038 Treaps 57 / 91


Motivation
Structure
Operations
Implicit Treaps

Main Operations

Basically, we want to support some common operations:


search, insertion, deletion of a key.
However, we can support more interesting operations:
the subtree size of a key.
the sum of values in the subtree a key.
k th smallest key in the tree.

How can we build a treap using these operations?


How can we build a treap in linear time?

CSEN 1038 Treaps 57 / 91


Motivation
Structure
Operations
Implicit Treaps

Key Insertion
insert(13, 4)

CSEN 1038 Treaps 58 / 91


Motivation
Structure
Operations
Implicit Treaps

Key Insertion
insert(13, 4)

CSEN 1038 Treaps 59 / 91


Motivation
Structure
Operations
Implicit Treaps

Key Insertion
insert(13, 4)

CSEN 1038 Treaps 60 / 91


Motivation
Structure
Operations
Implicit Treaps

Key Insertion
insert(13, 4)

CSEN 1038 Treaps 61 / 91


Motivation
Structure
Operations
Implicit Treaps

Key Insertion
insert(13, 4)

CSEN 1038 Treaps 62 / 91


Motivation
Structure
Operations
Implicit Treaps

Key Insertion
insert(13, 4)

CSEN 1038 Treaps 63 / 91


Motivation
Structure
Operations
Implicit Treaps

Key Insertion
insert(15, 18)

CSEN 1038 Treaps 64 / 91


Motivation
Structure
Operations
Implicit Treaps

Key Insertion
insert(15, 18)

CSEN 1038 Treaps 65 / 91


Motivation
Structure
Operations
Implicit Treaps

Key Insertion
insert(15, 18)

CSEN 1038 Treaps 66 / 91


Motivation
Structure
Operations
Implicit Treaps

Key Insertion
insert(15, 18)

CSEN 1038 Treaps 67 / 91


Motivation
Structure
Operations
Implicit Treaps

Key Insertion
insert(15, 18)

CSEN 1038 Treaps 68 / 91


Motivation
Structure
Operations
Implicit Treaps

Key Insertion
insert(15, 18)

CSEN 1038 Treaps 69 / 91


Motivation
Structure
Operations
Implicit Treaps

Key Insertion
insert(15, 18)

CSEN 1038 Treaps 70 / 91


Motivation
Structure
Operations
Implicit Treaps

Key Deletion
delete(13, 4)

CSEN 1038 Treaps 71 / 91


Motivation
Structure
Operations
Implicit Treaps

Key Deletion
delete(13, 4)

CSEN 1038 Treaps 72 / 91


Motivation
Structure
Operations
Implicit Treaps

Key Deletion
delete(13, 4)

CSEN 1038 Treaps 73 / 91


Motivation
Structure
Operations
Implicit Treaps

Key Deletion
delete(13, 4)

CSEN 1038 Treaps 74 / 91


Motivation
Structure
Operations
Implicit Treaps

Key Deletion
delete(13, 4)

CSEN 1038 Treaps 75 / 91


Motivation
Structure
Operations
Implicit Treaps

Key Deletion
delete(15, 18)

CSEN 1038 Treaps 76 / 91


Motivation
Structure
Operations
Implicit Treaps

Key Deletion
delete(15, 18)

CSEN 1038 Treaps 77 / 91


Motivation
Structure
Operations
Implicit Treaps

Key Deletion
delete(15, 18)

CSEN 1038 Treaps 78 / 91


Motivation
Structure
Operations
Implicit Treaps

Key Deletion
delete(15, 18)

CSEN 1038 Treaps 79 / 91


Motivation
Structure
Operations
Implicit Treaps

Key Deletion
delete(15, 18)

CSEN 1038 Treaps 80 / 91


Motivation
Structure
Operations
Implicit Treaps

Key Deletion
delete(15, 18)

CSEN 1038 Treaps 81 / 91


Motivation
Structure
Operations
Implicit Treaps

Treaps are more powerful than being ordinary binary search trees.
They can do things like:
inserting an element at any position in an array.
deleting an element from any position in an array.
range queries.
– max-key, min-key, sum, gcd, ...etc.
range updates.
– increment, set, reverse, rotate, ...etc.

Typically, we will build a treap on an array to support these


operations.

CSEN 1038 Treaps 82 / 91


Motivation
Structure
Operations
Implicit Treaps

Treaps are more powerful than being ordinary binary search trees.
They can do things like:
inserting an element at any position in an array.
deleting an element from any position in an array.
range queries.
– max-key, min-key, sum, gcd, ...etc.
range updates.
– increment, set, reverse, rotate, ...etc.

Typically, we will build a treap on an array to support these


operations.

CSEN 1038 Treaps 82 / 91


Motivation
Structure
Operations
Implicit Treaps

Treaps are more powerful than being ordinary binary search trees.
They can do things like:
inserting an element at any position in an array.
deleting an element from any position in an array.
range queries.
– max-key, min-key, sum, gcd, ...etc.
range updates.
– increment, set, reverse, rotate, ...etc.

Typically, we will build a treap on an array to support these


operations.

CSEN 1038 Treaps 82 / 91


Motivation
Structure
Operations
Implicit Treaps

Treaps are more powerful than being ordinary binary search trees.
They can do things like:
inserting an element at any position in an array.
deleting an element from any position in an array.
range queries.
– max-key, min-key, sum, gcd, ...etc.
range updates.
– increment, set, reverse, rotate, ...etc.

Typically, we will build a treap on an array to support these


operations.

CSEN 1038 Treaps 82 / 91


Motivation
Structure
Operations
Implicit Treaps

Treaps are more powerful than being ordinary binary search trees.
They can do things like:
inserting an element at any position in an array.
deleting an element from any position in an array.
range queries.
– max-key, min-key, sum, gcd, ...etc.
range updates.
– increment, set, reverse, rotate, ...etc.

Typically, we will build a treap on an array to support these


operations.

CSEN 1038 Treaps 82 / 91


Motivation
Structure
Operations
Implicit Treaps

Treaps are more powerful than being ordinary binary search trees.
They can do things like:
inserting an element at any position in an array.
deleting an element from any position in an array.
range queries.
– max-key, min-key, sum, gcd, ...etc.
range updates.
– increment, set, reverse, rotate, ...etc.

Typically, we will build a treap on an array to support these


operations.

CSEN 1038 Treaps 82 / 91


Motivation
Structure
Operations
Implicit Treaps

The key idea is that:

The array indices are the treap keys.


keys are not explicitly stored in the treap nodes,
but implicitly calculated on the fly.

CSEN 1038 Treaps 83 / 91


Motivation
Structure
Operations
Implicit Treaps

The key idea is that:

The array indices are the treap keys.


keys are not explicitly stored in the treap nodes,
but implicitly calculated on the fly.

CSEN 1038 Treaps 83 / 91


Motivation
Structure
Operations
Implicit Treaps

The key idea is that:

The array indices are the treap keys.


keys are not explicitly stored in the treap nodes,
but implicitly calculated on the fly.

CSEN 1038 Treaps 83 / 91


Motivation
Structure
Operations
Implicit Treaps

The key idea is that:

The array indices are the treap keys.


keys are not explicitly stored in the treap nodes,
but implicitly calculated on the fly.

CSEN 1038 Treaps 83 / 91


Motivation
Structure
Operations
Implicit Treaps

Implicit Key

CSEN 1038 Treaps 84 / 91


Motivation
Structure
Operations
Implicit Treaps

Implicit Key

CSEN 1038 Treaps 85 / 91


Motivation
Structure
Operations
Implicit Treaps

Implicit Key

CSEN 1038 Treaps 86 / 91


Motivation
Structure
Operations
Implicit Treaps

Implicit Key

CSEN 1038 Treaps 87 / 91


Motivation
Structure
Operations
Implicit Treaps

Implicit Key

CSEN 1038 Treaps 88 / 91


Motivation
Structure
Operations
Implicit Treaps

Implicit Key

CSEN 1038 Treaps 89 / 91


Motivation
Structure
Operations
Implicit Treaps

Implicit Key

CSEN 1038 Treaps 90 / 91


Motivation
Structure
Operations
Implicit Treaps

References

Threads@IIIT Hyderabad. Treaps : One Tree to Rule ’em all!.


Maximal article. Treaps.

*Hyperlinks
CSEN 1038 Treaps 91 / 91

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy