6.046_Lecture04_RandomizedQuicksort

6.046_Lecture04_RandomizedQuicksort - 6.046 Introduction to...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
6.046 Introduction to Algorithms, Lecture 4 February 14, 2005 Randomized Algorithms, Quicksort 1 Introduction to Algorithms 6.046J/18.401J Lecture 4 Prof. Manolis Kellis Today • Randomized algorithms: algorithms that flip coins – Matrix product checker: is AB=C ? – Quicksort: • Example of divide and conquer • Fast and practical sorting algorithm • Other applications on Wednesday – Friday (6.096): Application in computational biology • Discovering common motifs in DNA sequences Randomized Algorithms • Algorithms that make random decisions • That is: – Can generate a random number x from some range {1…R} – Make decisions based on the value of x • Why would it make sense ? Two cups, one coin • If you always choose a fixed cup, the adversary will put the coin in the other one, so the expected payoff = $0 • If you choose a random cup, the expected payoff = $0.5 Randomized Algorithms • Two basic types: – Typically fast (but sometimes slow): Las Vegas – Typically correct (but sometimes output garbage): Monte Carlo • The probabilities are defined by the random numbers of the algorithm! (not by random choices of the problem instance) Matrix Product • Compute C=A × B – Simple algorithm: O(n 3 ) time – Multiply two 2 × 2 matrices using 7 mult. O(n 2.81… ) time [Strassen’69] – Multiply two 70 × 70 matrices using 143640 multiplications O(n 2.795… ) time [Pan’78] –… –O ( n 2.376… ) [Coppersmith-Winograd]
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6.046 Introduction to Algorithms, Lecture 4 February 14, 2005 Randomized Algorithms, Quicksort 2 Matrix Product Checker •G i v e n : n × n matrices A,B,C • Goal: is A × B=C ? • We will see an O(n 2 ) algorithm that: – If answer= YES , then Pr[output=YES]=1 – If answer= NO , then Pr[output=YES] ½ The algorithm • Algorithm: – Choose a random binary vector x[1…n] , such that Pr[x i =1]=½ , i=1…n – Check if ABx=Cx • Does it run in O(n 2 ) time ? – YES, because ABx = A(Bx) Correctness • Let D=AB , need to check if D=C • What if D=C ? – Then Dx=Cx ,so the output is YES • What if D C ? – Presumably there exists x such that Dx Cx – We need to show there are many such x D C ? Vector product • Consider vectors d c (say, d i c i ) • Choose a random binary x • We have dx=cx iff (d-c)x=0 • Pr[(d-c)x=0]= ?
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/20/2012 for the course CS 6.006 taught by Professor Erikdemaine during the Spring '08 term at MIT.

Page1 / 9

6.046_Lecture04_RandomizedQuicksort - 6.046 Introduction to...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online