1 / 41

Randomized Algorithms: Data Structures

Randomized Algorithms: Data Structures. Randomized Treaps. Treap = TREe heAP Or, In Hebrew: ערמץ = ערמה עץ. Outline. Definition of the Problem Deterministic Data Structures Introducing: Treaps Analyzing Performance Conclusion. Definition of the Problem.

irish
Download Presentation

Randomized Algorithms: Data Structures

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Randomized Algorithms: Data Structures Randomized Algorithms - Treaps

  2. Randomized Treaps • Treap = TREe heAP • Or, In Hebrew: ערמץ = ערמה עץ Randomized Algorithms - Treaps

  3. Outline • Definition of the Problem • Deterministic Data Structures • Introducing: Treaps • Analyzing Performance • Conclusion 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: Randomized Algorithms - Treaps

  5. MakeSet(S) • Find(k, S) • Insert(k, S) • Join(S1, k, S2) Randomized Algorithms - Treaps

  6. Delete(k, S) • Paste(S1, S2) • Split(k, S) Randomized Algorithms - Treaps

  7. Deterministic Data StructuresBinary Search Trees • A standard solution to the problem. • For simplicity we will assume that the trees are endogenous, and thus, also full. Randomized Algorithms - Treaps

  8. Binary Search TreesPerformance Issues • Each of the 7 aforementioned operations could be implemented in o(H). • Ideally . • Easy to devise an order of insertion in which . Randomized Algorithms - Treaps

  9. Binary Search TreesPossible Deterministic Improvements • Balancing the bst • using rotations at each update operation. • Drawback • Could render significant overhead at each update operation. Randomized Algorithms - Treaps

  10. Splaying: • Move to the root a node accessed by find. • Analysis: • Guarantees an amortized time bound of o(log n). Randomized Algorithms - Treaps

  11. Drawback: • Restructuring of the tree at each find operation. • No assurance that a specific action will take a certain amount of time. Randomized Algorithms - Treaps

  12. 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. Randomized Algorithms - Treaps

  13. 7,30 4,26 11,27 2,13 12,22 • For Example:the set could be represented by the valid treap: Randomized Algorithms - Treaps

  14. Treapsimplementation (in brief) • All operations are implemented in a similar way to the BST solutions available. • When an action violates heap condition, use rotations. Randomized Algorithms - Treaps

  15. How a rotation is made b a C a b A B A B C Randomized Algorithms - Treaps

  16. Note, for future analyzing purposes, that all operations could be based upon find, insert and delete operations. 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. Randomized Algorithms - Treaps

  18. Proof:By induction: • for n=0, n=1: the theorem holds. Randomized Algorithms - Treaps

  19. 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. Randomized Algorithms - Treaps

  20. The theorem implies that we may choose any (distinct) priorities to our nodes, ensuring that are we are representing a valid treap. Randomized Algorithms - Treaps

  21. 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. Randomized Algorithms - Treaps

  22. Analyzing PerformanceMulmuley Games • For the sake of time performance, we will present a set of games, called Mulmuley Games. Randomized Algorithms - Treaps

  23. Mulmuley GamesGame A • Participants: • A set of players. Each assigned a distinct numerical key. • A set of bystanders. Each assigned a distinct numerical key. Randomized Algorithms - Treaps

  24. 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]. Randomized Algorithms - Treaps

  25. Lemma: for all p > 0, Ap = Hp. Randomized Algorithms - Treaps

  26. Mulmuley GamesGame 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. Randomized Algorithms - Treaps

  27. 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]. Randomized Algorithms - Treaps

  28. Lemma: 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. Randomized Algorithms - Treaps

  30. Theorem: The expected time for find, insert and delete operations on T is O(log n). Randomized Algorithms - Treaps

  31. 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 reagardsto the tree depth, it follows that they also are o(log n). Randomized Algorithms - Treaps

  32. Proof of the lemma: let us define: Randomized Algorithms - Treaps

  33. - Ancestors of x Randomized Algorithms - Treaps

  34. it is clear that : depth(x) = • And thus E[depth(x) ] = • Therfore, we will try and estimate and Randomized Algorithms - Treaps

  35. 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- ? Randomized Algorithms - Treaps

  36. 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 itis the largest element of s- inserted yet. 7,30 4,26 11,27 2,23 5,20 12,22 Randomized Algorithms - Treaps

  37. 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 Randomized Algorithms - Treaps

  38. 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. Randomized Algorithms - Treaps

  39. 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| Randomized Algorithms - Treaps

  40. 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 Randomized Algorithms - Treaps

  41. Theorem: The expected time for join, pasteand split involving sets S1 and S2 of sizes n and m respectively, is o(log n + log m). Randomized Algorithms - Treaps

More Related