1 / 20

CPSC 335

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

aleal
Download Presentation

CPSC 335

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. Randomized Algorithm • 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.

  3. Advantages of Randomized Algorithm • 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.

  4. Types of Randomized Algorithm • 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.

  5. Computational Complexity of A Randomized Algorithm • 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.

  6. Randomized Quicksort • 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

  7. Randomized Quicksort • 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. • 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 Selection • Randomized Las Vegas algorithm Expected running time -

  10. Randomized Selection • 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 .

  11. Testing String Equality • 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

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

  13. Testing String Equality • 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.

  14. Testing String Equality

  15. Pattern Matching • Given a string of text X= x1x2…xn and a pattern Y= y1y2…ym, 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).

  16. Monte Carlo Algorithm for Pattern Matching • Running time is O(m+n). • Follows the same Brute-force algorithm, but instead of comparing the pattern with each block X(j)=xjxj+1…xj+m-1, this algorithm compare the fingerprint Ip(Y) of the pattern with the fingerprints Ip(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).

  17. Pattern Matching

  18. References • 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.

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

  20. Thank You

More Related