SlideShare a Scribd company logo
Skip Lists
1
Skip Lists
2
Outline and Reading
 What is a skip list
 Operations
 Search
 Insertion
 Deletion
 Implementation
 Analysis
 Space usage
 Search and update times
Intro to Skip Lists
 Motivation:
 Unordered Arrays:
 Searching and removing takes O(n) times
 Inserting takes O(1) times
 Ordered Arrays:
 Searching takes O(log n) times
 Inserting and removing takes O(n) times
► Unordered LL: fast insertion, slow search
► Ordered LL: slow insertion, slow search
 Basic idea of skip lists
 Organize ordered list hierarchically so we don’t need to scan all elements in search
Skip Lists
3
Skip Lists
4
What is a Skip List
 A skip list for a set S of n distinct keys is a series of lists S0, S1 , … , Sh such that
 Each list Si contains the special keys + and -
 List S0 contains the keys of S in nondecreasing order
 Each list is a subsequence of the previous one, i.e.,
S0  S1  …  Sh
 List Sh contains only the two special keys
56 64 78 +31 34 44- 12 23 26
+-
+31-
64 +31 34- 23
S0
S1
S2
S3
Skip Lists
5
Skip List Node
 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 above
 Also, we define special keys
PLUS_INF and MINUS_INF, and
we modify the key comparator
to handle them
x
quad-node
Skip Lists
6
Search
 Steps for search a key x in a a skip list:
 Start at the first position of the top list
 At the current position p, we compare x with y  key(next(p))
x = y: Return next(p)
x > y: Scan forward
x < y: Drop down
 Repeat the above step. (If “drop down” pasts the bottom list, return null.)
 Example: search for 78
+-
S0
S1
S2
S3
+31-
64 +31 34- 23
56 64 78 +31 34 44- 12 23 26
scan forward
drop down
Find the interval
where x belong to…
Skip Lists
7
Skip Lists
8
Skip Lists
9
Skip Lists
10
Skip Lists
11
Skip Lists
12
Skip Lists
13
Skip Lists
14
Skip Lists
15
Skip Lists
16
Skip Lists
17
Skip Lists
18
Skip Lists
19
Skip Lists
20
Skip Lists
21
Skip Lists
22
Skip Lists
23
Skip Lists
24
Skip Lists
25
Skip Lists
26
Skip Lists
27
Skip Lists
28
Skip Lists
29
Implementation (1/2)
Skip Lists
30
Resutls due
to different
randomization
Another
linked list
implementation
Skip Lists
31
Implementation (2/2)
 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 above
 Also, we define special keys
PLUS_INF and MINUS_INF, and
we modify the key comparator
to handle them
x
quad-node
Skip Lists
32
Outline and Reading
 What is a skip list
 Operations
 Search
 Insertion
 Deletion
 Implementation
 Analysis
 Space usage
 Search and update times
Skip Lists
33
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
 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
Skip Lists
34
 To insert an item x into a skip list, we use a randomized algorithm:
 We repeatedly toss a coin until we get tails, and we denote with i the number of
times the coin came up heads
 If i  h, we add to the skip list new lists Sh+1, … , Si +1, each containing only the two
special keys
 We search for x in the skip list and find the positions p0, p1 , …, pi of the items with
largest key less than x in each list S0, S1, … , Si
 For j  0, …, i, we insert item x into list Sj after position pj
 Example: insert key 15, with i = 2
Insertion
+- 10 36
+-
23
23 +-
S0
S1
S2
+-
S0
S1
S2
S3
+- 10 362315
+- 15
+- 2315
p0
p1
p2
n nodes
n/2 nodes
in average
n/4 nodes
in average
Skip Lists
35
Deletion
 To remove an item with key x from a skip list, we proceed as
follows:
 We search for x in the skip list and find the positions p0, p1 , …, pi of the
items with key x, where position pj is in list Sj
 We remove positions p0, p1 , …, pi from the lists S0, S1, … , Si
 We remove all but one list containing only the two special keys
 Example: remove key 34
- +4512
- +
23
23- +
S0
S1
S2
- +
S0
S1
S2
S3
- +4512 23 34
- +34
- +23 34
p0
p1
p2
Skip Lists
36
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/2i
Fact 2: If each of n items is present
in a set with probability p, the
expected size of the set is np
 Consider a skip list with n items
 By Fact 1, we insert an item in list
Si with probability 1/2i
 By Fact 2, the expected size of list
Si is n/2i
 The expected number of nodes
used by the skip list is
nnn
n
h
h
i
i
h
i
i
2
2
1
2
2
1
2 00
<





-==  ==
Thus, the expected space
usage of a skip list with n
items is O(n)
Skip Lists
37
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 items
 By Fact 1, we insert an item in list Si with
probability 1/2i
 By Fact 3, the probability that list Si has at least
one item is at most n/2i
 By picking i = 3log n, we have that the
probability that S3log n has at least one item is
at most
n/23log n = n/n3 = 1/n2
 Thus a skip list with n items has height at
most 3log n with probability at least 1 - 1/n2
Search and Update Times
 The search time in a skip list is
proportional to the sum of
 #drop-downs
 #scan-forwards
 #drop-downs
 Bounded by the height of the skip list 
O(log n)
 #scan-forwards
 Each scan forward bounded by nodes in an
interval  O(2) in average for each scan
forward  O(log n) overall.
 Thus the complexity for search in a
skip list is O(log n)
 The analysis of insertion and deletion
gives similar results
Skip Lists
38
Skip Lists
39
Summary
 A skip list is a data structure for
dictionaries that uses a
randomized insertion algorithm
 In a skip list with n items
 The expected space used is O(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
Ad

More Related Content

What's hot (20)

Selection sorting
Selection sortingSelection sorting
Selection sorting
Himanshu Kesharwani
 
skip list
skip listskip list
skip list
iammutex
 
Doubly Linked List
Doubly Linked ListDoubly Linked List
Doubly Linked List
Ninad Mankar
 
Hashing PPT
Hashing PPTHashing PPT
Hashing PPT
Saurabh Kumar
 
Linked List
Linked ListLinked List
Linked List
Ashim Lamichhane
 
Searching algorithms
Searching algorithmsSearching algorithms
Searching algorithms
Trupti Agrawal
 
Quick sort
Quick sortQuick sort
Quick sort
Dhruv Sabalpara
 
Data Structures : hashing (1)
Data Structures : hashing (1)Data Structures : hashing (1)
Data Structures : hashing (1)
Home
 
Quick Sort
Quick SortQuick Sort
Quick Sort
Shweta Sahu
 
Radix sort presentation
Radix sort presentationRadix sort presentation
Radix sort presentation
Ratul Hasan
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
Pranay Neema
 
Binary Search
Binary SearchBinary Search
Binary Search
kunj desai
 
Searching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data StructureSearching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data Structure
Balwant Gorad
 
Insertion sort algorithm power point presentation
Insertion  sort algorithm power point presentation Insertion  sort algorithm power point presentation
Insertion sort algorithm power point presentation
University of Science and Technology Chitttagong
 
Sorting
SortingSorting
Sorting
Ashim Lamichhane
 
Searching, Sorting and Hashing Techniques
Searching, Sorting and Hashing TechniquesSearching, Sorting and Hashing Techniques
Searching, Sorting and Hashing Techniques
Selvaraj Seerangan
 
Insertion Sorting
Insertion SortingInsertion Sorting
Insertion Sorting
FarihaHabib123
 
Binary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of AlgorithmsBinary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of Algorithms
Drishti Bhalla
 
3.9 external sorting
3.9 external sorting3.9 external sorting
3.9 external sorting
Krish_ver2
 
Singly linked list
Singly linked listSingly linked list
Singly linked list
Amar Jukuntla
 

Similar to Skip lists (Advance Data structure) (20)

5.4 randamized algorithm
5.4 randamized algorithm5.4 randamized algorithm
5.4 randamized algorithm
Krish_ver2
 
Computer notes - Binary Search
Computer notes - Binary SearchComputer notes - Binary Search
Computer notes - Binary Search
ecomputernotes
 
computer notes - Data Structures - 32
computer notes - Data Structures - 32computer notes - Data Structures - 32
computer notes - Data Structures - 32
ecomputernotes
 
computer notes - Data Structures - 34
computer notes - Data Structures - 34computer notes - Data Structures - 34
computer notes - Data Structures - 34
ecomputernotes
 
Sorting
SortingSorting
Sorting
Saharamily
 
Sorting
SortingSorting
Sorting
Saurabh Mishra
 
List in Python Using Back Developers in Using More Use.
List in Python Using Back Developers in Using More Use.List in Python Using Back Developers in Using More Use.
List in Python Using Back Developers in Using More Use.
SravaniSravani53
 
presentation-225new
presentation-225newpresentation-225new
presentation-225new
Najmul Hoq
 
Sorting techniques
Sorting techniquesSorting techniques
Sorting techniques
Lovely Professional University
 
In three of the exercises below there is given a code of a method na.pdf
In three of the exercises below there is given a code of a method na.pdfIn three of the exercises below there is given a code of a method na.pdf
In three of the exercises below there is given a code of a method na.pdf
feelinggift
 
21-algorithms.ppt
21-algorithms.ppt21-algorithms.ppt
21-algorithms.ppt
Madurai Kamaraj University Madurai Tamil Nadu India
 
Skip Graphs and its Applications
Skip Graphs and its ApplicationsSkip Graphs and its Applications
Skip Graphs and its Applications
Ajay Bidyarthy
 
Randamization.pdf
Randamization.pdfRandamization.pdf
Randamization.pdf
Prashanth460337
 
Quicksort Algorithm..simply defined through animations..!!
Quicksort Algorithm..simply defined through animations..!!Quicksort Algorithm..simply defined through animations..!!
Quicksort Algorithm..simply defined through animations..!!
Mahesh Tibrewal
 
Address calculation-sort
Address calculation-sortAddress calculation-sort
Address calculation-sort
Vasim Pathan
 
21-algorithms (1).ppt
21-algorithms (1).ppt21-algorithms (1).ppt
21-algorithms (1).ppt
DaniloMislosAlbay
 
Chapter-2.pptx
Chapter-2.pptxChapter-2.pptx
Chapter-2.pptx
selemonGamo
 
21-algorithms.ppt
21-algorithms.ppt21-algorithms.ppt
21-algorithms.ppt
ashwinraiyani1
 
Algorithm, Pseudocode and Flowcharting in C++
Algorithm, Pseudocode and Flowcharting in C++Algorithm, Pseudocode and Flowcharting in C++
Algorithm, Pseudocode and Flowcharting in C++
Johnny Jean Tigas
 
Python data type
Python data typePython data type
Python data type
Jaya Kumari
 
5.4 randamized algorithm
5.4 randamized algorithm5.4 randamized algorithm
5.4 randamized algorithm
Krish_ver2
 
Computer notes - Binary Search
Computer notes - Binary SearchComputer notes - Binary Search
Computer notes - Binary Search
ecomputernotes
 
computer notes - Data Structures - 32
computer notes - Data Structures - 32computer notes - Data Structures - 32
computer notes - Data Structures - 32
ecomputernotes
 
computer notes - Data Structures - 34
computer notes - Data Structures - 34computer notes - Data Structures - 34
computer notes - Data Structures - 34
ecomputernotes
 
List in Python Using Back Developers in Using More Use.
List in Python Using Back Developers in Using More Use.List in Python Using Back Developers in Using More Use.
List in Python Using Back Developers in Using More Use.
SravaniSravani53
 
presentation-225new
presentation-225newpresentation-225new
presentation-225new
Najmul Hoq
 
In three of the exercises below there is given a code of a method na.pdf
In three of the exercises below there is given a code of a method na.pdfIn three of the exercises below there is given a code of a method na.pdf
In three of the exercises below there is given a code of a method na.pdf
feelinggift
 
Skip Graphs and its Applications
Skip Graphs and its ApplicationsSkip Graphs and its Applications
Skip Graphs and its Applications
Ajay Bidyarthy
 
Quicksort Algorithm..simply defined through animations..!!
Quicksort Algorithm..simply defined through animations..!!Quicksort Algorithm..simply defined through animations..!!
Quicksort Algorithm..simply defined through animations..!!
Mahesh Tibrewal
 
Address calculation-sort
Address calculation-sortAddress calculation-sort
Address calculation-sort
Vasim Pathan
 
Algorithm, Pseudocode and Flowcharting in C++
Algorithm, Pseudocode and Flowcharting in C++Algorithm, Pseudocode and Flowcharting in C++
Algorithm, Pseudocode and Flowcharting in C++
Johnny Jean Tigas
 
Python data type
Python data typePython data type
Python data type
Jaya Kumari
 
Ad

More from Shubham Shukla (6)

Tries
TriesTries
Tries
Shubham Shukla
 
Floyd warshall algo {dynamic approach}
Floyd warshall algo {dynamic approach}Floyd warshall algo {dynamic approach}
Floyd warshall algo {dynamic approach}
Shubham Shukla
 
Lecture 4 sql {basics keys and constraints}
Lecture 4 sql {basics  keys and constraints}Lecture 4 sql {basics  keys and constraints}
Lecture 4 sql {basics keys and constraints}
Shubham Shukla
 
Lecture 3 sql {basics ddl commands}
Lecture 3 sql {basics  ddl commands}Lecture 3 sql {basics  ddl commands}
Lecture 3 sql {basics ddl commands}
Shubham Shukla
 
Lecture 2 sql {basics date type, constrains , integrity types etc.}
Lecture 2 sql {basics  date type, constrains , integrity types etc.}Lecture 2 sql {basics  date type, constrains , integrity types etc.}
Lecture 2 sql {basics date type, constrains , integrity types etc.}
Shubham Shukla
 
Lecture 1 sql {installation &amp; uninstallation}
Lecture 1 sql {installation &amp; uninstallation}Lecture 1 sql {installation &amp; uninstallation}
Lecture 1 sql {installation &amp; uninstallation}
Shubham Shukla
 
Floyd warshall algo {dynamic approach}
Floyd warshall algo {dynamic approach}Floyd warshall algo {dynamic approach}
Floyd warshall algo {dynamic approach}
Shubham Shukla
 
Lecture 4 sql {basics keys and constraints}
Lecture 4 sql {basics  keys and constraints}Lecture 4 sql {basics  keys and constraints}
Lecture 4 sql {basics keys and constraints}
Shubham Shukla
 
Lecture 3 sql {basics ddl commands}
Lecture 3 sql {basics  ddl commands}Lecture 3 sql {basics  ddl commands}
Lecture 3 sql {basics ddl commands}
Shubham Shukla
 
Lecture 2 sql {basics date type, constrains , integrity types etc.}
Lecture 2 sql {basics  date type, constrains , integrity types etc.}Lecture 2 sql {basics  date type, constrains , integrity types etc.}
Lecture 2 sql {basics date type, constrains , integrity types etc.}
Shubham Shukla
 
Lecture 1 sql {installation &amp; uninstallation}
Lecture 1 sql {installation &amp; uninstallation}Lecture 1 sql {installation &amp; uninstallation}
Lecture 1 sql {installation &amp; uninstallation}
Shubham Shukla
 
Ad

Recently uploaded (20)

INDIA QUIZ FOR SCHOOLS | THE QUIZ CLUB OF PSGCAS | AUGUST 2024
INDIA QUIZ FOR SCHOOLS | THE QUIZ CLUB OF PSGCAS | AUGUST 2024INDIA QUIZ FOR SCHOOLS | THE QUIZ CLUB OF PSGCAS | AUGUST 2024
INDIA QUIZ FOR SCHOOLS | THE QUIZ CLUB OF PSGCAS | AUGUST 2024
Quiz Club of PSG College of Arts & Science
 
How to Configure Extra Steps During Checkout in Odoo 18 Website
How to Configure Extra Steps During Checkout in Odoo 18 WebsiteHow to Configure Extra Steps During Checkout in Odoo 18 Website
How to Configure Extra Steps During Checkout in Odoo 18 Website
Celine George
 
How to Change Sequence Number in Odoo 18 Sale Order
How to Change Sequence Number in Odoo 18 Sale OrderHow to Change Sequence Number in Odoo 18 Sale Order
How to Change Sequence Number in Odoo 18 Sale Order
Celine George
 
How To Maximize Sales Performance using Odoo 18 Diverse views in sales module
How To Maximize Sales Performance using Odoo 18 Diverse views in sales moduleHow To Maximize Sales Performance using Odoo 18 Diverse views in sales module
How To Maximize Sales Performance using Odoo 18 Diverse views in sales module
Celine George
 
Peer Assesment- Libby.docx..............
Peer Assesment- Libby.docx..............Peer Assesment- Libby.docx..............
Peer Assesment- Libby.docx..............
19lburrell
 
Dastur_ul_Amal under Jahangir Key Features.pptx
Dastur_ul_Amal under Jahangir Key Features.pptxDastur_ul_Amal under Jahangir Key Features.pptx
Dastur_ul_Amal under Jahangir Key Features.pptx
omorfaruqkazi
 
ITI COPA Question Paper PDF 2017 Theory MCQ
ITI COPA Question Paper PDF 2017 Theory MCQITI COPA Question Paper PDF 2017 Theory MCQ
ITI COPA Question Paper PDF 2017 Theory MCQ
SONU HEETSON
 
IPL QUIZ | THE QUIZ CLUB OF PSGCAS | 2025.pdf
IPL QUIZ | THE QUIZ CLUB OF PSGCAS | 2025.pdfIPL QUIZ | THE QUIZ CLUB OF PSGCAS | 2025.pdf
IPL QUIZ | THE QUIZ CLUB OF PSGCAS | 2025.pdf
Quiz Club of PSG College of Arts & Science
 
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
parmarjuli1412
 
The History of Kashmir Lohar Dynasty NEP.ppt
The History of Kashmir Lohar Dynasty NEP.pptThe History of Kashmir Lohar Dynasty NEP.ppt
The History of Kashmir Lohar Dynasty NEP.ppt
Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
Pope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptxPope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptx
Martin M Flynn
 
Aerospace Engineering Homework Help Guide – Expert Support for Academic Success
Aerospace Engineering Homework Help Guide – Expert Support for Academic SuccessAerospace Engineering Homework Help Guide – Expert Support for Academic Success
Aerospace Engineering Homework Help Guide – Expert Support for Academic Success
online college homework help
 
PUBH1000 Slides - Module 11: Governance for Health
PUBH1000 Slides - Module 11: Governance for HealthPUBH1000 Slides - Module 11: Governance for Health
PUBH1000 Slides - Module 11: Governance for Health
JonathanHallett4
 
"Bridging Cultures Through Holiday Cards: 39 Students Celebrate Global Tradit...
"Bridging Cultures Through Holiday Cards: 39 Students Celebrate Global Tradit..."Bridging Cultures Through Holiday Cards: 39 Students Celebrate Global Tradit...
"Bridging Cultures Through Holiday Cards: 39 Students Celebrate Global Tradit...
AlionaBujoreanu
 
How to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 PurchaseHow to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 Purchase
Celine George
 
Botany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic ExcellenceBotany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic Excellence
online college homework help
 
How to Use Upgrade Code Command in Odoo 18
How to Use Upgrade Code Command in Odoo 18How to Use Upgrade Code Command in Odoo 18
How to Use Upgrade Code Command in Odoo 18
Celine George
 
Peer Assessment_ Unit 2 Skills Development for Live Performance - for Libby.docx
Peer Assessment_ Unit 2 Skills Development for Live Performance - for Libby.docxPeer Assessment_ Unit 2 Skills Development for Live Performance - for Libby.docx
Peer Assessment_ Unit 2 Skills Development for Live Performance - for Libby.docx
19lburrell
 
The role of wall art in interior designing
The role of wall art in interior designingThe role of wall art in interior designing
The role of wall art in interior designing
meghaark2110
 
Classification of mental disorder in 5th semester bsc. nursing and also used ...
Classification of mental disorder in 5th semester bsc. nursing and also used ...Classification of mental disorder in 5th semester bsc. nursing and also used ...
Classification of mental disorder in 5th semester bsc. nursing and also used ...
parmarjuli1412
 
How to Configure Extra Steps During Checkout in Odoo 18 Website
How to Configure Extra Steps During Checkout in Odoo 18 WebsiteHow to Configure Extra Steps During Checkout in Odoo 18 Website
How to Configure Extra Steps During Checkout in Odoo 18 Website
Celine George
 
How to Change Sequence Number in Odoo 18 Sale Order
How to Change Sequence Number in Odoo 18 Sale OrderHow to Change Sequence Number in Odoo 18 Sale Order
How to Change Sequence Number in Odoo 18 Sale Order
Celine George
 
How To Maximize Sales Performance using Odoo 18 Diverse views in sales module
How To Maximize Sales Performance using Odoo 18 Diverse views in sales moduleHow To Maximize Sales Performance using Odoo 18 Diverse views in sales module
How To Maximize Sales Performance using Odoo 18 Diverse views in sales module
Celine George
 
Peer Assesment- Libby.docx..............
Peer Assesment- Libby.docx..............Peer Assesment- Libby.docx..............
Peer Assesment- Libby.docx..............
19lburrell
 
Dastur_ul_Amal under Jahangir Key Features.pptx
Dastur_ul_Amal under Jahangir Key Features.pptxDastur_ul_Amal under Jahangir Key Features.pptx
Dastur_ul_Amal under Jahangir Key Features.pptx
omorfaruqkazi
 
ITI COPA Question Paper PDF 2017 Theory MCQ
ITI COPA Question Paper PDF 2017 Theory MCQITI COPA Question Paper PDF 2017 Theory MCQ
ITI COPA Question Paper PDF 2017 Theory MCQ
SONU HEETSON
 
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
parmarjuli1412
 
Pope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptxPope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptx
Martin M Flynn
 
Aerospace Engineering Homework Help Guide – Expert Support for Academic Success
Aerospace Engineering Homework Help Guide – Expert Support for Academic SuccessAerospace Engineering Homework Help Guide – Expert Support for Academic Success
Aerospace Engineering Homework Help Guide – Expert Support for Academic Success
online college homework help
 
PUBH1000 Slides - Module 11: Governance for Health
PUBH1000 Slides - Module 11: Governance for HealthPUBH1000 Slides - Module 11: Governance for Health
PUBH1000 Slides - Module 11: Governance for Health
JonathanHallett4
 
"Bridging Cultures Through Holiday Cards: 39 Students Celebrate Global Tradit...
"Bridging Cultures Through Holiday Cards: 39 Students Celebrate Global Tradit..."Bridging Cultures Through Holiday Cards: 39 Students Celebrate Global Tradit...
"Bridging Cultures Through Holiday Cards: 39 Students Celebrate Global Tradit...
AlionaBujoreanu
 
How to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 PurchaseHow to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 Purchase
Celine George
 
Botany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic ExcellenceBotany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic Excellence
online college homework help
 
How to Use Upgrade Code Command in Odoo 18
How to Use Upgrade Code Command in Odoo 18How to Use Upgrade Code Command in Odoo 18
How to Use Upgrade Code Command in Odoo 18
Celine George
 
Peer Assessment_ Unit 2 Skills Development for Live Performance - for Libby.docx
Peer Assessment_ Unit 2 Skills Development for Live Performance - for Libby.docxPeer Assessment_ Unit 2 Skills Development for Live Performance - for Libby.docx
Peer Assessment_ Unit 2 Skills Development for Live Performance - for Libby.docx
19lburrell
 
The role of wall art in interior designing
The role of wall art in interior designingThe role of wall art in interior designing
The role of wall art in interior designing
meghaark2110
 
Classification of mental disorder in 5th semester bsc. nursing and also used ...
Classification of mental disorder in 5th semester bsc. nursing and also used ...Classification of mental disorder in 5th semester bsc. nursing and also used ...
Classification of mental disorder in 5th semester bsc. nursing and also used ...
parmarjuli1412
 

Skip lists (Advance Data structure)

  • 2. Skip Lists 2 Outline and Reading  What is a skip list  Operations  Search  Insertion  Deletion  Implementation  Analysis  Space usage  Search and update times
  • 3. Intro to Skip Lists  Motivation:  Unordered Arrays:  Searching and removing takes O(n) times  Inserting takes O(1) times  Ordered Arrays:  Searching takes O(log n) times  Inserting and removing takes O(n) times ► Unordered LL: fast insertion, slow search ► Ordered LL: slow insertion, slow search  Basic idea of skip lists  Organize ordered list hierarchically so we don’t need to scan all elements in search Skip Lists 3
  • 4. Skip Lists 4 What is a Skip List  A skip list for a set S of n distinct keys is a series of lists S0, S1 , … , Sh such that  Each list Si contains the special keys + and -  List S0 contains the keys of S in nondecreasing order  Each list is a subsequence of the previous one, i.e., S0  S1  …  Sh  List Sh contains only the two special keys 56 64 78 +31 34 44- 12 23 26 +- +31- 64 +31 34- 23 S0 S1 S2 S3
  • 5. Skip Lists 5 Skip List Node  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 above  Also, we define special keys PLUS_INF and MINUS_INF, and we modify the key comparator to handle them x quad-node
  • 6. Skip Lists 6 Search  Steps for search a key x in a a skip list:  Start at the first position of the top list  At the current position p, we compare x with y  key(next(p)) x = y: Return next(p) x > y: Scan forward x < y: Drop down  Repeat the above step. (If “drop down” pasts the bottom list, return null.)  Example: search for 78 +- S0 S1 S2 S3 +31- 64 +31 34- 23 56 64 78 +31 34 44- 12 23 26 scan forward drop down Find the interval where x belong to…
  • 30. Implementation (1/2) Skip Lists 30 Resutls due to different randomization Another linked list implementation
  • 31. Skip Lists 31 Implementation (2/2)  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 above  Also, we define special keys PLUS_INF and MINUS_INF, and we modify the key comparator to handle them x quad-node
  • 32. Skip Lists 32 Outline and Reading  What is a skip list  Operations  Search  Insertion  Deletion  Implementation  Analysis  Space usage  Search and update times
  • 33. Skip Lists 33 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  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
  • 34. Skip Lists 34  To insert an item x into a skip list, we use a randomized algorithm:  We repeatedly toss a coin until we get tails, and we denote with i the number of times the coin came up heads  If i  h, we add to the skip list new lists Sh+1, … , Si +1, each containing only the two special keys  We search for x in the skip list and find the positions p0, p1 , …, pi of the items with largest key less than x in each list S0, S1, … , Si  For j  0, …, i, we insert item x into list Sj after position pj  Example: insert key 15, with i = 2 Insertion +- 10 36 +- 23 23 +- S0 S1 S2 +- S0 S1 S2 S3 +- 10 362315 +- 15 +- 2315 p0 p1 p2 n nodes n/2 nodes in average n/4 nodes in average
  • 35. Skip Lists 35 Deletion  To remove an item with key x from a skip list, we proceed as follows:  We search for x in the skip list and find the positions p0, p1 , …, pi of the items with key x, where position pj is in list Sj  We remove positions p0, p1 , …, pi from the lists S0, S1, … , Si  We remove all but one list containing only the two special keys  Example: remove key 34 - +4512 - + 23 23- + S0 S1 S2 - + S0 S1 S2 S3 - +4512 23 34 - +34 - +23 34 p0 p1 p2
  • 36. Skip Lists 36 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/2i Fact 2: If each of n items is present in a set with probability p, the expected size of the set is np  Consider a skip list with n items  By Fact 1, we insert an item in list Si with probability 1/2i  By Fact 2, the expected size of list Si is n/2i  The expected number of nodes used by the skip list is nnn n h h i i h i i 2 2 1 2 2 1 2 00 <      -==  == Thus, the expected space usage of a skip list with n items is O(n)
  • 37. Skip Lists 37 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 items  By Fact 1, we insert an item in list Si with probability 1/2i  By Fact 3, the probability that list Si has at least one item is at most n/2i  By picking i = 3log n, we have that the probability that S3log n has at least one item is at most n/23log n = n/n3 = 1/n2  Thus a skip list with n items has height at most 3log n with probability at least 1 - 1/n2
  • 38. Search and Update Times  The search time in a skip list is proportional to the sum of  #drop-downs  #scan-forwards  #drop-downs  Bounded by the height of the skip list  O(log n)  #scan-forwards  Each scan forward bounded by nodes in an interval  O(2) in average for each scan forward  O(log n) overall.  Thus the complexity for search in a skip list is O(log n)  The analysis of insertion and deletion gives similar results Skip Lists 38
  • 39. Skip Lists 39 Summary  A skip list is a data structure for dictionaries that uses a randomized insertion algorithm  In a skip list with n items  The expected space used is O(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

Editor's Notes

  • #34: 二○一八年十月十六日
  翻译: