qq_31805127的博客

学习使我快乐

算法week4---algorithms-divide-conquer--part1(RSelect)

  1. Randomized Selection
    1.1 R Select (array A, length n, order statistic i)
    (0): if n =1 return A[1]
    (1):choose pivot p from A uniformly at random.
    (2):partition A around p;
    let j = new index of p
    (3): if j=i, return p;
    (4): if j > i, return RSelect (1st part of A, j-1, i)
    (5):if j > i , return RSelect(1st part of A, j-1, i)
    (6):if j < i: return RSelect(2nd part of A, n-j, i-j)
  2. Running Time of RSelect
    2.1 RSelect Theorem: for every input array of length n, the average running time of RSelect is O(n).
    2.2 Tracking Progress via Phases.
    Note: RSelect uses <=cn operations outside of the recursive call [for some constant c > 0]
    Notation: RSelect is in phase j if current array size between (34)j+1n and (34)jn.
    Xj= numbers of recursive calls during phase j.
    Note: running time of RSelect <=phasejXjc(34)jn
    (1) (34)jn : <= array size during phase j
    (2) c(34)jn: work per phase j subproblem.
    (3)Xj:of phase -j subproblems.
    2.3 Proof II: Reduction to Coin Flipping
    Xj :# of recursive calls during phase j
    Note: if RSelect choose a pivot giving a 25%75% spltit (or better): then current phase ends!(new subarray length at most 75% of old length).
    Recall: probability of 25%75%split or better is 50%.
    So: E[xj]<=expected number of times you need to flip a fair coin to get one “head”.
    (headsgoodpivot,tailsbadpivot)
    2.4 Proof III: Coin Flipping Analysis
    Let N= number of coin flips until you get heads
    (a “geometric random varible”)
    Note:E[N]=1+1αE[N]
    1: 1st coin flip.
    1α: probablity of tails
    E[N]: # of further coin flips needed in this case.
    Solution: E[N]=α (Recall E[xj]<=E[N])
    expected running time of RSelect:
    (2)E[cnphasej(34)jXj]cnphasej(34)jE[Xj]2cnphasej(34)j8cn=O(n)

    其中: E(ofcoinflipsN)=2
    phasej(34)j1134=4
阅读更多
上一篇算法三-----QUICKSORT
下一篇算法---algorithms-divide-conquer--graphs(week4) part2
想对作者说点什么? 我来说一句

算法算法算法算法算法算法

2008年12月24日 78KB 下载

c和java写的各种算法

2011年03月15日 688KB 下载

算法导论第1版,经典书籍

2011年04月19日 694KB 下载

epicflowepicflowepicflow 源码

2017年09月20日 43.52MB 下载

FASTica算法matlab代码

2017年09月17日 3KB 下载

十大算法之蒙特卡罗算法

2009年12月08日 1.16MB 下载

没有更多推荐了,返回首页

关闭
关闭