l12_skiplists

l12_skiplists - Introduction to Algorithms Massachusetts...

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

View Full Document Right Arrow Icon
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, first search in L 1 until about to go too far, then go down and search in L 2
Background image of page 1

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

View Full DocumentRight Arrow Icon
±² ³ 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
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

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 Right Arrow Icon
Ask a homework question - tutors are online