l12_skiplists

# l12_skiplists - Introduction to Algorithms Massachusetts...

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

Introduction to Algorithms October 25, 2005 Massachusetts Institute of Technology 6.046J/18.410J Professors Erik D. Demaine and Charles E. Leiserson Handout 17 Lecture Notes on Skip Lists Lecture 12 October 26, 2005 Erik Demaine Balanced tree structures we know at this point: red-black trees, B-trees, treaps. Could you implement them right now? Probably, with time. . . but without looking up any details? Skip lists are a simple randomized structure you’ll never forget. Starting from scratch Initial goal: just searches ignore updates (Insert/Delete) for now Simplest data structure: linked list Sorted linked list: ( n ) time 2 sorted linked lists: Each element can appear in 1 or both lists How to speed up search? Idea: Express and local subway lines Example: 14 , 23, 34 , 42 , 50, 59, 66, 72 , 79, 86, 96 , 103, 110, 116, 125 (What is this sequence?) Boxed values are “express” stops; others are normal stops Can quickly jump from express stop to next express stop, or from any stop to next normal stop Represented as two linked lists, one for express stops and one for all stops: 14 14 23 34 42 72 96 34 42 72 96 50 59 66 79 86 103 110 116 125 Every element is in bottom linked list ( L 2 ); some elements also in top linked list ( L 1 ) Link equal elements between the two levels To search, ﬁrst search in L 1 until about to go too far, then go down and search in L 2

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

View Full Document
±² ³ 2 Handout 17: Lecture Notes on Skip Lists Cost: Minimized when | L 1 | + | L 2 | | L 1 | = | L 1 | + n | L 1 | n | L 1 | = | L 1 | | L 1 | 2 = n | L 1 | = n search cost = 2 n Resulting 2-level structure: sqrt n sqrt n sqrt n sqrt n sqrt n 3 3 linked lists: 3 n · k k linked lists: k n · lg n
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 04/12/2011 for the course MATH 6.046J taught by Professor Demaine during the Fall '10 term at MIT.

### Page1 / 6

l12_skiplists - Introduction to Algorithms Massachusetts...

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

View Full Document
Ask a homework question - tutors are online