Download presentation

Presentation is loading. Please wait.

1
CS 225 Lab #11 – Skip Lists

2
Skip List Motivation: sorted arrays are nice for binary search, but they are bad when you add or remove elements alternative to AVL trees Skip List – a probabilistic extension of the linked list data structure to speed up the searching process based on multiple parallel, sorted linked lists has 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) time Solution: 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 lists Start 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 Insertion If 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 node 1/2 that it is a level-1 node 1/4 that it is a level-2 node 1/8 that it is a level-3 node 1/16 that it is a level-4 node 1/32 that it is a level-5 node

6
**Skip List Insertion (2)**

7
Searching a Skip List Scan Forward Step – move a pointer along the current level until it is at the right-most position on the present level with a key <= k If a node is found that matches the key, returns its value Drop 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 structure Simplifying Assumptions keys are unique positive integers by default, allocate space for 20 levels our skip lists only store keys, but not data We provided implementation for the insert function, but not remove or find functions

Similar presentations

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google