Lecture 5
Lecture 5
Lent 2020
Outline
Conditional Expectation
Quick-Sort
P[ B|A ] = P[ B ∩ A ] /P[ A ] .
f (a) = E[ Y |X = a ] ,
(1) E[ E[ Y |X ] ] = E[ Y ].
(2) E[ 1|X ] = 1
(3) Linearity:
For any constant c ∈ R, E[ cY |X ] = cE[ Y |X ]
E[ Y + Z |X ] = E[ Y |X ] + E[ Z |X ]
(4) If X is independent of Y , then E[ Y |X ] = E[ Y ] .
(5) if Y is a function of X , i.e. Y = f (X ), then E[ YZ |X ] = Y E[ Z |X ].
Particularly, E[ X |X ] = X
(6) Tower Property:
E[ E[ X |(Z , Y ) ] |Y ] = E[ X |Y ].
(7) Jensen Inequality:
if f is a convex real function, then f (E[ X |Y ]) ≤ E[ f (X )|Y ].
These properties greatly simplify calculations. Example: for our two dice
p3 p5,p4
E[ X1 + X2 |X1 ] = E[ X1 |X1 ] + E[ X2 |X1 ] = X1 + E[ X2 ] = X1 + 3.5
X
E[ E[ Y |X ] ] = E[ Y |X ](ω) · P[ {ω} ]
ω∈Ω
X
= E[ Y |X = x ] P[ X = x ]
x
XX
= y P[ Y = y |X = x ] P[ X = x ]
x y
XX
= y P[ Y = y , X = x ]
x y
X
= y P[ Y = y ]
y
= E[ Y ]
Bonus Exercise: Prove Property (1) using Properties (4) and (2).
Conditional Expectation
Quick-Sort
Algorithm: QuickSort
Input: Array of different number A.
Output: array A sorted in increasing order
Pick an element uniformly from the array, the so-called pivot .
If |A| = 0 or |A| = 1; return A.
Else
Generate two subarrays A1 and A2 :
A1 contains the elements that are smaller than the pivot ;
A2 contains the elements that are greater than the pivot ;
Recursively sort A1 and A2 .
If the initial pivot selected is the jth smallest value, then the set of values
smaller than it has size j − 1, and the set of values greater has size n − j.
Hence, as n − 1 comparisons with the pivot must be made, we have
n n−1
X 1 2X
Mn = (n − 1 + Mj−1 + Mn−j ) = n − 1 + Mj .
n n
j=1 j=1
Since M0 = 0.
Thus
(n + 1)Mn+1 − nMn = 2n + 2Mn .
Or equivalently
(n + 1)Mn+1 = 2n + (n + 2)Mn .
Conditional Expectation
Quick-Sort
Let G = min{k ≥ 1 : Xk = 1}, the number of coin flips until we get a head.
Solve
E[ G ] = p + (1 − p)(1 + E[ G ])
To give
E[ G ] = 1/p.
hP i h hP ii
M P1 M
We shall use E i=1 Xi = E E i=1 Xi |M . Observe that for any k ∈ N
" M
# " k
#
X X
f (k ) := E Xi M = k =E Xi M = k
i=1 i=1
k k
P3 P4 X
X
= E Xi M = k = E[ Xi ] = k · E[ Xi ] ,
i=1 i=1
hP i
M
since Xi are all equidistributed. Thus E i=1 Xi |M = f (M) = M · E[ Xi ] .
To conclude we have
" M #
P3
X
E Xi = E[ ME[ Xi ] ] = E[ M ] E[ Xi ] .
i=1