2 Skip ListMotivation:sorted arrays are nice for binary search, but they are bad when you add or remove elementsalternative to AVL treesSkip List – a probabilistic extension of the linked list data structure to speed up the searching processbased on multiple parallel, sorted linked listshas high probability of logarithmic running time
3 Skip List (2) We want to: Solution: create use sorted link lists to achieve logarithmic running times, but there is no mechanism for finding the middle node in a linked list in O(1) timeSolution:Have n-levels of linked lists, with each level having probability p that an element exists at that level
4 Skip List Construction Use some probability p that an element appears in the next level of skip listsStart with all elements in the bottom level.Use a pseudo random number generator modulo (1/p) to determine if an element exists in the next level up.Stop this process when no elements are chosen to exist in the next level up
5 Skip List InsertionIf p = ½ and we add a new element to the skip list, the following are the probabilities of the element appearing on the next levels:1 that is it is a level-0 node1/2 that it is a level-1 node1/4 that it is a level-2 node1/8 that it is a level-3 node1/16 that it is a level-4 node1/32 that it is a level-5 node
7 Searching a Skip ListScan Forward Step – move a pointer along the current level until it is at the right-most position on the present level with a key <= kIf a node is found that matches the key, returns its valueDrop Down Step – if you are not in the bottom row, move down one level in the skip list. If you are, then no element exists with that key
8 Skip List Implementation Today you'll be implementing the Skip List data structureSimplifying Assumptionskeys are unique positive integersby default, allocate space for 20 levelsour skip lists only store keys, but not dataWe provided implementation for the insert function, but not remove or find functions
Your consent to our cookies if you continue to use this website.