Randomized Algorithms - Treaps

Slides:



Advertisements
Similar presentations
Chapter 5: Tree Constructions
Advertisements

CS 225 Lab #11 – Skip Lists.
Polygon Triangulation
CSC 172 DATA STRUCTURES. SKIP LISTS Read Weiss
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.
2/14/13CMPS 3120 Computational Geometry1 CMPS 3120: Computational Geometry Spring 2013 Planar Subdivisions and Point Location Carola Wenk Based on: Computational.
1 Disjoint Sets Set = a collection of (distinguishable) elements Two sets are disjoint if they have no common elements Disjoint-set data structure: –maintains.
Bounds on Code Length Theorem: Let l ∗ 1, l ∗ 2,..., l ∗ m be optimal codeword lengths for a source distribution p and a D-ary alphabet, and let L ∗ be.
Introduction to Trees. Tree example Consider this program structure diagram as itself a data structure. main readinprintprocess sortlookup.
Rajat K. Pal. Chapter 3 Emran Chowdhury # P Presented by.
1 Huffman Codes. 2 Introduction Huffman codes are a very effective technique for compressing data; savings of 20% to 90% are typical, depending on the.
Tirgul 10 Rehearsal about Universal Hashing Solving two problems from theoretical exercises: –T2 q. 1 –T3 q. 2.
1 Trees. 2 Outline –Tree Structures –Tree Node Level and Path Length –Binary Tree Definition –Binary Tree Nodes –Binary Search Trees.
I/O-Algorithms Lars Arge Spring 2009 March 3, 2009.
Greedy Algorithms Reading Material: Chapter 8 (Except Section 8.5)
Trees and Red-Black Trees Gordon College Prof. Brinton.
Chapter 12 Trees. Copyright © 2005 Pearson Addison-Wesley. All rights reserved Chapter Objectives Define trees as data structures Define the terms.
Greedy Algorithms Like dynamic programming algorithms, greedy algorithms are usually designed to solve optimization problems Unlike dynamic programming.
Randomized Algorithms. Introduction Algorithm uses a random number to make at least one decision Running time depends on input and random numbers generated.
David Luebke 1 7/2/2015 Medians and Order Statistics Structures for Dynamic Sets.
Skip Lists1 Skip Lists William Pugh: ” Skip Lists: A Probabilistic Alternative to Balanced Trees ”, 1990  S0S0 S1S1 S2S2 S3S3 
Chapter 3: Arrays, Linked Lists, and Recursion
Princeton University COS 423 Theory of Algorithms Spring 2002 Kevin Wayne Fibonacci Heaps These lecture slides are adapted from CLRS, Chapter 20.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 20: Binary Trees.
C o n f i d e n t i a l HOME NEXT Subject Name: Data Structure Using C Unit Title: Trees.
Binary Trees Chapter 6.
Ch. 8 & 9 – Linear Sorting and Order Statistics What do you trade for speed?
Minimal Spanning Trees What is a minimal spanning tree (MST) and how to find one.
CHAPTER 71 TREE. Binary Tree A binary tree T is a finite set of one or more nodes such that: (a) T is empty or (b) There is a specially designated node.
Review Binary Tree Binary Tree Representation Array Representation Link List Representation Operations on Binary Trees Traversing Binary Trees Pre-Order.
Chapter 19: Binary Trees. Objectives In this chapter, you will: – Learn about binary trees – Explore various binary tree traversal algorithms – Organize.
Brought to you by Max (ICQ: TEL: ) February 5, 2005 Advanced Data Structures Introduction.
Chapter 12. Binary Search Trees. Search Trees Data structures that support many dynamic-set operations. Can be used both as a dictionary and as a priority.
Skip Lists Mrutyunjay. Introduction ▪ Linked Lists Benefits & Drawbacks: – Benefits: – Easy Insert and Deletes, implementations. – Drawbacks: – Hard to.
The Binary Heap. Binary Heap Looks similar to a binary search tree BUT all the values stored in the subtree rooted at a node are greater than or equal.
Chapter 6 Binary Trees. 6.1 Trees, Binary Trees, and Binary Search Trees Linked lists usually are more flexible than arrays, but it is difficult to use.
Binary Trees, Binary Search Trees RIZWAN REHMAN CENTRE FOR COMPUTER STUDIES DIBRUGARH UNIVERSITY.
David Luebke 1 10/25/2015 CS 332: Algorithms Skip Lists Hash Tables.
1 Heaps and Priority Queues Starring: Min Heap Co-Starring: Max Heap.
Chapter 9 Binary Tree and General Tree. Overview ● Two-way decision making is one of the fundamental concepts in computing.  A binary tree models two-way.
1 Searching Searching in a sorted linked list takes linear time in the worst and average case. Searching in a sorted array takes logarithmic time in the.
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.
Ihab Mohammed and Safaa Alwajidi. Introduction Hash tables are dictionary structure that store objects with keys and provide very fast access. Hash table.
Skip Lists 二○一七年四月二十五日
+ 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,
Tree Traversals, TreeSort 20 February Expression Tree Leaves are operands Interior nodes are operators A binary tree to represent (A - B) + C.
Rooted Tree a b d ef i j g h c k root parent node (self) child descendent leaf (no children) e, i, k, g, h are leaves internal node (not a leaf) sibling.
AVL trees1 AVL Trees Height of a node : The height of a leaf is 1. The height of a null pointer is zero. The height of an internal node is the maximum.
Advanced Data Structure By Kayman 21 Jan Outline Review of some data structures Array Linked List Sorted Array New stuff 3 of the most important.
AVL Trees and Heaps. AVL Trees So far balancing the tree was done globally Basically every node was involved in the balance operation Tree balancing can.
1 Trees 2 Binary trees Section Binary Trees Definition: A binary tree is a rooted tree in which no vertex has more than two children –Left and.
1 Chapter 6 Heapsort. 2 About this lecture Introduce Heap – Shape Property and Heap Property – Heap Operations Heapsort: Use Heap to Sort Fixing heap.
BINARY TREES Objectives Define trees as data structures Define the terms associated with trees Discuss tree traversal algorithms Discuss a binary.
Proof of correctness of Dijkstra’s algorithm: Basically, we need to prove two claims. (1)Let S be the set of vertices for which the shortest path from.
UNC Chapel Hill M. C. Lin Geometric Data Structures Reading: Chapter 10 of the Textbook Driving Applications –Windowing Queries Related Application –Query.
Priority Queues and Heaps Tom Przybylinski. Maps ● We have (key,value) pairs, called entries ● We want to store and find/remove arbitrary entries (random.
Trees Chapter 15.
Multiway Search Trees Data may not fit into main memory
MCS680: Foundations Of Computer Science
Lecture 7 Algorithm Analysis
Binary Tree and General Tree
(edited by Nadia Al-Ghreimil)
Chapter 5. Optimal Matchings
Randomized Algorithms: Data Structures
Enumerating Distances Using Spanners of Bounded Degree
Lecture 7 Algorithm Analysis
Lecture 7 Algorithm Analysis
(edited by Nadia Al-Ghreimil)
Compact routing schemes with improved stretch
CSCI 104 Skip Lists Mark Redekopp.
Presentation transcript:

Randomized Algorithms - Treaps Randomized Skip List Skip List Or, In Hebrew: רשימות דילוג 4/20/2017 Randomized Algorithms - Treaps

Randomized Algorithms - Treaps Outline Motivation for the skipping Skip List definitions and description Analyzing performance The role of randomness 4/20/2017 Randomized Algorithms - Treaps

Randomized Algorithms - Treaps Outline Motivation for the skipping Skip List definitions and description Analyzing performance The role of randomness 4/20/2017 Randomized Algorithms - Treaps

Randomized Algorithms – Skip List Starting from scratch Initial goal just search, no updates (insert, delete). Simplest Data Structure? linked list! Search? O(n)! Can we do it faster? yes we can! 4/20/2017 Randomized Algorithms – Skip List

Developing the skip list Let’s add an express lane. Can quickly jump from express stop to next express stop, or from any stop to next normal stop. To search, first search in the express layer until about to go to far, then go down and search in the local layer. 4/20/2017 Randomized Algorithms – Skip List

Randomized Algorithms – Skip List Search cost What is the search cost? 4/20/2017 Randomized Algorithms – Skip List

Randomized Algorithms – Skip List Search cost – Cont. This is minimized when: 4/20/2017 Randomized Algorithms – Skip List

Discovering skip lists If we keep adding linked list layers we get: 4/20/2017 Randomized Algorithms – Skip List

Randomized Algorithms - Treaps Outline Motivation for the skipping Skip List definitions and description Analyzing performance The role of randomness 4/20/2017 Randomized Algorithms - Treaps

Randomized Algorithms - Treaps Initial definitions Let S be a totally ordered set of n elements. A leveling with r levels of S, is a sequence of nested subsets (called levels) : where and Given a leveling for S, the level of any element x in s is defined as: 4/20/2017 Randomized Algorithms - Treaps

Randomized Algorithms - Treaps Skip List Description Given any leveling of the set S, we define the skip list corresponding to this structure like this: The level is stored in a sorted link list. Each node x in this linked list has a pile of nodes above it. There are horizontal and vertical pointers between nodes. For convenience, we assume that two special elements and belong to each of the levels. 4/20/2017 Randomized Algorithms - Treaps

Randomized Algorithms - Treaps Skip List Example For example, for this leveling: This is the skip list corresponding to it: 4/20/2017 Randomized Algorithms - Treaps

Skip list as binary tree An interval level I, is the set of elements of S, spanned by a specific horizontal pointer at level i. For example, for the previous skip list, this is the interval at level 2: 4/20/2017 Randomized Algorithms - Treaps

Skip list as binary tree The interval partition structure is more conveniently viewed as a tree, where each node corresponds to an interval. If an interval J at level i+1 contains as a subsets an interval I at level i, then node J is the parent of node I in the tree. For interval I at level i+1, C(I) denotes the number of children of Interval I at level i. 4/20/2017 Randomized Algorithms - Treaps

Randomized Algorithms - Treaps Searching skip lists Consider an element y, that is not necessarily an member of S, and assume we want to search for it in skip list s. Let be the interval at level j that contains y. 4/20/2017 Randomized Algorithms - Treaps

Searching skip lists – Cont. We can now view the nested sequence of intervals as a root-leaf path in the tree representation of the skip list. 4/20/2017 Randomized Algorithms - Treaps

Randomized Algorithms - Treaps Random skip list To complete the description of the skip list, we have to specify the choice of the leveling that underlies it. The basic idea is to chose a random leveling, thereby defining a random skip list. A random leveling is defined as follows: given the choice of level the level is defined by independently choosing to retain each element with probability ½. 4/20/2017 Randomized Algorithms - Treaps

Randomized Algorithms - Treaps Outline Motivation for the skipping Skip List definitions and description Analyzing performance The role of randomness 4/20/2017 Randomized Algorithms - Treaps

Randomized Algorithms - Treaps Search cost What is the expected time to find an element in a random skip list? We will show it is O(logn) with high probability. What is the expected space of a random skip list? O(n). Why? 4/20/2017 Randomized Algorithms - Treaps

Randomized Algorithms - Treaps Random procedure An alternative view of the random construction is as follows: Let l(x) for every be independent random variable, with geometric distribution. Let r be one more than the maximum of these random variables. Place x in each of the levels, .….. . As with random priorities in treaps, a random level is chosen once for every element in it’s insertion. 4/20/2017 Randomized Algorithms - Treaps

The expected number of levels Lemma: the number of levels r in a random leveling of a set S of size n is O(logn) with high probability. Proof: look at the board! Does it mean that the E[r]=O(logn)? Why? Is it enough? No! 4/20/2017 Randomized Algorithms - Treaps

Randomized Algorithms - Treaps The search path length The last result implies that the tree representing the skip list has height o(logn) with high probability. Unfortunately, since the tree need not be binary, it does not immediately follows that the search time is similarly bounded. The implementation of Find(x,s) corresponds to walking down the path 4/20/2017 Randomized Algorithms - Treaps

The search path length – Cont. Walking down the path is as follows: At level j, starting at the node , use a vertical pointer to descend to the leftmost child of the current interval; then using the horizontal pointers, move rightward till the node The cost of FIND(x,s) proportional to the number of levels as well as the number of intervals visited at each level. 4/20/2017 Randomized Algorithms - Treaps

The search path length is O(logn) Lemma 2: Let y be any element and consider the search path followed by FIND(y, S) in a random skip list for the set S of size n, then: A. is the length of the search path. B. 4/20/2017 Randomized Algorithms - Treaps

Randomized Algorithms - Treaps Proof of Lemma 2 Proof of A: the number of nodes visited at level j does not exceed the number of children of the interval therefore in each level, you walk through elements and in total . Proof of B: look at the board! This result shows that the expected time of search is o(logn). 4/20/2017 Randomized Algorithms - Treaps

Insert and delete in skip list Insert and delete operation can be done both in o(logn) expected time also. To insert an element y: a random level l(y) (may exceed r) should be chosen for y as described earlier. Then a search operation should find the search path of y Then update the correct intervals, and add pointers. Delete operation is just the converse of insert. 4/20/2017 Randomized Algorithms - Treaps

Randomized Algorithms - Treaps Outline Motivation for the skipping Skip List definitions and description Analyzing performance The role of randomness 4/20/2017 Randomized Algorithms - Treaps

Randomized Algorithms - Treaps The role of randomness What is the role of the randomness in skip lists? The random leveling of S enables us to avoid complicated “balancing” operations. This simplifies our algorithm and decreases the overhead. 4/20/2017 Randomized Algorithms - Treaps

.- cont The role of randomness It also saves us the need to “remember” the state of the node or the system. Unlike binary search trees, skip lists behavior is indifferent to the input distribution. 4/20/2017 Randomized Algorithms - Treaps