randomized algorithms - ict.iitk.ac.inย ยท randomized quicksort aim: to show p(๐‘ฟ > 8 l ๐‘”4/3...

39
Randomized Algorithms CS648 Lecture 26 A few memorable problems 1

Upload: others

Post on 15-Nov-2019

11 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized QuickSort Aim: To show P(๐‘ฟ > 8 l ๐‘”4/3 ) < โˆ’7 5 Elements of A arranged in ๐‘’ รœ Increasing order of values Right

Randomized Algorithms CS648

Lecture 26

A few memorable problems

1

Page 2: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized QuickSort Aim: To show P(๐‘ฟ > 8 l ๐‘”4/3 ) < โˆ’7 5 Elements of A arranged in ๐‘’ รœ Increasing order of values Right

RANDOMIZED INCREMENTAL CONSTRUCTION

2

Page 3: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized QuickSort Aim: To show P(๐‘ฟ > 8 l ๐‘”4/3 ) < โˆ’7 5 Elements of A arranged in ๐‘’ รœ Increasing order of values Right

Convex Hull algorithm

Theorem:

There is an O(๐’ ๐ฅ๐จ๐  ๐’ ) time Las Vegas algorithm for computing convex hull.

3

Assignment 4: Concentration of running time.

Page 4: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized QuickSort Aim: To show P(๐‘ฟ > 8 l ๐‘”4/3 ) < โˆ’7 5 Elements of A arranged in ๐‘’ รœ Increasing order of values Right

Randomized QuickSort

Aim: To show P(๐‘ฟ > 8๐‘› l๐‘œ๐‘”4/3 ๐‘›) < ๐‘›โˆ’7

4

๐‘’๐‘– Elements of A arranged in Increasing order of values

๐‘’๐‘—

Right perspective

Page 5: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized QuickSort Aim: To show P(๐‘ฟ > 8 l ๐‘”4/3 ) < โˆ’7 5 Elements of A arranged in ๐‘’ รœ Increasing order of values Right

Randomized QuickSort

Aim: To show P(๐‘ฟ > 8๐‘› l๐‘œ๐‘”4/3 ๐‘›) < ๐‘›โˆ’7

5

๐‘’๐‘– Elements of A arranged in Increasing order of values

Right perspective

Page 6: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized QuickSort Aim: To show P(๐‘ฟ > 8 l ๐‘”4/3 ) < โˆ’7 5 Elements of A arranged in ๐‘’ รœ Increasing order of values Right

Randomized QuickSort from perspective of ๐‘’๐‘–

6

Elements of A arranged in Increasing order of values

๐‘’๐‘–

๐‘’๐‘– leaves the algorithm

Page 7: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized QuickSort Aim: To show P(๐‘ฟ > 8 l ๐‘”4/3 ) < โˆ’7 5 Elements of A arranged in ๐‘’ รœ Increasing order of values Right

Randomized QuickSort from perspective of ๐‘’๐‘–

๐˜๐‘–: no. of recursive calls in which ๐‘’๐‘– participates before being selected as a pivot.

Question: Is there any relation between ๐— and ๐˜๐‘– ?

Answer: ๐— = ๐˜๐‘–๐‘›๐‘–=1

7

Page 8: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized QuickSort Aim: To show P(๐‘ฟ > 8 l ๐‘”4/3 ) < โˆ’7 5 Elements of A arranged in ๐‘’ รœ Increasing order of values Right

CONVEX HULL ALGORITHM

8

Page 9: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized QuickSort Aim: To show P(๐‘ฟ > 8 l ๐‘”4/3 ) < โˆ’7 5 Elements of A arranged in ๐‘’ รœ Increasing order of values Right

Randomized algorithm for convex hull

Convex-hull-algorithm(๐‘ท) { Let <๐’‘๐Ÿ,๐’‘๐Ÿ,โ€ฆ,๐’‘๐’ > be a uniformly random permutation of ๐‘ท;

๐‘ฏ triangle(๐’‘๐Ÿ,๐’‘๐Ÿ, ๐’‘๐Ÿ‘);

For ๐’Š = ๐Ÿ’ to ๐’ do

insert ๐’‘๐’Š and update ๐‘ฏ

return ๐‘ฏ;

}

9

Page 10: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized QuickSort Aim: To show P(๐‘ฟ > 8 l ๐‘”4/3 ) < โˆ’7 5 Elements of A arranged in ๐‘’ รœ Increasing order of values Right

10

Conflict graph : a powerful data structure

๐’„๐Ÿ’

๐’„๐Ÿ

๐’„๐Ÿ

๐’„๐Ÿ‘

๐’„๐Ÿ“

๐’„๐Ÿ”

๐’„๐Ÿ•

๐’„๐Ÿ–

cones ๐’ โˆ’ ๐’Š points ๐’„๐Ÿ

๐’„๐Ÿ‘

๐’„๐Ÿ’

๐’„๐Ÿ“

๐’„๐Ÿ”

๐’„๐Ÿ•

๐’„๐Ÿ–

๐’„๐Ÿ

Page 11: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized QuickSort Aim: To show P(๐‘ฟ > 8 l ๐‘”4/3 ) < โˆ’7 5 Elements of A arranged in ๐‘’ รœ Increasing order of values Right

Before entering the for loop

11

๐’„๐Ÿ

๐’„๐Ÿ

๐’„๐Ÿ‘

๐’„๐Ÿ

๐’„๐Ÿ

๐’„๐Ÿ‘

๐’ โˆ’ ๐Ÿ‘ points cones

Page 12: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized QuickSort Aim: To show P(๐‘ฟ > 8 l ๐‘”4/3 ) < โˆ’7 5 Elements of A arranged in ๐‘’ รœ Increasing order of values Right

INSERTING ๐’ŠTH POINT

12

Page 13: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized QuickSort Aim: To show P(๐‘ฟ > 8 l ๐‘”4/3 ) < โˆ’7 5 Elements of A arranged in ๐‘’ รœ Increasing order of values Right

๐’Šth iteration

13

๐’„๐Ÿ

๐’„๐Ÿ‘

๐’„๐Ÿ’

๐’„๐Ÿ“

๐’„๐Ÿ”

๐’„๐Ÿ•

๐’„๐Ÿ–

๐’„๐Ÿ

Page 14: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized QuickSort Aim: To show P(๐‘ฟ > 8 l ๐‘”4/3 ) < โˆ’7 5 Elements of A arranged in ๐‘’ รœ Increasing order of values Right

๐’Šth iteration

14

๐’„๐Ÿ

๐’„๐Ÿ

๐’„๐Ÿ‘

๐’„๐Ÿ’

๐’„๐Ÿ“

๐’„๐Ÿ”

๐’„๐Ÿ•

๐’„๐Ÿ–

๐’„๐Ÿ

๐’„๐Ÿ‘

๐’„๐Ÿ’

๐’„๐Ÿ“

๐’„๐Ÿ”

๐’„๐Ÿ•

๐’„๐Ÿ–

๐’ โˆ’ ๐’Š + ๐Ÿ points cones ๐’„๐Ÿ

Page 15: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized QuickSort Aim: To show P(๐‘ฟ > 8 l ๐‘”4/3 ) < โˆ’7 5 Elements of A arranged in ๐‘’ รœ Increasing order of values Right

๐’Šth iteration

15

๐’„๐Ÿ

๐’„๐Ÿ

๐’„๐Ÿ‘

๐’„๐Ÿ’

๐’„๐Ÿ“

๐’„๐Ÿ”

๐’„๐Ÿ•

๐’„๐Ÿ–

๐’„๐Ÿ

๐’„๐Ÿ‘

๐’„๐Ÿ’

๐’„๐Ÿ“

๐’„๐Ÿ”

๐’„๐Ÿ•

๐’„๐Ÿ–

๐’ โˆ’ ๐’Š + ๐Ÿ points cones ๐’„๐Ÿ

Page 16: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized QuickSort Aim: To show P(๐‘ฟ > 8 l ๐‘”4/3 ) < โˆ’7 5 Elements of A arranged in ๐‘’ รœ Increasing order of values Right

๐’Šth iteration

16

๐’„๐Ÿ

๐’„๐Ÿ

๐’„๐Ÿ‘

๐’„๐Ÿ’

๐’„๐Ÿ“

๐’„๐Ÿ”

๐’„๐Ÿ•

๐’„๐Ÿ–

๐’„๐Ÿ

๐’„๐Ÿ‘

๐’„๐Ÿ’

๐’„๐Ÿ“

๐’„๐Ÿ”

๐’„๐Ÿ•

๐’„๐Ÿ–

๐’ โˆ’ ๐’Š + ๐Ÿ points cones ๐’„๐Ÿ

Page 17: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized QuickSort Aim: To show P(๐‘ฟ > 8 l ๐‘”4/3 ) < โˆ’7 5 Elements of A arranged in ๐‘’ รœ Increasing order of values Right

๐’Šth iteration

17

๐’„๐Ÿ

๐’„๐Ÿ

๐’„๐Ÿ‘

๐’„๐Ÿ’

๐’„๐Ÿ“

๐’„๐Ÿ”

๐’„๐Ÿ•

๐’„๐Ÿ–

๐’„๐Ÿ

๐’„๐Ÿ‘

๐’„๐Ÿ’

๐’„๐Ÿ“

๐’„๐Ÿ”

๐’„๐Ÿ•

๐’„๐Ÿ–

๐’ โˆ’ ๐’Š points cones ๐’„๐Ÿ

Page 18: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized QuickSort Aim: To show P(๐‘ฟ > 8 l ๐‘”4/3 ) < โˆ’7 5 Elements of A arranged in ๐‘’ รœ Increasing order of values Right

๐’Šth iteration

18

๐’„๐Ÿ

๐’„๐Ÿ

๐’„๐Ÿ‘

๐’„๐Ÿ’

๐’„๐Ÿ“

๐’„๐Ÿ”

๐’„๐Ÿ•

๐’„๐Ÿ–

๐’„๐Ÿ

๐’„๐Ÿ‘

๐’„๐Ÿ’

๐’„๐Ÿ“

๐’„๐Ÿ”

๐’„๐Ÿ•

๐’„๐Ÿ–

๐’ โˆ’ ๐’Š points cones ๐’„๐Ÿ

Page 19: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized QuickSort Aim: To show P(๐‘ฟ > 8 l ๐‘”4/3 ) < โˆ’7 5 Elements of A arranged in ๐‘’ รœ Increasing order of values Right

๐’Šth iteration

19

๐’„๐Ÿ

๐’„๐Ÿ

๐’„๐Ÿ‘

๐’„๐Ÿ’

๐’„๐Ÿ“

๐’„๐Ÿ”

๐’„๐Ÿ•

๐’„๐Ÿ–

๐’„๐Ÿ

๐’„๐Ÿ‘

๐’„๐Ÿ’

๐’„๐Ÿ“

๐’„๐Ÿ”

๐’„๐Ÿ•

๐’„๐Ÿ–

๐’ โˆ’ ๐’Š points cones ๐’„๐Ÿ

Page 20: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized QuickSort Aim: To show P(๐‘ฟ > 8 l ๐‘”4/3 ) < โˆ’7 5 Elements of A arranged in ๐‘’ รœ Increasing order of values Right

๐’Šth iteration

20

๐’„๐Ÿ

๐’„๐Ÿ

๐’„๐Ÿ‘

๐’„๐Ÿ’

๐’„๐Ÿ“

๐’„๐Ÿ”

๐’„๐Ÿ•

๐’„๐Ÿ–

๐’„๐Ÿ

๐’„๐Ÿ‘

๐’„๐Ÿ’

๐’„๐Ÿ“

๐’„๐Ÿ”

๐’„๐Ÿ•

๐’„๐Ÿ–

๐’ โˆ’ ๐’Š points cones ๐’„๐Ÿ

Page 21: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized QuickSort Aim: To show P(๐‘ฟ > 8 l ๐‘”4/3 ) < โˆ’7 5 Elements of A arranged in ๐‘’ รœ Increasing order of values Right

๐’Šth iteration

21

๐’„๐Ÿ

๐’„๐Ÿ

๐’„๐Ÿ‘

๐’„๐Ÿ’

๐’„๐Ÿ“

๐’„๐Ÿ”

๐’„๐Ÿ•

๐’„๐Ÿ–

๐’„๐Ÿ

๐’„๐Ÿ‘

๐’„๐Ÿ’

๐’„๐Ÿ“

๐’„๐Ÿ”

๐’„๐Ÿ•

๐’„๐Ÿ–

๐’ โˆ’ ๐’Š points cones ๐’„๐Ÿ

๐’„โ€ฒ

๐’„"

Page 22: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized QuickSort Aim: To show P(๐‘ฟ > 8 l ๐‘”4/3 ) < โˆ’7 5 Elements of A arranged in ๐‘’ รœ Increasing order of values Right

๐’Šth iteration

22

๐’„๐Ÿ

๐’„โ€ฒ

๐’„"

๐’„๐Ÿ”

๐’„๐Ÿ•

๐’„๐Ÿ–

๐’„โ€ฒ

๐’„"

๐’„๐Ÿ”

๐’„๐Ÿ•

๐’„๐Ÿ–

๐’ โˆ’ ๐’Š points cones ๐’„๐Ÿ

Page 23: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized QuickSort Aim: To show P(๐‘ฟ > 8 l ๐‘”4/3 ) < โˆ’7 5 Elements of A arranged in ๐‘’ รœ Increasing order of values Right

Running time of ๐’Šth iteration

Running time of ๐’Šth iteration is of the order of

โ€ข Number of edges of convex hull that are destroyed

โ€ข Number of new edges of convex hull that are created

โ€ข Number of points in the two adjacent cones that get created

23

Total time for ๐’ iterations = O(๐’)

๐‘ฟ๐’Š

Key idea: No. of cones to which a point belongs during the algorithm

Page 24: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized QuickSort Aim: To show P(๐‘ฟ > 8 l ๐‘”4/3 ) < โˆ’7 5 Elements of A arranged in ๐‘’ รœ Increasing order of values Right

24

Page 25: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized QuickSort Aim: To show P(๐‘ฟ > 8 l ๐‘”4/3 ) < โˆ’7 5 Elements of A arranged in ๐‘’ รœ Increasing order of values Right

26

Page 26: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized QuickSort Aim: To show P(๐‘ฟ > 8 l ๐‘”4/3 ) < โˆ’7 5 Elements of A arranged in ๐‘’ รœ Increasing order of values Right

27

Page 27: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized QuickSort Aim: To show P(๐‘ฟ > 8 l ๐‘”4/3 ) < โˆ’7 5 Elements of A arranged in ๐‘’ รœ Increasing order of values Right

28

Page 28: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized QuickSort Aim: To show P(๐‘ฟ > 8 l ๐‘”4/3 ) < โˆ’7 5 Elements of A arranged in ๐‘’ รœ Increasing order of values Right

29

Page 29: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized QuickSort Aim: To show P(๐‘ฟ > 8 l ๐‘”4/3 ) < โˆ’7 5 Elements of A arranged in ๐‘’ รœ Increasing order of values Right

30

Page 30: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized QuickSort Aim: To show P(๐‘ฟ > 8 l ๐‘”4/3 ) < โˆ’7 5 Elements of A arranged in ๐‘’ รœ Increasing order of values Right

LOAD BALANCE

31

Page 31: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized QuickSort Aim: To show P(๐‘ฟ > 8 l ๐‘”4/3 ) < โˆ’7 5 Elements of A arranged in ๐‘’ รœ Increasing order of values Right

Balls into Bins

Ball-bin Experiment: There are ๐‘š balls and ๐‘› bins.

Each ball selects its bin randomly uniformly and independent of other balls

and falls into it.

Applications: โ€ข Hashing

โ€ข Load balancing in distributed environment 32

1 2 3 โ€ฆ ๐‘– โ€ฆ ๐‘›

1 2 3 4 5 โ€ฆ ๐‘š โˆ’ 1 ๐‘š

Page 32: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized QuickSort Aim: To show P(๐‘ฟ > 8 l ๐‘”4/3 ) < โˆ’7 5 Elements of A arranged in ๐‘’ รœ Increasing order of values Right

Balls into Bins

Question : What is the load of most heavily loaded bin ?

33

1 2 3 โ€ฆ ๐‘– โ€ฆ ๐‘›

1 2 3 4 5 โ€ฆ ๐‘š โˆ’ 1 ๐‘š

O(log ๐’ / log log ๐’)

Page 33: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized QuickSort Aim: To show P(๐‘ฟ > 8 l ๐‘”4/3 ) < โˆ’7 5 Elements of A arranged in ๐‘’ รœ Increasing order of values Right

Balls into Bins

34

1 2 3 โ€ฆ ๐‘– โ€ฆ ๐‘›

๐’Š

Page 34: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized QuickSort Aim: To show P(๐‘ฟ > 8 l ๐‘”4/3 ) < โˆ’7 5 Elements of A arranged in ๐‘’ รœ Increasing order of values Right

Balls into Bins

Question : What is the load of most heavily loaded bin ?

35

1 2 3 โ€ฆ ๐‘– โ€ฆ ๐‘›

O(log log ๐’)

๐’Š

Page 35: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized QuickSort Aim: To show P(๐‘ฟ > 8 l ๐‘”4/3 ) < โˆ’7 5 Elements of A arranged in ๐‘’ รœ Increasing order of values Right

A NOVEL SOLUTION

36

Page 36: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized QuickSort Aim: To show P(๐‘ฟ > 8 l ๐‘”4/3 ) < โˆ’7 5 Elements of A arranged in ๐‘’ รœ Increasing order of values Right

Balls into Bins

37

1 2 3 โ€ฆ ๐‘– โ€ฆ ๐‘›

Page 37: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized QuickSort Aim: To show P(๐‘ฟ > 8 l ๐‘”4/3 ) < โˆ’7 5 Elements of A arranged in ๐‘’ รœ Increasing order of values Right

Generalization

What if each ball chooses ๐’… bin randomly uniformly ?

What if there is asymmetry in breaking ties ?

38

O(๐ฅ๐จ๐  ๐ฅ๐จ๐  ๐’

๐ฅ๐จ๐  ๐’…)

Page 38: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized QuickSort Aim: To show P(๐‘ฟ > 8 l ๐‘”4/3 ) < โˆ’7 5 Elements of A arranged in ๐‘’ รœ Increasing order of values Right

Balls into Bins

39

1 2 3 โ€ฆ ๐‘›

2+ 1 โ€ฆ ๐‘›

๐’Š

O(๐ฅ๐จ๐  ๐ฅ๐จ๐  ๐’

๐’…)

Berthold Vรถcking: How asymmetry helps load balancing. J. ACM 50(4): 568-589 (2003)

Interested students should ponder over it. The following paper gives an elegant proof for this claim. This is the most beautiful proof I ever read.

Page 39: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized QuickSort Aim: To show P(๐‘ฟ > 8 l ๐‘”4/3 ) < โˆ’7 5 Elements of A arranged in ๐‘’ รœ Increasing order of values Right

This is the end of the course.

โ€ข If you liked the course, it is because of the radiating beauty of โ€œrandomized algorithmsโ€.

โ€ข If you dislikes the course, it might be because I did not do a good job.

โ€ข I look forward to your feedback/evaluation to improve.

โ€ข Thanks a lot and best wishes for your wishes.

โ€ข I am truly honored to teach the brightest students of my country

40