Randomized Algorithms: Tutorial 3 Hints For Homework 2
Randomized Algorithms: Tutorial 3 Hints For Homework 2
Tutorial 3
Hints for Homework 2
Outline
Hints for Homework 2
Randomized Quicksort (Exercise 4.20)
Michaels Algorithm (optional)
[1]
One of Three (optional)
[1]
[1]Probability and Computing, CMU 15-359, Fall 2007.
Hints for Homework 2
Exercise 1
Find variance in number of fixed points
assuming permutation is chosen
uniformly at random
Hint
Cannot use linearity to find the variance.
Just calculate it directly
Exercise 2
Weak Law of Large Numbers
independent RV X
1
, X
2
, , X
n
Same finite mean , finite std-dev
Show
Hint
Chebyshevs inequality
0
...
Pr lim
2 1
=
|
|
.
|
\
|
>
+ + +
c
n
X X X
n
n
Exercise 3 (Parameter Estimation)
Show that
Show for any belongs to (0,1)
|
|
.
|
\
|
+
|
|
.
|
\
|
< >
3
exp
2
exp ) |
~
Pr(|
2 2
c c
c
na na
p p p
o c
c
o
< > > ) |
~
Pr(| then ,
) / 2 ln( 2
if
2
p p p
a
n
Exercise 4
Let X
1
, X
2
, , X
n
be n Poisson trials
Let a
1
, a
2
, , a
n
be real in [0,1]
Let W =a
i
X
i
and =E[W].
Show that
Hint
MGF & Markov inequality
v
o
o
o
v o
|
|
.
|
\
|
+
< + >
+ ) 1 (
) 1 (
) ) 1 ( Pr(
e
W
Exercise 4
Somehow, you may need to show this
inequality to simplify terms:
For any x 2 [0,1],
e
tx
1 x(e
t
1)
Hint: can be proven by calculus
Exercise 5
Let X = X
1
+ X
2
+ + X
n
,
each X
i
= Geo(0.5)
Compare X with a sequence of fair
coin tosses Show that
|
|
.
|
\
|
+
< + >
) 1 ( 2
exp ) 2 ) 1 ( Pr(
2
o
o
o
n
n X
Randomized Quicksort
Quicksort(S) {
1. If |S|1, return S
2. Else, pick an item x from S
3. Divide S into S
1
and S
2
with
S
1
= list of all items smaller than x
S
2
= list of all items greater than x
4. List
1
= Quicksort(S
1
)
5. List
2
= Quicksort(S
2
)
6. return List
1
, x, List
2
}
Randomized Quicksort
In step 2, we choose x by picking an
item uniformly at random from S.
Runtime = expected O(n log n)
Can we show it runs in O(n log n) time
with high probability ?
Randomized Quicksort
Let s = size of the set to be sorted
at a particular node
Node:= point which decides on a pivot
Randomized Quicksort
s/2 3s/4
good node bad node
A good node is one whose pivot divides the set into two parts
with size of each part not exceeding 2s/3
Randomized Quicksort
Fact 1: # good nodes in any path is at
most c log
2
n, for some c
Proof:
# good nodes is at most
log n / log(3/2) = c log n
Randomized Quicksort
Fact 2: With probability 1 - 1/n
2
,
# nodes in a root-to-leaf path is
at most c log
2
n, for some c
Proof:
P := a root-to-leaf path,
l := length of P
B := # bad nodes in P
Randomized Quicksort
Proof (cont.): Now, we know that
B l c log n (why?)
and Pr(bad node) = 2/3
Pr(l > c log n)
Pr(B > c log n c log n)
(2/3)
c log n c log n
n
-2
( for large c )
Randomized Quicksort
Fact 3: With probability 1-1/n,
# nodes in the longest root-to-leaf
path is at most c log
2
n
Proof: Union Bound
Randomized Quicksort
Conclusion:
Runtime of Randomized Quicksort is
O(n log n) with prob at least 1-1/n
Proof:
Height of the tree is O(log n) with
probability at least 1-1/n
Runtime in this case: O(n log n)
Michaels Algorithm
Michaels Algorithm
Input: a set of 2D points
Determine the closest pair (and its dist)
Input points are stored in an array
Michaels Algorithm
Suppose we have a strange storage
data structure D :
When we give a point to D, it stores
the point and outputs the closest pair
of points stored in D
D
Output
Insert
D
Output
Michaels Algorithm
Our knowledge: Insertion time
depends on whether the closest pair is
changed or not.
If output is the same: 1 clock tick
D
Output
Insert
D
Output
Michaels Algorithm
If output is not the same: |D| clock ticks
Insert
D
Output
D
Output
Michaels Algorithm
With random insertion order,
show that the expected total number of
clock ticks used by D is O(n)
Proof:
X
i
: # clock ticks to insert i
th
point
X: the total clock ticks
Michaels Algorithm
Proof (cont.):
p = Pr( i
th
point causes answer change)
= Pr( i
th
point causes answer change)
= 2/i
E[X
i
] = i*p + 1*(1-p) = i* 2/i +1- 2/i 3
E[X] = O(n) by linearity of expectation
One of Three
One of Three
A company is developing a prediction
system by machine learning
For a given item, the prediction has
Pr(success) = p
1
Pr(failure) = p
2
Pr(not sure) = p
3
One of Three
The algorithm is run for n items
Let
X
1
: total # with correct prediction
X
2
: total # with failure prediction
X
3
: total # with not-sure prediction
Can we compute E[X
1
|X
3
=m] ?
One of Three
Answer:
(1) X
3
=m X
1
+X
2
= n = n-m
(2) Let p denote:
Pr(i
th
prediction correct | not not-sure)
= p
1
/ (p
1
+p
2
)
One of Three
The value of X
1
given X
3
=m is Bin(n,p)
E[X
1
|X
3
=m]
np
(n-m)p
1
/(p
1
+p
2
)