算法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 <= c n operations outside of the recursive call [for some constant c > 0]
    Notation: RSelect is in phase j if current array size between ( 3 4 ) j + 1 n and ( 3 4 ) j n .
    X j = numbers of recursive calls during phase j.
    Note: running time of RSelect <= p h a s e j X j c ( 3 4 ) j n
    (1) ( 3 4 ) j n : <= array size during phase j
    (2) c ( 3 4 ) j n : work per phase j subproblem.
    (3) X j :of phase -j subproblems.
    2.3 Proof II: Reduction to Coin Flipping
    X j :# 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 [ x j ] <= expected number of times you need to flip a fair coin to get one “head”.
    ( h e a d s g o o d p i v o t , t a i l s b a d p i v o t )
    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 [ x j ] <= E [ N ] )
    expected running time of RSelect:
    (2) E [ c n p h a s e j ( 3 4 ) j X j ] c n p h a s e j ( 3 4 ) j E [ X j ] 2 c n p h a s e j ( 3 4 ) j 8 c n = O ( n )

    其中: E ( o f c o i n f l i p s N ) = 2
    p h a s e j ( 3 4 ) j 1 1 3 4 = 4

猜你喜欢

转载自blog.csdn.net/qq_31805127/article/details/79964022