CS 261: Data Structures. Skip Lists

Similar documents
CS 350 : Data Structures Skip Lists

Skip Lists S 3 S 2 S 1. Skip Lists Goodrich, Tamassia

L10: Dictionary & Skip List

Worksheet 28: Skip Lists

Lecture 5. Treaps Find, insert, delete, split, and join in treaps Randomized search trees Randomized search tree time costs

AVL Trees. (AVL Trees) Data Structures and Programming Spring / 17

1 Probability Review. CS 124 Section #8 Hashing, Skip Lists 3/20/17. Expectation (weighted average): the expectation of a random quantity X is:

R has a ordered clustering index file on its tuples: Read index file to get the location of the tuple with the next smallest value

CS 106B Lecture 26: Esoteric Data Structures: Skip Lists and Bloom Filters

CSE100. Advanced Data Structures. Lecture 8. (Based on Paul Kube course materials)

Sorting. Data structures and Algorithms

Skip Lists in Julia. Drew Minnear. Massachusetts Institute of Technology. December 8, 2013

Disk Accesses. CS 361, Lecture 25. B-Tree Properties. Outline

Predictive Analysis: Evaluation and Experimentation. Heejun Kim

Lecture 7. Random number generation More randomized data structures Skip lists: ideas and implementation Skip list time costs

CS 561, Lecture 2 : Randomization in Data Structures. Jared Saia University of New Mexico

Quick-Sort. Quick-sort is a randomized sorting algorithm based on the divide-and-conquer paradigm:

Quick-Sort fi fi fi 7 9. Quick-Sort Goodrich, Tamassia

lecture17: AVL Trees

Red-Black, Splay and Huffman Trees

Chapter 13 Control Structures

Confidence Intervals. Dennis Sun Data 301

Data Structure - Skip List etc. -

Delaunay Triangulations

CS246: Mining Massive Datasets Jure Leskovec, Stanford University

CS 561, Lecture 2 : Hash Tables, Skip Lists, Bloom Filters, Count-Min sketch. Jared Saia University of New Mexico

CS246: Mining Massive Datasets Jure Leskovec, Stanford University

Balanced Search Trees. CS 3110 Fall 2010

Computer Programming. Basic Control Flow - Loops. Adapted from C++ for Everyone and Big C++ by Cay Horstmann, John Wiley & Sons

Announcements. Reading Material. Recap. Today 9/17/17. Storage (contd. from Lecture 6)

Delaunay Triangulations. Presented by Glenn Eguchi Computational Geometry October 11, 2001

Skip Lists: Motivation

Hash Table. A hash function h maps keys of a given type into integers in a fixed interval [0,m-1]

University of Illinois at Urbana-Champaign Department of Computer Science. Final Examination

Graduate Algorithms CS F-12 Amortized Analysis

Treaps. 1 Binary Search Trees (BSTs) CSE341T/CSE549T 11/05/2014. Lecture 19

DIVIDE AND CONQUER ALGORITHMS ANALYSIS WITH RECURRENCE EQUATIONS

Quick-Sort. Quick-Sort 1

Last time. Reasoning about programs. Coming up. Project Final Presentations. This Thursday, Nov 30: 4 th in-class exercise

Reasoning about programs

Microsoft Office Access 2007: Intermediate Course 01 Relational Databases

Lecture 8 Index (B+-Tree and Hash)

CS 106 Introduction to Computer Science I

Chapter 10: Efficient Collections (skip lists, trees)

Orthogonal range searching. Range Trees. Orthogonal range searching. 1D range searching. CS Spring 2009

Ch04 Balanced Search Trees

CS246: Mining Massive Datasets Jure Leskovec, Stanford University

Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur

CSED233: Data Structures (2017F) Lecture10:Hash Tables, Maps, and Skip Lists

Introduction. for large input, even access time may be prohibitive we need data structures that exhibit times closer to O(log N) binary search tree

Lecture 11: Multiway and (2,4) Trees. Courtesy to Goodrich, Tamassia and Olga Veksler

Binary Search Trees. Analysis of Algorithms

Presentation for use with the textbook, Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, 2015

COMP 430 Intro. to Database Systems. Indexing

Hands-on Lab 1: LabVIEW NI-DAQ Basics 1

Problem Set 5 Solutions

Chapter 12. Path Planning. Beard & McLain, Small Unmanned Aircraft, Princeton University Press, 2012,

CS 240 Fall Mike Lam, Professor. Priority Queues and Heaps

Sorting Goodrich, Tamassia Sorting 1

Adjust model for 3D Printing. Positioning - Orientate the part 13,0600,1489,1604(SP6)

Binary Trees (and Big O notation)

LSP 121. LSP 121 Math and Tech Literacy II. Topics. Loops. Loops. Loops

University of Waterloo CS240 Winter 2018 Assignment 3

Design and Analysis of Algorithms Prof. Madhavan Mukund Chennai Mathematical Institute. Week 02 Module 06 Lecture - 14 Merge Sort: Analysis

CSCI 104 Log Structured Merge Trees. Mark Redekopp

Graph Theory and Optimization Approximation Algorithms

CS 532: 3D Computer Vision 14 th Set of Notes

CS 137 Part 8. Merge Sort, Quick Sort, Binary Search. November 20th, 2017

Priority Queues and Binary Heaps

Some Search Structures. Balanced Search Trees. Binary Search Trees. A Binary Search Tree. Review Binary Search Trees

COMP171. AVL-Trees (Part 1)

Chapter 4: Sorting. Spring 2014 Sorting Fun 1

Splay tree, tree Marko Berezovský Radek Mařík PAL 2012

Splay Trees. (Splay Trees) Data Structures and Programming Spring / 27

Distributed Mutual Exclusion

arxiv: v3 [math.co] 9 Jan 2015

Direct Addressing Hash table: Collision resolution how handle collisions Hash Functions:

DATA STRUCTURES/UNIT 3

e-pg PATHSHALA- Computer Science Design and Analysis of Algorithms Module 10

Lecture 7. SchemeList, finish up; Universal Hashing introduction

Indexing: Overview & Hashing. CS 377: Database Systems

Control Flow. COMS W1007 Introduction to Computer Science. Christopher Conway 3 June 2003

Ensures that no such path is more than twice as long as any other, so that the tree is approximately balanced

Searching, Sorting. Arizona State University 1

Line Arrangements. Applications

*Starting Out with C++: From Control Structures through Objects, 7/E* by *Tony Gaddis* COMPUTER PROGRAMMING LECTURE 05 LOOPS IMRAN IHSAN

SELF-BALANCING SEARCH TREES. Chapter 11

Latest on Linear Sketches for Large Graphs: Lots of Problems, Little Space, and Loads of Handwaving. Andrew McGregor University of Massachusetts

CSE 373: Data Structures and Algorithms

CSC 261/461 Database Systems Lecture 17. Fall 2017

Streaming algorithms for embedding and computing edit distance

3. Priority Queues. ADT Stack : LIFO. ADT Queue : FIFO. ADT Priority Queue : pick the element with the lowest (or highest) priority.

Chapter 22 Splay Trees

BINARY SEARCH TREES cs2420 Introduction to Algorithms and Data Structures Spring 2015

5.1. Chapter 5: The Increment and Decrement Operators. The Increment and Decrement Operators. Looping. ++ is the increment operator.

9/29/2016. Chapter 4 Trees. Introduction. Terminology. Terminology. Terminology. Terminology

Approximation Algorithms

! A data type for which: ! An ADT may be implemented using various. ! Examples:

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #43. Multidimensional Arrays

1 ICS 161: Design and Analysis of Algorithms Lecture notes for January 23, Bucket Sorting

Transcription:

CS 261: Data Structures Skip Lists 1

Complexity Lists and Arrays OPERATIONS ORDINARY LISTS AND ARRAYS SORTED ARRAYS SORTED LISTS Add O(1) O(n) O(n) Remove O(n) O(n) O(n) Contains O(n) O(log n) O(n) 2

Sorted Linked Lists How to improve complexity of a sorted linked list? We could use two sorted linked lists, with pointers between them List 5 19 2

Two Sorted Linked Lists Constructed from the same elements Establish pointers between equal links down down down 5 19 2 4

Motivation Regular Trains vs. Express Trains down down down 5 19 2 5

Two Sorted Linked Lists : stores all elements : stores only a subset of elements down down down 5 19 2 6

How to Search for an Element? We start from the 1 st element of Stay on the "express line" as long as you can Then, take the "local line" down down down 5 19 2

How to Choose Elements for? Goal: Maximize fast access to all elements picks uniformly a subset of elements (e.g. every 2 nd, or rd, or 4 th element) down down down 5 19 2 8

How to Choose Elements for? But how exactly to uniformly sample elements for? down down down 5 19 2 9

The Goal: Minimize Complexity of Search down down down 5 19 2 10

What is Complexity of Search? num. of elements in L 1 + L 2 L 1 num. of elements in a segment of down down down 5 19 2 11

What is Complexity of Search? L 1 + L 2 L 1 down down down 5 19 2 12

What is Complexity of Search? minimize x + n x

What is Complexity of Search? minimum of the function d x + n x dx =0 14

What is Complexity of Search? d x + n x dx =1 n x 2 =0 ) x = p n 15

What is Complexity of Search? p n = = p n L 1 + L 2 L 1 = n down down down 5 19 2 16

What is Complexity of Search? 2 p n down down down 5 19 2 1

What is Complexity of Search? two sorted lists one sorted list down down down 5 19 2 18

How Many Lists Should We Form? If 2 lists have lower complexity, maybe lists will have even lower complexity down down down down down List 5 19 2 19

What is Complexity for Lists? down down down down down List 5 19 2 20

What is Complexity for Lists? down = x = x 2 down down down down List 5 19 2 21

What is Complexity for Lists? down down down down down List 5 19 2 22

What is Complexity for Lists? = p n down down down down down List 5 19 2 2

What is Complexity for Lists? lists 2 lists single list down down down down down List 5 19 2 24

What is Complexity for k Lists? for k linked lists: k kp n down down down down down List k......... 5 19 2 25

How Many Lists? minimize k kp n down down down down down List k......... 5 19 2 26

How Many Lists? minimize k kn 1 k = minimize k 2

How Many Lists? minimize k kn 1 k = minimize k log k + 1k log n 28

How Many Lists? d log k + 1 k log n dk =0 = 1 k 1 log n =0 k2 k = log n 29

Complexity for k=log n Lists? kn 1 k = (log n) n 1 log n down up down up down up down up down up List 5 19 2 0

n =2 log n n 1 log n =(2 log n ) 1 log n =2 (log n) n 1 log n = 2 log n

Complexity for log n Lists O(log n) down up down up down up down up down up List 5 19 2 2

Skip Lists Have It All Pugh 1989 Fast addition O(log n) Fast search O(log n) Fast removal O(log n) Disadvantage: - Slightly more complicated

Contains Skip List Makes a zig-zag motion top-to-bottom Complexity: O(log n), i.e., proportional to the number of linked lists 4

Contains Skip List 1. Start at topmost sentinel 2. Loop as follows 1. Slide right, get a link right before 2. If next element is OK, return true. If no down element, return false 4. Move down 5

Remove Skip List Makes a zig-zag motion top-to-bottom Only decrement the size at the bottom level Complexity: O(log n), i.e., proportional to the number of linked lists 6

Remove Skip List 1. Start at topmost sentinel 2. Loop as follows 1. Slide right, get a link right before 2. If next element is OK, remove it. If no down element, reduce size 4. Move down

How to construct a skip list when we do not know the number of elements in advance? 8

Add Skip List Add the element to the bottom list must increment size To move up to existing lists: Flip a coin, and if heads add the element up To add a new list at the top Flip a coin, and if heads make a new top list 9

Add Example Insert the following: 9 14 20 9 40

Add Example: Inserted : 9 14 Coin toss: T HT ( H = move up) down 14 9 14

Add Example: Inserted : 9 14 20 Coin toss: T HT HHH T List down down down 14 9 14 20 42

Complexity of Add Proportional to the height, not to the number of nodes in the list O(log n) 4

Skip List Sorting Algorithm Problem: Sort an array A Step 1. Copy elements from A into a skip list Step 2. Copy elements from the skip list to A 44

Skip List Sorting Algorithm Complexity: Step 1. Copy elements from A into a skip list O(??) Step 2. Copy elements from the skip list to A O(??) 45