SlideShare a Scribd company logo
1 of 38
Download to read offline
Seminar Report
                              On




RANDOMIZED ALGORITHM

                        Submitted by


                     ASHISH KUMAR




  In partial fulfillment of the requirements for the Degree of

       Bachelor of Technology (B. Tech)
                      in
       Computer Science and Engineering




      DIVISION OF COMPUTER ENGINEERING
              SCHOOL OF ENGINEERING
COCHIN UNIVERSTY OF SCIENCE AND TECHNOLOGY
                      COCHIN-682022

                     SEPTEMBER 2009
COCHIN UNIVERSTY OF SCIENCE AND TECHNOLOGY
         DIVISION OF COMPUTER ENGINEERING
          CENTRE FOR ENGINEERING STUDIES
                    COCHIN-682022




                            Certificate

         Certified that this is a bonafide record of the seminar entitled
                      “RANDOMIZED ALGORITHM”
                                    taken by

                               ASHISH KUMAR




of the VIIth semester ,Computer Science and Engineering in the year
2009 in partial fulfillment of the requirements to the award of Degree
Bachelor of Technology in Computer Science and Engineering of Cochin
University of Science and Technology.




Ms. Ramyamol                                           Dr. David Peter
Seminar Guide                                         Head of the Division


Place: Kochi-22
Date: 15.09.2009
ACKNOWLEDGEMENT


      I take this occasion to thank God, Almighty for blessing me with
his grace and taking my endeavor to a successful culmination. I extend
my sincere and heartfelt thanks to my esteemed guide, Ms. Ramyamol
for providing me with the right guidance and advice at the crucial
junctures and for showing me the right way. I extend my sincere thanks to
our respected head of the division Mr. David Peter, for allowing me to
use the facilities available. I would like to thank the other faculty
members also, at this occasion. Last but not least, I would like to thank
friends for the support and encouragement they have given us during the
course of my work.



                                                    Ashish Kumar




                                                                        i
ABSTRACT
      A randomized algorithm is defined as an algorithm that typically
uses the random bits as an auxiliary input to guide its behavior. It achievs
good performance in the "average case". Formally, the algorithm's
performance will be a random variable determined by the random bits,
with (hopefully) good expected value. The "worst case" is typically so
unlikely to occur that it can be ignored. First and foremost reason for
using randomized algorithms is simplicity. An easy randomized
algorithm can match the performance of a deterministic algorithm. For
some problems, the best-known randomized algorithms are faster than the
best-known deterministic algorithms. This is achieved by requiring that
the correct answer be found only with high probability or that the
algorithm should run in expected polynomial time. This means that the
randomized algorithm may not find a correct answer in some cases or
may take very long time.
Two types of Randomized Algorithms:
1. Las Vegas Algorithm
2. Monte Carlo Algorithm


         Las Vegas Algorithm: The randomized algorithm always outputs
the correct answer, it is just that there is a small probability of taking
long to execute.

        Monte Carlo Algorithm: The algorithm always completes quickly,
but allow a small probability of error. Quicksort is probably the most
familiar "real-world" algorithm in which randomness is very useful. The
deterministic version of this algorithm requires O(n2) time to sort n
numbers for some degenerate inputs -- such as the array elements being
already in sorted order! However, if the algorithm randomly permutes
                                                                           ii
elements before starting, it finishes in O(n log n) time with a high
probability, for any input. The difference between the two is crucial
when sorting large data sets.




                                                                   iii
LIST OF FIGURES
8. Min Cut………………………. ….……………………………..…20




                                          iv
TABLE OF CONTENTS

ACKNOWLEGMENT………………………………………………………….....…i
ABSTRACT……………………………………………………………………….....ii
LIST OF FIGURES…………………………………………………….…………....iv
TABLE OF CONTENTS…………………………………………………………......v

1. INTRODUCTION………………………………..........………………..…............1
2. TYPES OF ALGORITHM……………………………….............…….......……...1
3. RANDOMIZED ALGORITHM
       3.1Random Number Generation...………………………………..….…..…...5
       3.2 True Random number Vs pseudorandom number………....…….…….....5
       3.3 Generation Method
               3.3.1 Physical Method..........................................................................6
                3.3.2 Computational Method………………………………………...7
                3.3.3 Generation From a Probability Distribution...............................9
4. DETERMINISTIC ALGORITHM……..……………………..….………….......10
5. RANDOMIZED ALGORITHM……………………………….…...…………....10
         5.1 Why Randomized Algorithm…………………………………………...11
6. LAS VEGAS & MONTE CARLO
        6.1 Las Vegas Algorithm…………….....………………………….….….....12
        6.2 Monte Carlo Algorithm………..…………………………………..…....12
7. RANDOMIZED QUICK SORT
        7.1 Traditional Quicksort……………………………………………………14
       7.1 Randomized Quicksort……………..........................................................15
8. RANDOMIZED MIN-CUT ALGORITHM..........................................................18
9. COMPLEXITY CLASSES ....................................................................................22
10. ADVANTAGES…………...................................................................................25
11. DISADVANTAGES……………………………………………………………26
12. SCOPE…………………………………………………………………………..27
13. CONCLUSION…………………………………………………………………28
14. BIBLIOGRAPHY………………………………………………………………29




                                                                                                              v
vi
Randomized Algorithm                                          Seminar Report ‘09




                         1. INTRODUCTION
       An algorithm is any well-defined computational procedure that takes
some values, or set of values as input and produces some values or set of
values as output. An algorithm is thus a sequence of computational steps that
transform the input into the output. A problem can be represented as a tuple,
problem (instances, solutions). Where instances are the inputs to the problem
and solutions are the outputs to the problem. To solve a problem we can use
different algorithms. These algorithms differ dramatically in their efficiency.


       A randomized algorithm is defined as an algorithm that typically uses
the random bits as an auxiliary input to guide its behavior. It achieves good
performance in the "average case".



                    2. TYPES OF ALGORITHM
Algorithm classification
        Algorithms that use a similar problem-solving approach can be
grouped together. This classification scheme is neither exhaustive nor disjoint.
The purpose is not to be able to classify an algorithm as one type or another,
but to highlight the various ways in which a problem can be attacked.

A short list of categories
         Algorithm types considered include:

           –   Simple recursive algorithms

           –   Backtracking algorithms

           –   Divide and conquer algorithms

           –   Dynamic programming algorithms

           –   Greedy algorithms

           –   Branch and bound algorithms

Division of Computer Engineering                                                  1
Randomized Algorithm                                            Seminar Report ‘09




           –   Brute force algorithms

           –   Randomized algorithms



Simple recursive algorithms
       A simple recursive algorithm consist of following steps:

           –   Solves the base cases directly.

           –   Recurs with a simpler sub problem.

           –   Does some extra work to convert the solution to the simpler sub
               problem into a solution to the given problem.

       We call these “simple” because several of the other algorithm types are
       inherently recursive.

Backtracking algorithms

       Backtracking algorithms are based on a depth-first recursive search

A backtracking algorithm consists of following steps:

           –   Tests to see if a solution has been found, and if so, returns it;
               otherwise.

           –   For each choice that can be made at this point,

                   •   Make that choice

                   •   Recur

                   •   If the recursion returns a solution, return it

           –   If no choices remain, return failure.




Division of Computer Engineering                                                   2
Randomized Algorithm                                          Seminar Report ‘09




Divide and Conquer
       A divide and conquer algorithm consists of two parts:

           –    Divide the problem into smaller sub problems of the same type,
                and solve these sub problems recursively

           –    Combine the solutions to the subproblems into a solution to the
                original problem

        Traditionally, an algorithm is only called divide and conquer if it
contains two or more recursive calls.




Dynamic programming algorithms
               A dynamic programming algorithm remembers past results and
uses them to find new results. Dynamic programming is generally used for
optimization problems.

           –    Multiple solutions exist, need to find the “best” one

           –    Requires “optimal substructure” and “overlapping
                subproblems”

                    •   Optimal substructure: Optimal solution contains optimal
                        solutions to subproblems

                    •   Overlapping subproblems: Solutions to subproblems
                        can be stored and reused in a bottom-up fashion

   •   This differs from Divide and Conquer, where subproblems generally
       need not overlap.




Division of Computer Engineering                                               3
Randomized Algorithm                                           Seminar Report ‘09




Greedy algorithms
       An optimization problem is one in which you want to find, not just a
solution, but the best solution A “greedy algorithm” sometimes works well for
optimization problems.

      A greedy algorithm works in phases: At each phase:

           –   You take the best you can get right now, without regard for
               future consequences.

           –   You hope that by choosing a local optimum at each step, you
               will end up at a global optimum.




Brute force algorithm
      A brute force algorithm simply tries all possibilities until a satisfactory
solution is found Such an algorithm can be:

       Optimizing: Find the best solution. This may require finding all
solutions, or if a value for the best solution is known, it may stop when any
best solution is found.

Example: Finding the best path for a travelling salesman.

       Satisficing: Stop as soon as a solution is found that is good enough

Example: Finding a travelling salesman path that is within 10% of optimal.




Division of Computer Engineering                                                    4
Randomized Algorithm                                         Seminar Report ‘09




                        3. RANDOM NUMBER

3.1. Random number generation
           A random number generator (often abbreviated as RNG) is a
computational or physical device designed to generate a sequence of numbers
or symbols that lack any pattern, i.e. appear random. Hardware-based systems
for random number generation are widely used, but often fall short of this
goal, though they may meet some of the statistical tests for randomness
intended to ensure that they do not have any easily discernible patterns.
Methods for generating random results have existed since ancient times,
including dice, coin flipping, the shuffling of playing cards, the use of yarrow
stalks (by divination) in the I Ching, and many other techniques.

       The many applications of randomness have led to many different
methods for generating random data. These methods may vary as to how
unpredictable or statistically random they are, and how quickly they can
generate random numbers.

       Before the advent of computational random number generators,
generating large amounts of sufficiently random numbers (important in
statistics) required a lot of work. Results would sometimes be collected and
distributed as random number tables.

      A growing number of government-run lotteries, and lottery games, are
using RNGs instead of more traditional drawing methods, such as using ping-
pong or rubber balls.


3.2. "True" random numbers vs. pseudorandom numbers

      There are two principal methods used to generate random numbers.
One measures some physical phenomenon that is expected to be random and
then compensates for possible biases in the measurement process. The other
uses computational algorithms that produce long sequences of apparently

Division of Computer Engineering                                              5
Randomized Algorithm                                       Seminar Report ‘09




random results, which are in fact completely determined by a shorter initial
value, known as a seed or key. The latter type are often called pseudorandom
number generators.

       A "random number generator" based solely on deterministic
computation cannot be regarded as a "true" random number generator, since
its output is inherently predictable. How to distinguish a "true" random
number from the output of a pseudo-random number generator is a very
difficult problem. However, carefully chosen pseudo-random number
generators can be used instead of true random numbers in many applications.
Rigorous statistical analysis of the output is often needed to have confidence
in the algorithm.


3.3. Generation methods

3.3.1. Physical methods

         There is general agreement that, if there are such things as "true"
random numbers, they are most likely to be found by looking at physical
processes which are, as far as is known, unpredictable. The earliest methods
for generating random numbers — dice, coin flipping, roulette wheels — are
still used today, mainly in games and gambling as they tend to be too slow for
applications in statistics and cryptography.

       The generation of true random numbers outside the computer
environment is based on the theory of entropy. A physical random number
generator can be based on an essentially random atomic or subatomic physical
phenomenon whose unpredictability can be traced to the laws of quantum
mechanics. Sources of entropy include radioactive decay, thermal noise, shot
noise, clock drift, and atmospheric conditions.

       Various imaginative ways of collecting this entropic information have
been devised. Atari 8-bit computers used electronic noise from an analog

Division of Computer Engineering                                            6
Randomized Algorithm                                          Seminar Report ‘09




circuit to generate true random numbers. One common technique is to run a
hash function against a frame of a video stream from an unpredictable source.
Lavarand used this technique with images of a number of lava lamps. Lithium
Technologies uses a camera pointed at the sky on a windy and cloudy day.
HotBits measures radioactive decay with GM tubes, while Random.org uses
variations in the amplitude of atmospheric noise recorded with a normal radio.

       Some physical phenomena, such as thermal noise in Zener diodes
appear to be truly random and can be used as the basis for hardware random
number    generators.   However,     many    mechanical     phenomena    feature
asymmetries and systematic biases that make their outcomes not truly random.
The many successful attempts to exploit such phenomena by gamblers,
especially in roulette and blackjack are testimony to these effects.

      Another common entropy source is the behavior of human users of the
system, if such users exist. While humans are not considered good randomness
generators upon request, they generate random behavior quite well in the
context of playing mixed strategy games. Some security-related computer
software requires the user to input a lengthy string of mouse movements or
keyboard input to add a certain degree of randomness to computational
pseudo-random number generation.[


3.3.2. Computational methods

      Pseudo-random number generators (PRNGs) are algorithms that can
automatically create long runs (for example, millions of numbers long) with
good random properties but eventually the sequence repeats (or the memory
usage grows without bound). One of the most common PRNG is the linear
congruential generator, which uses the recurrence




Division of Computer Engineering                                               7
Randomized Algorithm                                          Seminar Report ‘09




to generate numbers. The maximum number of numbers the formula can
produce is the modulus, m. To avoid certain non-random properties of a single
linear congruential generator, several such random number generators with
slightly different values of the multiplier coeffient a are typically used in
parallel, with a "master" random number generator that selects from among
the several different generators.

         A simple pen-and-paper method for generating random numbers is
the so-called middle square method suggested by John Von Neumann. While
simple to implement, its output is of poor quality.

        Most computer programming languages include functions or library
routines that purport to be random number generators. They are often designed
to provide a random byte or word, or a floating point number uniformly
distributed between 0 and 1.

       Such library functions often have poor statistical properties and some
will repeat patterns after only tens of thousands of trials. They are often
initialized using a computer's real time clock as the seed. These functions may
provide enough randomness for certain tasks (for example video games) but
are unsuitable where high-quality randomness is required, such as in
cryptographic applications, statistics or numerical analysis. Much higher
quality random number sources are available on most operating systems; for
example /dev/random on various BSD flavors, Linux, Mac OS X, IRIX, and
Solaris, or CryptGenRandom for Microsoft Windows.

       An example of a simple random number generator that is
computationally fast, has good (albeit not cryptographically strong)
randomness properties, is (note that this example is not thread safe):




Division of Computer Engineering                                               8
Randomized Algorithm                                          Seminar Report ‘09



m_w = <choose-initializer>;
m_z = <choose-initializer>;


uint get_random()
{
    m_z = 36969 * (m_z & 65535) + (m_z >> 16);
    m_w = 18000 * (m_w & 65535) + (m_w >> 16);
    return (m_z << 16) + m_w; /* 32-bit result */
}


3.3.3. Generation from a probability distribution

         There are a couple of methods to generate a random number based on a
probability density function. These methods involve transforming a uniform
random number in some way. Because of this, these methods work equally
well in generating both pseudo-random and true random numbers. One
method, called the inversion method, involves integrating up to an area greater
than or equal to the random number (which should be generated between 0
and 1 for proper distributions). A second method, called the acceptance-
rejection method, involves choosing an x and y value and testing whether the
function of x is greater than the y value. If it is, the x value is accepted.
Otherwise, the x value is rejected and the algorithm tries again.




Division of Computer Engineering                                               9
Randomized Algorithm                                         Seminar Report ‘09




                   4. DETERMINISTIC ALGORITHM

       Goal is to solve the problem correctly (always) and quickly. Typically
the number of steps should be polynomial in the size of the input.




                 Input              Algorithm                  Output



                     5 RANDOMIZED ALGORITHM

      A randomized algorithm is defined as an algorithm that is allowed to
access a source of independent, unbiased random bits, and it is then allowed to
use these random bits to influence its computation.



                 Input              Algorithm                  Output




                                   Random bits



       Formally, the algorithm's performance will be a random variable
determined by the random bits, with (hopefully) good expected value. The
"worst case" is typically so unlikely to occur that it can be ignored. Bounds on
the performances of random algorithms depend on their random choices and
not on any assumptions about the inputs. It is important to distinguish this
form of probabilistic analysis of an algorithm, in which one assumes a
distribution on the inputs and analyses an algorithm that may itself be
deterministic.




Division of Computer Engineering                                             10
Randomized Algorithm                                          Seminar Report ‘09




5.1 WHY RANDOMIZED ALGORITHMS?

        Simplicity: - This is the first and foremost reason for using randomized
algorithms. There are numerous examples where an easy randomized
algorithm can match (or even surpass) the performance of a deterministic
algorithm.
Example: Sorting algorithms.
        The Merge-Sort algorithm is asymptotically best deterministic
algorithm. It is not too hard to describe. However, the same asymptotic
running time can be achieved by the simple randomized Quick-sort algorithm.
The algorithm picks a random element as a pivot and partitions the rest of the
elements: those smaller than the pivot and those bigger than the pivot. Recurse
on these two partitions. We will give the analysis of the running time later.
        Speed: - The best known randomized algorithms are faster than the
best known deterministic algorithms. This is achieved by requiring that the
correct answer be found only with high probability or that the algorithm
should run in expected polynomial time. This means that the randomized
algorithm may not find a correct answer in some cases or may take very long
time.
Example: Checking if a multi-variate polynomial is the zero polynomial.

There is no known deterministic polynomial-time algorithm that determines if
the given multi-variate polynomial is the zero polynomial. On the other hand,
there is a very simple and efficient randomized algorithm for this problem: just
evaluate the given polynomial at random points. Note that such a polynomial
could be represented implicitly. e.g., as a determinant of a matrix whose
entries contain different variables.




Division of Computer Engineering                                                11
Randomized Algorithm                                         Seminar Report ‘09




             6. LAS VEGAS AND MONTE CARLO

      There are two types of Randomized Algorithms:
1) Las Vegas Algorithm
2) Monte Carlo Algorithm


6.1 LAS VEGAS ALGORITHM: -
      Las Vegas Algorithm: The randomized algorithm always produces the
correct answer, but its runtime for each input is a random variable whose
expectation is bounded.
Example: Quick-sort algorithm


6.2 MONTE CARLO ALGORITHM: -
     The randomized algorithm runs for a fixed number of steps for each
input and produces an answer that is correct with a bounded probability. That
is it may produce incorrect solution .It has a fixed deterministic running time.
If the algorithm is run repeatedly with independent random choices each time,
the failure probability can be made arbitrarily small, at the expense of running
time. For decision problems (problems for which the answer to an instance is
YES or NO), there are two kinds of Monte Carlo algorithms: those with one-
sided error, and those with two-sided error. A Monte Carlo algorithm is said
to have two-sided error if there is a non-zero probability that it errs when it
outputs either YES or NO. It is said to have one-sided error if the probability
that it errs is zero for at least one of the possible outputs (YES / NO) that it
produces. Example: Min-Cut Algorithm. Which is better, Monte Carlo or Las
Vegas? The answer depends on the application. In some applications an
incorrect solution may be catastrophic. A Las Vegas algorithm is by definition
a Monte Carlo algorithm with error probability zero. It is possible to derive a
Las Vegas algorithm from a Monte Carlo algorithm. The efficiency of the
derivation procedure depends on the time taken to verify the correctness of a
solution to the problem.


Division of Computer Engineering                                             12
Randomized Algorithm                                       Seminar Report ‘09




      We say that a Las Vegas algorithm is an efficient Las Vegas algorithm
if on any input its expected running time is bounded by a polynomial function
of the input size. Similarly a Monte Carlo algorithm is an efficient Monte
Carlo algorithm if on any input its worst-case running time is bounded by a
polynomial function of the input size.




Division of Computer Engineering                                          13
Randomized Algorithm                                         Seminar Report ‘09




                   7. RANDOMIZED QUICKSORT

7.1 TRADITIONAL QUICKSORT

     Consider sorting a set S of n numbers into ascending order. Pick the first
element as the pivot element, say y. Partition the set S-{y} into two sets S1
and S2 , where S1 consists of those elements of S that are smaller than y, and
S2 has the remaining elements. Recursively sort S1 and S2 , then output the
elements of S1 in ascending order , followed by y ,and then the elements of S2
in ascending order.
     Analysis: -
     If we could find y in cn steps for some constant c, we could partition S-
{y} in n-1 additional steps by comparing each element of S with y; thus the
total number of steps in our sorting procedure would be given by the
recurrence
              T (n) <= 2T(n/2) + (c+1) n,
Where T(k) represents the time taken by this method to sort k numbers on the
worst-case input. This recurrence has the solution T(n) <= c n log n for a
constant c.
         The difficulty with the above scheme in practice is finding the
element y that splits S-{y} into two sets of the same size. One simple solution
is to choose an element of S at random. This does not always ensure a splitter
giving a roughly even split. However, it is reasonable to hope that in the
recursive algorithm we will be lucky fairly often. The result is an algorithm we
call RandQS, for Randomized Quicksort.




Division of Computer Engineering                                             14
Randomized Algorithm                                                         Seminar Report ‘09




7.2 RANDOMIZED QUICKSORT
       Randomized Quicksort algorithm makes random choices during
       execution.


    Algorithm RandQS:
    Input:      A set of numbers S.
    Output: The elements of S sorted in increasing order.
        1.Choose an element y uniformly at random from S: every
              element in S has equal probability of being chosen.
        2.By comparing each element of S with y, determine the set S 1 of
          elements smaller than y and the set S 2 of elements larger than y.
        3.Recursively sort S 1 and S 2 .Output the sorted version of S 1 ,
          followed by y, and then the sorted version of S 2 .




Analysis: -
       As for any sorting algorithms, we measure the running time of RandQS
in terms of the number of comparisons it performs .Our goal is to analyze the
expected number of comparisons in an execution of RandQS. All the
comparisons are performed in Step 2.
       Let S(i) be the ith smallest element in the input list S.
       Define the random variable X ij to assume the value 1 if S(i) and S(j)
are compared in an execution, and the value 0 otherwise. Thus X ij is a count of
comparisons between S(i) and S(j), and so the total number of comparisons is


                ∑������������ ∑������������ ≥������������ ������������ ij
                 ������������=1                R




                     E[ ∑������������ ∑������������ ≥������������ ������������ ij ]= ∑������������=1 ∑������������ ≥������������ ������������[������������ ij ]
                                                      ������������
       Expected runtime t of RandQS is

                t=       ������������=1                 R                                  R




Division of Computer Engineering                                                            15
Randomized Algorithm                                              Seminar Report ‘09




       Let P ij denote the probability that S(i) and S(j) are compared in
an execution. Since X ij only assumes the values 0 and 1,
                E[X ij ] = P ij *1+ (1-P ij )*0 = P ij
To compute P ij , we make two observations.
       1. There is a comparison between S(i) and S(j) if and only if S(i) or
           S(j) occurs earlier in the permutation ∏ than any element S(l) such
           that i<l<j. To see this, let S(k) be the earliest in ∏ from among all
           elements of rank between i and j. If k = i or j then S(i) will belong
           to the left sub-tree of S(k) while S(j) will belong to the right sub-
           tree of S(k), implying that there is no comparison between S(i) and
           S(j). Conversely, when k=I or j there is an ancestor-descendent
           relationship between S(i) and S(j), implying that the two elements
           are compared by RandQS.
       2. Any of the elements S(i),S(I+1),…,S(j) is equally likely to be the
           first of these elements to be chosen as a partitioning element, and
           hence to appear first in ∏. Thus, the probability that this first
           element is either S(i) or S(j) is exactly 2/(j-i+1).


Therefore, the expected runtime



t   = ∑������������ ∑������������ ≥������������ ������������[������������ ij ]
       ������������=1


     = ∑������������ ∑������������ ≥������������ ������������ ij
                                        R




        ������������=1

     = ∑������������ ∑������������ ≥������������
                                  2
                                  R




        ������������=1                ������������ −������������+1

     ≤ n ∑������������=1
                       2
          ������������         ������������

      ≅ 2n ln n
Note that 1+ 1/2 + 1/3 + … +1/n                                                    ≅ln n
Randomized Quicksort is a Las Vegas Algorithm.

Division of Computer Engineering                                                 16
Randomized Algorithm                                         Seminar Report ‘09




The expected running time holds for every input. It is an expectation that
depends only on the random choices made by the algorithm, and not on any
assumptions about the distribution of the input. The behavior of a randomized
algorithm can vary even on a single input, from one execution to another. The
running time becomes a random variable, and the running time analysis
involves understanding the distribution of this random variable.




Division of Computer Engineering                                            17
Randomized Algorithm                                           Seminar Report ‘09




                 8. RANDOMIZED MIN-CUT ALGORITHM

          Let G = (V,E) be a connected , undirected multigraph with n vertices.A
multigragh may contain multiple edges between any pair of vertices.A cut in
G is a set of edges whose removal results in G being broken into two or more
components. A min-cut is a cut of minimum cardinality. For instance, say this
graph represents a network, and we want to know how ”robust” it is in the
sense of the the minimum number of links whose failure causes the network to
become disconnected.The minimum cut problem is to find a cut of minimum
size.
          Min-cut algorithm
        Algorithm Min-Cut
        Input:   Connected, undirected multigragh G(V,E).
        Output: Size of the min-cut.
           1. while |V| >= 2 do
           2.     Pick an edge e randomly and contract it.
           3.     Remove Self Loops.
           4. end while
           5. Return |E| ;




          Once we have collapsed the first random edge, the rest of the algorithm
proceeds recursively on the remaining (n − 1)-node graph. Here is a lucky
example.




Division of Computer Engineering                                              18
Randomized Algorithm               Seminar Report ‘09




Division of Computer Engineering                  19
Randomized Algorithm                                                     Seminar Report ‘09




Analysis:-
        Look at what happens to the edges after they are contracted. They
become self loops and are removed. After the i-th iteration of the while loop,
or the i-th contraction, how many nodes remain: n− i. Let us assume that no
minimum-cut edge got contracted. (We want to know what is the probability
of this ’lucky event’ happening) Each node in the contracted graph has
degree>= k (Why? Because contractions do not decrease the min-cut). Thus
after the i-th iteration, the total number of edges in the graph is >= k(n−i)/2 .


The probability q 1 of picking one of those k edges in the first merging
steps
                                                                  ≤ k/(kn/2) ≤ n/2
The probability p 1 of not picking any of those k edges in the first merging
step
                                                                ≥ (1-2/n)
Repeat the same argument for the first n-2 merging steps.

Probability p of not picking any of those k edges in all the merging steps
                                                ≥ (1-2/n)(1-2/(n-1))(1-2/(n-2))…(1-2/3)



                           2                2                        2
Therefore, the probability of finding              the min-cut:

                           ������������           ������������−1                     3
             P ≥ (1-              ) (1-            )…………..(1- )
                     (������������−1)(������������−3)….(1)
                          ������������(������������−1)….3
                 =
                          2
                     ������������(������������−1)
                 =


        If we repeat the whole procedure n2/2 times, the probability of not
finding the min-cut is at most


                   (1− 2/n2 )n 2 / 2 ≅ 1/ e


Division of Computer Engineering                                                          20
Randomized Algorithm                                         Seminar Report ‘09




       By this process of repetition, we have managed to reduce the
probability of failure from 1-2/(n**2) to a more respectable 1/e. Further
execution of the algorithm will make the failure probability arbitrarily small-
the only consideration being that repetitions increase the running time.


       Randomized Min-cut is a Monte Carlo Algorithm.




Division of Computer Engineering                                            21
Randomized Algorithm                                          Seminar Report ‘09




                    9. COMPLEXITY CLASSES

       A complexity class is a collection of languages all of whose
recognition problems can be solved under prescribed bounds on the
computational resources. A language recognition problem is to decide whether
a given string x ∑* belongs to L. An algorithm solves a language
                 in
recognition problem for a specific language L by accepting (output YES) any
input string contained in L , and rejecting (output NO) any input string not
contained in L.We are primarily interested in various forms of efficient
algorithms, where efficient is defined as being polynomial time. Recall that an
algorithm has polynomial running time if it halts within nO(1) time on any input
of length n.
       Some basic complexity classes focusing on those involving
randomized algorithms are
   1) Randomized Polynomial time (RP)
   2) Zero-error Probabilistic Polynomial time(ZPP)
   3) Probabilistic Polynomial time(PP)
   4) Bounded-error Probabilistic Polynomial time (BPP)

9.1 CLASS RP
       The class RP (for randomized polynomial time) consists of all
languages L that have a randomized algorithm A running in worst case


               x ∈ L ⇒ Pr[A(x) accepts] >= ½
polynomial time such that for any input x in ∑*,


               x ∈ L ⇒ Pr[A(x) accepts] = 0
           •
           •

The choice of the bound on the error probability ½ is arbitrary. In fact , as was
observed in the case of the min-cut algorithm, independent repetitions of the
algorithm can be used to go from the case where the probability of success is
polynomially small to the case where the probability of error is exponentially
Division of Computer Engineering                                              22
Randomized Algorithm                                         Seminar Report ‘09




small while changing only the degree of the polynomial that bounds the
running time.Thus,the success probability can be changed to an inverse
polynomial function of the input size without significantly affecting the
definition of RP.

       Observe that an RP algorithm is a Monte Carlo algorithm that can err
only when x L. this is referred to as one-sided error. The class co-RP consists
of languages that have polynomial time randomized algorithms erring only in
the case when x L.A problem belonging to both RP and co-RP can be solved
by a randomized algorithm with zero-sided error, ie a Las Vegas algorithm.


9.2 CLASS ZPP
       The class ZPP is the class of languages which have Las Vegas
algorithms running in expected polynomial time.
       ZPP = RP ∩ co-RP


9.3 CLASS PP
       The class PP (for probabilistic polynomial time ) consists of all
languages L that have a Randomized algorithm A running in worst case
polynomial time such that for any input x in ∑*,

               x ∈ L ⇒ Pr[A(x) accepts] > ½

               x ∈ L ⇒ Pr[A(x) accepts] < ½
           •

           •


     To reduce the error probability of a two-sided error algorithm, we can
perform several independent iterations on the same input and produce the
output that occurs in the majority of these iterations. Unfortunately, the
definition of the class PP is rather weak: because we have no bound on how
far from ½ the probabilities are, it may not be possible to use a small number
of repetitions of an algorithm A with such two-sided error probability to obtain
an algorithm with significantly small error probability.



Division of Computer Engineering                                             23
Randomized Algorithm                                           Seminar Report ‘09




9.4 CLASS BPP
       The class BPP (for bounded error probabilistic polynomial time)
consists of all languages L that have a randomized algorithm A running in


               x ∈ L ⇒ Pr[A(x) accepts] >= ¾.
worst case polynomial time such that for any input x in ∑*,


               x ∈ L ⇒ Pr[A(x) accepts] <= ¼.
           •
           •


       For this class of algorithms the error probability can be reduced to 1/2n
with only a polynomial number of iterations. In fact the probability bounds ¾
and ¼ can be changed to ½ + 1/p(n) and ½ -1/p(n), respectively, for any
polynomially bounded function p(n) without affecting this error reduction
property or the definition of the class BPP to a significant extent.




Division of Computer Engineering                                              24
Randomized Algorithm                                       Seminar Report ‘09




                          10. ADVANTAGES

       There are two principal advantages to randomized algorithms. The first
is performance. For many problems, randomized algorithms run faster than
best-known deterministic algorithms.


       Second, many randomized algorithms are simpler to describe and
implement than deterministic algorithms of comparable performance.
Randomized Quicksort is an example.




Division of Computer Engineering                                          25
Randomized Algorithm                                        Seminar Report ‘09




                        11. DISADVANTAGES

       Difficulty to sample the distributions using only random bits:-For
example, consider an algorithm that picks a random real number from some
interval. This requires infinitely many random bits.


       There is sometimes a non-trivial computational overhead associated
with sampling from a seemingly well-behaved distribution. For example,
consider the program of using a source of unbiased random bits to sample
uniformly from a set S whose cardinality is not a power of 2.




Division of Computer Engineering                                           26
Randomized Algorithm                                        Seminar Report ‘09




                                12. SCOPE

    Number theoretic algorithms:
              Primary testing
              (Monte Carlo)
    Data structures:
              Sorting, order statistics, searching, and computational geometry.
    Algebraic identities:
              Polynomial and matrix identity verification and Interactive
              proof systems.
   Mathematical programming:
              Faster algorithms for linear Programming, Rounding linear
       program solutions to integer program solutions,
    Graph algorithms:
              Minimum spanning trees, shortest paths and minimum cuts.
    Counting and enumeration:
              Matrix permanent and Counting combinatorial structures.
   Parallel and distributed computing:
              Deadlock avoidance, distributed Consensus.
    Probabilistic existence proofs:
              Show that a combinatorial object arises with nonzero
       probability among objects drawn from a suitable probability space.




Division of Computer Engineering                                            27
Randomized Algorithm                                       Seminar Report ‘09




                          13. CONCLUSION

       The ideas underlying randomized algorithms can be traced back to
Monte Carlo methods used in numerical analysis, statistical physics, and
simulation. A randomized algorithm is defined as an algorithm that typically
uses the random bits as an auxiliary input to guide its behavior. It achieves
good performance in the "average case". Formally, the algorithm's
performance will be a random variable determined by the random bits, with
(hopefully) good expected value. The "worst case" is typically so unlikely to
occur that it can be ignored. Randomized algorithms take a random bit to
randomize the algorithm. For randomized quick sort expected running time
holds for every input.



       There are some interesting complexity classes involving randomized
       algorithms:
    1. Randomized Polynomial time (RP)
    2. Zero-error Probabilistic Polynomial time (ZPP)
    3. Probabilistic Polynomial time (PP)
    4. Bounded-error Probabilistic Polynomial time (BPP).




Division of Computer Engineering                                          28
Randomized Algorithm                                   Seminar Report ‘09




                       14. BIBLIOGRAPHY
Books:-

Rajeev Motwani and Prabhakar Raghavan:
    Randomized Algorithms, Cambridge University Press 1995.


Thomas H Cormen, Charles E Leiserson,Ronald L Rivest and
    Clifford Stein: Introduction to Algorithms,


Websites:-

http://en.wikipedia.org/wiki/Probabilistic_algorithm
http://en.wikipedia.org/wiki/Las_Vegas_algorithm
http://www.nist.gov/dads/HTML/LasVegas.html
http://www.nist.gov/dads/HTML/monteCarlo.html




Division of Computer Engineering                                      29
Randomized Algorithm               Seminar Report ‘09




Division of Computer Engineering                  30

More Related Content

What's hot

Algorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to AlgorithmsAlgorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to AlgorithmsMohamed Loey
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notationsEhtisham Ali
 
Binary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of AlgorithmsBinary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of AlgorithmsDrishti Bhalla
 
Design and analysis of algorithms
Design and analysis of algorithmsDesign and analysis of algorithms
Design and analysis of algorithmsDr Geetha Mohan
 
AI_Session 10 Local search in continious space.pptx
AI_Session 10 Local search in continious space.pptxAI_Session 10 Local search in continious space.pptx
AI_Session 10 Local search in continious space.pptxAsst.prof M.Gokilavani
 
Unification and Lifting
Unification and LiftingUnification and Lifting
Unification and LiftingMegha Sharma
 
Algorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms IAlgorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms IMohamed Loey
 
Decision Tree - C4.5&CART
Decision Tree - C4.5&CARTDecision Tree - C4.5&CART
Decision Tree - C4.5&CARTXueping Peng
 
Greedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack ProblemGreedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack ProblemMadhu Bala
 
Lecture 3 insertion sort and complexity analysis
Lecture 3   insertion sort and complexity analysisLecture 3   insertion sort and complexity analysis
Lecture 3 insertion sort and complexity analysisjayavignesh86
 

What's hot (20)

Algorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to AlgorithmsAlgorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to Algorithms
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
 
Binary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of AlgorithmsBinary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of Algorithms
 
Design and analysis of algorithms
Design and analysis of algorithmsDesign and analysis of algorithms
Design and analysis of algorithms
 
A greedy algorithms
A greedy algorithmsA greedy algorithms
A greedy algorithms
 
Unit 1 chapter 1 Design and Analysis of Algorithms
Unit 1   chapter 1 Design and Analysis of AlgorithmsUnit 1   chapter 1 Design and Analysis of Algorithms
Unit 1 chapter 1 Design and Analysis of Algorithms
 
Randomized algorithms ver 1.0
Randomized algorithms ver 1.0Randomized algorithms ver 1.0
Randomized algorithms ver 1.0
 
AI_Session 10 Local search in continious space.pptx
AI_Session 10 Local search in continious space.pptxAI_Session 10 Local search in continious space.pptx
AI_Session 10 Local search in continious space.pptx
 
Unification and Lifting
Unification and LiftingUnification and Lifting
Unification and Lifting
 
Algorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms IAlgorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms I
 
Decision Tree - C4.5&CART
Decision Tree - C4.5&CARTDecision Tree - C4.5&CART
Decision Tree - C4.5&CART
 
AI Lecture 1 (introduction)
AI Lecture 1 (introduction)AI Lecture 1 (introduction)
AI Lecture 1 (introduction)
 
Minimum spanning tree
Minimum spanning treeMinimum spanning tree
Minimum spanning tree
 
And or graph
And or graphAnd or graph
And or graph
 
Analysis of algorithm
Analysis of algorithmAnalysis of algorithm
Analysis of algorithm
 
Learning in AI
Learning in AILearning in AI
Learning in AI
 
Greedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack ProblemGreedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack Problem
 
Lecture 3 insertion sort and complexity analysis
Lecture 3   insertion sort and complexity analysisLecture 3   insertion sort and complexity analysis
Lecture 3 insertion sort and complexity analysis
 
Binary search
Binary searchBinary search
Binary search
 
NLP
NLPNLP
NLP
 

Viewers also liked

VietRees_Newsletter_65_Tuan2_Thang1
VietRees_Newsletter_65_Tuan2_Thang1VietRees_Newsletter_65_Tuan2_Thang1
VietRees_Newsletter_65_Tuan2_Thang1internationalvr
 
หนังสืองานพระราชทานเพลิงศพ สรีระสังขาร หลวงตามหาบัว
หนังสืองานพระราชทานเพลิงศพ สรีระสังขาร หลวงตามหาบัวหนังสืองานพระราชทานเพลิงศพ สรีระสังขาร หลวงตามหาบัว
หนังสืองานพระราชทานเพลิงศพ สรีระสังขาร หลวงตามหาบัวRachabodin Suwannakanthi
 
District 30 - 2011 ISAT
District 30 - 2011 ISATDistrict 30 - 2011 ISAT
District 30 - 2011 ISATAndrew Kohl
 
VietnamRealEstate_E-Directory_VN_Q1_2009
VietnamRealEstate_E-Directory_VN_Q1_2009VietnamRealEstate_E-Directory_VN_Q1_2009
VietnamRealEstate_E-Directory_VN_Q1_2009internationalvr
 
White paper on Spool space in teradata
White paper on Spool space in teradataWhite paper on Spool space in teradata
White paper on Spool space in teradataSanjeev Kumar Jaiswal
 
Guide Assessment4learning
Guide Assessment4learningGuide Assessment4learning
Guide Assessment4learningDai Barnes
 
Application development for mobile phones
Application development for mobile phonesApplication development for mobile phones
Application development for mobile phonesSanjeev Kumar Jaiswal
 
eCMO 2010 Unleash the power of mobile advertising
eCMO 2010 Unleash the power of mobile advertisingeCMO 2010 Unleash the power of mobile advertising
eCMO 2010 Unleash the power of mobile advertisingHKAIM
 
HKAIM Chairman Report 2007 2008
HKAIM Chairman Report 2007 2008HKAIM Chairman Report 2007 2008
HKAIM Chairman Report 2007 2008HKAIM
 
Basics of JSON (JavaScript Object Notation) with examples
Basics of JSON (JavaScript Object Notation) with examplesBasics of JSON (JavaScript Object Notation) with examples
Basics of JSON (JavaScript Object Notation) with examplesSanjeev Kumar Jaiswal
 
Dyu各學系網站2014招生行銷力提升對策 20140207
Dyu各學系網站2014招生行銷力提升對策 20140207Dyu各學系網站2014招生行銷力提升對策 20140207
Dyu各學系網站2014招生行銷力提升對策 20140207gctarng gctarng
 
5. Social 2.0 Web 3.0 Retake Control Of Your Own Cloud Edmon Chung
5. Social 2.0   Web 3.0 Retake Control Of Your Own Cloud   Edmon Chung5. Social 2.0   Web 3.0 Retake Control Of Your Own Cloud   Edmon Chung
5. Social 2.0 Web 3.0 Retake Control Of Your Own Cloud Edmon ChungHKAIM
 

Viewers also liked (20)

Mission to Taipei
Mission to TaipeiMission to Taipei
Mission to Taipei
 
VietRees_Newsletter_65_Tuan2_Thang1
VietRees_Newsletter_65_Tuan2_Thang1VietRees_Newsletter_65_Tuan2_Thang1
VietRees_Newsletter_65_Tuan2_Thang1
 
NewWave
NewWaveNewWave
NewWave
 
หนังสืองานพระราชทานเพลิงศพ สรีระสังขาร หลวงตามหาบัว
หนังสืองานพระราชทานเพลิงศพ สรีระสังขาร หลวงตามหาบัวหนังสืองานพระราชทานเพลิงศพ สรีระสังขาร หลวงตามหาบัว
หนังสืองานพระราชทานเพลิงศพ สรีระสังขาร หลวงตามหาบัว
 
General Digital Archive Package Tool
General Digital Archive Package ToolGeneral Digital Archive Package Tool
General Digital Archive Package Tool
 
District 30 - 2011 ISAT
District 30 - 2011 ISATDistrict 30 - 2011 ISAT
District 30 - 2011 ISAT
 
Are you already?
Are you already?Are you already?
Are you already?
 
Wimax vsWi-fi
Wimax vsWi-fiWimax vsWi-fi
Wimax vsWi-fi
 
VietnamRealEstate_E-Directory_VN_Q1_2009
VietnamRealEstate_E-Directory_VN_Q1_2009VietnamRealEstate_E-Directory_VN_Q1_2009
VietnamRealEstate_E-Directory_VN_Q1_2009
 
White paper on Spool space in teradata
White paper on Spool space in teradataWhite paper on Spool space in teradata
White paper on Spool space in teradata
 
Guide Assessment4learning
Guide Assessment4learningGuide Assessment4learning
Guide Assessment4learning
 
Application development for mobile phones
Application development for mobile phonesApplication development for mobile phones
Application development for mobile phones
 
eCMO 2010 Unleash the power of mobile advertising
eCMO 2010 Unleash the power of mobile advertisingeCMO 2010 Unleash the power of mobile advertising
eCMO 2010 Unleash the power of mobile advertising
 
Chpt1
Chpt1Chpt1
Chpt1
 
HKAIM Chairman Report 2007 2008
HKAIM Chairman Report 2007 2008HKAIM Chairman Report 2007 2008
HKAIM Chairman Report 2007 2008
 
Basics of JSON (JavaScript Object Notation) with examples
Basics of JSON (JavaScript Object Notation) with examplesBasics of JSON (JavaScript Object Notation) with examples
Basics of JSON (JavaScript Object Notation) with examples
 
Dyu各學系網站2014招生行銷力提升對策 20140207
Dyu各學系網站2014招生行銷力提升對策 20140207Dyu各學系網站2014招生行銷力提升對策 20140207
Dyu各學系網站2014招生行銷力提升對策 20140207
 
Protest
ProtestProtest
Protest
 
5. Social 2.0 Web 3.0 Retake Control Of Your Own Cloud Edmon Chung
5. Social 2.0   Web 3.0 Retake Control Of Your Own Cloud   Edmon Chung5. Social 2.0   Web 3.0 Retake Control Of Your Own Cloud   Edmon Chung
5. Social 2.0 Web 3.0 Retake Control Of Your Own Cloud Edmon Chung
 
Forcesfor good
Forcesfor goodForcesfor good
Forcesfor good
 

Similar to Randomized Algorithm

Design & Analysis of Algorithm course .pptx
Design & Analysis of Algorithm course .pptxDesign & Analysis of Algorithm course .pptx
Design & Analysis of Algorithm course .pptxJeevaMCSEKIOT
 
Algorithm - Introduction
Algorithm - IntroductionAlgorithm - Introduction
Algorithm - IntroductionMadhu Bala
 
Ds03 part i algorithms by jyoti lakhani
Ds03 part i algorithms   by jyoti lakhaniDs03 part i algorithms   by jyoti lakhani
Ds03 part i algorithms by jyoti lakhanijyoti_lakhani
 
19IS402_LP1_LM_22-23.pdf
19IS402_LP1_LM_22-23.pdf19IS402_LP1_LM_22-23.pdf
19IS402_LP1_LM_22-23.pdfGOWTHAMR721887
 
Ds03 algorithms jyoti lakhani
Ds03 algorithms jyoti lakhaniDs03 algorithms jyoti lakhani
Ds03 algorithms jyoti lakhanijyoti_lakhani
 
CH-1.1 Introduction (1).pptx
CH-1.1 Introduction (1).pptxCH-1.1 Introduction (1).pptx
CH-1.1 Introduction (1).pptxsatvikkushwaha1
 
Introduction to Algorithms Complexity Analysis
Introduction to Algorithms Complexity Analysis Introduction to Algorithms Complexity Analysis
Introduction to Algorithms Complexity Analysis Dr. Pankaj Agarwal
 
Ic lecture6 architecture and algo
Ic lecture6 architecture and algoIc lecture6 architecture and algo
Ic lecture6 architecture and algoAttaullahRahimoon
 
Algorithm and Complexity-Lesson 1.pptx
Algorithm and Complexity-Lesson 1.pptxAlgorithm and Complexity-Lesson 1.pptx
Algorithm and Complexity-Lesson 1.pptxApasra R
 
UNIT-1-PPTS-DAA.ppt
UNIT-1-PPTS-DAA.pptUNIT-1-PPTS-DAA.ppt
UNIT-1-PPTS-DAA.pptracha49
 
Introduction to Design Algorithm And Analysis.ppt
Introduction to Design Algorithm And Analysis.pptIntroduction to Design Algorithm And Analysis.ppt
Introduction to Design Algorithm And Analysis.pptBhargaviDalal4
 
Week1 programming challenges
Week1 programming challengesWeek1 programming challenges
Week1 programming challengesDhanu Srikar
 
Analysis of Algorithms
Analysis of AlgorithmsAnalysis of Algorithms
Analysis of AlgorithmsAmna Saeed
 
Design & Analysis of Algorithms Lecture Notes
Design & Analysis of Algorithms Lecture NotesDesign & Analysis of Algorithms Lecture Notes
Design & Analysis of Algorithms Lecture NotesFellowBuddy.com
 
Algorithms Design Patterns
Algorithms Design PatternsAlgorithms Design Patterns
Algorithms Design PatternsAshwin Shiv
 
Architecture Algorithm Definition
Architecture Algorithm DefinitionArchitecture Algorithm Definition
Architecture Algorithm DefinitionGaditek
 

Similar to Randomized Algorithm (20)

Algorithm.pptx
Algorithm.pptxAlgorithm.pptx
Algorithm.pptx
 
Design & Analysis of Algorithm course .pptx
Design & Analysis of Algorithm course .pptxDesign & Analysis of Algorithm course .pptx
Design & Analysis of Algorithm course .pptx
 
Algorithm - Introduction
Algorithm - IntroductionAlgorithm - Introduction
Algorithm - Introduction
 
Ds03 part i algorithms by jyoti lakhani
Ds03 part i algorithms   by jyoti lakhaniDs03 part i algorithms   by jyoti lakhani
Ds03 part i algorithms by jyoti lakhani
 
19IS402_LP1_LM_22-23.pdf
19IS402_LP1_LM_22-23.pdf19IS402_LP1_LM_22-23.pdf
19IS402_LP1_LM_22-23.pdf
 
Ds03 algorithms jyoti lakhani
Ds03 algorithms jyoti lakhaniDs03 algorithms jyoti lakhani
Ds03 algorithms jyoti lakhani
 
CH-1.1 Introduction (1).pptx
CH-1.1 Introduction (1).pptxCH-1.1 Introduction (1).pptx
CH-1.1 Introduction (1).pptx
 
Introduction to Algorithms Complexity Analysis
Introduction to Algorithms Complexity Analysis Introduction to Algorithms Complexity Analysis
Introduction to Algorithms Complexity Analysis
 
Ic lecture6 architecture and algo
Ic lecture6 architecture and algoIc lecture6 architecture and algo
Ic lecture6 architecture and algo
 
ADA complete notes
ADA complete notesADA complete notes
ADA complete notes
 
Algorithm and Complexity-Lesson 1.pptx
Algorithm and Complexity-Lesson 1.pptxAlgorithm and Complexity-Lesson 1.pptx
Algorithm and Complexity-Lesson 1.pptx
 
UNIT-1-PPTS-DAA.ppt
UNIT-1-PPTS-DAA.pptUNIT-1-PPTS-DAA.ppt
UNIT-1-PPTS-DAA.ppt
 
UNIT-1-PPTS-DAA.ppt
UNIT-1-PPTS-DAA.pptUNIT-1-PPTS-DAA.ppt
UNIT-1-PPTS-DAA.ppt
 
Introduction to Design Algorithm And Analysis.ppt
Introduction to Design Algorithm And Analysis.pptIntroduction to Design Algorithm And Analysis.ppt
Introduction to Design Algorithm And Analysis.ppt
 
Week1 programming challenges
Week1 programming challengesWeek1 programming challenges
Week1 programming challenges
 
Analysis of Algorithms
Analysis of AlgorithmsAnalysis of Algorithms
Analysis of Algorithms
 
Daa
DaaDaa
Daa
 
Design & Analysis of Algorithms Lecture Notes
Design & Analysis of Algorithms Lecture NotesDesign & Analysis of Algorithms Lecture Notes
Design & Analysis of Algorithms Lecture Notes
 
Algorithms Design Patterns
Algorithms Design PatternsAlgorithms Design Patterns
Algorithms Design Patterns
 
Architecture Algorithm Definition
Architecture Algorithm DefinitionArchitecture Algorithm Definition
Architecture Algorithm Definition
 

Recently uploaded

Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptx4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptxmary850239
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSMae Pangan
 
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...DhatriParmar
 
Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operationalssuser3e220a
 
Mental Health Awareness - a toolkit for supporting young minds
Mental Health Awareness - a toolkit for supporting young mindsMental Health Awareness - a toolkit for supporting young minds
Mental Health Awareness - a toolkit for supporting young mindsPooky Knightsmith
 
Grade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptxGrade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptxkarenfajardo43
 
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxDIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxMichelleTuguinay1
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
MS4 level being good citizen -imperative- (1) (1).pdf
MS4 level   being good citizen -imperative- (1) (1).pdfMS4 level   being good citizen -imperative- (1) (1).pdf
MS4 level being good citizen -imperative- (1) (1).pdfMr Bounab Samir
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfPatidar M
 
Multi Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP ModuleMulti Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP ModuleCeline George
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDecoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDhatriParmar
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxlancelewisportillo
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptxmary850239
 

Recently uploaded (20)

Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptx4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptx
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHS
 
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
 
Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operational
 
Mental Health Awareness - a toolkit for supporting young minds
Mental Health Awareness - a toolkit for supporting young mindsMental Health Awareness - a toolkit for supporting young minds
Mental Health Awareness - a toolkit for supporting young minds
 
Grade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptxGrade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptx
 
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxDIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptxINCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
 
MS4 level being good citizen -imperative- (1) (1).pdf
MS4 level   being good citizen -imperative- (1) (1).pdfMS4 level   being good citizen -imperative- (1) (1).pdf
MS4 level being good citizen -imperative- (1) (1).pdf
 
Mattingly "AI & Prompt Design: Large Language Models"
Mattingly "AI & Prompt Design: Large Language Models"Mattingly "AI & Prompt Design: Large Language Models"
Mattingly "AI & Prompt Design: Large Language Models"
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdf
 
Multi Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP ModuleMulti Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP Module
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDecoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
 
Paradigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTAParadigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTA
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
 
prashanth updated resume 2024 for Teaching Profession
prashanth updated resume 2024 for Teaching Professionprashanth updated resume 2024 for Teaching Profession
prashanth updated resume 2024 for Teaching Profession
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx
 

Randomized Algorithm

  • 1. Seminar Report On RANDOMIZED ALGORITHM Submitted by ASHISH KUMAR In partial fulfillment of the requirements for the Degree of Bachelor of Technology (B. Tech) in Computer Science and Engineering DIVISION OF COMPUTER ENGINEERING SCHOOL OF ENGINEERING COCHIN UNIVERSTY OF SCIENCE AND TECHNOLOGY COCHIN-682022 SEPTEMBER 2009
  • 2. COCHIN UNIVERSTY OF SCIENCE AND TECHNOLOGY DIVISION OF COMPUTER ENGINEERING CENTRE FOR ENGINEERING STUDIES COCHIN-682022 Certificate Certified that this is a bonafide record of the seminar entitled “RANDOMIZED ALGORITHM” taken by ASHISH KUMAR of the VIIth semester ,Computer Science and Engineering in the year 2009 in partial fulfillment of the requirements to the award of Degree Bachelor of Technology in Computer Science and Engineering of Cochin University of Science and Technology. Ms. Ramyamol Dr. David Peter Seminar Guide Head of the Division Place: Kochi-22 Date: 15.09.2009
  • 3. ACKNOWLEDGEMENT I take this occasion to thank God, Almighty for blessing me with his grace and taking my endeavor to a successful culmination. I extend my sincere and heartfelt thanks to my esteemed guide, Ms. Ramyamol for providing me with the right guidance and advice at the crucial junctures and for showing me the right way. I extend my sincere thanks to our respected head of the division Mr. David Peter, for allowing me to use the facilities available. I would like to thank the other faculty members also, at this occasion. Last but not least, I would like to thank friends for the support and encouragement they have given us during the course of my work. Ashish Kumar i
  • 4. ABSTRACT A randomized algorithm is defined as an algorithm that typically uses the random bits as an auxiliary input to guide its behavior. It achievs good performance in the "average case". Formally, the algorithm's performance will be a random variable determined by the random bits, with (hopefully) good expected value. The "worst case" is typically so unlikely to occur that it can be ignored. First and foremost reason for using randomized algorithms is simplicity. An easy randomized algorithm can match the performance of a deterministic algorithm. For some problems, the best-known randomized algorithms are faster than the best-known deterministic algorithms. This is achieved by requiring that the correct answer be found only with high probability or that the algorithm should run in expected polynomial time. This means that the randomized algorithm may not find a correct answer in some cases or may take very long time. Two types of Randomized Algorithms: 1. Las Vegas Algorithm 2. Monte Carlo Algorithm Las Vegas Algorithm: The randomized algorithm always outputs the correct answer, it is just that there is a small probability of taking long to execute. Monte Carlo Algorithm: The algorithm always completes quickly, but allow a small probability of error. Quicksort is probably the most familiar "real-world" algorithm in which randomness is very useful. The deterministic version of this algorithm requires O(n2) time to sort n numbers for some degenerate inputs -- such as the array elements being already in sorted order! However, if the algorithm randomly permutes ii
  • 5. elements before starting, it finishes in O(n log n) time with a high probability, for any input. The difference between the two is crucial when sorting large data sets. iii
  • 6. LIST OF FIGURES 8. Min Cut………………………. ….……………………………..…20 iv
  • 7. TABLE OF CONTENTS ACKNOWLEGMENT………………………………………………………….....…i ABSTRACT……………………………………………………………………….....ii LIST OF FIGURES…………………………………………………….…………....iv TABLE OF CONTENTS…………………………………………………………......v 1. INTRODUCTION………………………………..........………………..…............1 2. TYPES OF ALGORITHM……………………………….............…….......……...1 3. RANDOMIZED ALGORITHM 3.1Random Number Generation...………………………………..….…..…...5 3.2 True Random number Vs pseudorandom number………....…….…….....5 3.3 Generation Method 3.3.1 Physical Method..........................................................................6 3.3.2 Computational Method………………………………………...7 3.3.3 Generation From a Probability Distribution...............................9 4. DETERMINISTIC ALGORITHM……..……………………..….………….......10 5. RANDOMIZED ALGORITHM……………………………….…...…………....10 5.1 Why Randomized Algorithm…………………………………………...11 6. LAS VEGAS & MONTE CARLO 6.1 Las Vegas Algorithm…………….....………………………….….….....12 6.2 Monte Carlo Algorithm………..…………………………………..…....12 7. RANDOMIZED QUICK SORT 7.1 Traditional Quicksort……………………………………………………14 7.1 Randomized Quicksort……………..........................................................15 8. RANDOMIZED MIN-CUT ALGORITHM..........................................................18 9. COMPLEXITY CLASSES ....................................................................................22 10. ADVANTAGES…………...................................................................................25 11. DISADVANTAGES……………………………………………………………26 12. SCOPE…………………………………………………………………………..27 13. CONCLUSION…………………………………………………………………28 14. BIBLIOGRAPHY………………………………………………………………29 v
  • 8. vi
  • 9. Randomized Algorithm Seminar Report ‘09 1. INTRODUCTION An algorithm is any well-defined computational procedure that takes some values, or set of values as input and produces some values or set of values as output. An algorithm is thus a sequence of computational steps that transform the input into the output. A problem can be represented as a tuple, problem (instances, solutions). Where instances are the inputs to the problem and solutions are the outputs to the problem. To solve a problem we can use different algorithms. These algorithms differ dramatically in their efficiency. A randomized algorithm is defined as an algorithm that typically uses the random bits as an auxiliary input to guide its behavior. It achieves good performance in the "average case". 2. TYPES OF ALGORITHM Algorithm classification Algorithms that use a similar problem-solving approach can be grouped together. This classification scheme is neither exhaustive nor disjoint. The purpose is not to be able to classify an algorithm as one type or another, but to highlight the various ways in which a problem can be attacked. A short list of categories Algorithm types considered include: – Simple recursive algorithms – Backtracking algorithms – Divide and conquer algorithms – Dynamic programming algorithms – Greedy algorithms – Branch and bound algorithms Division of Computer Engineering 1
  • 10. Randomized Algorithm Seminar Report ‘09 – Brute force algorithms – Randomized algorithms Simple recursive algorithms A simple recursive algorithm consist of following steps: – Solves the base cases directly. – Recurs with a simpler sub problem. – Does some extra work to convert the solution to the simpler sub problem into a solution to the given problem. We call these “simple” because several of the other algorithm types are inherently recursive. Backtracking algorithms Backtracking algorithms are based on a depth-first recursive search A backtracking algorithm consists of following steps: – Tests to see if a solution has been found, and if so, returns it; otherwise. – For each choice that can be made at this point, • Make that choice • Recur • If the recursion returns a solution, return it – If no choices remain, return failure. Division of Computer Engineering 2
  • 11. Randomized Algorithm Seminar Report ‘09 Divide and Conquer A divide and conquer algorithm consists of two parts: – Divide the problem into smaller sub problems of the same type, and solve these sub problems recursively – Combine the solutions to the subproblems into a solution to the original problem Traditionally, an algorithm is only called divide and conquer if it contains two or more recursive calls. Dynamic programming algorithms A dynamic programming algorithm remembers past results and uses them to find new results. Dynamic programming is generally used for optimization problems. – Multiple solutions exist, need to find the “best” one – Requires “optimal substructure” and “overlapping subproblems” • Optimal substructure: Optimal solution contains optimal solutions to subproblems • Overlapping subproblems: Solutions to subproblems can be stored and reused in a bottom-up fashion • This differs from Divide and Conquer, where subproblems generally need not overlap. Division of Computer Engineering 3
  • 12. Randomized Algorithm Seminar Report ‘09 Greedy algorithms An optimization problem is one in which you want to find, not just a solution, but the best solution A “greedy algorithm” sometimes works well for optimization problems. A greedy algorithm works in phases: At each phase: – You take the best you can get right now, without regard for future consequences. – You hope that by choosing a local optimum at each step, you will end up at a global optimum. Brute force algorithm A brute force algorithm simply tries all possibilities until a satisfactory solution is found Such an algorithm can be: Optimizing: Find the best solution. This may require finding all solutions, or if a value for the best solution is known, it may stop when any best solution is found. Example: Finding the best path for a travelling salesman. Satisficing: Stop as soon as a solution is found that is good enough Example: Finding a travelling salesman path that is within 10% of optimal. Division of Computer Engineering 4
  • 13. Randomized Algorithm Seminar Report ‘09 3. RANDOM NUMBER 3.1. Random number generation A random number generator (often abbreviated as RNG) is a computational or physical device designed to generate a sequence of numbers or symbols that lack any pattern, i.e. appear random. Hardware-based systems for random number generation are widely used, but often fall short of this goal, though they may meet some of the statistical tests for randomness intended to ensure that they do not have any easily discernible patterns. Methods for generating random results have existed since ancient times, including dice, coin flipping, the shuffling of playing cards, the use of yarrow stalks (by divination) in the I Ching, and many other techniques. The many applications of randomness have led to many different methods for generating random data. These methods may vary as to how unpredictable or statistically random they are, and how quickly they can generate random numbers. Before the advent of computational random number generators, generating large amounts of sufficiently random numbers (important in statistics) required a lot of work. Results would sometimes be collected and distributed as random number tables. A growing number of government-run lotteries, and lottery games, are using RNGs instead of more traditional drawing methods, such as using ping- pong or rubber balls. 3.2. "True" random numbers vs. pseudorandom numbers There are two principal methods used to generate random numbers. One measures some physical phenomenon that is expected to be random and then compensates for possible biases in the measurement process. The other uses computational algorithms that produce long sequences of apparently Division of Computer Engineering 5
  • 14. Randomized Algorithm Seminar Report ‘09 random results, which are in fact completely determined by a shorter initial value, known as a seed or key. The latter type are often called pseudorandom number generators. A "random number generator" based solely on deterministic computation cannot be regarded as a "true" random number generator, since its output is inherently predictable. How to distinguish a "true" random number from the output of a pseudo-random number generator is a very difficult problem. However, carefully chosen pseudo-random number generators can be used instead of true random numbers in many applications. Rigorous statistical analysis of the output is often needed to have confidence in the algorithm. 3.3. Generation methods 3.3.1. Physical methods There is general agreement that, if there are such things as "true" random numbers, they are most likely to be found by looking at physical processes which are, as far as is known, unpredictable. The earliest methods for generating random numbers — dice, coin flipping, roulette wheels — are still used today, mainly in games and gambling as they tend to be too slow for applications in statistics and cryptography. The generation of true random numbers outside the computer environment is based on the theory of entropy. A physical random number generator can be based on an essentially random atomic or subatomic physical phenomenon whose unpredictability can be traced to the laws of quantum mechanics. Sources of entropy include radioactive decay, thermal noise, shot noise, clock drift, and atmospheric conditions. Various imaginative ways of collecting this entropic information have been devised. Atari 8-bit computers used electronic noise from an analog Division of Computer Engineering 6
  • 15. Randomized Algorithm Seminar Report ‘09 circuit to generate true random numbers. One common technique is to run a hash function against a frame of a video stream from an unpredictable source. Lavarand used this technique with images of a number of lava lamps. Lithium Technologies uses a camera pointed at the sky on a windy and cloudy day. HotBits measures radioactive decay with GM tubes, while Random.org uses variations in the amplitude of atmospheric noise recorded with a normal radio. Some physical phenomena, such as thermal noise in Zener diodes appear to be truly random and can be used as the basis for hardware random number generators. However, many mechanical phenomena feature asymmetries and systematic biases that make their outcomes not truly random. The many successful attempts to exploit such phenomena by gamblers, especially in roulette and blackjack are testimony to these effects. Another common entropy source is the behavior of human users of the system, if such users exist. While humans are not considered good randomness generators upon request, they generate random behavior quite well in the context of playing mixed strategy games. Some security-related computer software requires the user to input a lengthy string of mouse movements or keyboard input to add a certain degree of randomness to computational pseudo-random number generation.[ 3.3.2. Computational methods Pseudo-random number generators (PRNGs) are algorithms that can automatically create long runs (for example, millions of numbers long) with good random properties but eventually the sequence repeats (or the memory usage grows without bound). One of the most common PRNG is the linear congruential generator, which uses the recurrence Division of Computer Engineering 7
  • 16. Randomized Algorithm Seminar Report ‘09 to generate numbers. The maximum number of numbers the formula can produce is the modulus, m. To avoid certain non-random properties of a single linear congruential generator, several such random number generators with slightly different values of the multiplier coeffient a are typically used in parallel, with a "master" random number generator that selects from among the several different generators. A simple pen-and-paper method for generating random numbers is the so-called middle square method suggested by John Von Neumann. While simple to implement, its output is of poor quality. Most computer programming languages include functions or library routines that purport to be random number generators. They are often designed to provide a random byte or word, or a floating point number uniformly distributed between 0 and 1. Such library functions often have poor statistical properties and some will repeat patterns after only tens of thousands of trials. They are often initialized using a computer's real time clock as the seed. These functions may provide enough randomness for certain tasks (for example video games) but are unsuitable where high-quality randomness is required, such as in cryptographic applications, statistics or numerical analysis. Much higher quality random number sources are available on most operating systems; for example /dev/random on various BSD flavors, Linux, Mac OS X, IRIX, and Solaris, or CryptGenRandom for Microsoft Windows. An example of a simple random number generator that is computationally fast, has good (albeit not cryptographically strong) randomness properties, is (note that this example is not thread safe): Division of Computer Engineering 8
  • 17. Randomized Algorithm Seminar Report ‘09 m_w = <choose-initializer>; m_z = <choose-initializer>; uint get_random() { m_z = 36969 * (m_z & 65535) + (m_z >> 16); m_w = 18000 * (m_w & 65535) + (m_w >> 16); return (m_z << 16) + m_w; /* 32-bit result */ } 3.3.3. Generation from a probability distribution There are a couple of methods to generate a random number based on a probability density function. These methods involve transforming a uniform random number in some way. Because of this, these methods work equally well in generating both pseudo-random and true random numbers. One method, called the inversion method, involves integrating up to an area greater than or equal to the random number (which should be generated between 0 and 1 for proper distributions). A second method, called the acceptance- rejection method, involves choosing an x and y value and testing whether the function of x is greater than the y value. If it is, the x value is accepted. Otherwise, the x value is rejected and the algorithm tries again. Division of Computer Engineering 9
  • 18. Randomized Algorithm Seminar Report ‘09 4. DETERMINISTIC ALGORITHM Goal is to solve the problem correctly (always) and quickly. Typically the number of steps should be polynomial in the size of the input. Input Algorithm Output 5 RANDOMIZED ALGORITHM A randomized algorithm is defined as an algorithm that is allowed to access a source of independent, unbiased random bits, and it is then allowed to use these random bits to influence its computation. Input Algorithm Output Random bits Formally, the algorithm's performance will be a random variable determined by the random bits, with (hopefully) good expected value. The "worst case" is typically so unlikely to occur that it can be ignored. Bounds on the performances of random algorithms depend on their random choices and not on any assumptions about the inputs. It is important to distinguish this form of probabilistic analysis of an algorithm, in which one assumes a distribution on the inputs and analyses an algorithm that may itself be deterministic. Division of Computer Engineering 10
  • 19. Randomized Algorithm Seminar Report ‘09 5.1 WHY RANDOMIZED ALGORITHMS? Simplicity: - This is the first and foremost reason for using randomized algorithms. There are numerous examples where an easy randomized algorithm can match (or even surpass) the performance of a deterministic algorithm. Example: Sorting algorithms. The Merge-Sort algorithm is asymptotically best deterministic algorithm. It is not too hard to describe. However, the same asymptotic running time can be achieved by the simple randomized Quick-sort algorithm. The algorithm picks a random element as a pivot and partitions the rest of the elements: those smaller than the pivot and those bigger than the pivot. Recurse on these two partitions. We will give the analysis of the running time later. Speed: - The best known randomized algorithms are faster than the best known deterministic algorithms. This is achieved by requiring that the correct answer be found only with high probability or that the algorithm should run in expected polynomial time. This means that the randomized algorithm may not find a correct answer in some cases or may take very long time. Example: Checking if a multi-variate polynomial is the zero polynomial. There is no known deterministic polynomial-time algorithm that determines if the given multi-variate polynomial is the zero polynomial. On the other hand, there is a very simple and efficient randomized algorithm for this problem: just evaluate the given polynomial at random points. Note that such a polynomial could be represented implicitly. e.g., as a determinant of a matrix whose entries contain different variables. Division of Computer Engineering 11
  • 20. Randomized Algorithm Seminar Report ‘09 6. LAS VEGAS AND MONTE CARLO There are two types of Randomized Algorithms: 1) Las Vegas Algorithm 2) Monte Carlo Algorithm 6.1 LAS VEGAS ALGORITHM: - Las Vegas Algorithm: The randomized algorithm always produces the correct answer, but its runtime for each input is a random variable whose expectation is bounded. Example: Quick-sort algorithm 6.2 MONTE CARLO ALGORITHM: - The randomized algorithm runs for a fixed number of steps for each input and produces an answer that is correct with a bounded probability. That is it may produce incorrect solution .It has a fixed deterministic running time. If the algorithm is run repeatedly with independent random choices each time, the failure probability can be made arbitrarily small, at the expense of running time. For decision problems (problems for which the answer to an instance is YES or NO), there are two kinds of Monte Carlo algorithms: those with one- sided error, and those with two-sided error. A Monte Carlo algorithm is said to have two-sided error if there is a non-zero probability that it errs when it outputs either YES or NO. It is said to have one-sided error if the probability that it errs is zero for at least one of the possible outputs (YES / NO) that it produces. Example: Min-Cut Algorithm. Which is better, Monte Carlo or Las Vegas? The answer depends on the application. In some applications an incorrect solution may be catastrophic. A Las Vegas algorithm is by definition a Monte Carlo algorithm with error probability zero. It is possible to derive a Las Vegas algorithm from a Monte Carlo algorithm. The efficiency of the derivation procedure depends on the time taken to verify the correctness of a solution to the problem. Division of Computer Engineering 12
  • 21. Randomized Algorithm Seminar Report ‘09 We say that a Las Vegas algorithm is an efficient Las Vegas algorithm if on any input its expected running time is bounded by a polynomial function of the input size. Similarly a Monte Carlo algorithm is an efficient Monte Carlo algorithm if on any input its worst-case running time is bounded by a polynomial function of the input size. Division of Computer Engineering 13
  • 22. Randomized Algorithm Seminar Report ‘09 7. RANDOMIZED QUICKSORT 7.1 TRADITIONAL QUICKSORT Consider sorting a set S of n numbers into ascending order. Pick the first element as the pivot element, say y. Partition the set S-{y} into two sets S1 and S2 , where S1 consists of those elements of S that are smaller than y, and S2 has the remaining elements. Recursively sort S1 and S2 , then output the elements of S1 in ascending order , followed by y ,and then the elements of S2 in ascending order. Analysis: - If we could find y in cn steps for some constant c, we could partition S- {y} in n-1 additional steps by comparing each element of S with y; thus the total number of steps in our sorting procedure would be given by the recurrence T (n) <= 2T(n/2) + (c+1) n, Where T(k) represents the time taken by this method to sort k numbers on the worst-case input. This recurrence has the solution T(n) <= c n log n for a constant c. The difficulty with the above scheme in practice is finding the element y that splits S-{y} into two sets of the same size. One simple solution is to choose an element of S at random. This does not always ensure a splitter giving a roughly even split. However, it is reasonable to hope that in the recursive algorithm we will be lucky fairly often. The result is an algorithm we call RandQS, for Randomized Quicksort. Division of Computer Engineering 14
  • 23. Randomized Algorithm Seminar Report ‘09 7.2 RANDOMIZED QUICKSORT Randomized Quicksort algorithm makes random choices during execution. Algorithm RandQS: Input: A set of numbers S. Output: The elements of S sorted in increasing order. 1.Choose an element y uniformly at random from S: every element in S has equal probability of being chosen. 2.By comparing each element of S with y, determine the set S 1 of elements smaller than y and the set S 2 of elements larger than y. 3.Recursively sort S 1 and S 2 .Output the sorted version of S 1 , followed by y, and then the sorted version of S 2 . Analysis: - As for any sorting algorithms, we measure the running time of RandQS in terms of the number of comparisons it performs .Our goal is to analyze the expected number of comparisons in an execution of RandQS. All the comparisons are performed in Step 2. Let S(i) be the ith smallest element in the input list S. Define the random variable X ij to assume the value 1 if S(i) and S(j) are compared in an execution, and the value 0 otherwise. Thus X ij is a count of comparisons between S(i) and S(j), and so the total number of comparisons is ∑������������ ∑������������ ≥������������ ������������ ij ������������=1 R E[ ∑������������ ∑������������ ≥������������ ������������ ij ]= ∑������������=1 ∑������������ ≥������������ ������������[������������ ij ] ������������ Expected runtime t of RandQS is t= ������������=1 R R Division of Computer Engineering 15
  • 24. Randomized Algorithm Seminar Report ‘09 Let P ij denote the probability that S(i) and S(j) are compared in an execution. Since X ij only assumes the values 0 and 1, E[X ij ] = P ij *1+ (1-P ij )*0 = P ij To compute P ij , we make two observations. 1. There is a comparison between S(i) and S(j) if and only if S(i) or S(j) occurs earlier in the permutation ∏ than any element S(l) such that i<l<j. To see this, let S(k) be the earliest in ∏ from among all elements of rank between i and j. If k = i or j then S(i) will belong to the left sub-tree of S(k) while S(j) will belong to the right sub- tree of S(k), implying that there is no comparison between S(i) and S(j). Conversely, when k=I or j there is an ancestor-descendent relationship between S(i) and S(j), implying that the two elements are compared by RandQS. 2. Any of the elements S(i),S(I+1),…,S(j) is equally likely to be the first of these elements to be chosen as a partitioning element, and hence to appear first in ∏. Thus, the probability that this first element is either S(i) or S(j) is exactly 2/(j-i+1). Therefore, the expected runtime t = ∑������������ ∑������������ ≥������������ ������������[������������ ij ] ������������=1 = ∑������������ ∑������������ ≥������������ ������������ ij R ������������=1 = ∑������������ ∑������������ ≥������������ 2 R ������������=1 ������������ −������������+1 ≤ n ∑������������=1 2 ������������ ������������ ≅ 2n ln n Note that 1+ 1/2 + 1/3 + … +1/n ≅ln n Randomized Quicksort is a Las Vegas Algorithm. Division of Computer Engineering 16
  • 25. Randomized Algorithm Seminar Report ‘09 The expected running time holds for every input. It is an expectation that depends only on the random choices made by the algorithm, and not on any assumptions about the distribution of the input. The behavior of a randomized algorithm can vary even on a single input, from one execution to another. The running time becomes a random variable, and the running time analysis involves understanding the distribution of this random variable. Division of Computer Engineering 17
  • 26. Randomized Algorithm Seminar Report ‘09 8. RANDOMIZED MIN-CUT ALGORITHM Let G = (V,E) be a connected , undirected multigraph with n vertices.A multigragh may contain multiple edges between any pair of vertices.A cut in G is a set of edges whose removal results in G being broken into two or more components. A min-cut is a cut of minimum cardinality. For instance, say this graph represents a network, and we want to know how ”robust” it is in the sense of the the minimum number of links whose failure causes the network to become disconnected.The minimum cut problem is to find a cut of minimum size. Min-cut algorithm Algorithm Min-Cut Input: Connected, undirected multigragh G(V,E). Output: Size of the min-cut. 1. while |V| >= 2 do 2. Pick an edge e randomly and contract it. 3. Remove Self Loops. 4. end while 5. Return |E| ; Once we have collapsed the first random edge, the rest of the algorithm proceeds recursively on the remaining (n − 1)-node graph. Here is a lucky example. Division of Computer Engineering 18
  • 27. Randomized Algorithm Seminar Report ‘09 Division of Computer Engineering 19
  • 28. Randomized Algorithm Seminar Report ‘09 Analysis:- Look at what happens to the edges after they are contracted. They become self loops and are removed. After the i-th iteration of the while loop, or the i-th contraction, how many nodes remain: n− i. Let us assume that no minimum-cut edge got contracted. (We want to know what is the probability of this ’lucky event’ happening) Each node in the contracted graph has degree>= k (Why? Because contractions do not decrease the min-cut). Thus after the i-th iteration, the total number of edges in the graph is >= k(n−i)/2 . The probability q 1 of picking one of those k edges in the first merging steps ≤ k/(kn/2) ≤ n/2 The probability p 1 of not picking any of those k edges in the first merging step ≥ (1-2/n) Repeat the same argument for the first n-2 merging steps. Probability p of not picking any of those k edges in all the merging steps ≥ (1-2/n)(1-2/(n-1))(1-2/(n-2))…(1-2/3) 2 2 2 Therefore, the probability of finding the min-cut: ������������ ������������−1 3 P ≥ (1- ) (1- )…………..(1- ) (������������−1)(������������−3)….(1) ������������(������������−1)….3 = 2 ������������(������������−1) = If we repeat the whole procedure n2/2 times, the probability of not finding the min-cut is at most (1− 2/n2 )n 2 / 2 ≅ 1/ e Division of Computer Engineering 20
  • 29. Randomized Algorithm Seminar Report ‘09 By this process of repetition, we have managed to reduce the probability of failure from 1-2/(n**2) to a more respectable 1/e. Further execution of the algorithm will make the failure probability arbitrarily small- the only consideration being that repetitions increase the running time. Randomized Min-cut is a Monte Carlo Algorithm. Division of Computer Engineering 21
  • 30. Randomized Algorithm Seminar Report ‘09 9. COMPLEXITY CLASSES A complexity class is a collection of languages all of whose recognition problems can be solved under prescribed bounds on the computational resources. A language recognition problem is to decide whether a given string x ∑* belongs to L. An algorithm solves a language in recognition problem for a specific language L by accepting (output YES) any input string contained in L , and rejecting (output NO) any input string not contained in L.We are primarily interested in various forms of efficient algorithms, where efficient is defined as being polynomial time. Recall that an algorithm has polynomial running time if it halts within nO(1) time on any input of length n. Some basic complexity classes focusing on those involving randomized algorithms are 1) Randomized Polynomial time (RP) 2) Zero-error Probabilistic Polynomial time(ZPP) 3) Probabilistic Polynomial time(PP) 4) Bounded-error Probabilistic Polynomial time (BPP) 9.1 CLASS RP The class RP (for randomized polynomial time) consists of all languages L that have a randomized algorithm A running in worst case x ∈ L ⇒ Pr[A(x) accepts] >= ½ polynomial time such that for any input x in ∑*, x ∈ L ⇒ Pr[A(x) accepts] = 0 • • The choice of the bound on the error probability ½ is arbitrary. In fact , as was observed in the case of the min-cut algorithm, independent repetitions of the algorithm can be used to go from the case where the probability of success is polynomially small to the case where the probability of error is exponentially Division of Computer Engineering 22
  • 31. Randomized Algorithm Seminar Report ‘09 small while changing only the degree of the polynomial that bounds the running time.Thus,the success probability can be changed to an inverse polynomial function of the input size without significantly affecting the definition of RP. Observe that an RP algorithm is a Monte Carlo algorithm that can err only when x L. this is referred to as one-sided error. The class co-RP consists of languages that have polynomial time randomized algorithms erring only in the case when x L.A problem belonging to both RP and co-RP can be solved by a randomized algorithm with zero-sided error, ie a Las Vegas algorithm. 9.2 CLASS ZPP The class ZPP is the class of languages which have Las Vegas algorithms running in expected polynomial time. ZPP = RP ∩ co-RP 9.3 CLASS PP The class PP (for probabilistic polynomial time ) consists of all languages L that have a Randomized algorithm A running in worst case polynomial time such that for any input x in ∑*, x ∈ L ⇒ Pr[A(x) accepts] > ½ x ∈ L ⇒ Pr[A(x) accepts] < ½ • • To reduce the error probability of a two-sided error algorithm, we can perform several independent iterations on the same input and produce the output that occurs in the majority of these iterations. Unfortunately, the definition of the class PP is rather weak: because we have no bound on how far from ½ the probabilities are, it may not be possible to use a small number of repetitions of an algorithm A with such two-sided error probability to obtain an algorithm with significantly small error probability. Division of Computer Engineering 23
  • 32. Randomized Algorithm Seminar Report ‘09 9.4 CLASS BPP The class BPP (for bounded error probabilistic polynomial time) consists of all languages L that have a randomized algorithm A running in x ∈ L ⇒ Pr[A(x) accepts] >= ¾. worst case polynomial time such that for any input x in ∑*, x ∈ L ⇒ Pr[A(x) accepts] <= ¼. • • For this class of algorithms the error probability can be reduced to 1/2n with only a polynomial number of iterations. In fact the probability bounds ¾ and ¼ can be changed to ½ + 1/p(n) and ½ -1/p(n), respectively, for any polynomially bounded function p(n) without affecting this error reduction property or the definition of the class BPP to a significant extent. Division of Computer Engineering 24
  • 33. Randomized Algorithm Seminar Report ‘09 10. ADVANTAGES There are two principal advantages to randomized algorithms. The first is performance. For many problems, randomized algorithms run faster than best-known deterministic algorithms. Second, many randomized algorithms are simpler to describe and implement than deterministic algorithms of comparable performance. Randomized Quicksort is an example. Division of Computer Engineering 25
  • 34. Randomized Algorithm Seminar Report ‘09 11. DISADVANTAGES Difficulty to sample the distributions using only random bits:-For example, consider an algorithm that picks a random real number from some interval. This requires infinitely many random bits. There is sometimes a non-trivial computational overhead associated with sampling from a seemingly well-behaved distribution. For example, consider the program of using a source of unbiased random bits to sample uniformly from a set S whose cardinality is not a power of 2. Division of Computer Engineering 26
  • 35. Randomized Algorithm Seminar Report ‘09 12. SCOPE  Number theoretic algorithms: Primary testing (Monte Carlo)  Data structures: Sorting, order statistics, searching, and computational geometry.  Algebraic identities: Polynomial and matrix identity verification and Interactive proof systems. Mathematical programming: Faster algorithms for linear Programming, Rounding linear program solutions to integer program solutions,  Graph algorithms: Minimum spanning trees, shortest paths and minimum cuts.  Counting and enumeration: Matrix permanent and Counting combinatorial structures. Parallel and distributed computing: Deadlock avoidance, distributed Consensus.  Probabilistic existence proofs: Show that a combinatorial object arises with nonzero probability among objects drawn from a suitable probability space. Division of Computer Engineering 27
  • 36. Randomized Algorithm Seminar Report ‘09 13. CONCLUSION The ideas underlying randomized algorithms can be traced back to Monte Carlo methods used in numerical analysis, statistical physics, and simulation. A randomized algorithm is defined as an algorithm that typically uses the random bits as an auxiliary input to guide its behavior. It achieves good performance in the "average case". Formally, the algorithm's performance will be a random variable determined by the random bits, with (hopefully) good expected value. The "worst case" is typically so unlikely to occur that it can be ignored. Randomized algorithms take a random bit to randomize the algorithm. For randomized quick sort expected running time holds for every input. There are some interesting complexity classes involving randomized algorithms: 1. Randomized Polynomial time (RP) 2. Zero-error Probabilistic Polynomial time (ZPP) 3. Probabilistic Polynomial time (PP) 4. Bounded-error Probabilistic Polynomial time (BPP). Division of Computer Engineering 28
  • 37. Randomized Algorithm Seminar Report ‘09 14. BIBLIOGRAPHY Books:- Rajeev Motwani and Prabhakar Raghavan: Randomized Algorithms, Cambridge University Press 1995. Thomas H Cormen, Charles E Leiserson,Ronald L Rivest and Clifford Stein: Introduction to Algorithms, Websites:- http://en.wikipedia.org/wiki/Probabilistic_algorithm http://en.wikipedia.org/wiki/Las_Vegas_algorithm http://www.nist.gov/dads/HTML/LasVegas.html http://www.nist.gov/dads/HTML/monteCarlo.html Division of Computer Engineering 29
  • 38. Randomized Algorithm Seminar Report ‘09 Division of Computer Engineering 30