Randomized Algorithms: Data Structures

Slides:



Advertisements
Similar presentations
AVL Trees1 Part-F2 AVL Trees v z. AVL Trees2 AVL Tree Definition (§ 9.2) AVL trees are balanced. An AVL Tree is a binary search tree such that.
Advertisements

AVL Trees CS II – Fall /8/2010. Announcements HW#2 is posted – Uses AVL Trees, so you have to implement an AVL Tree class. Most of the code is provided.
Tirgul 5 AVL trees.
TCSS 342 AVL Trees v1.01 AVL Trees Motivation: we want to guarantee O(log n) running time on the find/insert/remove operations. Idea: keep the tree balanced.
CSE 326: Data Structures AVL Trees
Binary Search Trees1 ADT for Map: Map stores elements (entries) so that they can be located quickly using keys. Each element (entry) is a key-value pair.
Chapter 10 Search Structures Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures.
0 Course Outline n Introduction and Algorithm Analysis (Ch. 2) n Hash Tables: dictionary data structure (Ch. 5) n Heaps: priority queue data structures.
Randomized Algorithms - Treaps
AVL Trees Amanuel Lemma CS252 Algoithms Dec. 14, 2000.
Search Trees. Binary Search Tree (§10.1) A binary search tree is a binary tree storing keys (or key-element pairs) at its internal nodes and satisfying.
1 Trees 4: AVL Trees Section 4.4. Motivation When building a binary search tree, what type of trees would we like? Example: 3, 5, 8, 20, 18, 13, 22 2.
Balanced Search Trees Problem: Efficiency of BST is related to tree’s height.  search, insert and remove follow a path from root to desired location 
Outline Binary Trees Binary Search Tree Treaps. Binary Trees The empty set (null) is a binary tree A single node is a binary tree A node has a left child.
Lecture 11COMPSCI.220.FS.T Balancing an AVLTree Two mirror-symmetric pairs of cases to rebalance the tree if after the insertion of a new key to.
+ David Kauchak cs312 Review. + Midterm Will be posted online this afternoon You will have 2 hours to take it watch your time! if you get stuck on a problem,
D. ChristozovCOS 221 Intro to CS II AVL Trees 1 AVL Trees: Balanced BST Binary Search Trees Performance Height Balanced Trees Rotation AVL: insert, delete.
Priority Queues and Heaps. John Edgar  Define the ADT priority queue  Define the partially ordered property  Define a heap  Implement a heap using.
Theory of Computational Complexity Probability and Computing Chapter Hikaru Inada Iwama and Ito lab M1.
School of Computing Clemson University Fall, 2012
Part-D1 Binary Search Trees
Lecture 15 Nov 3, 2013 Height-balanced BST Recall:
Binary search trees Definition
Lec 13 Oct 17, 2011 AVL tree – height-balanced tree Other options:
COMP9024: Data Structures and Algorithms
BCA-II Data Structure Using C
Multiway Search Trees Data may not fit into main memory
Search Trees.
Binary Search Trees A binary search tree is a binary tree
AVL Trees 6/25/2018 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M.
Lecture 15 AVL Trees Slides modified from © 2010 Goodrich, Tamassia & by Prof. Naveen Garg’s Lectures.
Splay Trees Binary search trees.
Binary Search Tree (BST)
Splay Trees.
CSE373: Data Structures & Algorithms Lecture 7: AVL Trees
Red-Black Trees 9/12/ :44 AM AVL Trees v z AVL Trees.
Summary of General Binary search tree
Treaps.
COSC160: Data Structures Linked Lists
Heaps 9/13/2018 3:17 PM Heaps Heaps.
Splay Trees Binary search trees.
CSE373: Data Structures & Algorithms Lecture 7: AVL Trees
Binary Trees, Binary Search Trees
Chapter 22 : Binary Trees, AVL Trees, and Priority Queues
AVL Trees 4/29/15 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H.
Red-Black Trees 11/13/2018 2:07 AM AVL Trees v z AVL Trees.
Part-D1 Priority Queues
Multi-Way Search Trees
Red-Black Trees 11/26/2018 3:42 PM AVL Trees v z AVL Trees.
(2,4) Trees /26/2018 3:48 PM (2,4) Trees (2,4) Trees
A Kind of Binary Tree Usually Stored in an Array
Splay Trees In balanced tree schemes, explicit rules are followed to ensure balance. In splay trees, there are no such rules. Search, insert, and delete.
v z Chapter 10 AVL Trees Acknowledgement: These slides are adapted from slides provided with Data Structures and Algorithms in C++, Goodrich,
Divide-and-Conquer 7 2  9 4   2   4   7
CSE373: Data Structures & Algorithms Lecture 5: AVL Trees
Data Structures Sorting Haim Kaplan & Uri Zwick December 2014.
(2,4) Trees /24/2019 7:30 PM (2,4) Trees (2,4) Trees
Binary Trees, Binary Search Trees
Red-Black Trees 2/24/ :17 AM AVL Trees v z AVL Trees.
AVL-Trees (Part 1).
Binary SearchTrees [CLRS] – Chap 12.
(2,4) Trees /6/ :26 AM (2,4) Trees (2,4) Trees
Red-Black Trees 5/19/2019 6:39 AM AVL Trees v z AVL Trees.
1 Lecture 13 CS2013.
Chapter 12&13: Binary Search Trees (BSTs)
Binary Trees, Binary Search Trees
Splay Trees Binary search trees.
Dictionaries 二○一九年九月二十四日 ADT for Map:
Heaps 9/29/2019 5:43 PM Heaps Heaps.
CS210- Lecture 19 July 18, 2005 Agenda AVL trees Restructuring Trees
Presentation transcript:

Randomized Algorithms: Data Structures 11/15/2018 Randomized Algorithms - Treaps

Randomized Algorithms - Treaps Randomized Treaps Treap = TREe heAP Or, In Hebrew: ערמץ = ערמה עץ 11/15/2018 Randomized Algorithms - Treaps

Randomized Algorithms - Treaps Outline Definition of the Problem Deterministic Data Structures Introducing: Treaps Analyzing Performance Conclusion 11/15/2018 Randomized Algorithms - Treaps

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

Randomized Algorithms - Treaps MakeSet(S) Find(k, S) Insert(k, S) Join(S1, k, S2) 11/15/2018 Randomized Algorithms - Treaps

Randomized Algorithms - Treaps Delete(k, S) Paste(S1, S2) Split(k, S) 11/15/2018 Randomized Algorithms - Treaps

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

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

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

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

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

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

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

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

Randomized Algorithms - Treaps How a rotation is made b a a C b A B A B C 11/15/2018 Randomized Algorithms - Treaps

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

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

Randomized Algorithms - Treaps Proof: By induction: for n=0, n=1: the theorem holds. 11/15/2018 Randomized Algorithms - Treaps

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

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

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

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

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

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

Randomized Algorithms - Treaps Lemma: for all p > 0, Ap = Hp. 11/15/2018 Randomized Algorithms - Treaps

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

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

Randomized Algorithms - Treaps Lemma: 11/15/2018 Randomized Algorithms - Treaps

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

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

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

Randomized Algorithms - Treaps Proof of the lemma: let us define: 11/15/2018 Randomized Algorithms - Treaps

Randomized Algorithms - Treaps - Ancestors of x 11/15/2018 Randomized Algorithms - Treaps

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

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

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

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

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

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

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

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