Randomized Algorithms Prof. Dr. Th. Ottmann University of Freiburg

Slides:



Advertisements
Similar presentations
Order Statistics Sorted
Advertisements

Theory of Computing Lecture 3 MAS 714 Hartmut Klauck.
“Devo verificare un’equivalenza polinomiale…Che fò? Fò dù conti” (Prof. G. Di Battista)
WS Algorithmentheorie 03 – Randomized Algorithms (Primality Testing) Prof. Dr. Th. Ottmann.
COM 5336 Cryptography Lecture 7a Primality Testing
Introduction to Algorithms
1 Today’s Material Medians & Order Statistics – Ch. 9.
Divide and Conquer Strategy
Divide and Conquer. Recall Complexity Analysis – Comparison of algorithm – Big O Simplification From source code – Recursive.
Quicksort CSE 331 Section 2 James Daly. Review: Merge Sort Basic idea: split the list into two parts, sort both parts, then merge the two lists
Spring 2015 Lecture 5: QuickSort & Selection
Randomized Algorithms Fundamentals of Algorithmics.
Nattee Niparnan. Recall  Complexity Analysis  Comparison of Two Algos  Big O  Simplification  From source code  Recursive.
Sorting and selection – Part 2 Prof. Noah Snavely CS1114
Quicksort Ack: Several slides from Prof. Jim Anderson’s COMP 750 notes. UNC Chapel Hill1.
Introduction to Algorithms Chapter 7: Quick Sort.
Updated QuickSort Problem From a given set of n integers, find the missing integer from 0 to n using O(n) queries of type: “what is bit[j]
WS Algorithmentheorie 03 – Randomized Algorithms (Overview and randomised Quicksort) Prof. Dr. Th. Ottmann.
Quicksort Many of the slides are from Prof. Plaisted’s resources at University of North Carolina at Chapel Hill.
Convex Hulls Computational Geometry, WS 2006/07 Lecture 2 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät für.
CS 253: Algorithms Chapter 7 Mergesort Quicksort Credit: Dr. George Bebis.
Data Structures, Spring 2006 © L. Joskowicz 1 Data Structures – LECTURE 4 Comparison-based sorting Why sorting? Formal analysis of Quick-Sort Comparison.
TDDB56 DALGOPT-D DALG-C Lecture 8 – Sorting (part I) Jan Maluszynski - HT Sorting: –Intro: aspects of sorting, different strategies –Insertion.
Tutorial 4 The Quicksort Algorithm. QuickSort  Divide: Choose a pivot, P Form a subarray with all elements ≤ P Form a subarray with all elements > P.
Quicksort CIS 606 Spring Quicksort Worst-case running time: Θ(n 2 ). Expected running time: Θ(n lg n). Constants hidden in Θ(n lg n) are small.
WS Algorithmentheorie 03 – Randomized Algorithms (Public Key Cryptosystems) Prof. Dr. Th. Ottmann.
S: Application of quicksort on an array of ints: partitioning.
Study Group Randomized Algorithms Jun 7, 2003 Jun 14, 2003.
Theory I Algorithm Design and Analysis (9 – Randomized algorithms) Prof. Dr. Th. Ottmann.
WS Algorithmentheorie 03 – Randomized Algorithms (Public Key Cryptosystems) Prof. Dr. Th. Ottmann.
Randomized Algorithms. Introduction Algorithm uses a random number to make at least one decision Running time depends on input and random numbers generated.
Computer Algorithms Lecture 10 Quicksort Ch. 7 Some of these slides are courtesy of D. Plaisted et al, UNC and M. Nicolescu, UNR.
CSE 321 Discrete Structures Winter 2008 Lecture 10 Number Theory: Primality.
10 Algorithms in 20th Century Science, Vol. 287, No. 5454, p. 799, February 2000 Computing in Science & Engineering, January/February : The Metropolis.
Stochastic Algorithms Some of the fastest known algorithms for certain tasks rely on chance Stochastic/Randomized Algorithms Two common variations – Monte.
RSA Parameter Generation Bob needs to: - find 2 large primes p,q - find e s.t. gcd(e, Á (pq))=1 Good news: - primes are fairly common: there are about.
Prabhas Chongstitvatana 1 Primality Testing Is a given odd integer prime or composite ? No known algorithm can solve this problem with certainty in a reasonable.
Chapter 14 Randomized algorithms Introduction Las Vegas and Monte Carlo algorithms Randomized Quicksort Randomized selection Testing String Equality Pattern.
Approximation Algorithms Pages ADVANCED TOPICS IN COMPLEXITY THEORY.
Randomized Algorithms Pasi Fränti Treasure island Treasure worth awaits 5000 DAA expedition 5000 ? ? Map for sale: 3000.
Nattee Niparnan. Recall  Complexity Analysis  Comparison of Two Algos  Big O  Simplification  From source code  Recursive.
Computer Science 101 Fast Searching and Sorting. Improving Efficiency We got a better best case by tweaking the selection sort and the bubble sort We.
Analysis of Algorithms These slides are a modified version of the slides used by Prof. Eltabakh in his offering of CS2223 in D term 2013.
CPSC 335 Randomized Algorithms Dr. Marina Gavrilova Computer Science University of Calgary Canada.
The Selection Problem. 2 Median and Order Statistics In this section, we will study algorithms for finding the i th smallest element in a set of n elements.
Computation Model and Complexity Class. 2 An algorithmic process that uses the result of a random draw to make an approximated decision has the ability.
PROBABILISTIC COMPUTATION By Remanth Dabbati. INDEX  Probabilistic Turing Machine  Probabilistic Complexity Classes  Probabilistic Algorithms.
QuickSort (Ch. 7) Like Merge-Sort, based on the three-step process of divide- and-conquer. Input: An array A[1…n] of comparable elements, the starting.
Divide-and-Conquer. Outline Introduction Merge Sort Quick Sort Closest pair of points Large integer multiplication.
Umans Complexity Theory Lectures Lecture 7b: Randomization in Communication Complexity.
Computer Science 101 Fast Algorithms. What Is Really Fast? n O(log 2 n) O(n) O(n 2 )O(2 n )
Prof. Amr Goneid, AUC1 Analysis & Design of Algorithms (CSCE 321) Prof. Amr Goneid Department of Computer Science, AUC Part 1. Complexity Bounds.
RSA cryptosystem--preview Suppose n=p  q and  (n)=(p-1)(q-1), where p and q are big primes. Select (find) a and b, such that a  b=1 mod  (n). K=(n,p,q,a,b),
Divide and Conquer Strategy
ICS 353: Design and Analysis of Algorithms
NP-Completness Turing Machine. Hard problems There are many many important problems for which no polynomial algorithms is known. We show that a polynomial-time.
1 Recursive algorithms Recursive solution: solve a smaller version of the problem and combine the smaller solutions. Example: to find the largest element.
CSC317 1 Quicksort on average run time We’ll prove that average run time with random pivots for any input array is O(n log n) Randomness is in choosing.
MA/CSSE 473 Day 09 Modular Division Revisited Fermat's Little Theorem Primality Testing.
CS6045: Advanced Algorithms Sorting Algorithms. Sorting Input: sequence of numbers Output: a sorted sequence.
Quick Sort Divide: Partition the array into two sub-arrays
Lecture 8 Randomized Algorithms
QuickSort QuickSort Best, Worst Average Cases K-th Ordered Statistic
CS 583 Analysis of Algorithms
Probabilistic algorithms
Randomized Algorithms
Ack: Several slides from Prof. Jim Anderson’s COMP 202 notes.
Probabilistic algorithms
Quicksort Quick sort Correctness of partition - loop invariant
Presentation transcript:

Randomized Algorithms Prof. Dr. Th. Ottmann University of Freiburg

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 A[l … r-1]p pA[l...m – 1]A[m r] Quicksort Unsorted part A[l,r] in an array A

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

5 Division of the Array l r

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) + … = 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 then ramdomly choose a pivot-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? if n = 2 then return true; if n even then return false; for i = 1 to  n/2 do 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 p k only.

11 Randomised Primality Test Theorem 1: (Fermat‘s theorem) Is p prim and 1 < a < p, then a p-1 mod p = 1. Theorem 2: Is p prim and 0 < a < p, then the equation a 2 mod 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 a p-1 simultaneously check whether the test of theorem 2 is fulfilled for all numbers occurring during the computation of a p-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 a n-1 mod n 3 if a n-1 mod n = 1 4 then n ist möglicherweise prim 5 else n ist definitiv nicht prim Prob(n ist nicht prim, aber a n-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.