Skip Lists. What is a Skip List. Skip Lists 3/19/14

Similar documents
RANDOMIZED ALGORITHMS

WHAT IS A SKIP LIST? S 2 S 1. A skip list for a set S of distinct (key, element) items is a series of lists

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

Skip List. CS 561, Lecture 11. Skip List. Skip List

Fast Sorting and Selection. A Lower Bound for Worst Case

Design and Analysis of Algorithms

Dictionary: an abstract data type

Dictionary: an abstract data type

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

Outline Resource Introduction Usage Testing Exercises. Linked Lists COMP SCI / SFWR ENG 2S03. Department of Computing and Software McMaster University

AVL Trees. Manolis Koubarakis. Data Structures and Programming Techniques

Randomized Sorting Algorithms Quick sort can be converted to a randomized algorithm by picking the pivot element randomly. In this case we can show th

Data Structures and Algorithms " Search Trees!!

Lecture 4: Stacks and Queues

Name: Firas Rassoul-Agha

Chapter 18 Sampling Distribution Models

Motivation. Dictionaries. Direct Addressing. CSE 680 Prof. Roger Crawfis

Ling 289 Contingency Table Statistics

Search Trees. Chapter 10. CSE 2011 Prof. J. Elder Last Updated: :52 AM

SkipList. Searching a key x in a sorted linked list. inserting a key into a Sorted linked list. To insert

27 Binary Arithmetic: An Application to Programming

CIS 2033 Lecture 5, Fall

Hash Tables. Given a set of possible keys U, such that U = u and a table of m entries, a Hash function h is a

Chapter 5 Data Structures Algorithm Theory WS 2017/18 Fabian Kuhn

CS 361: Probability & Statistics

CS 240 Data Structures and Data Management. Module 4: Dictionaries

Recitation 6. Randomization. 6.1 Announcements. RandomLab has been released, and is due Monday, October 2. It s worth 100 points.

CS155: Probability and Computing: Randomized Algorithms and Probabilistic Analysis

Lecture 7: Amortized analysis

Collision. Kuan-Yu Chen ( 陳冠宇 ) TR-212, NTUST

A Brief Proof of the Riemann Hypothesis, Giving Infinite Results. Item Total Pages

Breadth First Search, Dijkstra s Algorithm for Shortest Paths

Parameter Learning With Binary Variables

Lecture 16. Error-free variable length schemes (contd.): Shannon-Fano-Elias code, Huffman code

CSE525: Randomized Algorithms and Probabilistic Analysis April 2, Lecture 1

STA 247 Solutions to Assignment #1

Searching, mainly via Hash tables

CS 125 Section #12 (More) Probability and Randomized Algorithms 11/24/14. For random numbers X which only take on nonnegative integer values, E(X) =

Lecture 10 Algorithmic version of the local lemma

Lecture 8: Probability

Probability and Statistics

Lecture 1 : Probabilistic Method

Math 180B Problem Set 3

CMPSCI 240: Reasoning Under Uncertainty

Sampling: A Brief Review. Workshop on Respondent-driven Sampling Analyst Software

Lecture 1: Overview of percolation and foundational results from probability theory 30th July, 2nd August and 6th August 2007

arxiv: v2 [cs.dc] 28 Apr 2013

Presentation for use with the textbook, Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, Union-Find Structures

Computer Sciences Department

Introductory Probability

Search Trees. EECS 2011 Prof. J. Elder Last Updated: 24 March 2015

Entropy. Probability and Computing. Presentation 22. Probability and Computing Presentation 22 Entropy 1/39

Exam 1 Solutions. Problem Points Score Total 145

Homework 2. Spring 2019 (Due Thursday February 7)

1 Maintaining a Dictionary

The Central Limit Theorem

Design of discrete-event simulations

N/4 + N/2 + N = 2N 2.

1 Approximate Quantiles and Summaries

CS 246 Review of Proof Techniques and Probability 01/14/19

Theorem 1.7 [Bayes' Law]: Assume that,,, are mutually disjoint events in the sample space s.t.. Then Pr( )

Balanced Allocation Through Random Walk

PROBABILITY THEORY 1. Basics

Data Structure. Mohsen Arab. January 13, Yazd University. Mohsen Arab (Yazd University ) Data Structure January 13, / 86

10.4 The Kruskal Katona theorem

X = X X n, + X 2

Linear Models for Regression CS534

A Brief Review of Probability, Bayesian Statistics, and Information Theory

Objective - To understand experimental probability

Math 416 Lecture 3. The average or mean or expected value of x 1, x 2, x 3,..., x n is

Analysis of Algorithms

Randomized Algorithms

Cuckoo Hashing and Cuckoo Filters

Priority queues implemented via heaps

CMPT 307 : Divide-and-Conqer (Study Guide) Should be read in conjunction with the text June 2, 2015

P (E) = P (A 1 )P (A 2 )... P (A n ).

Another way of saying this is that amortized analysis guarantees the average case performance of each operation in the worst case.

A Measurement of Randomness in Coin Tossing

6.041/6.431 Spring 2009 Quiz 1 Wednesday, March 11, 7:30-9:30 PM. SOLUTIONS

Outline Resource Introduction Usage Testing Exercises. Linked Lists COMP SCI / SFWR ENG 2S03. Department of Computing and Software McMaster University

Statistical Methods for NLP

MAT2377. Ali Karimnezhad. Version September 9, Ali Karimnezhad

Advanced Analysis of Algorithms - Midterm (Solutions)

1.225J J (ESD 205) Transportation Flow Systems

Propagating Knapsack Constraints in Sublinear Time

An Introduction to Bioinformatics Algorithms Hidden Markov Models

Advanced Algorithms (2IL45)

CS Communication Complexity: Applications and New Directions

Biased Quantiles. Flip Korn Graham Cormode S. Muthukrishnan

NORTHWESTERN UNIVERSITY Tuesday, Oct 6th, 2015 ANSWERS FALL 2015 NU PUTNAM SELECTION TEST

Linear Algebra Section 2.6 : LU Decomposition Section 2.7 : Permutations and transposes Wednesday, February 13th Math 301 Week #4

Coin tossing space. 0,1 consisting of all sequences (t n ) n N, represents the set of possible outcomes of tossing a coin infinitely many times.

CMSC 132, Object-Oriented Programming II Summer Lecture 6:

Bayesian Updating with Discrete Priors Class 11, Jeremy Orloff and Jonathan Bloom

Dynamic Programming Part 2: Probability, Combinatorics, and Bitmasks

Outline Conditional Probability The Law of Total Probability and Bayes Theorem Independent Events. Week 4 Classical Probability, Part II

Executive Assessment. Executive Assessment Math Review. Section 1.0, Arithmetic, includes the following topics:

Algorithm Design Strategies V

Chap 1: Experiments, Models, and Probabilities. Random Processes. Chap 1 : Experiments, Models, and Probabilities

Different encodings generate different circuits

Transcription:

Presentation for use with the textbook Data Structures and Algorithms in Java, 6 th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser, Wiley, 2014 Skip Lists 15 15 23 10 15 23 36 Skip Lists 1 What is a Skip List A skip list for a set S of distinct (key, element) items is a series of lists,,, S h such that n Each list S i contains the special keys and n List contains the keys of S in nondecreasing order n Each list is a subsequence of the previous one, i.e., S h n List S h contains only the two special keys We show how to use a skip list to implement the map ADT 31 23 31 34 64 12 23 26 31 34 44 56 64 78 Skip Lists 2 1

Search We search for a key x in a a skip list as follows: n We start at the first position of the top list n At the current position p, we compare x with y key(next(p)) x = y: we return element(next(p)) x > y: we scan forward x < y: we drop down n If we try to drop down past the bottom list, we return null Example: search for 78 scan forward 31 drop down 23 31 34 64 12 23 26 31 34 44 56 64 78 Skip Lists 3 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 n the coins are unbiased, and n 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 Skip Lists 4 2

Insertion To insert an entry (x, o) into a skip list, we use a randomized algorithm: n We repeatedly toss a coin until we get tails, and we denote with i the number of times the coin came up heads n If i h, we add to the skip list new lists S h+1,, S i +1, each containing only the two special keys n 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 i n For j 0,, i, we insert item (x, o) into list S j after position p j Example: insert key 15, with i = 2 p 2 p 1 23 p 0 10 23 36 15 15 23 10 15 23 36 Skip Lists 5 Deletion To remove an entry with key x from a skip list, we proceed as follows: n 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 n We remove positions p 0, p 1,, p i from the lists,,, S i n We remove all but one list containing only the two special keys Example: remove key 34 p 2 34 p 1 23 34 p0 23 12 23 34 45 12 23 45 Skip Lists 6 3

Implementation We can implement a skip list with quad-nodes A quad-node stores: n entry n link to the node prev n link to the node next n link to the node below n link to the node above Also, we define special keys PLUS_INF and MINUS_INF, and we modify the key comparator to handle them quad-node x Skip Lists 7 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 entries is present in a set with probability p, the expected size of the set is np Consider a skip list with n entries n By Fact 1, we insert an entry in list S i with probability 1/2 i n 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 h h n 1 = n 2n i < i 2 i= 0 2 i= 0 " Thus, the expected space usage of a skip list with n items is O(n) Skip Lists 8 4

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 entires n By Fact 1, we insert an entry in list S i with probability 1/2 i n 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 log n has at least one entry is at most n/2 3log n = n/n 3 = 1/n 2 Thus a skip list with n entries has height at most 3log n with probability at least 1-1/n 2 Skip Lists 9 Search and Update Times The search time in a skip list is proportional to n the number of drop-down steps, plus n 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 n A scan-forward step is associated with a former coin toss that gave tails By Fact 4, in each list the expected number of scanforward 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 Skip Lists 10 5

Summary A skip list is a data structure for maps that uses a randomized insertion algorithm In a skip list with n entries n The expected space used is O(n) 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 Skip Lists 11 6