Download - Hop, Jump, and Leap
Hop, Jump, and Leap
Dhruv Matani and Gaurav Menghani
Hop, Jump, and Leap*
Dhruv Matani and Gaurav Menghani
* In O(lg n) with high probability
Hop, Jump, and Leap
• Skip Lists are a simple and powerful data-structure.
• Augmenting skip-lists to achieve decent running times for most problems.
• By decent, we mean O(lg n) w.h.p
Hop, Jump, and Leap
Order Maintenance
O(1) Amortized
Insert
O(1) Query
Static RMQ O(n) pre-processing
O(1) Query
In class, we saw:
Hop, Jump, and Leap
Order Maintenance
O(lg n) w.h.p O(lg n) w.h.p. Query
Dynamic RMQ O(lg n) w.h.p. Insert
O(lg n) w.h.p. Query
Today, we shall see:
Dynamic Range Minimum Query using
Skip Lists
71
81
131
301
261
191
241
271
71
262
83
192
71
85
192
71
85
192
Find element at Index 4
71
81
131
301
261
191
241
271
71
262
83
192
71
85
192
71
85
192
Find the element at index 4
71
81
131
301
261
191
241
271
71
262
83
192
71
85
192
71
85
192
Find the element at index 4
6
71
81
131
301
261
191
241
271
71
262
83
192
71
85
192
71
85
192
Find the element at index 4
1
71
81
131
301
261
191
241
271
71
262
83
192
71
85
192
71
85
192
Find the element at index 4
6
71
81
131
301
261
191
241
271
71
262
83
192
71
85
192
71
85
192
Find the element at index 4
1
71
81
131
301
261
191
241
271
71
262
83
192
71
85
192
71
85
192
Find the element at index 4
3
71
81
131
301
261
191
241
271
71
262
83
192
71
85
192
71
85
192
Find the element at index 4
6
71
81
131
301
261
191
241
271
71
262
83
192
71
85
192
71
85
192
Find the element at index 4
3
71
81
131
301
261
191
241
271
71
262
83
192
71
85
192
71
85
192
Find the element at index 4
4
Find minimum in range [3, 7]
71
81
131
301
261
191
241
271
71
262
83
192
71
85
192
71
85
192
Find min [3,7]
71
81
131
301
261
191
241
271
71
262
83
192
71
85
192
71
85
192
Find min [3,7]
[3,7]
71
81
131
301
261
191
241
271
71
262
83
192
71
85
192
71
85
192
Find min [3,7]
[3,7[ = ]3,6[ ,]7,7]
71
81
131
301
261
191
241
271
71
262
83
192
71
85
192
71
85
192
Find min [3,7]
[3,6]
[7,7]
71
81
131
301
261
191
241
271
71
262
83
192
71
85
192
71
85
192
Find min [3,7]
[3,6]
[7,7]
71
81
131
301
261
191
241
271
71
262
83
192
71
85
192
71
85
192
Find min [3,7]
[3,6]
[7,7]
71
81
131
301
261
191
241
271
71
262
83
192
71
85
192
71
85
192
Find min [3,7]
[7,7]
[3,6]
71
81
131
301
261
191
241
271
71
262
83
192
71
85
192
71
85
192
Find min [3,7]
[7,7]
[3,6[ = ]3,3[ ,]4,6]
71
81
131
301
261
191
241
271
71
262
83
192
71
85
192
71
85
192
Find min [3,7]
[7,7]
[4,6]
71
81
131
301
261
191
241
271
71
262
83
192
71
85
192
71
85
192
Find min [3,7]
[7,7]
[4,6]
[3,3]
71
81
131
301
261
191
241
271
71
262
83
192
71
85
192
71
85
192
Find min [3,7]
[7,7]
[4,6]
[3,3]
71
81
131
301
261
191
241
271
71
262
83
192
71
85
192
71
85
192
Find min [3,7]
[7,7]
[4,6]
[3,3]
71
81
131
301
261
191
241
271
71
262
83
192
71
85
192
71
85
192
Find min [3,7]
[7,7]
[4,6]
[3,3]
71
81
131
301
261
191
241
271
71
262
83
192
71
85
192
71
85
192
Find min [3,7]
[7,7]
[4,6]
[3,3]
Insert element with Value 5
at Index 5
71
81
131
301
261
191
241
271
71
262
83
192
71
85
192
71
85
192
Insert 5 at index 5
71
81
131
301
261
191
241
271
71
262
83
192
71
85
192
71
85
192
Insert 5 at index 5
51
71
81
131
301
261
191
241
271
71
262
83
192
71
85
192
71
85
192
Insert 5 at index 5
51
]8,2[]5,2[
71
81
131
301
261
191
241
271
71
262
82
192
71
85
192
71
85
192
Insert 5 at index 5
51
]8,2[]5,2[52]5,2[
71
81
131
301
261
191
241
271
71
262
82
192
71
85
192
71
85
192
Insert 5 at index 5
51
]8,2[
52
]5,4[
71
81
131
301
261
191
241
271
71
262
82
192
71
82
192
71
85
192
Insert 5 at index 5
51
]8,2[
52
]5,4[54]5,4[
71
81
131
301
261
191
241
271
71
262
82
192
71
82
192
71
85
192
Insert 5 at index 5
51
]8,2[
52
54
]5,4[
71
81
131
301
261
191
241
271
71
262
82
192
71
82
192
71
56
192
Insert 5 at index 5
51
]8,2[
52
54
]5,4[
71
81
131
301
261
191
241
271
71
262
82
192
71
82
192
71
56
192
Insert 5 at index 5
51
52
54
Order Maintenance using
Skip Lists
• To perform Order Maintenance, we insert an element after a given element.
• This costs O(lg n) w.h.p
• Does X precede Y?– Is the rank(X) < rank(Y)?
• This costs O(lg n) w.h.p
71
81
131
301
261
191
241
271
71
262
83
192
71
85
192
71
85
192
Does 13 precede 19?
71
81
131
301
261
191
241
271
71
262
83
192
71
85
192
71
85
192
Does 13 precede 19? Rank(13) = 1 + 2 + 1 = 4
71
81
131
301
261
191
241
271
71
262
83
192
71
85
192
71
85
192
Does 13 precede 19? Rank(19) = 1 + 5 + 1 = 7
The End