Skip List: ADS Skip List Iii I.T - I Sem
Skip List: ADS Skip List Iii I.T - I Sem
SKIP LIST
Skip List Skip list is a variant list for the linked list. Skip lists are made up of a series of nodes connected one after the other. Each node contains a key and value pair as well as one or more references or pointers to nodes further along in the list. The number of references each node contains is determined randomly. This gives skip lists their probabilistic nature, and the number of references a node contains is called its node level. There are two special nodes in the skip list one is head node which is the starting node of the list which consists of every level of pointer and tail node is the last node of the list. The skip list is an efficient implementation of dictionary using sorted chain. This is because in skip list each node consists of forward references of more than one node at a time. A skip list S for a map M consists of a series of lists { So , S1 , .. . , Sh,}. Each list Si stores a subset of the entries of M sorted by increasing order of keys. In addition, the lists in S satisfy the following: List So which is in level 0 contains every entry of the map M List S1 which is in level 1 includes every second element of S0 List. List S2 which is in level 2 includes every fourth element of S1 list. Similarly List Si which is in level I includes every 2I th element of its previous Si-1 list An element is a level i element iff it is in the chains from levels 0 through i
Page 1
ADS
SKIP LIST
Search Operation Searching for a key with in a skip list begins at the header from the highest level of skip list and moving forward in the list comparing node keys to the key_val. If the node key is less than the key_val, the search continues moving forward at the same level. If the node key is equal to or greater than the key_val, the search drops down one level in the same node and continues forward. This process continues until the desired key_val has been found if it is present in the skip list. If it is not, the search will either continue to the end of the list or until the first key with a value greater than the search key is found.
Page 2
ADS
SKIP LIST
Insertion into skip list There are two tasks that should be done before insertion operation 1. Before insertion of any new node, the place for this new node in the skip list is searched. Hence before any insertion to take place the search routine executes. The update[ ] array in the search routine is used to keep track of the references to the
nodes where the search drops down one level. update[i] contains a pointer to the rightmost node of level i or higher that is to the left of the location of the insertion. If an insertion generates a node with a level greater than the previous maximum level of the list, we update the maximum level of the list and initialize the appropriate portions of the update vector.
Page 3
ADS
SKIP LIST
2. The level for the new node is retrieved by the routine randomLevel( ). Then a new node is actually created and inserted in the skip list in the specific level. Determining the level of new node When a new element is inserted into the list, a node with a random level is inserted to represent the element. Random levels are generated on the basis of probabilistic approach with a simple pattern: 50% are level 1, 25% are level 2, 12.5% are level 3 and so on. To get away from these conventions, consider fraction p of the nodes with level i pointers also have level i+1 pointers where p=1/2. Levels are generated without reference to the number of elements in the list.
Page 4
ADS
SKIP LIST
For example
Deletion from skip list First of all, the deletion makes use of search algorithm and searches the node that is to be deleted. If the key to be deleted is found, the node containing the key is removed. While searching, a vector update[ ] is maintained so that when the search is complete update[i] contains a pointer to the rightmost node of level i or higher that is to the left of the location of the deletion. After each deletion, we check if we have deleted the maximum element of the list and if so, decrease the maximum level of the list. Algorithm for Deletion
Page 5
ADS
SKIP LIST
For example
Analysis of Skip List Operations The time required to execute the Search, Delete and Insert operations is dominated by the time required to search for the appropriate element. For the Insert and Delete operations, there is an additional cost proportional to the level of the node being inserted or deleted. The time required to find an element is proportional to the length of the search path, which is determined by the pattern in which elements with different levels appear as we traverse the list. Despite the poor worst case performance, skip list are a valuable representation method, as the expected complexity of methods insert, delete and search is O(log n).
Page 6