Lecture 13: Partitioning a random experiment into - CSE

Randomized Algorithms
CS648
Lecture 13
Expected duration of a randomized experiment
Part I
1
COUPON COLLECTOR PROBLEM
2
Coupon Collector Problem
β€’
β€’
There is a bag containing 𝑛 distinct coupons.
Each coupon has a unique label from ∈ [𝑛].
Experiment:
Repeat
1. Select a coupon randomly uniformly from the bag
2. Note down its label
3. Place the coupon back into the bag
Until every coupon has appeared at least once
𝑿: the number of iterations of the loop (number of coupons drawn).
Question: What is E[𝑿] ?
3
Example
𝑛=5
1 4 5
3 2
3
1
3
3
1
2
2
1
5
1
3
5
5
5
1
2
1
2
5
4
4
1
2
3
3
2
2
3
3
3
1
1
5
1
3
5
3
4
Done in 14 samplings
Done in 12 samplings
3
2
2
5
4
Coupon Collector Problem
𝑿: the number of iterations of the loop (number of coupons drawn).
Question: What is E[𝑿] ?
Standard method:
E[𝑿] =
π‘˜β‰₯𝑛 π‘˜
βˆ™ 𝐏(𝑿 = π‘˜)
?
No easy way !!
5
Coupon Collector Problem
no
coupon
seen
all
coupons
seen
This transition is not sudden. In fact it is a gradual
transition through various discrete stages. Can you
see these discrete stages ?
6
Coupon Collector Problem
no
coupon
seen
1
2
3
4
all
coupons
seen
This transition is not sudden. In fact it is a gradual
transition through various discrete stages. Can you
see these discrete stages ?
7
Reviewing Example
𝑛=5
1 4 5
3 2
0
5
3
1
3
3
1
2
2
1
5
1
3
5
3
4
8
Reviewing Example
Each instance of coupon
collector problem has to
pass through these
stages. Does it give you
some inspiration to
calculate E[X] ?
𝑛=5
1 4 5
3 2
1
0
3
2
1
3
3
2
1
0
5
0
5
1
3
3
1
1
2
4
2
3
2
5
3
3
5
1
2
5
4
3
3
1
3
4
3
2
5
4
3
2
1
4
2
2
1
5
1
2
3
1
3
5
4
1
5
2
5
9
Coupon Collector Problem
𝑿: the number of iterations of the loop (number of coupons drawn).
Question: What is E[𝑿] ?
𝑿=
π‘Ώπ’Š
πŸŽβ‰€π’Š<𝒏
th distinct coupon was selected
π‘Ώπ’Š = no. of coupons sampled from the moment π’Š??
to the moment π’Š ??
+ 𝟏 th distinct coupon was selected
10
Reviewing Example
𝑛=5
1 4 5
3 2
π‘ΏπŸŽ =1
0
π‘ΏπŸ =1
1
3
π‘ΏπŸ =4
π‘ΏπŸ‘ =3
2
1
π‘ΏπŸ’ =5
3
3
3
1
2
5
4
2
1
5
1
3
5
3
4
This picture validates the
equality 𝑿 = πŸŽβ‰€π’Š<𝒏 π‘Ώπ’Š
11
Coupon Collector Problem
𝑿: the number of iterations of the loop (number of coupons drawn).
𝑿=
π‘Ώπ’Š
πŸŽβ‰€π’Š<𝒏

𝐄[𝐗] =
𝐄[𝐗 π’Š ]
πŸŽβ‰€π’Š<𝒏
Question: What is 𝐄[𝐗 π’Š ] ?
12
Calculating E[𝑋𝑖 ]
𝑛
Experiment (in (𝑖 + 1)th stage):
Repeat
1. Select a coupon randomly uniformly
from the bag
2. Note down its label
3. Place the coupon back into the bag
Until (𝑖 + 1)th distinct coupon appears.
13
Calculating E[𝑋𝑖 ]
𝑛
𝑖
Experiment (in (𝑖 + 1)th stage):
Repeat
1. Select a coupon randomly uniformly
from the bag
2. Note down its label
3. Place the coupon back into the bag
Until (𝑖 + 1)th distinct coupon appears.
𝑝 =Probability an iteration is successful
(𝑛 βˆ’ 𝑖)/𝑛
Question: What is 𝑝 ?
E[𝑋𝑖 ] = π‘˜>0 π‘˜π(𝑋𝑖 = π‘˜)
= π‘˜>0 π‘˜ 1 βˆ’ 𝑝 π‘˜βˆ’1 𝑝
= 1/𝑝
= 𝑛/(𝑛 βˆ’ 𝑖)
14
Coupon Collector Problem
𝑿: the number of iterations of the loop (number of coupons drawn).
𝑿 = πŸŽβ‰€π’Š<𝒏 π‘Ώπ’Š

𝐄[𝐗] = πŸŽβ‰€π’Š<𝒏 𝐄[𝐗 π’Š ]
=
=
𝑛
πŸŽβ‰€π’Š<𝒏 π‘›βˆ’π‘–
1
𝑛 πŸŽβ‰€π’Š<𝒏 π‘›βˆ’π‘–
= 𝑛𝐻𝑛
= 𝑢(𝑛 log 𝑛)
Theorem: Expected duration of coupon collector experiment is 𝑢(𝑛 log 𝑛) .
15
DISCRETE RANDOM WALK ON A LINE
16
Discrete Random Walk
0
1
2
3
4
5
6
7
8
…
n
n+1
β€’ Particle starts from origin
β€’ In each second, particle moves 1 unit to the left or to the right with equal
probability.
β€’ While at origin, the particle moves to 1 always.
Question: What is the expected number of steps of the random walk to reach
milestone n ?
17
An example
0
1
2
3
4
5
6
7
8
…
I, and perhaps
you too,
could not notice
the walk. So let
us trace the walk
slowly.
18
Formalism
𝑋𝑖→𝑗 :
No. of steps of a random walk which starts at 𝑖 and terminates on reaching 𝑗 for the first time.
Aim: To calculate E[𝑋0→𝑛 ]
19
Careful look at the example
0
1
2
3
4
5
6
7
8
…
Can you break the
walk 0οƒ 8 into
stages ? Think
carefully …
20
Careful look at the example
0
1
2
3
4
5
6
7
8
…
Walk starting from 0 and terminating at 5
21
Careful look at the example
0
1
2
3
4
5
6
7
8
…
Walk starting from 0 and terminating at 5
Walk starting from 5 and terminating at 8
22
Relation among π‘Ώπ’Šβ†’π’‹ ’s
For any 𝑖 < π‘˜ < 𝑗
𝑋𝑖→𝑗 = π‘‹π‘–β†’π‘˜ + π‘‹π‘˜β†’π‘—
Breaking 𝑋0→𝑛 down to the limits, we get
𝑋0→𝑛 = 0≀𝑖<𝑛 𝑋𝑖→𝑖+1
Hence using linearity of expectation
E[𝑋0→𝑛 ] =
0≀𝑖<𝑛 E[𝑋𝑖→𝑖+1 ]
23
Relation among π‘Ώπ’Šβ†’π’‹ ’s
0
1
2
3
4
5
6
7
8
…
𝑋0β†’1
1
𝑋1β†’2
1
𝑋2β†’3
3
𝑋3β†’4
1
𝑋4β†’5
5
𝑋5β†’6
1
𝑋6β†’7
𝑋7β†’8
5
11
𝑋0β†’8
28
24
HOW TO CALCULATE
E[π‘Ώπ’Šβ†’π’Š+𝟏 ] ?
25
Conditional Expectation
Given any event Ξ΅ and a random variable π‘Œ defined over a probability space
(𝛀,P).
E[π‘Œ| Ξ΅]
E[π‘Œ| Ξ΅]
Ξ΅
Ξ΅
Ξ©
E[π‘Œ] = E[π‘Œ| Ξ΅] βˆ™ P(Ξ΅) + E[π‘Œ| Ξ΅] βˆ™P(Ξ΅)
A useful tool to calculate expected
value of a random variable
26
Calculating E[𝑋𝑖→𝑖+1 ]
0
1
𝑖
…
𝑖+1
E[𝑋𝑖→𝑖+1 ] = ??
½ βˆ™E[𝑋𝑖→𝑖+1 | first move is L] + ½ βˆ™E[𝑋𝑖→𝑖+1 | first move is R]
= ½ βˆ™E[𝑋𝑖→𝑖+1 | first move is L] + ½ . 1
= ½ βˆ™E[𝑋𝑖→𝑖+1 | first move is L] + ½
?
27
Calculating E[𝑋𝑖→𝑖+1 | first move is L]
0
1
…
𝑖
𝑖+1
E[𝑋𝑖→𝑖+1 | first move is L] = ??
1 + E[π‘‹π‘–βˆ’1→𝑖+1 ]
= 1 + E[π‘‹π‘–βˆ’1→𝑖 ] + E[𝑋𝑖→𝑖+1 ]
//by linearity of expectation
28
Calculating E[𝑋𝑖→𝑖+1 ]
0
1
…
𝑖
𝑖+1
E[𝑋𝑖→𝑖+1 ] = ½ βˆ™E[𝑋𝑖→𝑖+1 | first move is L] + ½ . 1
= ½ βˆ™ 1 + E[π‘‹π‘–βˆ’1→𝑖 ] + E[𝑋𝑖→𝑖+1 ] + ½ . 1
= 1 + ½ βˆ™ E[π‘‹π‘–βˆ’1→𝑖 ] + E[𝑋𝑖→𝑖+1 ]
 2 E[𝑋𝑖→𝑖+1 ] = 2 + E[π‘‹π‘–βˆ’1→𝑖 ] + E[𝑋𝑖→𝑖+1 ]
 E[𝑋𝑖→𝑖+1 ] = 2 + E[π‘‹π‘–βˆ’1→𝑖 ]
Question: What is E[𝑋0β†’1 ] ?
1
Question: What is E[𝑋1β†’2 ] ?
3
Question: What is E[𝑋𝑖→𝑖+1 ] ?
Answer: ??
2𝑖 + 1
29
CALCULATING E[π‘ΏπŸŽβ†’π’ ]
30
Calculating E[𝑋0→𝑛 ]
0
1
2
3
4
5
6
7
…
𝑛
𝑛+1
Lemma (just proved): E[𝑋𝑖→𝑖+1 ] = 2𝑖 + 1
E[𝑋0→𝑛 ] = 0≀𝑖<𝑛 E[𝑋𝑖→𝑖+1 ]
= 0≀𝑖<𝑛(2𝑖 + 1)
= 2 0≀𝑖<𝑛 𝑖 + 0≀𝑖<𝑛 1
=𝑛 π‘›βˆ’1 + 𝑛
= 𝑛2
31
Theorem: Expected number of steps of a random walk starting from 0 and
terminating on reaching 𝑛 is 𝑛2 .
32
Expected duration of a random experiment
Let X denote the random variable for the duration of a randomized
experiment.
To calculate E[X], the following approach is sometimes useful:
β€’ Partition the experiment into stages carefully.
β€’ Calculate expected duration of each stage.
β€’ Using linearity of expectation, calculate E[X].
In the next class, we shall discuss more non-trivial randomized algorithms
which are analyzed using this method.
33