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.

Slides:



Advertisements
Similar presentations
David Luebke 1 6/7/2014 CS 332: Algorithms Skip Lists Introduction to Hashing.
Advertisements

© 2004 Goodrich, Tamassia Skip Lists1 S0S0 S1S1 S2S2 S3S
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.
CS 225 Lab #11 – Skip Lists.
The Dictionary ADT: Skip List Implementation
SKIP LISTS Amihood Amir Incorporationg the slides of Goodrich and Tamassia (2004)
Alon Efrat Computer Science Department University of Arizona SkipList.
COP 3502: Computer Science I (Note Set #21) Page 1 © Mark Llewellyn COP 3502: Computer Science I Spring 2004 – Note Set 21 – Balancing Binary Trees School.
© 2004 Goodrich, Tamassia Hash Tables1  
B+-Trees (PART 1) What is a B+ tree? Why B+ trees? Searching a B+ tree
Quick Sort, Shell Sort, Counting Sort, Radix Sort AND Bucket Sort
Binary Trees, Binary Search Trees CMPS 2133 Spring 2008.
More on Randomized Data Structures. Motivation for Randomized Data Structures We’ve seen many data structures with good average case performance on random.
CS 206 Introduction to Computer Science II 04 / 27 / 2009 Instructor: Michael Eckmann.
Data Structures Lecture 13 Fang Yu Department of Management Information Systems National Chengchi University Fall 2010.
Binary Search Trees Briana B. Morrison Adapted from Alan Eugenio.
© 2004 Goodrich, Tamassia Skip Lists1  S0S0 S1S1 S2S2 S3S3    2315.
BST Data Structure A BST node contains: A BST contains
Tirgul 8 Universal Hashing Remarks on Programming Exercise 1 Solution to question 2 in theoretical homework 2.
CS 206 Introduction to Computer Science II 12 / 03 / 2008 Instructor: Michael Eckmann.
CSE 326 Randomized Data Structures David Kaplan Dept of Computer Science & Engineering Autumn 2001.
Unit 11a 1 Unit 11: Data Structures & Complexity H We discuss in this unit Graphs and trees Binary search trees Hashing functions Recursive sorting: quicksort,
Hash Tables1 Part E Hash Tables  
Randomized Algorithms. Introduction Algorithm uses a random number to make at least one decision Running time depends on input and random numbers generated.
Week 10: Heap and Priority queue. Any feature here?
Skip Lists1 Skip Lists William Pugh: ” Skip Lists: A Probabilistic Alternative to Balanced Trees ”, 1990  S0S0 S1S1 S2S2 S3S3 
Marc Smith and Jim Ten Eyck
CPSC 335 BTrees Dr. Marina Gavrilova Computer Science University of Calgary Canada.
Introduction To Algorithms CS 445 Discussion Session 2 Instructor: Dr Alon Efrat TA : Pooja Vaswani 02/14/2005.
CSCE 3110 Data Structures & Algorithm Analysis Binary Search Trees Reading: Chap. 4 (4.3) Weiss.
Chapter Tow Search Trees BY HUSSEIN SALIM QASIM WESAM HRBI FADHEEL CS 6310 ADVANCE DATA STRUCTURE AND ALGORITHM DR. ELISE DE DONCKER 1.
Chapter 19 - basic definitions - order statistics ( findkth( ) ) - balanced binary search trees - Java implementations Binary Search Trees 1CSCI 3333 Data.
1 Hash Tables  a hash table is an array of size Tsize  has index positions 0.. Tsize-1  two types of hash tables  open hash table  array element type.
Skip Lists Mrutyunjay. Introduction ▪ Linked Lists Benefits & Drawbacks: – Benefits: – Easy Insert and Deletes, implementations. – Drawbacks: – Hard to.
AVL Trees Amanuel Lemma CS252 Algoithms Dec. 14, 2000.
Algorithm Evaluation. What’s an algorithm? a clearly specified set of simple instructions to be followed to solve a problem a way of doing something What.
DATA STRUCTURE & ALGORITHMS (BCS 1223) CHAPTER 8 : SEARCHING.
CS 162 Intro to Programming II Searching 1. Data is stored in various structures – Typically it is organized on the type of data – Optimized for retrieval.
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.
Binary Trees, Binary Search Trees RIZWAN REHMAN CENTRE FOR COMPUTER STUDIES DIBRUGARH UNIVERSITY.
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.
1 Joe Meehean.  We wanted a data structure that gave us... the smallest item then the next smallest then the next and so on…  This ADT is called a priority.
CS 206 Introduction to Computer Science II 04 / 22 / 2009 Instructor: Michael Eckmann.
Skip Lists 二○一七年四月二十五日
Sorting: Implementation Fundamental Data Structures and Algorithms Klaus Sutner February 24, 2004.
Hashtables. An Abstract data type that supports the following operations: –Insert –Find –Remove Search trees can be used for the same operations but require.
Binary Search Trees (BSTs) 18 February Binary Search Tree (BST) An important special kind of binary tree is the BST Each node stores some information.
Week 15 – Wednesday.  What did we talk about last time?  Review up to Exam 1.
CSCE 3110 Data Structures & Algorithm Analysis Rada Mihalcea Dictionaries. Reading Weiss Chap. 5, Sec
2/19/2016 3:18 PMSkip Lists1  S0S0 S1S1 S2S2 S3S3    2315.
Chapter 9 Recursion © 2006 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
Copyright © 2009 Curt Hill Look Ups A Recurring Theme.
329 3/30/98 CSE 143 Searching and Sorting [Sections 12.4, ]
Chapter 16: Searching, Sorting, and the vector Type.
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.
Hashing Exercises.
Quick-Sort To understand quick-sort, let’s look at a high-level description of the algorithm 1) Divide : If the sequence S has 2 or more elements, select.
Skip Lists S3 + - S2 + - S1 + - S0 + -
Skip Lists.
Skip Lists S3 + - S2 + - S1 + - S0 + -
Skip Lists S3 + - S2 + - S1 + - S0 + -
Sorted Maps © 2014 Goodrich, Tamassia, Goldwasser Skip Lists.
Dictionaries < > = /3/2018 8:58 AM Dictionaries
Searching CLRS, Sections 9.1 – 9.3.
Parasol Lab, Dept. CSE, Texas A&M University
Quick-Sort 4/25/2019 8:10 AM Quick-Sort     2
CS210- Lecture 17 July 12, 2005 Agenda Collision Handling
1 Lecture 13 CS2013.
Presentation transcript:

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 of partially sorted data is optimally bad for binary search trees. Skip Lists make use of some randomization to maintain O(log n) search and update times –These are on average figures Analysis of skip lists is interesting –Worst case is potentially very bad –We will not cover the analysis here.

CS351 Software Engineering (AY05)3 Randomness Skip lists need random numbers Systems provide pseudo-random number generators Usually a linear congruential feedback algorithm: –X i = ( A x X i-1 + B) mod C –X 0 is called the “seed” value Yields numbers in the range [0,1] Note: NOT REALLY RANDOM! Computers DO NOT produce random numbers – these are deterministic –Some applications need truly random numbers – this is hard!

CS351 Software Engineering (AY05)4 Skip Lists A Skip List for a Dictionary D is a series of lists: {S 0, S 1, …, S h } –S 0 contains all the elements in D –S i contains a randomly chosen subset of elements from S i-1 –Each list S i is sorted We introduce two special elements: -  & +  which have their obvious meaning. –Each list S i contains these, S h contains only these.

CS351 Software Engineering (AY05)5 -- -- -- -- -- + ++ ++ ++ ++ S0S0 S1S1 S2S2 S3S3 S4S4 A Tower Levels H = height of a skip list

CS351 Software Engineering (AY05)6 Skip List - Informal We set the lists up so that: –An item that is in S i is in S i+1 with probability ½ So S 1 has about n/2 items in it –S 2 has about n/4 items –S i has about n/(2 i ) items The height of the skip list is about log 2 (n) NOTE: Unlike a binary search tree, this “halving” property is not enforced –It is approximate

CS351 Software Engineering (AY05)7 Skip List Operations We use a positional abstraction Operations After(p) – position after p on the same level Before(p) – position before p on the same level Below(p) – position below p in the same tower Above(p) – position above p in the same tower

CS351 Software Engineering (AY05)8 Searching Simple: binary search (modified) –The upper level lists provide something like a “thumb index” Algorithm for searching for the key k in a skip list –Returns p = reference to the key in the list which is equal or larger than k p  first element of S k while below(p)  null do p  below(p) {drop down} while key(after(p))  k do p  after(p) {scan forward}

CS351 Software Engineering (AY05)9 Inserting Uses insertAfterAbove(p,q,(k,e)) which inserts (k,e) after p and above q. Also uses the search we just did. p  SkipSearch(k) q  insertAfterAbove(p,null,(k,e)) while random() < ½ do while above(p) = null do p  before(p) {scan backwards} p  above(p) {jump up} q  insertAfterAbove(p,q,(k,e)) NOTE: the outer while loop might run for a very long time! –Normal to limit the height to something reasonable….

CS351 Software Engineering (AY05)10 Deleting Removal of an item is easier than insertion We simply find the item (SkipSearch(k)) –Then we remove this from the list S 0 –We recursively remove it from the lists S i above this This is simply deletion from a linked list, which is simple...

CS351 Software Engineering (AY05)11 Skip Lists - Summary Towers can be more compactly stored –No need to store the (k,e) tuple – only need the key Height is unbounded, need to limit: –H = 3  log 2 n  is viewed as safe –Note that this isn’t really an issue as the random number generator will not continue to generate values  ½ Search time = Insert time = Delete time = log 2 (n) –No problems with ordered data being inserted..

CS351 Software Engineering (AY05)12 Skip Lists - Summary The above and before methods are not needed –We can always insert, search and delete using a simple scan-forward-and-down regime –For deletion, we will encounter the item at the top of a tower, for example... Storage overhead is therefore just a (key,next,down) triple for each tower element... Total space requirement is expected to be <<2n entities (all S i ).