randomized algorithms by p2i6L5


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

 Cormen, Lieserson, Rivest, and Stein, Introduction to

 Horowitz, Sahni, and Rajasekaran, Computer Algorithms in

CS 8833       Algorithms
       Randomized Algorithms
 Randomized algorithms make use of a
  randomizer (such as a random number
 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
    CS 8833   Algorithms
    Major Classes of Randomized
   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
    – 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
    – 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
   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
   In practice we typically use pseudo-random number

    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
    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