Randomized Algorithms - ict.iitk.ac.inย ยท Randomized Quick Sort from perspective of ๐‘’ and ๐‘’...

39
Randomized Algorithms CS648 Lecture 2 โ€ข Three interesting problems โ€ข Balls into bins โ€ข Balls out of bin โ€ข Randomized Quick Sort โ€ข Random Variable and Expected value 1

Transcript of Randomized Algorithms - ict.iitk.ac.inย ยท Randomized Quick Sort from perspective of ๐‘’ and ๐‘’...

Page 1: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized Quick Sort from perspective of ๐‘’ and ๐‘’ In order to analyze the Randomized Quick Sort algorithm from the perspective of ๐‘’

Randomized Algorithms CS648

Lecture 2 โ€ข Three interesting problems

โ€ข Balls into bins โ€ข Balls out of bin โ€ข Randomized Quick Sort

โ€ข Random Variable and Expected value

1

Page 2: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized Quick Sort from perspective of ๐‘’ and ๐‘’ In order to analyze the Randomized Quick Sort algorithm from the perspective of ๐‘’

Recap from last lecture

โ€ข Probability space (๐›€,P)

โ€ข Events

โ€ข Probability of union of events

โ€ข Partition theorem :

If events ๐€1,โ€ฆ, ๐€๐‘›partition the sample space ๐›€ then

โ€ข Conditional probability

2

P[A|B] = ๐[๐€โˆฉ๐]

๐[๐]

P(AUB) = P(A) + P(B) โˆ’ P(AโˆฉB)

P(B) = P(๐€๐‘–โˆฉB๐‘– )

Page 3: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized Quick Sort from perspective of ๐‘’ and ๐‘’ In order to analyze the Randomized Quick Sort algorithm from the perspective of ๐‘’

BALLS INTO BINS

3

Page 4: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized Quick Sort from perspective of ๐‘’ and ๐‘’ In order to analyze the Randomized Quick Sort algorithm from the perspective of ๐‘’

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 4

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

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

Page 5: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized Quick Sort from perspective of ๐‘’ and ๐‘’ In order to analyze the Randomized Quick Sort algorithm from the perspective of ๐‘’

Balls into Bins

Question : What is the probability that there is at least one empty bin ?

5

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

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

Page 6: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized Quick Sort from perspective of ๐‘’ and ๐‘’ In order to analyze the Randomized Quick Sort algorithm from the perspective of ๐‘’

Balls into Bins

What is the probability space (ฮฉ,P) ?

โ€ข | ฮฉ | = ๐‘›๐‘š

โ€ข P(ฯ‰) = 1/ ๐‘›๐‘š for each ฯ‰ฯต ฮฉ

6

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

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

Page 7: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized Quick Sort from perspective of ๐‘’ and ๐‘’ In order to analyze the Randomized Quick Sort algorithm from the perspective of ๐‘’

Balls into Bins

Let us define event ๐‘ฌ๐‘—๐‘–

โ€ข Events ๐‘ฌ๐‘—๐‘– and ๐‘ฌ๐‘—

๐‘˜ are ??

โ€ข Events ๐‘ฌ๐‘—๐‘– and ๐‘ฌ๐‘™

๐‘˜ are ??

โ€ข Events ๐‘ฌ๐‘—๐‘– and ๐‘ฌ๐‘™

๐‘– are ??

7

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

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

disjoint

Independent

Independent

: ๐‘—th ball falls into ๐‘–th bin.

Page 8: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized Quick Sort from perspective of ๐‘’ and ๐‘’ In order to analyze the Randomized Quick Sort algorithm from the perspective of ๐‘’

Balls into Bins

๐‘ฌ๐‘—๐‘– : ๐‘—th ball enters ๐‘–th bin.

โ€ข Pr[๐‘ฌ๐‘—๐‘–] = ??

โ€ข Pr[๐‘ฌ๐‘—๐‘–] = ??

โ€ข Pr[๐‘–th bin is empty] = ??

=(1 โˆ’ 1

๐‘› )๐‘š

8

1๐‘›

1 โˆ’1

๐‘›

Pr[๐‘ฌ1๐‘– โˆฉ๐‘ฌ2

๐‘– โ€ฆโˆฉ๐‘ฌ๐‘š๐‘–] = Pr[๐‘ฌ1

๐‘– ] โจฏ โ€ฆPr[๐‘ฌ๐‘š๐‘–]

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

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

Page 9: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized Quick Sort from perspective of ๐‘’ and ๐‘’ In order to analyze the Randomized Quick Sort algorithm from the perspective of ๐‘’

Balls into Bins

โ€ข Pr[๐‘–th bin is empty] = (1 โˆ’ 1

๐‘› )๐‘š

โ€ข Pr[๐‘–th and ๐‘˜th bin are empty] = ??

โ€ข Pr[a specified set of ๐‘™ bins are empty] = ??

9

(1 โˆ’ 2๐‘›

)๐‘š

(1 โˆ’ ๐‘™๐‘› )๐‘š

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

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

Page 10: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized Quick Sort from perspective of ๐‘’ and ๐‘’ In order to analyze the Randomized Quick Sort algorithm from the perspective of ๐‘’

Balls into Bins

Question: What is the probability that there is at least one empty bin ?

Attempt 1: Explore the sample space associated with the โ€œballs into binsโ€.

Attempt 2: ??

Define ๐€๐‘– : โ€œ๐‘–th bin is emptyโ€

Event โ€œthere is at least one empty binโ€ = ๐€๐‘–๐‘›๐‘–=1

10

Express the event as union of some events โ€ฆ

Page 11: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized Quick Sort from perspective of ๐‘’ and ๐‘’ In order to analyze the Randomized Quick Sort algorithm from the perspective of ๐‘’

Balls into Bins

Theorem: For events ๐€1,โ€ฆ, ๐€๐‘›defined over a probability space (๐›€,P), then

P( ๐€๐‘–๐‘›๐‘–=1 ) = P(๐€๐‘–)๐‘–

โˆ’ P(๐€๐‘– ๐€๐‘— )๐‘–<๐‘—

+ P(๐€๐‘– ๐€๐‘— ๐€๐‘˜ )๐‘–<๐‘—<๐‘˜

โˆ’ โ€ฆ

(โˆ’1)๐‘›+1 P(๐€1 ๐€2 โ€ฆ ๐€๐‘›)

--------------------------------------------------------------------

= (๐‘›1)(1 โˆ’ 1

๐‘› )๐‘š

โˆ’ (๐‘›2)(1 โˆ’ 2

๐‘› )๐‘š

+ (๐‘›3)(1 โˆ’ 3

๐‘› )๐‘š

โˆ’ โ€ฆ

+ โˆ’1 ๐‘˜+1(๐‘›๐‘˜) (1 โˆ’ ๐‘˜

๐‘› )๐‘š

โ€ฆ 11

๐‘(๐‘›,๐‘š)

Page 12: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized Quick Sort from perspective of ๐‘’ and ๐‘’ In order to analyze the Randomized Quick Sort algorithm from the perspective of ๐‘’

Balls into Bins

Homework Exercise:

What is the probability that there are exactly ๐‘˜ empty bins ?

Hint: You will need to use ๐‘(๐‘›,๐‘š) with suitable values of ๐‘›.

12

Page 13: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized Quick Sort from perspective of ๐‘’ and ๐‘’ In order to analyze the Randomized Quick Sort algorithm from the perspective of ๐‘’

BALLS OUT OF BIN

13

Page 14: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized Quick Sort from perspective of ๐‘’ and ๐‘’ In order to analyze the Randomized Quick Sort algorithm from the perspective of ๐‘’

Balls Out of Bin

There is a bin containing ๐‘Ÿ red balls and ๐‘ blue balls.

Balls are taken out from the bag

Question: What is the probability that appears ahead of all blue balls. ?

14

uniformly randomly and without replacement.

What if ๐‘Ÿ = 1 ?

Page 15: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized Quick Sort from perspective of ๐‘’ and ๐‘’ In order to analyze the Randomized Quick Sort algorithm from the perspective of ๐‘’

Balls Out of Bin

There is a bin containing 1 red ball and ๐‘ blue balls.

Balls are taken out from the bag

Question: What is the probability that appears ahead of all blue balls ?

Question: What is the probability that appears at ๐’Šth place ? 15

uniformly randomly and without replacement.

1

๐‘ + 1

1

๐‘ + 1

Page 16: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized Quick Sort from perspective of ๐‘’ and ๐‘’ In order to analyze the Randomized Quick Sort algorithm from the perspective of ๐‘’

Balls Out of Bin

There is a bin containing ๐‘Ÿ red balls and ๐‘ blue balls.

Balls are taken out from the bag

Question: What is the probability that appears ahead of all blue balls ?

Homework: Give formal arguments in support of your answer. 16

uniformly randomly and without replacement.

1

๐‘ + 1

Page 17: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized Quick Sort from perspective of ๐‘’ and ๐‘’ In order to analyze the Randomized Quick Sort algorithm from the perspective of ๐‘’

RANDOMIZED QUICK SORT

17

Page 18: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized Quick Sort from perspective of ๐‘’ and ๐‘’ In order to analyze the Randomized Quick Sort algorithm from the perspective of ๐‘’

18

How to solve a problem ?

Page 19: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized Quick Sort from perspective of ๐‘’ and ๐‘’ In order to analyze the Randomized Quick Sort algorithm from the perspective of ๐‘’

Perspective

19

does matter

Page 20: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized Quick Sort from perspective of ๐‘’ and ๐‘’ In order to analyze the Randomized Quick Sort algorithm from the perspective of ๐‘’

Randomized Quick Sort

Input: ๐‘จ[0..๐‘› โˆ’ 1]

RandomizedQuickSort(๐‘จ,๐’, ๐’“) //For the first call, ๐’ =0, ๐’“=๐‘› โˆ’ 1

{ If (๐’ < ๐’“)

๐’™ an element selected randomly uniformly from ๐‘จ[๐’..๐’“];

๐’Š Partition(๐‘จ,๐’,๐’“,x);

RandomizedQuickSort(๐‘จ,๐’, ๐’Š โˆ’ ๐Ÿ);

RandomizedQuickSort(๐‘จ,๐’Š + ๐Ÿ, ๐’“)

}

Assumption : All elements are distinct (if not, break the ties arbitrarily)

Notation : ๐‘’๐‘– : ๐‘–th smallest element of array ๐‘จ.

Question: What is the probability that ๐‘’๐‘– is compared with ๐‘’๐‘— ?

20

Recall that the execution of RandomizedQuickSort is totally immune to the permutation of ๐‘จ.

Page 21: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized Quick Sort from perspective of ๐‘’ and ๐‘’ In order to analyze the Randomized Quick Sort algorithm from the perspective of ๐‘’

Randomized Quick Sort

Input: ๐‘จ[0..๐‘› โˆ’ 1]

RandomizedQuickSort(๐‘จ,๐’, ๐’“) //For the first call, ๐’ =0, ๐’“=๐‘› โˆ’ 1

{ If (๐’ < ๐’“)

๐’™ an element selected randomly uniformly from ๐‘จ[๐’..๐’“];

๐’Š Partition(๐‘จ,๐’,๐’“,x);

RandomizedQuickSort(๐‘จ,๐’, ๐’Š โˆ’ ๐Ÿ);

RandomizedQuickSort(๐‘จ,๐’Š + ๐Ÿ, ๐’“)

}

The sample space : all recursion trees (rooted binary trees on ๐‘› nodes).

21

Page 22: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized Quick Sort from perspective of ๐‘’ and ๐‘’ In order to analyze the Randomized Quick Sort algorithm from the perspective of ๐‘’

Randomized Quick Sort

Input: ๐‘จ[๐ŸŽ..๐’ โˆ’ ๐Ÿ]

RandomizedQuickSort(๐‘จ,๐’, ๐’“) //For the first call, ๐’ =0, ๐’“=๐‘› โˆ’ 1

{ If (๐’ < ๐’“)

๐’™ an element selected randomly uniformly from ๐‘จ[๐’..๐’“];

๐’Š Partition(๐‘จ,๐’,๐’“,x);

RandomizedQuickSort(๐‘จ,๐’, ๐’Š โˆ’ ๐Ÿ);

RandomizedQuickSort(๐‘จ,๐’Š + ๐Ÿ, ๐’“)

}

22

๐‘’4

๐‘’2

๐‘’1 ๐‘’3

๐‘’6

๐‘’5 ๐‘’7

๐’ = 7 1

7โ‹…1

3โ‹…1

3

Page 23: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized Quick Sort from perspective of ๐‘’ and ๐‘’ In order to analyze the Randomized Quick Sort algorithm from the perspective of ๐‘’

Randomized Quick Sort

Input: ๐‘จ[๐ŸŽ..๐’ โˆ’ ๐Ÿ]

RandomizedQuickSort(๐‘จ,๐’, ๐’“) //For the first call, ๐’ =0, ๐’“=๐‘› โˆ’ 1

{ If (๐’ < ๐’“)

๐’™ an element selected randomly uniformly from ๐‘จ[๐’..๐’“];

๐’Š Partition(๐‘จ,๐’,๐’“,x);

RandomizedQuickSort(๐‘จ,๐’, ๐’Š โˆ’ ๐Ÿ);

RandomizedQuickSort(๐‘จ,๐’Š + ๐Ÿ, ๐’“)

}

23

๐’ = 7 ๐‘’5

๐‘’6

๐‘’7

๐‘’2

๐‘’1 ๐‘’4

๐‘’3

1

7โ‹…1

4โ‹…1

2โ‹…1

2

Page 24: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized Quick Sort from perspective of ๐‘’ and ๐‘’ In order to analyze the Randomized Quick Sort algorithm from the perspective of ๐‘’

Randomized Quick Sort

Question: What is the probability that ๐‘’๐‘– is compared with ๐‘’๐‘— ?

Attempt 1: Explore the sample space associated with Randomized Quick Sort.

add the probability of each recursion tree in which ๐‘’๐‘– is compared with ๐‘’๐‘—.

Attempt 2: ??

24

View the execution of RandomizedQuickSort from perspective of ๐‘’๐‘– and ๐‘’๐‘—

Not a feasible way to calculate the probability

Page 25: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized Quick Sort from perspective of ๐‘’ and ๐‘’ In order to analyze the Randomized Quick Sort algorithm from the perspective of ๐‘’

Randomized Quick Sort from perspective of ๐‘’๐‘– and ๐‘’๐‘—

In order to analyze the Randomized Quick Sort algorithm from the perspective of ๐‘’๐‘– and ๐‘’๐‘—, we do the following:

โ€ข We visualize elements ๐‘’1, โ€ฆ , ๐‘’๐‘› arranged from left to right in increasing order of values.

โ€ข This visualization ensures that the two subarrays which we sort recursively lie to left and right of the pivot element. In this way we can focus on the subarray containing ๐‘’๐‘– and ๐‘’๐‘—easily.

โ€ข Note that this visualization is just for the sake of analysis. It will be grossly wrong if you interpret it as if we are sorting an already sorted array.

25

Go through the next few slides slowly and patiently, pondering at each step. Never accept anything until and unless you can see the underlying truth yourself.

Page 26: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized Quick Sort from perspective of ๐‘’ and ๐‘’ In order to analyze the Randomized Quick Sort algorithm from the perspective of ๐‘’

Randomized Quick Sort from perspective of ๐‘’๐‘– and ๐‘’๐‘—

26

Elements of A arranged in Increasing order of values

๐‘’๐‘– ๐‘’๐‘—

Page 27: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized Quick Sort from perspective of ๐‘’ and ๐‘’ In order to analyze the Randomized Quick Sort algorithm from the perspective of ๐‘’

Randomized Quick Sort from perspective of ๐‘’๐‘– and ๐‘’๐‘—

Observation:

๐‘’๐‘– and ๐‘’๐‘— get compared during an instance of Randomized Quick Sort iff

the first pivot element from ๐‘บ๐‘–๐‘— is either ๐‘’๐‘– or ๐‘’๐‘—.

Let us define two events.

๐ต๐‘– : first pivot element selected from ๐‘บ๐‘–๐‘— during Randomized Quick Sort is ๐‘’๐‘–.

๐ต๐‘— : first pivot element selected from ๐‘บ๐‘–๐‘— during Randomized Quick Sort is ๐‘’๐‘—.

Pr[๐‘’๐‘– and ๐‘’๐‘— get compared] = ??

27

๐‘’๐‘– ๐‘’๐‘—

๐‘บ๐‘–๐‘—

Pr[๐ต๐‘–U๐ต๐‘—]

Page 28: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized Quick Sort from perspective of ๐‘’ and ๐‘’ In order to analyze the Randomized Quick Sort algorithm from the perspective of ๐‘’

Randomized Quick Sort from perspective of ๐‘’๐‘– and ๐‘’๐‘—

Pr[๐‘’๐‘– and ๐‘’๐‘— get compared] = Pr[๐ต๐‘–U๐ต๐‘—]

= Pr[๐ต๐‘–] + Pr[๐ต๐‘—] - Pr[๐ต๐‘– โˆฉ๐ต๐‘—]

= Pr[๐ต๐‘–] + Pr[๐ต๐‘—]

= 1

๐‘—โˆ’๐‘–+1 + 1

๐‘—โˆ’๐‘–+1

= 2

๐‘—โˆ’๐‘–+1

28

๐‘’๐‘– ๐‘’๐‘—

๐‘บ๐‘–๐‘—

What relation exists between ๐ต๐‘– and ๐ต๐‘— ?

๐ต๐‘– and ๐ต๐‘— are disjoint events.

What is Pr[๐ต๐‘–] ? Pr[๐ต๐‘–] =

1

|๐‘บ๐‘–๐‘—|.

Page 29: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized Quick Sort from perspective of ๐‘’ and ๐‘’ In order to analyze the Randomized Quick Sort algorithm from the perspective of ๐‘’

Randomized Quick Sort from perspective of ๐‘’๐‘– and ๐‘’๐‘—

Theorem: During Randomized-Quick-Sort on ๐‘› elements,

the probability ๐‘’๐‘– and ๐‘’๐‘— are compared with probability 2

๐‘—โˆ’๐‘–+1 .

Inferences: โ€ข Probability depends upon the rank separation ๐‘— โˆ’ ๐‘– + 1

โ€ข Probability ----------?----------- the size of the array.

โ€ข Probability ๐‘’๐‘– and ๐‘’๐‘–+1 are compared = ? .

โ€ข Probability of comparison of ๐‘’0 and ๐‘’๐‘›โˆ’1 = ? .

29

is independent of

1 2

๐‘›

Page 30: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized Quick Sort from perspective of ๐‘’ and ๐‘’ In order to analyze the Randomized Quick Sort algorithm from the perspective of ๐‘’

PROBABILITY THEORY

โ€ข Random variable

and

โ€ข expected value

30

Page 31: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized Quick Sort from perspective of ๐‘’ and ๐‘’ In order to analyze the Randomized Quick Sort algorithm from the perspective of ๐‘’

Random variable

31

Randomized-Quick-Sort

on array of size n

Number of HEADS in 5 tosses

Sum of numbers in 4 throws

Number of comparisons

Page 32: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized Quick Sort from perspective of ๐‘’ and ๐‘’ In order to analyze the Randomized Quick Sort algorithm from the perspective of ๐‘’

Random variable

Definition: A random variable defined over a probability space (ฮฉ,P)

is a mapping ฮฉ R.

โ€ข ๐‘ฟ(ฯ‰) : the value of ๐‘ฟ on elementary event ฯ‰ โˆˆ ๐›€ .

Notations for random variables :

โ€ข ๐‘ฟ, ๐’€, ๐‘ผ, โ€ฆ(capital letters)

32

ฮฉ

R

Set of real numbers

๐‘ฟ

Page 33: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized Quick Sort from perspective of ๐‘’ and ๐‘’ In order to analyze the Randomized Quick Sort algorithm from the perspective of ๐‘’

Many Random Variables for the same Probability space

Random Experiment: Throwing a dice two times

โ€ข X : the largest number seen

โ€ข Y : sum of the two numbers seen

33

X(ฯ‰) = 6 ฯ‰

Y(ฯ‰) = 9

Page 34: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized Quick Sort from perspective of ๐‘’ and ๐‘’ In order to analyze the Randomized Quick Sort algorithm from the perspective of ๐‘’

Expected Value of a random variable (average value)

Definition: Expected value of a random variable X defined over a probability space (ฮฉ,P) is

E[X] = X(ฯ‰) โจฏ P(ฯ‰)ฯ‰ฯต ฮฉ

34

ฮฉ

X= a X= b

X= c

E[X] = aโจฏ P(X = a)aฯต X

Page 35: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized Quick Sort from perspective of ๐‘’ and ๐‘’ In order to analyze the Randomized Quick Sort algorithm from the perspective of ๐‘’

Examples

Random experiment 1: A fair coin is tossed n times

Random Variable X: The number of HEADS

E[X] = ๐‘– โจฏ P(X =๐‘–)๐‘–

= ๐‘– โจฏ๐‘›๐‘–๐‘– (1 2 )

๐‘– (1 2 )๐‘›โˆ’๐‘–

= ๐‘› 2

Random Experiment 2: 4 balls into 3 bins

Random Variable X: The number of empty bins

E[X] = ๐‘– โจฏ P(X =๐‘–)๐‘–

35

Page 36: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized Quick Sort from perspective of ๐‘’ and ๐‘’ In order to analyze the Randomized Quick Sort algorithm from the perspective of ๐‘’

Can we solve these problems ? Random Experiment 1 : There are ๐‘š balls and ๐‘› bins.

Each ball falls into a bin selected randomly uniformly and independently.

Random Variable X: The number of empty bins

E[X]= ??

Random Experiment 2 : A bin contains ๐‘Ÿ red balls and ๐‘ blue balls in a bin.

The balls are taken out randomly uniformly without replacement.

Random Variable X: The number of red balls preceding all blue balls.

E[X]= ??

Random Experiment 3 Randomized Quick sort on ๐‘› elements Random Variable X: The number of comparisons

E[X]= ??

36

Page 37: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized Quick Sort from perspective of ๐‘’ and ๐‘’ In order to analyze the Randomized Quick Sort algorithm from the perspective of ๐‘’

โ€ข Spend at least 2 hours today trying to solve the 3 problems given in the previous slide.

โ€ข These 2 hours will be very valuable for you in the long run.

I really mean it.

37

Page 38: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized Quick Sort from perspective of ๐‘’ and ๐‘’ In order to analyze the Randomized Quick Sort algorithm from the perspective of ๐‘’

Fun with probability

38

Page 39: Randomized Algorithms - ict.iitk.ac.inย ยท Randomized Quick Sort from perspective of ๐‘’ and ๐‘’ In order to analyze the Randomized Quick Sort algorithm from the perspective of ๐‘’

Stick problem

We break the stick at ๐’ points selected randomly uniformly.

39

What is the probability that the ๐’ + ๐Ÿ pieces can be joined to form a polygon ?