1 / 13

Randomized Algorithms

Randomized Algorithms. Prof. Dr. Th. Ottmann University of Freiburg ottmann@informatik.uni-freiburg.de. Classes of Randomised Algorithms. Las Vegas type Yield always a correct result. For a specific input: Performance (runtime) may be bad, but the extected runtime is good!

Download Presentation

Randomized Algorithms

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. Randomized Algorithms Prof. Dr. Th. Ottmann University of Freiburg ottmann@informatik.uni-freiburg.de

  2. Classes of Randomised Algorithms Las Vegas type • Yield always a correct result. • For a specific input: Performance (runtime) may be bad, but the extected runtime is good! • Example: Randomised version of Quicksort Monte Carlo type(most correctly): • May produce an incorrect result (with a certain error probability). • For each specific input: (Worst case) runtime is good • Example: Randomised primality test.

  3. Quicksort Unsorted part A[l,r] in an array A A[l … r-1] p A[l...m – 1] p A[m + 1...r] Quicksort Quicksort

  4. Quicksort Algorithm:Quicksort Input: unsorted part [l, r] of an array A Output: sorted part [l, r] of the array A • ifr > l • then choose pivot-element p = A[r] 3 m = divide(A, l , r) /* partition Awith respect top: A[l],....,A[m – 1]  p  A[m + 1],...,A[r] */ • Quicksort(A, l , m - 1) Quicksort (A, m + 1, r)

  5. Division of the Array r l

  6. Division • divide(A, l , r): • Yields the index of the pivot elements in A • Can be carried out in time O(r – l)

  7. Worst-Case-Input n elements: Runtime: (n-1) + (n-2) + … + 2 + 1 = n(n-1)/2

  8. Randomised Version of Quicksort Algorithmus: Quicksort Input: unsorted part [l, r] of an array A Output: sorted part [l, r] of the array A if r > l thenramdomly choose apivot-element p = A[i] in the part [l, r] of the array; exchange A[ i] and A[r]; m = divide(A, l, r); /* divide A with respect to p: A[l],....,A[m – 1] p  A[m + 1],...,A[r] */ Quicksort(A, l, m - 1); Quicksort(A, m + 1, r)

  9. Primality Test Definition: The natural number p 2 is prime, iff a | p implies a = 1 or a = p. Algorithm:Deterministic primality test(naive version) Input: A natural number n 2 Output: Answer to the question: Is n prime? ifn = 2 then return true; if n even then return false; fori = 1 ton/2do if 2i + 1 divides n then return false return true Runtime: (n)

  10. Primality Test Goal: Randomised algorithm • With polynomial runtime • If the algorithm yields the answer“not prime”, then n is definitely not prime. • If the algorithm yields the answer “prime”, then this answer is wrong with a certain error probability p>0 , i.e. n is prime with a certain probability (1- p) only. k iterations of the algorithm: the algorithm yields the wrong answer with probability pkonly.

  11. Randomised Primality Test Theorem 1: (Fermat‘s theorem) Is p prim and 1 < a < p, then ap-1mod p =1. Theorem 2: Is p prim and 0 < a < p, then the equation a2mod p = 1 Has exactly two solutions, namely a = 1 und a = p – 1. Randomised algorithm: Choose an a with 1 < a < p randomly and check whether it fulfills the test of theorem 1; while computing ap-1 simultaneously check whether the test of theorem 2 is fulfilled for all numbers occurring during the computation of ap-1 using the fast exponentiation method.

  12. Randomisierter Primzahltest Algorithmus: Randomisierter Primzahltest 1 1 Wähle a im Bereich [2, n-1] zufällig 2 Berechne an-1 mod n 3 ifan-1 mod n= 1 4 thenn ist möglicherweise prim 5 elsen ist definitiv nicht prim Prob(n ist nicht prim, aber an-1 mod n = 1 ) ?

  13. Randomised Primality Test Theorem: Is n not prime, then there are at most n – 4/ 9 numbers 0 < a < n, such that the randomized algorithm for primality testing yields the wrong result.

More Related