Randomized Quicksort
running time is independent of input ordering
• No assumptions about the input distribution
NP Specific input elict the worst-case behavior
the worst-case is determined only by a random-number generator
Pivot on random element
Analysis:
T (n) = R.V for running time assuming Rand # ' s Independent
For k = 0,1,2,..., n-1
X_k =[1, if partition genrates a k:n-k-1 split
[0 otherwise
X_k is an indicator random variable (indicator random variable) only 1 or 0
E[x_k]= 0*pr{x_k=0}+1*pr{x_k=1}
= Pr{x_k=1}
= 1/n
Each element have 1/n chance to be pivot
T (n) =[t (0) +t (n-1) +θ (n) if 0: (n-1) split
=[t (1) +t (n-2) +θ (n) if 1: (n-2) split
=[....
=[t (n-1) +t (0) +θ (n) if n-1:0 split
N-1
=∑x_k (T (k) +t (n-k-1) +θ (n))
K=0
E[t (n)]=e[∑ ...]
n-1
=∑x_k (t (k) +t (n-k-1) +θ (n))
k=0
n-1
=∑e (x_k) *e[x_k (t (k) +t (n-k-1) +θ (n))]
k=0
n-1 n-1 n-1
=1/n *∑e[t (k)] + 1/n*∑e[t (n-k-1)] + 1/n*∑θ (n
k=0 k=0 &NBS P k=0
n-1
=2/n *∑e[t (k)] +θ (n)
; k=0
absorb k=0,1 terms intoθ (n) for technical convenience
& nbsp n-1
E[t (n))] = 2/n *∑e[t (k)] +θ (n)
&NB Sp k=0
Prove e[t (N)] <= a LG (n) for const A>0
Chosose a big enough so
An LG (n) >= e[t (n)] for small n
N-1
Use FACT:∑KLG (k) <= 1/2* n^2 ' LG (n) -1/8 * n^2
k=2
Substitution:
N-1
E[t (n)]<= 2/n*∑ak LG (k) +θ (n)
k=2
<= 2a/n * (n^2 LG (n)-1/8 * n^2) +θ (n)
= an LG (n)-(An/4-θ (n))
Desired-residual
<= an LG (n) If a big enough so that AN/4 >θ (n)
Random quick sorting of learning records