Download Lecture 7: Application of Union theorem: Maximum load

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
Transcript
Randomized Algorithms
CS648
Lecture 7
Two applications of Union Theorem
β€’ Balls into Bin experiment : Maximum load
β€’
Randomized Quick Sort: Concentration of the running time
1
Union theorem
Theorem: Suppose there is an event πœ€ defined over a probability space (𝛀,P)
such that
πœ€=
𝑖
πœ€π‘– , then
P(πœ€ ) ≀ π’Š 𝐏(πœ€π‘– )
Furthermore, if 𝐏(πœ€π‘– ) is same for each 𝑖, then
P(πœ€ ) ≀ 𝑛 𝐏(πœ€π‘– )
2
Union theorem
When to use Union theorem: Suppose we wish to get an upper bound on
P(πœ€ ) but it turns out to be difficult to calculate P(πœ€ ) directly.
How to use Union theorem: Try to express
πœ€ as union of 𝑛 events πœ€π‘– (usually
identical) such that it is easy to calculate P(πœ€π‘– ).
Then we can get an upper bound on P(πœ€ ) as
P(πœ€ ) ≀ 𝑛 𝐏(πœ€π‘– )
3
APPLICATION 1 OF THE UNION THEOREM
BALLS INTO BINS: MAXIMUM LOAD
4
Balls into Bins
1
1
2
3 4
2
5
3
…
…
i
m-1 m
…
n
Ball-bin Experiment: There are π‘š balls and 𝑛 bins. Each ball selects its bin
randomly uniformly and independent of other balls and falls into it.
Used in:
β€’
β€’
Hashing
Load balancing in distributed environment
5
Balls into Bins
1
1
2
3 4
2
5
3
…
…
j
m-1 m
…
n
Ball-bin Experiment: There are π‘š balls and 𝑛 bins. Each ball selects its bin
randomly uniformly and independent of other balls and falls into it.
Theorem: For the case when π‘š = 𝑛, prove that with very high probability,
every bin has O(log 𝑛) balls.
6
Balls into Bins
The main difficulty and the way out
1
1
Event
πœ€:
2
3 4
2
5
3
…
…
j
m-1 m
…
n
There is some bin having at least c log 𝑛 balls.
Observation: It is too difficult to calculate P(πœ€ ) directly.
Question: What is the way out?
7
Balls into Bins
From perspective of 𝑗th bin
1
1
2
3 4
2
5
3
…
…
j
m-1 m
…
πœ€ : There is some bin having at least c log 𝑛 balls.
 P(πœ€ ) ≀
Event πœ€π‘— : 𝑗th bin has at least c log 𝑛 balls.
Question: What is the relation πœ€ and πœ€π‘— ?
Answer: πœ€ = 𝑗 πœ€π‘—
n
Event
πœ€
𝑗 𝐏( 𝑗 )
8
Balls into Bins
From perspective of 𝑗th bin
1
1
2
3 4
2
5
3
…
…
j
m-1 m
…
n
πœ€ : There is some bin having at least c log 𝑛 balls.
 P(πœ€ ) ≀ 𝑗 𝐏(πœ€π‘— )
Event πœ€π‘— : 𝑗th bin has at least c log 𝑛 balls.
Observation: In order to show P(πœ€ ) < π‘›βˆ’4 , it suffice to show P(πœ€π‘— ) < ??π‘›βˆ’5
P(πœ€π‘— ) < π‘›βˆ’5
Event
9
AIM: TO SHOW
P(πœ€π‘— ) < π‘›βˆ’5
P(𝑗TH BIN HAS AT LEAST
𝐜 π₯𝐨𝐠 𝑛 BALLS) < π‘›βˆ’5
10
Calculating P(πœ€π‘— )
P[πœ€π‘— ] =
𝑖=𝑐 log 𝑛
=
𝑖=𝑐 log 𝑛
≀
𝑖=𝑐 log 𝑛
π‘›βˆ™ π‘›βˆ’1 π‘›βˆ’2 …(π‘›βˆ’π‘–+1) 1 𝑖
(𝑛 )
𝑖=𝑐 log 𝑛
𝑖!
1
𝑖=𝑐 log 𝑛
𝑖!
=
≀
≀
≀
≀
P(𝑗th bin has 𝑖 balls)
𝑛
βˆ™ (𝑛1 )𝑖 βˆ™ (1 βˆ’ 𝑛1 )π‘›βˆ’π‘–
𝑖
𝑛
1
βˆ™ (𝑛 )𝑖
𝑖
1
2
1
2
1
2
𝑖=𝑐 log 𝑛
(𝑒𝑖 )𝑖
𝑖=𝑐 log 𝑛
𝑒
𝑖
(𝑐 log
)
𝑛
𝑖=2𝑒 log 𝑛
Using Stirling’s formula π‘š! β‰ˆ (π‘šπ‘’ )π‘š 2πœ‹π‘š
Choosing 𝑐 = 2𝑒
𝑒
𝑖
(2𝑒 log
)
𝑛
≀ (12 )2𝑒 log 𝑛
≀ π‘›βˆ’2𝑒 ≀ π‘›βˆ’5
11
Balls into Bins
Theorem:
If 𝑛 balls are thrown randomly uniformly and independently into bins 𝑛, then
with probability 1 βˆ’ π‘›βˆ’4 , maximum load of any bin will be O(log 𝑛) balls.
Note:
With slightly more careful calculation, it can be shown that the maximum
load will be O((log 𝑛)/log log 𝑛).
12
APPLICATION 2 OF THE UNION THEOREM
RANDOMIZED QUICK SORT:
THE SECRET OF ITS POPULARITY
13
Concentration of Randomized Quick Sort
𝟏
𝒏
…
A
𝐗 : random variable for the no. of comparisons during Randomized Quick Sort
We know: E[𝐗]= 2𝑛 lπ‘œπ‘”π‘’ 𝑛 βˆ’ 𝑢(𝑛)
Our aim: P(𝐗 > 𝑐 𝑛 lπ‘œπ‘”π‘ 𝑛) < π‘›βˆ’π‘‘
For any constant 𝑑, we can find constants 𝑐 and 𝑏 such that the above
inequality holds.
We shall show that P(𝐗 > 8𝑛 lπ‘œπ‘”4/3 𝑛) < π‘›βˆ’7
14
Concentration of Randomized Quick Sort
Tools needed
1.
Slightly generalized Union theorem:
Suppose there is an event πœ€ defined over a probability space (𝛀,P) such that
πœ€ βŠ†=
𝑖
πœ€π‘– , then
P(πœ€ ) ≀
π’Š
𝐏(πœ€π‘– )
2. Probability that we get less than 𝑑 HEADS during 8𝑑 tosses of a fair coin is
3
less than ( )8𝑑 .
4
15
Randomized QuickSort
The main difficulty and the way out
Elements of A arranged in
Increasing order of values
𝑒𝑖
𝑒𝑗
Question: What is the main difficulty in showing P(𝐗 > 8𝑛 lπ‘œπ‘”4/3 𝑛) < π‘›βˆ’7
Answer: No direct way to bound P(𝐗 > 8𝑛 lπ‘œπ‘”4/3 𝑛) because
β€’ sample space is too huge
β€’ Sample space is non-uniform
Question: How could we bound E[𝐗] ?
Answer: (by taking microscopic view of Randomized Quick sort)
16
Randomized QuickSort
The main difficulty and the way out
Elements of A arranged in
Increasing order of values
𝑒𝑖
Question: What is the main difficulty in showing P(𝐗 > 8𝑛 lπ‘œπ‘”4/3 𝑛) < π‘›βˆ’7
Answer: No direct way to bound P(𝐗 > 8𝑛 lπ‘œπ‘”4/3 𝑛) because
β€’ sample space is too huge
β€’ Sample space is non-uniform
Question: How could we bound E[𝐗] ?
Answer: (by taking microscopic view of Randomized Quick sort)
17
Randomized QuickSort
from perspective of 𝑒𝑖
Elements of A arranged in
Increasing order of values
𝑒𝑖
𝑒𝑖 leaves the
algorithm
18
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 π˜π‘–
19
Randomized QuickSort
A new way to count the comparisons
Elements of A arranged in
Increasing order of values
Key idea:
Assign each comparison during a recursive calls to the non-pivot element.
Question: Is there any relation between 𝐗 and π˜π‘– ?
Answer: 𝐗 = 𝑛𝑖=1 π˜π‘–
Observation: If 𝐗 > 8𝑛 π₯𝐨𝐠 πŸ’/πŸ‘ 𝑛, there must be at least one 𝑖 such that
π˜π‘– > 8 π₯𝐨𝐠 πŸ’/πŸ‘ 𝑛
20
Randomized QuickSort
Applying Union theorem
Observation: If 𝐗 > 8𝑛 π₯𝐨𝐠 πŸ’/πŸ‘ 𝑛, there must be at least one 𝑖 such that
π˜π‘– > 8 π₯𝐨𝐠 πŸ’/πŸ‘ 𝑛
Event πœ€ : 𝐗 > 8𝑛 π₯𝐨𝐠 πŸ’/πŸ‘ 𝑛
Event πœ€π‘– : π˜π‘– > 8 π₯𝐨𝐠 πŸ’/πŸ‘ 𝑛
Question: What is the relation πœ€ and πœ€π‘– ?
Answer: πœ€ βŠ†
 P(πœ€ ) ≀
πœ€π‘–
𝑖 𝐏(πœ€π‘– )
𝑖
Observation: In order to show P(πœ€ ) < π‘›βˆ’7 , it suffice to show P(πœ€π‘– ) < ??π‘›βˆ’8
P(π˜π‘– > 8 π₯𝐨𝐠 πŸ’/πŸ‘ 𝑛) < π‘›βˆ’8
21
AIM: TO SHOW
P(π˜π‘– > 8 π₯𝐨𝐠 πŸ’/πŸ‘ 𝑛) < π‘›βˆ’8
22
Randomized Quick Sort
Increasing order of values
…
middle-half
Definition: a recursive call is good if the pivot is selected from the middle
half, and bad otherwise.
1
P(a recursive call is good) = ??
2
Notation: The size of a recursive call is the size of the subarray it sorts.
23
Randomized Quick Sort
Increasing order of values
…
middle-half
Observation: If a recursive call is good, size of each of its child-recursive calls
reduces by a factor of πŸ‘ πŸ’.
24
Randomized Quick Sort
𝑒𝑖
Increasing order of values
…
middle-half
Question: What is the maximum no. of good recursive calls can 𝑒𝑖 have ?
Answer: π₯𝐨𝐠 πŸ’/πŸ‘ 𝑛.
25
Randomized Quick Sort
Summary from the perspective of 𝑒𝑖
During Randomized Quick Sort element 𝑒𝑖
β€’ Participates in a sequence of recursive calls each of which is good
independently with probability 1/2.
β€’ 𝑒𝑖 leaves the algorithm on or before participating in π₯𝐨𝐠 πŸ’/πŸ‘ 𝑛 good
recursive calls.
πœ€π‘– can be re-stated as:
𝑒𝑖 participated in more than 8 π₯𝐨𝐠 πŸ’/πŸ‘ 𝑛 recursive calls but fewer than
π₯𝐨𝐠 πŸ’/πŸ‘ 𝑛 turned out to be good.
3 8 π₯𝐨𝐠 πŸ’/πŸ‘ 𝑛
)
<
(
)
𝑖
4
= π‘›βˆ’8
P(πœ€
Probability we get less than 𝑑 HEADS
3
during 8𝑑 tosses of a fair coin < (4)8𝑑 .
26
Randomized Quick Sort
Final result
Theorem: Let 𝐗 be the random variable for the no. of comparisons during
Randomized Quick Sort on input of size 𝑛
P(𝐗 > 8𝑛 lπ‘œπ‘”4/3 𝑛) < π‘›βˆ’7
Homework: Rework the calculation to find the smallest possible 𝑐 such that
P(𝐗 > 𝑐𝑛 lπ‘œπ‘”π‘’ 𝑛) < π‘›βˆ’2
27
SOME WELL KNOWN AND WELL STUDIED
RANDOM VARIABLES
28
Bernoulli Random Variable
Bernoulli Random Variable:
A random variable X is said to be a Bernoulli random variable with parameter
𝑝 if it takes value 1 with probability 𝑝 and takes value 0 with probability 1 βˆ’ 𝑝.
The corresponding random experiment is usually called a Bernoulli trial.
Example: Tossing a coin (of HEADS probability= 𝑝) once, HEADS corresponds to
1 and TAILS corresponds to 0.
E[X] = 𝑝
29
Binomial Random Variable
Binomial Random Variable:
Let 𝑋1 ,…, 𝑋𝑛 be 𝑛 independent Bernoulli random variables with parameter 𝑝,
then random variable X= 𝑋1 + β‹― +𝑋𝑛 is said to be a Binomial random
variable with parameters 𝑛 and 𝑝.
Example: number of HEADS when we toss a coin (of HEADs probability= 𝑝) 𝑛
times.
Homework:
Prove, without any knowledge of binomial coefficients, that E[X] = 𝑛𝑝.
30
Geometric Random Variable
Geometric Random Variable:
Consider an infinite sequence of independent and identical Bernoulli trials
with parameter 𝑝. Let X denote the number of these trials upto and including
the trial which gives the first 1 is called a Geometric random variable with
parameter 𝑝.
Example: Number of tosses of a coin (of HEADs probability= 𝑝) to get the first
HEADS.
Homework:
β€’ Find the probability P(X= 𝑖).
β€’ Prove, that E[X] = 1/𝑝
31
Negative Binomial Random Variable
Negative Binomial Random Variable:
Let 𝑋1 ,…, 𝑋𝑛 be 𝑛 independent Geometric random variables with parameter 𝑝,
then random variable X= 𝑋1 + β‹― +𝑋𝑛 is said to be a negative-Binomial random
variable with parameters 𝑛 and 𝑝.
Example: number of tosses of a coin (of HEADs probability= 𝑝) to get 𝑛 HEADS.
Homework:
β€’ Guess why it is called β€œnegative” Binomial random variable.
β€’ Find the probability P(X= 𝑖).
β€’ Prove, without any knowledge of binomial coefficients, that E[X] = 𝑛/𝑝
32