Data Structures and Analysis (COMP 410)

Slides:



Advertisements
Similar presentations
CS 225 Lab #11 – Skip Lists.
Advertisements

Skip Lists Present By PAKDEE PATTANAJEDSADA SITTHICHOK SNANSIENG SIWAKORN THAMMAYTHA PATOMPOL TAESUJI
Alon Efrat Computer Science Department University of Arizona SkipList.
Binary Trees, Binary Search Trees CMPS 2133 Spring 2008.
AA Trees another alternative to AVL trees. Balanced Binary Search Trees A Binary Search Tree (BST) of N nodes is balanced if height is in O(log N) A balanced.
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,
Skip Lists1 Skip Lists William Pugh: ” Skip Lists: A Probabilistic Alternative to Balanced Trees ”, 1990  S0S0 S1S1 S2S2 S3S3 
CSCE 3110 Data Structures & Algorithm Analysis Binary Search Trees Reading: Chap. 4 (4.3) Weiss.
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.
Binary Trees, Binary Search Trees RIZWAN REHMAN CENTRE FOR COMPUTER STUDIES DIBRUGARH UNIVERSITY.
David Stotts Computer Science Department UNC Chapel Hill.
David Stotts Computer Science Department UNC Chapel Hill.
Red–black trees.  Define the red-black tree properties  Describe and implement rotations  Implement red-black tree insertion  We will skip red-black.
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.
Skip Lists 二○一七年四月二十五日
CMSC 341 Skip Lists. 8/3/2007 UMBC CMSC 341 SkipList 2 Looking Back at Sorted Lists Sorted Linked List What is the worst case performance of find( ),
David Stotts Computer Science Department UNC Chapel Hill.
Binary Search Trees (BST)
Tree Data Structures. Heaps for searching Search in a heap? Search in a heap? Would have to look at root Would have to look at root If search item smaller.
2014-T2 Lecture 27 School of Engineering and Computer Science, Victoria University of Wellington  Lindsay Groves, Marcus Frean, Peter Andreae, and Thomas.
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.
8/3/2007CMSC 341 BTrees1 CMSC 341 B- Trees D. Frey with apologies to Tom Anastasio.
(c) University of Washington20c-1 CSC 143 Binary Search Trees.
Skip Lists. Linked Lists Fast modifications given a pointer Slow traversals to random point.
Skip Lists S3   S2   S1   S0  
Sorted Maps © 2014 Goodrich, Tamassia, Goldwasser Skip Lists.
Data Structures and Analysis (COMP 410)
Definitions and Bottom-Up Insertion
AA Trees.
CSCE 3110 Data Structures & Algorithm Analysis
CSCE 3110 Data Structures & Algorithm Analysis
CSSE 230 Day 25 Skip Lists.
CSC212 Data Structure - Section AB
Efficiency of in Binary Trees
Searching an Array: Binary Search
Data Structures and Analysis (COMP 410)
Binary Search Tree Chapter 10.
COSC160: Data Structures Linked Lists
Data Structures and Analysis (COMP 410)
COMP 103 Binary Search Trees.
Tree data structure.
Binary Trees, Binary Search Trees
Binary Search Trees.
Data Structures and Analysis (COMP 410)
CMSC 341 Lecture 10 B-Trees Based on slides from Dr. Katherine Gibson.
Data Structures and Analysis (COMP 410)
Data Structures and Analysis (COMP 410)
Chapter 15 Lists Objectives
Tree data structure.
CMSC 341 Skip Lists 1.
Skip Lists S3 + - S2 + - S1 + - S0 + -
B- Trees D. Frey with apologies to Tom Anastasio
Sorted Maps © 2014 Goodrich, Tamassia, Goldwasser Skip Lists.
B- Trees D. Frey with apologies to Tom Anastasio
CMSC 341 Skip Lists.
CMSC 341 Skip Lists.
Searching CLRS, Sections 9.1 – 9.3.
Data Structures and Analysis (COMP 410)
Data Structures and Analysis (COMP 410)
B- Trees D. Frey with apologies to Tom Anastasio
Pseudorandom number, Universal Hashing, Chaining and Linear-Probing
CSC 143 Binary Search Trees.
CSCI 104 Skip Lists Mark Redekopp.
Mark Redekopp David Kempe
CMSC 341 Skip Lists.
CSC 421: Algorithm Design & Analysis
Skip Lists The non-list List Copyright © 2016 Curt Hill.
Presentation transcript:

Data Structures and Analysis (COMP 410) David Stotts Computer Science Department UNC Chapel Hill

( some slides adapted from UMd CMSC 420, Bill Pugh et al. ) Skip Lists ( some slides adapted from UMd CMSC 420, Bill Pugh et al. )

Skip List Generalization of sorted linked list Invented by Bill Pugh (UMd) in 1990 Original CACM paper: Pugh, W. (1990). "Skip lists: A probabilistic alternative to balanced trees" (PDF). Communications of the ACM. 33 (6): 668. An alternative to balanced BST Probabilistic Data Structure we roll dice, flip coins to build the structure but first …

x x x x x “Perfect” skip list first… no dice Multiple lists, multi-level list, O(log N) levels Level i+1 has half as many items as level i Level i+1 divides level i in half x 12 3 x 4 14 2 x 3 1 7 13 17 x x 3 4 7 12 13 14 17 sentinels

x x x x x “Perfect” skip list first… no dice List nodes are variable size… each with 1 to O(log N) pointers Sentinels at each end of “empty list” Each level lets you “skip over” many items below in one hop x 12 3 x 4 14 2 x 3 1 7 13 17 x x 3 4 7 12 13 14 17 sentinels

x x x x x “Perfect” skip list Search path… find(7) Start at top level, move right on a level, down as compare x 3 12 x 2 4 x 1 7 x x

x x x x x Now add probability Imperfect list, randomized order of cell sizes Cell size is chosen on add by roll-of-dice Level i not guaranteed to have twice level i+1, but random numbers will make it near twice Level i not guaranteed to split level i-1 into equal parts x 3 x 2 x 1 x x

Example insert insert(9) 3 29 74 42 12 9 Roll dice: get a 1 new node should be a one-level cell

Example insert insert(35) Roll dice: get a 3 9 X X 3 12 29 42 74 X Roll dice: get a 3 new node should be a three-level cell 35

Example insert insert(35) Roll dice: get a 3 9 X X 3 12 29 35 42 74 X Roll dice: get a 3 new node should be a three-level cell

Another example

Another example

Another example

Another example

Rolling the Dice function genRandomLevel ( ) { // generate an integer 0 or larger // following a distribution where 0 is 0.5 likely // 1 is .025 likely, 2 is .0125 likely, 3 is .00625, // etc. var ranLev=0; while ( Math.random() > 0.5 ) ranLev++; return ranLev; }

Checking the distribution var nLevels = 16; var nTrials = 1000; var SL = makeSkipList(nLevels); var levHits = [ ]; for (var i=0; i<nLevels; i++) { levHits[i]=0; } for (var i=0; i<nTrials; i++) { levHits[ SL.dice(nLevels) ]++; } alert(levHits); Gives these node level counts: 9965, 5037, 2519, 1263, 619, 289, 149, 84, 30, 24, 14, 6, 0, 1, 0, 0

ADT: SKLIST of Elt OO Signature new:  SKLIST insert: Elt  remove: Elt  find: Elt  Boolean (searching) size:  Int+ (non-negative integers) empty:  Boolean

SKLIST Implementation Time complexity of operations insert worst: O(n), avg: O(log n) remove worst: O(n), avg: O(log n) find worst: O(n), avg: O(log n) empty O(1) size O(1) iterator O(n) (traversal)

Beyond this is just templates END Beyond this is just templates