Hop, Jump, and Leap

48
Hop, Jump, and Leap Dhruv Matani and Gaurav Menghani

description

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. - PowerPoint PPT Presentation

Transcript of Hop, Jump, and Leap

Page 1: Hop, Jump, and Leap

Hop, Jump, and Leap

Dhruv Matani and Gaurav Menghani

Page 2: Hop, Jump, and Leap

Hop, Jump, and Leap*

Dhruv Matani and Gaurav Menghani

* In O(lg n) with high probability

Page 3: Hop, Jump, and Leap

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

Page 4: Hop, Jump, and Leap

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:

Page 5: Hop, Jump, and Leap

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:

Page 6: Hop, Jump, and Leap

Dynamic Range Minimum Query using

Skip Lists

Page 7: Hop, Jump, and Leap

71

81

131

301

261

191

241

271

71

262

83

192

71

85

192

71

85

192

Page 8: Hop, Jump, and Leap

Find element at Index 4

Page 9: Hop, Jump, and Leap

71

81

131

301

261

191

241

271

71

262

83

192

71

85

192

71

85

192

Find the element at index 4

Page 10: Hop, Jump, and Leap

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

Page 11: Hop, Jump, and Leap

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

Page 12: Hop, Jump, and Leap

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

Page 13: Hop, Jump, and Leap

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

Page 14: Hop, Jump, and Leap

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

Page 15: Hop, Jump, and Leap

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

Page 16: Hop, Jump, and Leap

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

Page 17: Hop, Jump, and Leap

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

Page 18: Hop, Jump, and Leap

Find minimum in range [3, 7]

Page 19: Hop, Jump, and Leap

71

81

131

301

261

191

241

271

71

262

83

192

71

85

192

71

85

192

Find min [3,7]

Page 20: Hop, Jump, and Leap

71

81

131

301

261

191

241

271

71

262

83

192

71

85

192

71

85

192

Find min [3,7]

[3,7]

Page 21: Hop, Jump, and Leap

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]

Page 22: Hop, Jump, and Leap

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]

Page 23: Hop, Jump, and Leap

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]

Page 24: Hop, Jump, and Leap

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]

Page 25: Hop, Jump, and Leap

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]

Page 26: Hop, Jump, and Leap

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]

Page 27: Hop, Jump, and Leap

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]

Page 28: Hop, Jump, and Leap

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]

Page 29: Hop, Jump, and Leap

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]

Page 30: Hop, Jump, and Leap

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]

Page 31: Hop, Jump, and Leap

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]

Page 32: Hop, Jump, and Leap

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]

Page 33: Hop, Jump, and Leap

Insert element with Value 5

at Index 5

Page 34: Hop, Jump, and Leap

71

81

131

301

261

191

241

271

71

262

83

192

71

85

192

71

85

192

Insert 5 at index 5

Page 35: Hop, Jump, and Leap

71

81

131

301

261

191

241

271

71

262

83

192

71

85

192

71

85

192

Insert 5 at index 5

51

Page 36: Hop, Jump, and Leap

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[

Page 37: Hop, Jump, and Leap

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[

Page 38: Hop, Jump, and Leap

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[

Page 39: Hop, Jump, and Leap

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[

Page 40: Hop, Jump, and Leap

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[

Page 41: Hop, Jump, and Leap

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[

Page 42: Hop, Jump, and Leap

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

Page 43: Hop, Jump, and Leap

Order Maintenance using

Skip Lists

Page 44: Hop, Jump, and Leap

• 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

Page 45: Hop, Jump, and Leap

71

81

131

301

261

191

241

271

71

262

83

192

71

85

192

71

85

192

Does 13 precede 19?

Page 46: Hop, Jump, and Leap

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

Page 47: Hop, Jump, and Leap

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

Page 48: Hop, Jump, and Leap

The End