Skip list

Skip list

Invented in 1990 by William Pugh, a skip list is a probabilistic data structure, based on multiple parallel, sorted linked lists, with efficiency comparable to a binary search tree (order log "n" average time for most operations).

Underlying the skip list is an augmentation of an ordered linked list with additional forward links, added in a randomized way with a geometric/negative binomial distribution [cite journal |last=Pugh |first=William |title=Skip lists: a probabilistic alternative to balanced trees |journal=Communications of the ACM |volume=33 |issue=6 |year=1990 |month=June |pages=668–676 |doi=10.1145/78973.78977] , so that a search in the list may quickly skip parts of the list (hence the name). Insert, search and delete operations are performed in logarithmic randomized time.

Description

A skip list is built in layers. The bottom layer is an ordinary ordered linked list. Each higher layer acts as an "express lane" for the lists below, where an element in layer "i" appears in layer "i"+1 with some fixed probability "p" (two commonly-used values for "p" are 1/2 or 1/4). On average, each element appears in 1/(1-"p") lists, and the tallest element (usually a special head element at the front of the skip list) in log_{1/p} n, lists.

A search for a target element is started with the head element in the top list, and proceeds horizontally until the current element is greater than or equal to the target. If the current element is equal to the target, it has been found. If the current element is greater than the target, go back to the previous element and drop down vertically to the next lower list and repeat the procedure. The expected number of steps in each linked list is easily seen to be 1/"p", by tracing the search path backwards from the target until reaching an element that appears in the next higher list. So the total "expected" cost of a search is (log_{1/p} n)/p,, which is mathcal{O}(log n), when "p" is a constant. By choosing different values of "p", it is possible to trade search costs against storage costs.

Implementation Details

Although the above diagram is drawn as several, separate linked lists with some repeated node values--implying a total of 1+3+5+10 = 19 total nodes, in practice one would not implement a skip list this way because of the "drop down vertically" step. In fact there are only 10 total nodes in the diagram, but several of them contain more than one pointer.

Insertions and deletions are implemented much like the corresponding linked-list operations, except that "tall" elements must be inserted into or deleted from more than one linked list.

Θ(n) operations, which force us to visit every node in ascending order (such as printing the entire list) provide the opportunity to perform a behind-the-scenes derandomization of the level structure of the skip-list in an optimal way, bringing the skip list to mathcal{O}(log n) search time (Choose the level of the i'th finite node to be 1 plus the number of times we can repeatedly divide i by 2 before it becomes odd. Also, i=0 for the negative infinity header as we have the usual special case of choosing the highest possible level for negative and/or positive infinite nodes.). However this also allows someone to know where all of the higher-than-level 1 nodes are and delete them.

Alternatively, we could make the level structure quasi-random in the following way:

make all nodes level 1 j = 1 while the number of nodes at level j > 1 for each i'th node at level j if i is odd if i is not the last node at level j randomly choose whether to promote it to level j+1 else do not promote end if else if i is even and node i-1 was not promoted promote it to level j+1 end if end for j = j + 1 end while

Like the derandomized version, quasi-randomization is only done when there is some other reason to be running a Θ(n) operation (which visits every node).

The advantage of this quasi-randomness is that it doesn't give away nearly as much level-structure related information to an adversarial user as the de-randomized one. This is desirable because an adversarial user who is able to tell which nodes are not at the lowest level can pessimize performance by simply deleting higher-level nodes. The search performance is still guaranteed to be logarithmic.

It would be tempting to make the following "optimization": In the part which says "Next, for each i'th...", forget about doing a coin-flip for each even-odd pair. Just flip a coin once to decide whether to promote only the even ones or only the odd ones. Instead of Θ(n lg n) coin flips, there would only be Θ(lg n) of them. Unfortunately, this gives the adversarial user a 50/50 chance of being correct upon guessing that all of the even numbered nodes (among the ones at level 1 or higher) are higher than level one. This is despite the property that he has a very low probability of guessing that a particular node is at level N for some integer N.

The following proves these two claims concerning the advantages of quasi-randomness over the totally derandomized version. First, to prove that the search time is guaranteed to be logarithmic. Suppose a node n is searched for, where n is the position of the found node among the nodes of level 1 or higher. If n is even, then there is a 50/50 chance that it is higher than level 1. However, if it is not higher than level 1 then node n-1 is guaranteed to be higher than level 1. If n is odd, then there is a 50/50 chance that it is higher than level 1. Suppose that it is not; there is a 50/50 chance that node n-1 is higher than level 1. Suppose that this is not either; we are guaranteed that node n-2 is higher than level 1. The analysis can then be repeated for nodes of level 2 or higher, level 3 or higher, etc. always keeping in mind that n is the position of the node among the ones of level k or higher for integer k. So the search time is constant in the best case (if the found node is the highest possible level) and 2 times the worst case for the search time for the totally derandomized skip-list (because we have to keep moving left twice rather than keep moving left once).

Next, an examination of the probability of an adversarial user's guess of a node being level k or higher being correct. First, the adversarial user has a 50/50 chance of correctly guessing that a particular node is level 2 or higher. This event is independent of whether or not the user correctly guesses at some other node being level 2 or higher. If the user knows the positions of two consecutive nodes of level 2 or higher, and knows that the one on the left is in an odd numbered position among the nodes of level 2 or higher, the user has a 50/50 chance of correctly guessing which one is of level 3 or higher. So, the user's probability of being correct, when guessing that a node is level 3 or higher, is 1/4. Inductively continuing this analysis, we see that the user's probability of guessing that a particular node is level k or higher is 1/(2^(k-1)).

The above analyses only work when the number of nodes is a power of two. However, because of the third rule which says, "Finally, if i is odd and also the last node at level 1 then do not promote." (where we substitute the appropriate level number for 1) it becomes a sequence of exact-power-of-two-sized skiplists, concatenated onto each other, for which the analysis does work. In fact, the exact powers of two correspond to the binary representation for the number of nodes in the whole list.

A skip list, upon which we have not recently performed either of the above mentioned Θ(n) operations, does not provide the same absolute worst-case performance guarantees as more traditional balanced tree data structures, because it is always possible (though with very low probability) that the coin-flips used to build the skip list will produce a badly balanced structure. However, they work well in practice, and the randomized balancing scheme has been argued to be easier to implement than the deterministic balancing schemes used in balanced binary search trees. Skip lists are also useful in parallel computing, where insertions can be done in different parts of the skip list in parallel without any global rebalancing of the data structure. Such parallelism can be especially advantageous for resource discovery in an ad-hoc Wireless network because a randomized skip list can be made robust to the loss of any single node [cite paper | last=Shah | first=Gauri Ph.D. | coauthors=James Aspnes | title=Distributed Data Structures for Peer-to-Peer Systems | date=December 2003 | url=http://www.cs.yale.edu/homes/shah/pubs/thesis.pdf | format=PDF | accessdate=2008-09-23] .] .

There has been some evidence that skip lists have worse real-world performance and space requirements than B trees due to memory locality and other issues [http://resnet.uoregon.edu/~gurney_j/jmpc/skiplist.html] .

History

Skip lists were invented by William Pugh. He details how they work in "Skip lists: a probabilistic alternative to balanced trees" in Communications of the ACM, June 1990, 33(6) 668-676.See also [http://citeseer.ist.psu.edu/pugh90skip.html citations] and [ftp://ftp.cs.umd.edu/pub/skipLists/ downloadable documents] .

To quote the inventor:

:"Skip lists are a probabilistic data structure that seem likely to supplant balanced trees as the implementation method of choice for many applications. Skip list algorithms have the same asymptotic expected time bounds as balanced trees and are simpler, faster and use less space."

References

ee also

*Deterministic skip list

External links

* [http://people.ksp.sk/~kuko/bak/index.html Skip List Applet] by Kubo Kovac
* [http://www.sccnet.com.br/jackson/SkipList/index.php?link=implementacao Skip List Applet - Portuguese] by Jackson Porciúncula (very good)
* [http://nist.gov/dads/HTML/skiplist.html Skip list description] from the Dictionary of Algorithms and Data Structures
* [http://www.codeproject.com/csharp/SkipList1.asp A Skip List in C#]
* [http://dekorte.com/projects/opensource/SkipDB/ SkipDB, a BerkeleyDB-style database implemented using skip lists.]
* [ftp://ftp.cs.umd.edu/pub/skipLists/skiplists.pdf William Pugh's original paper]
* [http://iamwww.unibe.ch/~wenger/DA/SkipList/ Thomas Wenger's demo applet on skiplists]
* [http://www.cs.mu.oz.au/aia/SkipList.html A Java Applet that emphasizes more on visualizing the steps of the algorithm]
* [http://ocw.mit.edu/ans7870/6/6.046j/f05/lecturenotes/ocw-6.046-26oct2005.mp3 Prof. Erik Demaine's lecture on skip lists] from MIT's OpenCourseWare program. (Audio)
* [http://java.sun.com/javase/6/docs/api/java/util/concurrent/ConcurrentSkipListSet.html Java 6 ConcurrentSkipListSet]
* [http://infohost.nmt.edu/tcc/help/lang/python/examples/pyskip/ John Shipman's didactic zero-defect implementation in Python]
* [http://msdn.microsoft.com/en-us/library/ms379573.aspx An Extensive Examination of Data Structures Using C# 2.0: Building a Better Binary Search Tree]
* [http://www.codersource.net/csharp_skip_list.aspx C# Skip List: A Simpler Alternative to Binary Trees?]


Wikimedia Foundation. 2010.

Игры ⚽ Поможем сделать НИР

Look at other dictionaries:

  • Skip-list — Une Skip list (liste à enjambements) est une structure de données probabiliste, à base de listes chaînées parallèles. La plupart de ses opérations s effectuent en O(log n)[1] avec une grande probabilité. Sommaire 1 Description 2 Opération de… …   Wikipédia en Français

  • Skip list — Una skip list o lista por saltos es una Estructura de datos, basada en Listas enlazadas paralelas con eficiencia comparable a la de un árbol binario (tiempo en orden O(log n) para la mayoría de las operaciones). Una lista por saltos se construye… …   Wikipedia Español

  • Skip list — Una skip list o lista por saltos es una Estructura de datos, basada en Listas enlazadas paralelas con eficiencia comparable a la de un árbol binario (tiempo en orden O(log n) para la mayoría de las operaciones). Una lista por saltos se construye… …   Enciclopedia Universal

  • Skip liste — Skip list Une Skip list (liste à enjambements) est une structure de données probabiliste, à base de listes chaînées parallèles. La plupart de ses opérations s effectuent en O(log n)[1] avec une grande probabilité. Sommaire 1 Description 2… …   Wikipédia en Français

  • List of terms relating to algorithms and data structures — The [http://www.nist.gov/dads/ NIST Dictionary of Algorithms and Data Structures] is a reference work maintained by the U.S. National Institute of Standards and Technology. It defines a large number of terms relating to algorithms and data… …   Wikipedia

  • Skip (homonymie) — Cette page d’homonymie répertorie les différents sujets et articles partageant un même nom. Sur les autres projets Wikimedia : « Skip (homonymie) », sur le Wiktionnaire (dictionnaire universel) Un skip est une benne roulant sur un… …   Wikipédia en Français

  • List of combinatorics topics — This is a list of combinatorics topics.A few decades ago it might have been said that combinatorics is little more than a way to classify poorly understood problems, and some standard remedies. Great progress has been made since 1960.This page is …   Wikipedia

  • Skip James — The only photograph of James in his youth. Background information Birth name Nehemiah Curtis James Born …   Wikipedia

  • List of Skip Beat chapters — Skip Beat! by Yoshiki Nakamura is currently being published in Japan by Hakusensha. It is being serialized in the magazine Hana to Yume since February of 2005. In North America it is being published by the Shojo Beat label. There are currently 19 …   Wikipedia

  • Skip Weshner — (1927 1995) was a disc jockey on stations in New York and Los Angeles from the mid 1950 s until the mid 1980 s. In particular, he hosted a popular show on KRHM FM in Los Angeles. He hosted Accent On Sound on WBAI (FM) and later WNCN (FM) in New… …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”