csc 172 data structures

26
CSC 172 DATA STRUCTURES

Upload: ella

Post on 07-Jan-2016

39 views

Category:

Documents


0 download

DESCRIPTION

CSC 172 DATA STRUCTURES. SKIP LISTS Read Weiss 10.4.2. SKIP LISTS. Dictionary Data Structure Efficient. SKIP LISTS. Dictionary Data Structure (insert delete lookup) Efficient O(lg n). SKIP LISTS. Dictionary Data Structure (insert delete lookup) Efficient O(lg n). SKIP LISTS. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: CSC 172  DATA STRUCTURES

CSC 172 DATA STRUCTURES

Page 2: CSC 172  DATA STRUCTURES

SKIP LISTSRead Weiss 10.4.2

Page 3: CSC 172  DATA STRUCTURES

SKIP LISTS Dictionary Data Structure Efficient

Page 4: CSC 172  DATA STRUCTURES

SKIP LISTS Dictionary Data Structure (insert delete lookup) Efficient O(lg n)

Page 5: CSC 172  DATA STRUCTURES

SKIP LISTS Dictionary Data Structure (insert delete lookup) Efficient O(lg n)

Page 6: CSC 172  DATA STRUCTURES

SKIP LISTS Dictionary Data Structure Efficient (with high probability) Randomized

Page 7: CSC 172  DATA STRUCTURES

SKIP LISTS Dictionary Data Structure Efficient (with high probability) Randomized Easy to implement

Page 8: CSC 172  DATA STRUCTURES

LISTS

How much time does it take to search a sorted linked list?

How can this be improved?

Page 9: CSC 172  DATA STRUCTURES

EXAMPLE

Page 10: CSC 172  DATA STRUCTURES

EXAMPLE What is this sequence?

14,23,28,34,42,50,59,66,72,79,86,96,103,110

Page 11: CSC 172  DATA STRUCTURES

EXAMPLE What is this sequence?

14,23,34,42,50,59,66,72,79,86,96,103,110

Page 12: CSC 172  DATA STRUCTURES

EXAMPLE What is this sequence?

14,23,34,42,50,59,66,72,79,86,96,103,110,116,125

Page 13: CSC 172  DATA STRUCTURES

SKIP LISTS Use two lists L

2 stores all element

L1 stores some elements

Links between shared elements

Page 14: CSC 172  DATA STRUCTURES

Lookup on a skip list

Page 15: CSC 172  DATA STRUCTURES

Lookup on a skip list

1)Take L1 until you go too far2)Back up one3)Transfer to L24)Take L2 until you find element

(or go too far – not found – or insert)

Page 16: CSC 172  DATA STRUCTURES

Lookup on a skip list

How should we distribute the L1 list? What is the time cost of a search?

Page 17: CSC 172  DATA STRUCTURES

Lookup on a skip list

How should we distribute the L1 list? What is the time cost of a search?

Minimize : L1.length + (L2.length/L1.length)

Page 18: CSC 172  DATA STRUCTURES

NEXT STEP 2 linked lists 2(n^(1/2)) Can we improve this further?

Page 19: CSC 172  DATA STRUCTURES

NEXT STEP 2 linked lists 2(n^(1/2)) Can we improve this further? 3 linked lists 3(n^(1/3)) k linked lists k(n^(1/k)) N linked lists ???? lg n linked lists lg n (n^(1/lg n))

Page 20: CSC 172  DATA STRUCTURES

BALLANCED SKIP LISTS Ideal as long as structure is maintained

Page 21: CSC 172  DATA STRUCTURES

BALLANCED SKIP LISTS Ideal as long as structure is maintained Insertions and deletions mess up structure

Page 22: CSC 172  DATA STRUCTURES

INSERTION ON SKIP LISTS Search to find location Must insert on bottom list Which other lists? FLIP A COIN

If heads add to level above and flip again. If tails done.

Page 23: CSC 172  DATA STRUCTURES

INSERTION ON SKIP LISTS FLIP A COIN

If heads add to level above and flip again. If tails done.

½ of the elements go up one level¼ of the elements go up 2 levels1/8 of the elements go up 3 levels

Page 24: CSC 172  DATA STRUCTURES

INSERTION ON SKIP LISTS EXAMPLE

Page 25: CSC 172  DATA STRUCTURES

ANALYSIS Intuitively:

Height of the structure is O(lg n)How many coin flips do we need to get lg n heads?

Page 26: CSC 172  DATA STRUCTURES