Download presentation

Presentation is loading. Please wait.

Published byElvis Castillon Modified over 3 years ago

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 Mounts notes (linked from website)

Similar presentations

Presentation is loading. Please wait....

OK

CS 225 Lab #11 – Skip Lists.

CS 225 Lab #11 – Skip Lists.

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Ppt on polynomials download youtube A ppt on artificial intelligence Ppt on is matter around us pure Ppt on railway track laying Pulmonary anatomy and physiology ppt on cells Ppt on column chromatography principle Ppt on nuclear family and joint family images Ppt on conservation of soil Ppt on effect of global warming on weather radar Ppt on classroom management