17 views

Uploaded by SunnyyLeone

Skip Lists explained

- jemh115
- The Book
- zgjidhja - ushtrime1
- Dictionaries
- LectureNotes_1a_Logif
- CPRE281_HW05
- 02-AsymptoticNotations
- Introduction to DAA
- Maximum Lifetime Scheduling for Target Coverage and Data Collection in Wireless Sensor Networks
- Functions in Informatica
- Dynamic Prog Final Paper
- ASN1 Tagging
- Normal Distribution.pptx
- LOWE. Probability Theory
- dc02_show.pps
- On Generating All Maximal Independent Set
- Robotics (26)
- Bi Go
- Jurdzinski - 2000 - A Discrete Strategy Improvement Algorithm for Solving Parity Games.ps
- Probability

You are on page 1of 12

Skip Lists

+! "!

!

0

!

1

!

2

!

3

+! "!

10 36 23 15

+! "!

15

+! "!

23 15

1f18f2005 +:1+ AN Skip Lists 2

Outline and Reading

What is a skip list (3.5)

Operations

Search (3.5.1)

!nsertion (3.5.2)

Deletion (3.5.2)

!mplementation

Analysis (3.5.3)

Space usage

Search and update times

1f18f2005 +:1+ AN Skip Lists 3

What is a Skip List

A skip list for a set ! of distinct (key, element) items is a series of

lists !

0

, !

1

, . , !

"

such that

Each list !

#

contains the special keys +! and "!

List !

0

contains the keys of ! in nondecreasing order

Each list is a subsequence of the previous one, i.e.,

!

0

#!

1

# .# !

"

List !

"

contains only the two special keys

We show how to use a skip list to implement the dictionary ADT

56 64 78

+!

31 34 44

"!

12 23 26

+! "!

+!

31

"!

64

+!

31 34

"!

23

!

0

!

1

!

2

!

3

1f18f2005 +:1+ AN Skip Lists +

Search

We search for a key % in a a skip list as follows:

We start at the first position of the top list

At the current position &, we compare % with ' $()'(*+,)-(&))

% = ': we return ).)/)0,(*+,)-(&))

% > ': we scan forward"

% < ': we drop down"

!f we try to drop down past the bottom list, we return 123!4563789

Example: search for 78

+! "!

!

0

!

1

!

2

!

3

+!

31

"!

64

+!

31 34

"!

23

56 64 78

+!

31 34 44

"!

12 23 26

1f18f2005 +:1+ AN Skip Lists 5

Randomized Algorithms

A randomized algorithm

performs coin tosses (i.e.,

uses random bits) to control

its execution

!t contains statements of the

type

: $-*0;</()

!" : = 0

do A .

$%&$ : = 1}

do B .

!ts 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

1f18f2005 +:1+ AN Skip Lists 6

To insert an item (%, <) into a skip list, we use a randomized

algorithm:

We repeatedly toss a coin until we get tails, and we denote with #

the number of times the coin came up heads

!f # % ", we add to the skip list new lists !

"+1

, . , !

# +1

, each

containing only the two special keys

We search for % in the skip list and find the positions &

0

, &

1

, ., &

#

of the items with largest key less than % in each list !

0

, !

1

, . , !

#

For = $0, ., #, we insert item (%, <) into list !

=

after position &

=

Example: insert key 15, with # = 2

!nsertion

+! "!

10 36

+! "!

23

23 +! "!

!

0

!

1

!

2

+! "!

!

0

!

1

!

2

!

3

+! "!

10 36 23 15

+! "!

15

+! "!

23 15

&

0

&

1

&

2

1f18f2005 +:1+ AN Skip Lists 7

Deletion

To remove an item with key % from a skip list, we proceed as

follows:

We search for % in the skip list and find the positions &

0

, &

1

, ., &

#

of the items with key %, where position &

=

is in list !

=

We remove positions &

0

, &

1

, ., &

#

from the lists !

0

, !

1

, . , !

#

We remove all but one list containing only the two special keys

Example: remove key 34

"! +!

45 12

"! +!

23

23 "! +!

!

0

!

1

!

2

"! +!

!

0

!

1

!

2

!

3

"! +!

45 12 23 34

"! +!

34

"! +!

23 34

&

0

&

1

&

2

1f18f2005 +:1+ AN Skip Lists 8

!mplementation

We can implement a skip list

with quad-nodes

A quad-node stores:

item

link to the node before

link to the node after

link to the node below

link to the node after

Also, we define special keys

PLUS_!NF and N!NUS_!NF,

and we modify the key

comparator to handle them

%

quad-node

1f18f2005 +:1+ AN Skip Lists 9

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 #

consecutive heads when

flipping a coin is 1/2

#

Fact 2: !f each of 0 items is

present in a set with

probability &, the expected size

of the set is 0&

Consider a skip list with 0

items

By Fact 1, we insert an item

in list !

#

with probability 1/2

#

By Fact 2, the expected size

of list !

#

is 0/2

#

The expected number of

nodes used by the skip list is

! !

!

"

#

#

"

#

#

2

2

1

2

0 0

< =

= =

Thus, the expected space

usage of a skip list with 0

items is 2(0)

1f18f2005 +:1+ AN Skip Lists 10

Height

The running time of the

search an insertion

algorithms is affected by the

height " of the skip list

We show that with high

probability, a skip list with 0

items has height 2(log 0)

We use the following

additional probabilistic fact:

Fact 3: !f each of 0 events has

probability &, the probability

that at least one event

occurs is at most 0&

Consider a skip list with 0

items

By Fact 1, we insert an item in

list !

#

with probability 1/2

#

By Fact 3, the probability that

list !

#

has at least one item is

at most 0/2

#

By picking # = 3log 0, we have

that the probability that !

3log 0

has at least one item is

at most

0/2

3log 0

= 0/0

3

= 1/0

2

Thus a skip list with 0 items

has height at most 3log 0 with

probability at least 1 " 1/0

2

1f18f2005 +:1+ AN Skip Lists 11

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 2(log 0)

with high probability

To analyze the scan-forward

steps, we use yet another

probabilistic fact:

Fact +: 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 +, in each list the

expected number of scan-

forward steps is 2

Thus, the expected number of

scan-forward steps is 2(log 0)

We conclude that a search in a

skip list takes 2(log 0)

expected time

The analysis of insertion and

deletion gives similar results

1f18f2005 +:1+ AN Skip Lists 12

Summary

A skip list is a data

structure for

dictionaries that uses a

randomized insertion

algorithm

!n a skip list with 0

items

The expected space used

is 2(0)

The expected search,

insertion and deletion

time is 2(log 0)

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

- jemh115Uploaded byMoulinaDas
- The BookUploaded bywondewin
- zgjidhja - ushtrime1Uploaded byBlerta
- DictionariesUploaded byArnold Aravind
- LectureNotes_1a_LogifUploaded byelfinos
- CPRE281_HW05Uploaded byJessica
- 02-AsymptoticNotationsUploaded byinstance one
- Introduction to DAAUploaded byagrawalpriyanka
- Functions in InformaticaUploaded byShiva CH
- Maximum Lifetime Scheduling for Target Coverage and Data Collection in Wireless Sensor NetworksUploaded byKavin Rkz
- Dynamic Prog Final PaperUploaded byPierre-Adolph Nii Armah Armah
- ASN1 TaggingUploaded by徐兵
- Normal Distribution.pptxUploaded bysanthiyasandy
- LOWE. Probability TheoryUploaded byRicardo
- dc02_show.ppsUploaded byscribdacct123
- On Generating All Maximal Independent SetUploaded bySimon Piga Diaz
- Robotics (26)Uploaded byapi-19801502
- Bi GoUploaded byFarizParahitaRoestam
- Jurdzinski - 2000 - A Discrete Strategy Improvement Algorithm for Solving Parity Games.psUploaded byKernel5
- ProbabilityUploaded byMuhammad Saqib Jadoon
- hw1solUploaded bynishchith
- 3ec36143ab474e511905f73ea626caecIN_2Uploaded byArnab Sankar Tah
- ProbabilityUploaded byNaresh Gill
- Final Exam 1436-1437 Term 1Uploaded byMohsenMahroos
- IJETTCS-2018-05-01-1Uploaded byAnonymous vQrJlEN
- Reducing Polynomial FractionsUploaded byhelojagt
- Theory of SearchUploaded byecd4282003
- sheet3Uploaded byaSDFGHJ
- Probability ScriptUploaded byAsoriano16
- Dsa Mk Lect10Uploaded byimjd2

- State of the City PublicationUploaded byCity of Mobile, Alabama
- iso_13485_medical_devices_2016.pdfUploaded byDito Priyambodo
- Www.wmi.Badw.de Teaching Lecturenotes SLTTP II TTP2013 Kap4Uploaded bySurendra Singh
- mock congress research paperUploaded byapi-303073122
- The Lake House - A Gourmet HeavenUploaded byKiwi Collection
- brochure-kone-e-link_tcm59-18662.pdfUploaded byFelipe Raul Chumpitaz Guevara
- en2z0911-ge51r0408Uploaded bylang74
- HR Audit QuestionnaireUploaded bydavidvilla9009
- Sales PromotionUploaded bySharifMahmud
- Call for Paper to AuthorsUploaded byhalibu shwan
- Project-Proposal-Template (1).docUploaded byNaila Naseer
- 20131214154002195Uploaded byRainingGirl
- In Re Crystallex - Shareholder Motion to Permit Oppression Claim - 22 January 2018Uploaded byLatin American Herald Tribune
- travel connectionsUploaded byapi-272011389
- osmosis lab report introductionUploaded byapi-327823961
- daily story simile stella snow queenUploaded byapi-300281604
- Abdominal PainUploaded byZahid A Sayeed
- Bai Tap Bo Tro Tieng Anh 7 Unit 14- - Tại 123doc.vnUploaded byHoàngNhi
- Transcaer Ammonia Training 2011Transports IG Rev10Uploaded byashraf
- Protect Your Health Recognize Mould !Uploaded bywinmargbm
- 2018 Korea Designers Collective in CoterieUploaded byHelen Oh
- Aiza 3 Mas DrugsUploaded byemmanemman
- weqweqweUploaded byheherson juan
- required_info_map.txtUploaded byjohn
- ORGANISATIONAL STRUCTURE AND CULTURE APPROACHES TO MANAGEMENT AND LEADERSHIPUploaded byEqamia Qishme
- IEAG Corporate FactsheetUploaded byMatt
- Commision on Macroeconomic and Health Bg P2 Oral and Dental DiseasesUploaded byAnonymous 9aIw2a
- User.manual.lpc17xxUploaded bymikfra
- ReferenceUploaded byInggrid
- Bobcat S250Uploaded bysvcing