算法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
阅读更多

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