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

Transcript of Randomized Algorithms - ict.iitk.ac.inΒ Β· Randomized QuickSort Aim: To show P(𝑿 > 8 l 𝑔4/3 )...

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