randomized algorithms by p2i6L5

VIEWS: 11 PAGES: 6

									                     Algorithms
             Randomized Algorithms
 Major Sources:
 Brassard and Bratley, Algorithmics: Theory and Practice

 Cormen, Lieserson, Rivest, and Stein, Introduction to
 Algorithms

 Horowitz, Sahni, and Rajasekaran, Computer Algorithms in
 C++




CS 8833       Algorithms
       Randomized Algorithms
 Randomized algorithms make use of a
  randomizer (such as a random number
  generator).
 Some of the decisions of the algorithm
  depend on the output of the randomizer.
    – The output may vary from run to run.
    – The execution time may vary from run to
      run.
    CS 8833   Algorithms
    Major Classes of Randomized
             Algorithms
   Las Vegas algorithms:
    – Always produce the same (correct) output for the same input
    – Execution time depends on the randomizer
    – Goal is often to minimize the odds of encountering worst case
      performance
    – Example: Randomized quick sort
   Monte Carlo algorithms:
    – Occasionally gives an incorrect answer
    – The probability of an incorrect answer is required to be low.
    – Typically does not display variation in execution time for a particular
      input
    – Goal is to provide an answer that has a high likelihood of being
      correct in a reasonable time
    – Example: Determining primality of an integer with several hundred
      decimal digits.


    CS 8833       Algorithms
         Analysis of Probabilistic
               Algorithms
   Analysis is often complex and typically requires
    concepts from
    – Probability
    – Statistics
    – Number theory
   Assume availability of Random(a,b) which returns an
    integer between a and b, inclusive with each integer
    being equally likely.
   Assume cost of producing a single random value is
    constant
   In practice we typically use pseudo-random number
    generators

    CS 8833    Algorithms
    Randomly Permuting Arrays
 Many randomized algorithms randomize
  the input by randomly permuting the
  elements of an array.
 Two algorithms given in text
    – Permute by sorting (page 101)
    – Randomize in place (page 103)



    CS 8833   Algorithms
    RANDOMIZE-IN-PLACE(A)
    1    n  length[A]
    2    for i  1 to n do
    3           swap A[i]  A[RANDOM(i,n)]




•   How many permutations are there of n items?
•   For each permutation of n items, what is the probability that
    permutation will be produced by the above algorithm?




CS 8833        Algorithms

								
To top