skip lists present by pakdee pattanajedsada 530632030 sitthichok snansieng 530632034 siwakorn...
TRANSCRIPT
Skip Lists
Present ByPAKDEE PATTANAJEDSADA 530632030
SITTHICHOK SNANSIENG 530632034SIWAKORN THAMMAYTHA 530632032
PATOMPOL TAESUJI 530632101
Outline
• Introduction• ADT• Implementation & Complexity– Search– Insert– Remove
Introduction “Skip Lists”“Skip Lists” were developed around 1989 by William
Pugh of the University of Maryland. Professor Pugh sees Skip Lists as a viable alternative to balanced trees such as AVL trees or to self-adjusting trees such as splay trees.
The find, insert, and remove operations on ordinary binary search trees are efficient,
when the input data is random; but less efficient, when the input data are ordered. Skip List
performance for these same operations and for any data set is about as good as that of randomly-built binary search trees – namely,
Skip List performance :
Skip Lists are sorted linked lists with two differences:• the nodes in an ordinary list have one 'next'
reference. The nodes in a Skip List have many 'next' references (called forward references).
• the number of forward references for a given node is determined probabilistically.
We speak of a Skip List node having levels, one level per forward reference. The number of levels in a node is called the size of the node.
In an ordinary sorted list, insert, remove, and find operations require sequential traversal of the list. This results in performance per operation. “Skip Lists” allow intermediate nodes in the list to be ``skipped'' during a traversal - resulting in an expected performance of per operation.
Skip List - ADT Specialized Method• after(p): Return position
after p on same level.• before(p): Return position
before p on same level.• below(p): Return position
below p on same tower.• above(p): Return position
above p on same tower.
Return null if no position!
56 64 +31 34 44- 12 23 26
+-
+31-
64 +31 44- 23
S0
S1
S2
S3
72
Search(x)• We search for a key x in a a skip list as follows:
– We start at the first position of the top list – At the current position p, we compare x with y key(after(p))
x = y: we return element(after(p))x > y: we “scan forward” x < y: we “drop down”
– If we try to drop down past the bottom list, we return NO_SUCH_KEY• Example: search for 78
+-
S0
S1
S2
S3
+31-
64 +31 34- 23
56 64 78 +31 34 44- 12 23 26
Example of a (perfect)Skip List
Complexity• 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 O(log n) with high probability
• Worst Case -> O(n)
56 64 +31 34 44- 12 23 26
+-
+31-
64 +31 44- 23
S0
S1
S2
S3
72
• To insert an item (x, o) 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, o) 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
+- 2315p0
p1
p2
Insertion - Example
• Consider inserting the value 8 into the skip list below, and assume that the new node is
• assigned to level 2:
Insertion - Example
Insertion - Example
Insertion - Example
Insertion – Pseudo code
Insertion - Psudocode
Deletion(List, keySearch)• Logically, deleting a node should be the opposite of insertion. The same
basic principles• apply:
- first we must find the node that precedes the node to be deleted, if any, remembering
• the nodes containing "pass" pointers- if the succeeding node contains the targeted key value- update the "pass" pointers that point to the target node- delete the targeted node- if necessary, adjust the head node to reduce the number of levels in the list
Example Delete of Skip List
Example Deletion of Skip List
• deletion begin with a search, which will probably have cost Θ( log N ) .
Deletion Code
Reference
• Skip Lists This document was generated using the LaTeX2HTML translator Version 99.1 release (March 30, 1999)
• Copyright © 1993, 1994, 1995, 1996, Nikos Drakos, Computer Based Learning Unit, University of Leeds. Copyright © 1997, 1998, 1999, Ross Moore, Mathematics Department, Macquarie University, Sydney.
• The command line arguments were: latex2html -split 0 -no_navigation skip_lists.tex
• The translation was initiated by Thomas Anastasio on 2000-02-19
Question & Answer
Q&A