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! 5664 313444 122326 31 64 31 44 23 S0S0 S1S1 S2S2 S3S3 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 S0S0 S1S1 S2S2 S3S3 31 64 3134 23 56 6478 313444 122326
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) 5664 313444 122326 31 64 31 44 23 S0S0 S1S1 S2S2 S3S3 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 S h 1, …, S i 1, each containing only the two special keys – 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 0, S 1, …, S i – For j 0, …, i, we insert item (x, o) into list S j after position p j Example: insert key 15, with i 2 Insertion 10 36 23 S0S0 S1S1 S2S2 S0S0 S1S1 S2S2 S3S3 103623 15 2315 p0p0 p1p1 p2p2
Insertion - Example Consider inserting the value 8 into the skip list below, and assume that the new node is assigned to level 2:
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
Your consent to our cookies if you continue to use this website.