Presentation is loading. Please wait.

Presentation is loading. Please wait.

CPSC 335 Randomized Algorithms Dr. Marina Gavrilova Computer Science University of Calgary Canada.

Similar presentations


Presentation on theme: "CPSC 335 Randomized Algorithms Dr. Marina Gavrilova Computer Science University of Calgary Canada."— Presentation transcript:

1 CPSC 335 Randomized Algorithms Dr. Marina Gavrilova Computer Science University of Calgary Canada

2  A randomized algorithm can be defined as one that receives, in addition to its input, a stream of random bits that it can use in the course of its action for the purpose of making random choices.  A randomized algorithm may give different results when applied to the same input in different runs. Randomized Algorithm

3  There are two main advantages of randomized algorithms: - First, often the execution time or space requirement is smaller than that of the best deterministic algorithm. - Second, randomized algorithms are extremely simple to comprehend and implement. Advantages of Randomized Algorithm

4  Las Vegas algorithms: constitute those randomized algorithms that always give a correct solution, or do not have any correct solutionat all.  Monte Carlo Algorithms: These algorithms always give an answer, but may occasionally produce an answer that is incorrect. Types of Randomized Algorithm

5  If A is a randomized algorithm, then its running time on a fixed instance I of size n may vary from one execution to another.  Therefore, a more natural measure of performance is the expected running time of A on a fixed instance I.  This is the mean time taken by algorithm A to solve the instance I over and over. Thus, it is natural to talk about the worst case expected time and the average case expected time. Computational Complexity of A Randomized Algorithm

6  The running time of quicksort is on the average, provided that all permutations of the input elements are equally likely. This is not the case in many applications. If the input is already sorted, then its running time is Randomized Quicksort

7  One approach to guarantee a running time of on the average is to introduce a preprocessing step with purpose to permute the elements to be sorted randomly. This step can be performed in time. Randomized Quicksort  Another approach is to introduce an element of randomness into the algorithm. This can be done by selecting the pivot on which to split the elements randomly. The result of choosing the pivot randomly is to relax the assumption that all permutations of the input elements are equally likely.

8 Randomized Quicksort

9  Randomized Las Vegas algorithm Expected running time - Randomized Selection

10  Theorem: The expected number of elements comparisons performed by Algorithm RANDOMIZEDSELECT on input of size n is less than 4n. Its expected running time is. Randomized Selection

11  Let two parties A and B communicate over a reliable communication channel.  They want to determine whether x = y, x and y are two long strings of A and B respectively.  Cost of using the channel – extremely expensive.  Another alternative – A derives much shorter string (serve as a ‘ fingerprint ’ ) from x and send it to B. B follows the same procedure.  If they are equal, B conclude that x = y Testing String Equality

12  One method of fingerprinting is to choose a prime number p and then use the fingerprint function - I p (x) = I (x) (mod p).  The number of bits transmitted is thus smaller. If, then obviously,. The converse is also true. If I p (x) = I p (y), then it is not necessarily the case that x = y. Testing String Equality

13  The wellness of this method is that, for fixed p, there are certain pair of strings x and y on which the method will always fail.  To get around this problem of the existence of these pairs x and y – chose p at random every time the equality of two strings is to be checked, rather than agree on p in advance. Testing String Equality

14

15  Given a string of text X= x 1 x 2 … x n and a pattern Y= y 1 y 2 … y m, where, determine whether or not the pattern appears in the text.  The most straightforward method for solving this problem is to move the pattern across the entire text, and in every position compare the pattern with the portion of the text of length m. This Brute-force method leads to an O(mn) running time in the worst case. More complicated deterministic algorithms have running time O(m+n). Pattern Matching

16  Running time is O(m+n).  Follows the same Brute-force algorithm, but instead of comparing the pattern with each block X(j)=x j x j+1 … x j+m-1, this algorithm compare the fingerprint I p (Y) of the pattern with the fingerprints I p (X(j)) of the blocks of text.  The key observation is that, when one block of text is shifted to the next, the fingerprint of the new block X(j+1) can easily be computed from the fingerprint of X(j). Monte Carlo Algorithm for Pattern Matching

17 Pattern Matching

18  M. E. Dyer and A. M. Frieze, A randomized algorithm for fixed-dimensional linear programming, Joural of Mathematical Programming, vol.44, no. 1- 3,May, 1989.  V. V. Patel, G. Deodhare and T. Viswanath, Some applications of randomized algorithms for control system design, Automatica,vol. 38, no. 12, Dcember 2002. References

19 Define Las Vegas and Monte Carlo algorithms Explain how randomized pattern matching works Describe testing string equality algorithm Describe randomized quicksort method 19 Review questions

20 Thank You


Download ppt "CPSC 335 Randomized Algorithms Dr. Marina Gavrilova Computer Science University of Calgary Canada."

Similar presentations


Ads by Google