Download presentation
Presentation is loading. Please wait.
1
Randomized Algorithms: Data Structures
11/15/2018 Randomized Algorithms - Treaps
2
Randomized Algorithms - Treaps
Randomized Treaps Treap = TREe heAP Or, In Hebrew: ערמץ = ערמה עץ 11/15/2018 Randomized Algorithms - Treaps
3
Randomized Algorithms - Treaps
Outline Definition of the Problem Deterministic Data Structures Introducing: Treaps Analyzing Performance Conclusion 11/15/2018 Randomized Algorithms - Treaps
4
Definition of the Problem
Maintain a collection of items. Each of which is given a unique key. Support a group of 7 operations and queries over these items: 11/15/2018 Randomized Algorithms - Treaps
5
Randomized Algorithms - Treaps
MakeSet(S) Find(k, S) Insert(k, S) Join(S1, k, S2) 11/15/2018 Randomized Algorithms - Treaps
6
Randomized Algorithms - Treaps
Delete(k, S) Paste(S1, S2) Split(k, S) 11/15/2018 Randomized Algorithms - Treaps
7
Deterministic Data Structures Binary Search Trees
A standard solution to the problem. For simplicity we will assume that the trees are endogenous, and thus, also full. 11/15/2018 Randomized Algorithms - Treaps
8
Binary Search Trees Performance Issues
Each of the 7 aforementioned operations could be implemented in o(H). Ideally Easy to devise an order of insertion in which 11/15/2018 Randomized Algorithms - Treaps
9
Binary Search Trees Possible Deterministic Improvements
Balancing the bst using rotations at each update operation. Drawback Could render significant overhead at each update operation. 11/15/2018 Randomized Algorithms - Treaps
10
Randomized Algorithms - Treaps
Splaying: Move to the root a node accessed by find. Analysis: Guarantees an amortized time bound of o(log n). 11/15/2018 Randomized Algorithms - Treaps
11
Randomized Algorithms - Treaps
Drawback: Restructuring of the tree at each find operation. No assurance that a specific action will take a certain amount of time. 11/15/2018 Randomized Algorithms - Treaps
12
Randomized Algorithms - Treaps
Introducing: Treaps Consider a binary tree where each node v contains a pair of values (both should be distinct from other nodes) : a key – should suffice the binary search condition. a priority – should suffice the heap condition. 11/15/2018 Randomized Algorithms - Treaps
13
Randomized Algorithms - Treaps
For Example: the set could be represented by the valid treap: 7,30 11,27 4,26 2,13 12,22 11/15/2018 Randomized Algorithms - Treaps
14
Treaps implementation (in brief)
All operations are implemented in a similar way to the BST solutions available. When an action violates heap condition, use rotations. 11/15/2018 Randomized Algorithms - Treaps
15
Randomized Algorithms - Treaps
How a rotation is made b a a C b A B A B C 11/15/2018 Randomized Algorithms - Treaps
16
Randomized Algorithms - Treaps
Note, for future analyzing purposes, that all operations could be based upon find, insert and delete operations. 11/15/2018 Randomized Algorithms - Treaps
17
On choosing priorities
Theorem: Let S= be any set of key-priority pairs such that the keys and the priorities are distinct. Then, there exist a unique treap T(S) for it. 11/15/2018 Randomized Algorithms - Treaps
18
Randomized Algorithms - Treaps
Proof: By induction: for n=0, n=1: the theorem holds. 11/15/2018 Randomized Algorithms - Treaps
19
Randomized Algorithms - Treaps
for n>1: without the loss of generality, assume that V = (k1,p1) is the node with the highest priority: Assign V to root. recursively apply on both sub trees emerging from splitting by p1. 11/15/2018 Randomized Algorithms - Treaps
20
Randomized Algorithms - Treaps
The theorem implies that we may choose any (distinct) priorities to our nodes, ensuring that are we are representing a valid treap. 11/15/2018 Randomized Algorithms - Treaps
21
Randomized Algorithms - Treaps
We will choose our priorities in the following manner: Upon insertion of a new key, a priority is randomly and uniformly chosen for it, in such a way that no previous node contains this priority. The priority for a specific element remains constant. The ordering of keys and values is completely uncorrelated. 11/15/2018 Randomized Algorithms - Treaps
22
Analyzing Performance Mulmuley Games
For the sake of time performance, we will present a set of games, called Mulmuley Games. 11/15/2018 Randomized Algorithms - Treaps
23
Randomized Algorithms - Treaps
Mulmuley Games Game A Participants: A set of players. Each assigned a distinct numerical key. A set of bystanders. Each assigned a distinct numerical key. 11/15/2018 Randomized Algorithms - Treaps
24
Randomized Algorithms - Treaps
The course of the game consists of repeatedly sampling from P union B. Without replacement, until the pool is empty. A random variable V is defined as the number of samples in which a player p is chosen such that p is the largest player chosen to this point. The value of the game Ap is E[V]. 11/15/2018 Randomized Algorithms - Treaps
25
Randomized Algorithms - Treaps
Lemma: for all p > 0, Ap = Hp. 11/15/2018 Randomized Algorithms - Treaps
26
Randomized Algorithms - Treaps
Mulmuley Games Game D Participants: A set of players. Each assigned a distinct numerical key. A set of bystanders. Each assigned a distinct numerical key. A set of triggers. Each assigned a distinct numerical key. 11/15/2018 Randomized Algorithms - Treaps
27
Randomized Algorithms - Treaps
The course of the game consists of repeatedly sampling from P union B union T. Without replacement, until the pool is empty. A random variable V is defined as the number of samples in which a player p is chosen such that p is the largest player chosen to this point. Only after a trigger was chosen. The value of the game is E[V]. 11/15/2018 Randomized Algorithms - Treaps
28
Randomized Algorithms - Treaps
Lemma: 11/15/2018 Randomized Algorithms - Treaps
29
Analyzing Performance
We will present and prove several theorems, regarding time bounds of operations on random treaps. For the following, assume that T is a random treap for a set S of size n. 11/15/2018 Randomized Algorithms - Treaps
30
Randomized Algorithms - Treaps
Theorem: The expected time for find, insert and delete operations on T is O(log n). 11/15/2018 Randomized Algorithms - Treaps
31
Randomized Algorithms - Treaps
Lemma: for an element of rank k (regarding its key), it holds that: The lemma implies that the depth of each element is o(log n) each of the operations ( find, insert and delete) are linear in reagards to the tree depth, it follows that they also are o(log n). 11/15/2018 Randomized Algorithms - Treaps
32
Randomized Algorithms - Treaps
Proof of the lemma: let us define: 11/15/2018 Randomized Algorithms - Treaps
33
Randomized Algorithms - Treaps
- Ancestors of x 11/15/2018 Randomized Algorithms - Treaps
34
Randomized Algorithms - Treaps
it is clear that : depth(x) = And thus E[depth(x) ] = Therfore, we will try and estimate and 11/15/2018 Randomized Algorithms - Treaps
35
Randomized Algorithms - Treaps
Let us write S= ordered by their priority. (hence p1 > p2 > … > pn) We will insert the elements into the tree by this order (notice that no rotations are needed) When will an element belong to S- ? 11/15/2018 Randomized Algorithms - Treaps
36
Randomized Algorithms - Treaps
In other words, we will be counting right-going arcs in the path between the root and x. Inserting elements larger than x, doesn’t affect the counting An element will belong to q- if it is the largest element of s- inserted yet. 7,30 4,26 11,27 2,23 5,20 12,22 11/15/2018 Randomized Algorithms - Treaps
37
Randomized Algorithms - Treaps
Notice that this resembles Game A with P = S- , B = S\S- and thus p = k, following that Similarly it can be shown that Therefore 11/15/2018 Randomized Algorithms - Treaps
38
Randomized Algorithms - Treaps
Theorem: The expected number of rotations required during an insert or delete operation is at most 2. We will prove that for each element x defined as before, it holds that the number of rotations is 2. 11/15/2018 Randomized Algorithms - Treaps
39
Randomized Algorithms - Treaps
Proof: Let us define: Rx – the right spine of the left subtree of X. Lx – the left spine of the right subtree of X. Observation 1: the number of rotations needed during these operations is |Rx| + |Lx| 11/15/2018 Randomized Algorithms - Treaps
40
Randomized Algorithms - Treaps
In a similar to the one taken in the previous theorem, we can show that E[|Rx|] is in fact similar to Game D with p = k-1 , t = 1 , b = n – k Which yeilds that E[|Rx|] = 1 – 1/k. It can also be shown, by the same method that E[|Lx|] = 1 – 1/(n-k+1). Therefore E[|Lx|] + E[|Rx|] <= 2 11/15/2018 Randomized Algorithms - Treaps
41
Randomized Algorithms - Treaps
Theorem: The expected time for join, paste and split involving sets S1 and S2 of sizes n and m respectively, is o(log n + log m). 11/15/2018 Randomized Algorithms - Treaps
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.