1 / 12

CMSC420: Skip Lists

CMSC420: Skip Lists. Kinga Dobolyi Based off notes by Dave Mount. What is the purpose of this class?. Data storage Speed Trees Binary search tree Could degenerate into a linked list AVL tree Better performance, difficult to implement Splay tree Good overall performance -- amortized.

jenis
Download Presentation

CMSC420: Skip Lists

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CMSC420: Skip Lists Kinga Dobolyi Based off notes by Dave Mount

  2. What is the purpose of this class? • Data storage • Speed • Trees • Binary search tree • Could degenerate into a linked list • AVL tree • Better performance, difficult to implement • Splay tree • Good overall performance -- amortized

  3. Can we do “better” • Linked list • Simple to implement • Poor runtime: O(n) • Better runtime • Guaranteed O(logn) • Difficult to implement • Can we have both for general data? • What are the tradeoffs?

  4. Skip Lists • Generalization of a linked list • O(logn) runtime of balanced trees • What is the trick? • Randomized data structure • Efficient in the expected case • Unlike BST, the expected case has nothing to do with the order of the keys being inserted • Probability that it performs badly is very small

  5. General idea • How can we make linked lists better? • Why are lists crummy? What takes forever? • What if we could skip over many elements at a time?

  6. Implementation • Start with a sorted linked list • Add another layer linking every other element • Repeat for that layer, etc • Think of as a hierarchy of sorted linked lists

  7. Skip list runtime • How high does this stack go? • Level 0: n • Level 1: n/2 • Level 2: n/4 • Height of stack will be logn • So search through the skiplist will be O(logn) • But can we maintain this guarantee of efficiency?

  8. Perfect vs Random Skip List • What we just described is a perfect skip list • What happens when you add or delete elements? • To maintain perfect balance • Random skip list • Need to decide when to promote a node to some i level • Use randomization, with a chance of 50%, to decide when to promote a node

  9. Random Skip list • If, on average, we promote half of the nodes at every level • Our skiplist will maintain this O(logn) property in the expected case • It is also likely that, overall, nodes will have a uniform distribution and not bunch up at the ends

  10. Insertion

  11. Exercise • Argue that the expected runtime of search in a skiplist is in O(logn) • What about insertion and deletion?

  12. Easy to implement • For details, see Dave Mount’s notes (linked from website)

More Related