WARM-UP. Chapter 9 (Standards 10.4.1 / 10.4.2) THE AGE OF IMPERIALISM.
CSC 172 DATA STRUCTURES. SKIP LISTS Read Weiss 10.4.2.
-
Upload
ariel-medina -
Category
Documents
-
view
224 -
download
4
Transcript of CSC 172 DATA STRUCTURES. SKIP LISTS Read Weiss 10.4.2.
![Page 1: CSC 172 DATA STRUCTURES. SKIP LISTS Read Weiss 10.4.2.](https://reader035.fdocuments.us/reader035/viewer/2022062712/56649c785503460f9492dd7e/html5/thumbnails/1.jpg)
CSC 172 DATA STRUCTURES
![Page 2: CSC 172 DATA STRUCTURES. SKIP LISTS Read Weiss 10.4.2.](https://reader035.fdocuments.us/reader035/viewer/2022062712/56649c785503460f9492dd7e/html5/thumbnails/2.jpg)
SKIP LISTSRead Weiss 10.4.2
![Page 3: CSC 172 DATA STRUCTURES. SKIP LISTS Read Weiss 10.4.2.](https://reader035.fdocuments.us/reader035/viewer/2022062712/56649c785503460f9492dd7e/html5/thumbnails/3.jpg)
SKIP LISTS Dictionary Data Structure Efficient
![Page 4: CSC 172 DATA STRUCTURES. SKIP LISTS Read Weiss 10.4.2.](https://reader035.fdocuments.us/reader035/viewer/2022062712/56649c785503460f9492dd7e/html5/thumbnails/4.jpg)
SKIP LISTS Dictionary Data Structure (insert delete lookup) Efficient O(lg n)
![Page 5: CSC 172 DATA STRUCTURES. SKIP LISTS Read Weiss 10.4.2.](https://reader035.fdocuments.us/reader035/viewer/2022062712/56649c785503460f9492dd7e/html5/thumbnails/5.jpg)
SKIP LISTS Dictionary Data Structure (insert delete lookup) Efficient O(lg n)
![Page 6: CSC 172 DATA STRUCTURES. SKIP LISTS Read Weiss 10.4.2.](https://reader035.fdocuments.us/reader035/viewer/2022062712/56649c785503460f9492dd7e/html5/thumbnails/6.jpg)
SKIP LISTS Dictionary Data Structure Efficient (with high probability) Randomized
![Page 7: CSC 172 DATA STRUCTURES. SKIP LISTS Read Weiss 10.4.2.](https://reader035.fdocuments.us/reader035/viewer/2022062712/56649c785503460f9492dd7e/html5/thumbnails/7.jpg)
SKIP LISTS Dictionary Data Structure Efficient (with high probability) Randomized Easy to implement
![Page 8: CSC 172 DATA STRUCTURES. SKIP LISTS Read Weiss 10.4.2.](https://reader035.fdocuments.us/reader035/viewer/2022062712/56649c785503460f9492dd7e/html5/thumbnails/8.jpg)
LISTS
How much time does it take to search a sorted linked list?
How can this be improved?
![Page 9: CSC 172 DATA STRUCTURES. SKIP LISTS Read Weiss 10.4.2.](https://reader035.fdocuments.us/reader035/viewer/2022062712/56649c785503460f9492dd7e/html5/thumbnails/9.jpg)
EXAMPLE
![Page 10: CSC 172 DATA STRUCTURES. SKIP LISTS Read Weiss 10.4.2.](https://reader035.fdocuments.us/reader035/viewer/2022062712/56649c785503460f9492dd7e/html5/thumbnails/10.jpg)
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. SKIP LISTS Read Weiss 10.4.2.](https://reader035.fdocuments.us/reader035/viewer/2022062712/56649c785503460f9492dd7e/html5/thumbnails/11.jpg)
EXAMPLE What is this sequence?
14,23,34,42,50,59,66,72,79,86,96,103,110
![Page 12: CSC 172 DATA STRUCTURES. SKIP LISTS Read Weiss 10.4.2.](https://reader035.fdocuments.us/reader035/viewer/2022062712/56649c785503460f9492dd7e/html5/thumbnails/12.jpg)
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 Read Weiss 10.4.2.](https://reader035.fdocuments.us/reader035/viewer/2022062712/56649c785503460f9492dd7e/html5/thumbnails/13.jpg)
SKIP LISTS Use two lists L
2 stores all element
L1 stores some elements
Links between shared elements
![Page 14: CSC 172 DATA STRUCTURES. SKIP LISTS Read Weiss 10.4.2.](https://reader035.fdocuments.us/reader035/viewer/2022062712/56649c785503460f9492dd7e/html5/thumbnails/14.jpg)
Lookup on a skip list
![Page 15: CSC 172 DATA STRUCTURES. SKIP LISTS Read Weiss 10.4.2.](https://reader035.fdocuments.us/reader035/viewer/2022062712/56649c785503460f9492dd7e/html5/thumbnails/15.jpg)
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. SKIP LISTS Read Weiss 10.4.2.](https://reader035.fdocuments.us/reader035/viewer/2022062712/56649c785503460f9492dd7e/html5/thumbnails/16.jpg)
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. SKIP LISTS Read Weiss 10.4.2.](https://reader035.fdocuments.us/reader035/viewer/2022062712/56649c785503460f9492dd7e/html5/thumbnails/17.jpg)
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. SKIP LISTS Read Weiss 10.4.2.](https://reader035.fdocuments.us/reader035/viewer/2022062712/56649c785503460f9492dd7e/html5/thumbnails/18.jpg)
NEXT STEP 2 linked lists 2(n^(1/2)) Can we improve this further?
![Page 19: CSC 172 DATA STRUCTURES. SKIP LISTS Read Weiss 10.4.2.](https://reader035.fdocuments.us/reader035/viewer/2022062712/56649c785503460f9492dd7e/html5/thumbnails/19.jpg)
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. SKIP LISTS Read Weiss 10.4.2.](https://reader035.fdocuments.us/reader035/viewer/2022062712/56649c785503460f9492dd7e/html5/thumbnails/20.jpg)
BALLANCED SKIP LISTS Ideal as long as structure is maintained
![Page 21: CSC 172 DATA STRUCTURES. SKIP LISTS Read Weiss 10.4.2.](https://reader035.fdocuments.us/reader035/viewer/2022062712/56649c785503460f9492dd7e/html5/thumbnails/21.jpg)
BALLANCED SKIP LISTS Ideal as long as structure is maintained Insertions and deletions mess up structure
![Page 22: CSC 172 DATA STRUCTURES. SKIP LISTS Read Weiss 10.4.2.](https://reader035.fdocuments.us/reader035/viewer/2022062712/56649c785503460f9492dd7e/html5/thumbnails/22.jpg)
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. SKIP LISTS Read Weiss 10.4.2.](https://reader035.fdocuments.us/reader035/viewer/2022062712/56649c785503460f9492dd7e/html5/thumbnails/23.jpg)
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. SKIP LISTS Read Weiss 10.4.2.](https://reader035.fdocuments.us/reader035/viewer/2022062712/56649c785503460f9492dd7e/html5/thumbnails/24.jpg)
INSERTION ON SKIP LISTS EXAMPLE
![Page 25: CSC 172 DATA STRUCTURES. SKIP LISTS Read Weiss 10.4.2.](https://reader035.fdocuments.us/reader035/viewer/2022062712/56649c785503460f9492dd7e/html5/thumbnails/25.jpg)
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. SKIP LISTS Read Weiss 10.4.2.](https://reader035.fdocuments.us/reader035/viewer/2022062712/56649c785503460f9492dd7e/html5/thumbnails/26.jpg)