2/19/2016 3:18 PMSkip Lists1  S0S0 S1S1 S2S2 S3S3  103623 15   2315.

Slides:



Advertisements
Similar presentations
© 2004 Goodrich, Tamassia Skip Lists1 S0S0 S1S1 S2S2 S3S
Advertisements

Skip Lists. Outline and Reading What is a skip list (§9.4) – Operations (§9.4.1) – Search – Insertion – Deletion Implementation Analysis (§9.4.2) – Space.
The Dictionary ADT: Skip List Implementation
SKIP LISTS Amihood Amir Incorporationg the slides of Goodrich and Tamassia (2004)
Skip Lists Present By PAKDEE PATTANAJEDSADA SITTHICHOK SNANSIENG SIWAKORN THAMMAYTHA PATOMPOL TAESUJI
CSC 172 DATA STRUCTURES. SKIP LISTS Read Weiss
October 26, 2005Copyright © by Erik D. Demaine and Charles E. LeisersonL11.1 Introduction to Algorithms 6.046J/18.401J LECTURE12 Skip Lists Data.
Expected Running Times and Randomized Algorithms Instructor Neelima Gupta
© 2004 Goodrich, Tamassia Quick-Sort     29  9.
© 2004 Goodrich, Tamassia QuickSort1 Quick-Sort     29  9.
Quick-Sort     29  9.
© 2004 Goodrich, Tamassia Quick-Sort     29  9.
Data Structures Lecture 13 Fang Yu Department of Management Information Systems National Chengchi University Fall 2010.
© 2004 Goodrich, Tamassia Skip Lists1  S0S0 S1S1 S2S2 S3S3    2315.
CSC311: Data Structures 1 Chapter 9: Maps and Dictionaries Objectives: Map ADT Hash tables –Hash functions and hash code –Compression functions and collisions.
Dictionaries and Hash Tables1  
CSC401 – Analysis of Algorithms Lecture Notes 7 Multi-way Search Trees and Skip Lists Objectives: Introduce multi-way search trees especially (2,4) trees,
6/14/2015 6:48 AM(2,4) Trees /14/2015 6:48 AM(2,4) Trees2 Outline and Reading Multi-way search tree (§3.3.1) Definition Search (2,4)
Skip Lists Michael Oudshoorn. CS351 Software Engineering (AY05)2 Skip Lists Binary Search Trees: O(log n) –If, and only if, the tree is “balanced” Insertion.
© 2004 Goodrich, Tamassia Selection1. © 2004 Goodrich, Tamassia Selection2 The Selection Problem Given an integer k and n elements x 1, x 2, …, x n, taken.
Hash Tables1 Part E Hash Tables  
© 2004 Goodrich, Tamassia Merge Sort1 Quick-Sort     29  9.
© 2004 Goodrich, Tamassia (2,4) Trees
1 CSC401 – Analysis of Algorithms Lecture Notes 9 Radix Sort and Selection Objectives  Introduce no-comparison-based sorting algorithms: Bucket-sort and.
Selection1. 2 The Selection Problem Given an integer k and n elements x 1, x 2, …, x n, taken from a total order, find the k-th smallest element in this.
Skip Lists1 Skip Lists William Pugh: ” Skip Lists: A Probabilistic Alternative to Balanced Trees ”, 1990  S0S0 S1S1 S2S2 S3S3 
Introduction To Algorithms CS 445 Discussion Session 2 Instructor: Dr Alon Efrat TA : Pooja Vaswani 02/14/2005.
Skip Lists Mrutyunjay. Introduction ▪ Linked Lists Benefits & Drawbacks: – Benefits: – Easy Insert and Deletes, implementations. – Drawbacks: – Hard to.
CSC Analysis of Algorithms 3-1 CSC401 – Analysis of Algorithms Chapter 3 Search Trees and Skip Lists Objectives: Review binary search trees and present.
Sorting Fun1 Chapter 4: Sorting     29  9.
Maps, Hash Tables, Skip Lists, Sets last Update: Nov 4, 2014 EECS2011: Maps, Hash Tables, Skip Lists, Sets1.
Randomized Algorithms CSc 4520/6520 Design & Analysis of Algorithms Fall 2013 Slides adopted from Dmitri Kaznachey, George Mason University and Maciej.
Fall 2006 CSC311: Data Structures 1 Chapter 10: Search Trees Objectives: Binary Search Trees: Search, update, and implementation AVL Trees: Properties.
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.
Skip Lists 二○一七年四月二十五日
© 2004 Goodrich, Tamassia Trees
© 2004 Goodrich, Tamassia Quick-Sort     29  9.
CHAPTER 9 HASH TABLES, MAPS, AND SKIP LISTS ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++,
Instructor Neelima Gupta Expected Running Times and Randomized Algorithms Instructor Neelima Gupta
Lecture 9COMPSCI.220.FS.T Lower Bound for Sorting Complexity Each algorithm that sorts by comparing only pairs of elements must use at least 
CSCE 3110 Data Structures & Algorithm Analysis Rada Mihalcea Dictionaries. Reading Weiss Chap. 5, Sec
Towers of Hanoi Move n (4) disks from pole A to pole B such that a larger disk is never put on a smaller disk A BC ABC.
1 Binary Search Trees   . 2 Ordered Dictionaries Keys are assumed to come from a total order. New operations: closestKeyBefore(k) closestElemBefore(k)
QuickSort by Dr. Bun Yue Professor of Computer Science CSCI 3333 Data.
Skip Lists – Why? BSTs –Worse case insertion, search O(n) –Best case insertion, search O(log n) –Where your run fits in O(n) – O(log n) depends on the.
Maps 1/28/2018 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser,
Skip Lists S3   S2   S1   S0  
Sorted Maps © 2014 Goodrich, Tamassia, Goldwasser Skip Lists.
Skip Lists 5/10/2018 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M.
Searching an Array: Binary Search
Quick-Sort 9/12/2018 3:26 PM Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
Skip Lists S3 + - S2 + - S1 + - S0 + -
Selection Selection 1 Quick-Sort Quick-Sort 10/30/16 13:52
Objectives Introduce different known sorting algorithms
Skip Lists.
Skip Lists S3 + - S2 + - S1 + - S0 + -
(2,4) Trees /26/2018 3:48 PM (2,4) Trees (2,4) Trees
SKIP LIST & SKIP GRAPH James Aspnes Gauri Shah
Skip Lists S3 + - S2 + - S1 + - S0 + -
Sorted Maps © 2014 Goodrich, Tamassia, Goldwasser Skip Lists.
Dictionaries < > = /3/2018 8:58 AM Dictionaries
Parasol Lab, Dept. CSE, Texas A&M University
(2,4) Trees /24/2019 7:30 PM (2,4) Trees (2,4) Trees
Quick-Sort 2/25/2019 2:22 AM Quick-Sort     2
Copyright © Aiman Hanna All rights reserved
Quick-Sort 4/8/ :20 AM Quick-Sort     2 9  9
Skip List: formally A skip list for a set S of distinct (key, element) items is a series of lists S0, S1 , … , Sh such that Each list Si contains the special.
Quick-Sort 4/25/2019 8:10 AM Quick-Sort     2
CS210- Lecture 17 July 12, 2005 Agenda Collision Handling
CS210- Lecture 20 July 19, 2005 Agenda Multiway Search Trees 2-4 Trees
Presentation transcript:

2/19/2016 3:18 PMSkip Lists1  S0S0 S1S1 S2S2 S3S3    2315

2/19/2016 3:18 PMSkip Lists2 Outline and Reading What is a skip list (§8.4) Operations Search (§8.4.1) Insertion (§8.4.2) Deletion (§8.4.2) Implementation Analysis (§8.4.3) Space usage Search and update times

2/19/2016 3:18 PMSkip Lists3 What is a Skip List A skip list for a set S of distinct (key, element) items is a series of lists S 0, S 1, …, S h such that Each list S i contains the special keys  and  List S 0 contains the keys of S in nondecreasing order Each list is a subsequence of the previous one, i.e., S 0  S 1  …  S h List S h contains only the two special keys We show how to use a skip list to implement the dictionary ADT     31  64  3134  23 S0S0 S1S1 S2S2 S3S3

2/19/2016 3:18 PMSkip Lists4 Search We search for a key x in a a skip list as follows: We start at the first position of the top list At the current position p, we compare x with y  key(after(p)) x  y : we return element(after(p)) x  y : we “scan forward” x  y : we “drop down” If we try to drop down past the bottom list, we return NO_SUCH_KEY Example: search for 78  S0S0 S1S1 S2S2 S3S3  31  64  3134   

2/19/2016 3:18 PMSkip Lists5 Randomized Algorithms A randomized algorithm performs coin tosses (i.e., uses random bits) to control its execution It contains statements of the type b  random() if b  0 do A … else { b  1} do B … Its running time depends on the outcomes of the coin tosses We analyze the expected running time of a randomized algorithm under the following assumptions the coins are unbiased, and the coin tosses are independent The worst-case running time of a randomized algorithm is often large but has very low probability (e.g., it occurs when all the coin tosses give “heads”) We use a randomized algorithm to insert items into a skip list

2/19/2016 3:18 PMSkip Lists6 To insert an item (x, o) into a skip list, we use a randomized algorithm: We repeatedly toss a coin until we get tails, and we denote with i the number of times the coin came up heads If i  h, we add to the skip list new lists S h  1, …, S i  1, each containing only the two special keys We search for x in the skip list and find the positions p 0, p 1, …, p i of the items with largest key less than x in each list S 0, S 1, …, S i For j  0, …, i, we insert item (x, o) into list S j after position p j Example: insert key 15, with i  2 Insertion    23   S0S0 S1S1 S2S2  S0S0 S1S1 S2S2 S3S3    2315 p0p0 p1p1 p2p2

2/19/2016 3:18 PMSkip Lists7 Deletion To remove an item with key x from a skip list, we proceed as follows: We search for x in the skip list and find the positions p 0, p 1, …, p i of the items with key x, where position p j is in list S j We remove positions p 0, p 1, …, p i from the lists S 0, S 1, …, S i We remove all but one list containing only the two special keys Example: remove key 34  4512  23  S0S0 S1S1 S2S2  S0S0 S1S1 S2S2 S3S3     p0p0 p1p1 p2p2

Example 8.9 (page 395) 2/19/2016 3:18 PMSkip Lists8 S0S0  S1S1  S2S2  S3S3  S4S4  17 S5S5 

Search 2/19/2016 3:18 PMSkip Lists9 S0S0 S1S1 S2S2 S3S3 S4S4 S5S5      17  Search for key 50 O (log n)

insert 2/19/2016 3:18 PMSkip Lists10 S0S0  S1S1  S2S2  S3S3  S4S4  17 S5S5  42 Insert 42 O (log n)

Remove 2/19/2016 3:18 PMSkip Lists11 S0S0  S1S1  S2S2  S3S3  S4S4  17 S5S5  42 Remove 25 O (log n)

2/19/2016 3:18 PMSkip Lists12 Implementation We can implement a skip list with quad-nodes A quad-node stores: item link to the node before link to the node above link to the node below link to the node after Also, we define special keys PLUS_INF and MINUS_INF, and we modify the key comparator to handle them x quad-node

2/19/2016 3:18 PMSkip Lists13 Space Usage The space used by a skip list depends on the random bits used by each invocation of the insertion algorithm We use the following two basic probabilistic facts: Fact 1: The probability of getting i consecutive heads when flipping a coin is 1  2 i Fact 2: If each of n items is present in a set with probability p, the expected size of the set is np Consider a skip list with n items By Fact 1, we insert an item in list S i with probability 1  2 i By Fact 2, the expected size of list S i is n  2 i The expected number of nodes used by the skip list is Thus, the expected space usage of a skip list with n items is O(n)

2/19/2016 3:18 PMSkip Lists14 Height The running time of the search an insertion algorithms is affected by the height h of the skip list We show that with high probability, a skip list with n items has height O(log n) We use the following additional probabilistic fact: Fact 3: If each of n events has probability p, the probability that at least one event occurs is at most np Consider a skip list with n items By Fact 1, we insert an item in list S i with probability 1  2 i By Fact 3, the probability that list S i has at least one item is at most n  2 i By picking i  3log n, we have that the probability that S 3log n has at least one item is at most n  2 3log n  n  n 3  1  n 2 Thus a skip list with n items has height at most 3log n with probability at least 1  1  n 2

2/19/2016 3:18 PMSkip Lists15 Search and Update Times The search time in a skip list is proportional to the number of drop-down steps, plus the number of scan-forward steps The drop-down steps are bounded by the height of the skip list and thus are O(log n) with high probability To analyze the scan-forward steps, we use yet another probabilistic fact: Fact 4: The expected number of coin tosses required in order to get tails is 2 When we scan forward in a list, the destination key does not belong to a higher list A scan-forward step is associated with a former coin toss that gave tails By Fact 4, in each list the expected number of scan- forward steps is 2 Thus, the expected number of scan-forward steps is O(log n) We conclude that a search in a skip list takes O(log n) expected time The analysis of insertion and deletion gives similar results

2/19/2016 3:18 PMSkip Lists16 Summary A skip list is a data structure for dictionaries that uses a randomized insertion algorithm In a skip list with n items The expected space used is O(n) The expected search, insertion and deletion time is O(log n) Using a more complex probabilistic analysis, one can show that these performance bounds also hold with high probability Skip lists are fast and simple to implement in practice