# day16 - COP 3502H Advanced List Structures(Day 16...

This preview shows pages 1–3. Sign up to view the full content.

Introduction to Skip Lists Linked lists have one serious drawback: They require sequential scanning to locate an element during a search. The search must start from the beginning of the list and terminates when either the search element is found or the end of the list is encountered without finding the search element. Ordering the elements in the list can speed up the searching, but a linear (sequential) search is still required. There have been several hybrid list structures that have been developed which allow searching in a list to occur in other than sequential fashion. Most commonly these techniques allow the search to “skip over” certain nodes in the list to avoid the cost of the sequential search. The skip list is one such variant of the ordered list which make nonsequential searching possible. A Simple Skip List Can you think of a simple way to reduce the worst case “cost” (in terms of the potential number of comparisons that need to be made against the search element) of a search in an ordered linear list of n nodes from n comparisons to n/2+1 comparisons? The way to do this is to maintain one additional pointer (reference) to the middle element in the list. With this single additional reference, all searches begin with a comparison against this middle list element. If the search is for an element smaller than the middle element, the only the left- half of the list need to be searched and if the search element is larger than the middle element, only the right-half of the list will be searched. This technique is basically the simplest form of a skip list. In general, skip lists will reduce the cost of a given search much more dramatically, as we will shortly discover. Figures 1 and 2 shown below, illustrate the simple skip list principle. (Figure 1) A simple ordered linked list with head and tail nodes Advanced List Structures - 1 COP 3502H - Advanced List Structures (Day 16) 20 24 30 40 60 75 80

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Now consider the simple ordered list shown above with the addition of a single pointer to the middle of the list, which in this case is the node containing the element 40. This new list is shown in the Figure 2. (Figure 2) A simple skip list with a pointer to the middle of the list The number of nodes in the list in the two figures above is seven. If the search in the original ordered list were for the value 80, exactly seven ( n ) comparisons with values in the list would be performed before the search element was located in the list. Using the simple skip list the number of comparisons for this search decreases to exactly four ( n/2+1 ). Skip Lists Skip lists, in general, extend the concept illustrated above with the simple skip lists to various levels of extreme. The level to which the skip list is extended depends upon the desired level of trade-off between the increasing level of complexity of the structure and the benefit in terms of reducing the number of comparisons required per search. Consider the skip list illustrated in Figure 3:
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 21

day16 - COP 3502H Advanced List Structures(Day 16...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online