lecture_04

lecture_04 - Introduction to Algorithms 6.046J/18.401J...

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

View Full Document Right Arrow Icon
Introduction to Algorithms 6.046J/18.401J Lecture 4 Prof. Piotr Indyk
Background image of page 1

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

View Full DocumentRight Arrow Icon
September 20, 2004 (c) Piotr Indyk & Charles Leiserson L4.2 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
Background image of page 2
September 20, 2004 (c) Piotr Indyk & Charles Leiserson L4.3 Randomized Algorithms • Algorithms that make random decisions •T h a t i s : – Can generate a random number x from some range {1…R} – Make decisions based on the value of x • Why would it make sense ?
Background image of page 3

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

View Full DocumentRight Arrow Icon
September 20, 2004 (c) Piotr Indyk & Charles Leiserson L4.4 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
Background image of page 4
September 20, 2004 (c) Piotr Indyk & Charles Leiserson L4.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)
Background image of page 5

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

View Full DocumentRight Arrow Icon
September 20, 2004 (c) Piotr Indyk & Charles Leiserson L4.6 Matrix Product •C o m p u t e 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 6
September 20, 2004 (c) Piotr Indyk & Charles Leiserson L4.7 Matrix Product Checker • Given: 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] ½
Background image of page 7

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

View Full DocumentRight Arrow Icon
September 20, 2004 (c) Piotr Indyk & Charles Leiserson L4.8 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)
Background image of page 8
September 20, 2004 (c) Piotr Indyk & Charles Leiserson L4.9 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
Background image of page 9

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

View Full DocumentRight Arrow Icon
September 20, 2004 (c) Piotr Indyk & Charles Leiserson L4.10 D C ?
Background image of page 10