480 likes | 601 Views
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.
E N D
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 In class, we saw:
Hop, Jump, and Leap Today, we shall see:
7 1 8 5 19 2 7 1 8 5 19 2 7 1 26 2 8 3 19 2 7 1 30 1 26 1 13 1 8 1 24 1 19 1 27 1
Find the element at index 4 7 1 8 5 19 2 7 1 8 5 19 2 7 1 26 2 8 3 19 2 7 1 30 1 26 1 13 1 8 1 24 1 19 1 27 1
Find the element at index 4 7 1 8 5 19 2 6 7 1 8 5 19 2 7 1 26 2 8 3 19 2 7 1 30 1 26 1 13 1 8 1 24 1 19 1 27 1
Find the element at index 4 7 1 8 5 19 2 1 7 1 8 5 19 2 7 1 26 2 8 3 19 2 7 1 30 1 26 1 13 1 8 1 24 1 19 1 27 1
Find the element at index 4 7 1 8 5 19 2 6 7 1 8 5 19 2 7 1 26 2 8 3 19 2 7 1 30 1 26 1 13 1 8 1 24 1 19 1 27 1
Find the element at index 4 7 1 8 5 19 2 7 1 8 5 19 2 1 7 1 26 2 8 3 19 2 7 1 30 1 26 1 13 1 8 1 24 1 19 1 27 1
Find the element at index 4 7 1 8 5 19 2 7 1 8 5 19 2 7 1 26 2 8 3 19 2 3 7 1 30 1 26 1 13 1 8 1 24 1 19 1 27 1
Find the element at index 4 7 1 8 5 19 2 7 1 8 5 19 2 7 1 26 2 8 3 19 2 6 7 1 30 1 26 1 13 1 8 1 24 1 19 1 27 1
Find the element at index 4 7 1 8 5 19 2 7 1 8 5 19 2 7 1 26 2 8 3 19 2 3 7 1 30 1 26 1 13 1 8 1 24 1 19 1 27 1
Find the element at index 4 7 1 8 5 19 2 7 1 8 5 19 2 7 1 26 2 8 3 19 2 4 7 1 30 1 26 1 13 1 8 1 24 1 19 1 27 1
Find min [3,7] 7 1 8 5 19 2 7 1 8 5 19 2 7 1 26 2 8 3 19 2 7 1 30 1 26 1 13 1 8 1 24 1 19 1 27 1
Find min [3,7] 7 1 8 5 19 2 [3,7] 7 1 8 5 19 2 7 1 26 2 8 3 19 2 7 1 30 1 26 1 13 1 8 1 24 1 19 1 27 1
Find min [3,7] [3,7] = [3,6], [7,7] 7 1 8 5 19 2 7 1 8 5 19 2 7 1 26 2 8 3 19 2 7 1 30 1 26 1 13 1 8 1 24 1 19 1 27 1
Find min [3,7] [7,7] 7 1 8 5 19 2 7 1 8 5 19 2 [3,6] 7 1 26 2 8 3 19 2 7 1 30 1 26 1 13 1 8 1 24 1 19 1 27 1
Find min [3,7] [7,7] 7 1 8 5 19 2 7 1 8 5 19 2 [3,6] 7 1 26 2 8 3 19 2 7 1 30 1 26 1 13 1 8 1 24 1 19 1 27 1
Find min [3,7] [7,7] 7 1 8 5 19 2 [3,6] 7 1 8 5 19 2 7 1 26 2 8 3 19 2 7 1 30 1 26 1 13 1 8 1 24 1 19 1 27 1
Find min [3,7] [7,7] 7 1 8 5 19 2 7 1 8 5 19 2 [3,6] 7 1 26 2 8 3 19 2 7 1 30 1 26 1 13 1 8 1 24 1 19 1 27 1
Find min [3,7] [7,7] 7 1 8 5 19 2 7 1 8 5 19 2 [3,6] = [3,3], [4,6] 7 1 26 2 8 3 19 2 7 1 30 1 26 1 13 1 8 1 24 1 19 1 27 1
Find min [3,7] [7,7] 7 1 8 5 19 2 7 1 8 5 19 2 [4,6] 7 1 26 2 8 3 19 2 7 1 30 1 26 1 13 1 8 1 24 1 19 1 27 1
Find min [3,7] [7,7] 7 1 8 5 19 2 7 1 8 5 19 2 [4,6] 7 1 26 2 8 3 19 2 7 1 30 1 26 1 13 1 8 1 24 1 19 1 27 1 [3,3]
Find min [3,7] [7,7] 7 1 8 5 19 2 7 1 8 5 19 2 [4,6] 7 1 26 2 8 3 19 2 [3,3] 7 1 30 1 26 1 13 1 8 1 24 1 19 1 27 1
Find min [3,7] [7,7] 7 1 8 5 19 2 7 1 8 5 19 2 [4,6] 7 1 26 2 8 3 19 2 [3,3] 7 1 30 1 26 1 13 1 8 1 24 1 19 1 27 1
Find min [3,7] [7,7] 7 1 8 5 19 2 7 1 8 5 19 2 [4,6] 7 1 26 2 8 3 19 2 [3,3] 7 1 30 1 26 1 13 1 8 1 24 1 19 1 27 1
Find min [3,7] 7 1 8 5 19 2 7 1 8 5 19 2 [4,6] 7 1 26 2 8 3 19 2 [3,3] [7,7] 7 1 30 1 26 1 13 1 8 1 24 1 19 1 27 1
Insert 5 at index 5 7 1 8 5 19 2 7 1 8 5 19 2 7 1 26 2 8 3 19 2 7 1 30 1 26 1 13 1 8 1 24 1 19 1 27 1
Insert 5 at index 5 7 1 8 5 19 2 7 1 8 5 19 2 7 1 26 2 8 3 19 2 5 1 7 1 30 1 26 1 13 1 8 1 24 1 19 1 27 1
Insert 5 at index 5 7 1 8 5 19 2 7 1 8 5 19 2 7 1 26 2 8 3 19 2 [5,2] [8,2] 5 1 7 1 30 1 26 1 13 1 8 1 24 1 19 1 27 1
Insert 5 at index 5 7 1 8 5 19 2 7 1 8 5 19 2 7 1 26 2 5 2 8 2 19 2 [5,2] [5,2] [8,2] 5 1 7 1 30 1 26 1 13 1 8 1 24 1 19 1 27 1
Insert 5 at index 5 7 1 8 5 19 2 7 1 8 5 19 2 [5,4] [8,2] 7 1 26 2 5 2 8 2 19 2 5 1 7 1 30 1 26 1 13 1 8 1 24 1 19 1 27 1
Insert 5 at index 5 7 1 8 5 19 2 7 1 5 4 8 2 19 2 [5,4] [5,4] [8,2] 7 1 26 2 5 2 8 2 19 2 5 1 7 1 30 1 26 1 13 1 8 1 24 1 19 1 27 1
Insert 5 at index 5 7 1 8 5 19 2 [5,4] [8,2] 7 1 5 4 8 2 19 2 7 1 26 2 5 2 8 2 19 2 5 1 7 1 30 1 26 1 13 1 8 1 24 1 19 1 27 1
Insert 5 at index 5 7 1 5 6 19 2 [5,4] [8,2] 7 1 5 4 8 2 19 2 7 1 26 2 5 2 8 2 19 2 5 1 7 1 30 1 26 1 13 1 8 1 24 1 19 1 27 1
Insert 5 at index 5 7 1 5 6 19 2 7 1 5 4 8 2 19 2 7 1 26 2 5 2 8 2 19 2 5 1 7 1 30 1 26 1 13 1 8 1 24 1 19 1 27 1
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
Does 13 precede 19? 7 1 8 5 19 2 7 1 8 5 19 2 7 1 26 2 8 3 19 2 7 1 30 1 26 1 13 1 8 1 24 1 19 1 27 1
Does 13 precede 19? Rank(13) = 1 + 2 + 1 = 4 7 1 8 5 19 2 7 1 8 5 19 2 7 1 26 2 8 3 19 2 7 1 30 1 26 1 13 1 8 1 24 1 19 1 27 1
Does 13 precede 19? Rank(19) = 1 + 5 + 1 = 7 7 1 8 5 19 2 7 1 8 5 19 2 7 1 26 2 8 3 19 2 7 1 30 1 26 1 13 1 8 1 24 1 19 1 27 1