码迷,mamicode.com
首页 > 编程语言 > 详细

随机快速排序学习记录

时间:2016-01-10 15:39:56      阅读:276      评论:0      收藏:0      [点我收藏+]

标签:

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 ,let
X_k =[ 1 ,if partition genrates a k : n-k-1 split
[ 0 otherwise
X_k is an 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 has 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                     k=0
          n-1
=2/n *∑E[T(k)] + Θ(n)
          k=0
Absorb k=0,1 terms into Θ(n) for technical convenience
                       n-1
E[T(n))] = 2/n *∑E[T(k)] + Θ(n)
                       k=0

Prove E[T(n)] <= an lg(n) for const a>0
chosose a big enough so that
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 *(1/2 * 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)

随机快速排序学习记录

标签:

原文地址:http://www.cnblogs.com/xvbb/p/5118506.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!