{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lecture_04

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

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

Introduction to Algorithms 6.046J/18.401J Lecture 4 Prof. Piotr Indyk

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

View Full Document
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
September 20, 2004 (c) Piotr Indyk & Charles Leiserson L4.3 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 ?

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

View Full Document
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
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)

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

View Full Document
September 20, 2004 (c) Piotr Indyk & Charles Leiserson L4.6 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]
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] ½

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

View Full Document
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)
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

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

View Full Document
September 20, 2004 (c) Piotr Indyk & Charles Leiserson L4.10 D C ?
September 20, 2004 (c) Piotr Indyk & Charles Leiserson L4.11 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]= ? (d-c): d 1 -c 1 d 2 -c 2 d i -c i d n -c n x: x 1 x 2 x i x n = Σ j i (d j -c j )x j + (d i -c i )x i

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

View Full Document
September 20, 2004 (c) Piotr Indyk & Charles Leiserson L4.12 Analysis, ctd. If x i =0 , then (c-d)x=S 1 If x i =1 , then (c-d)x=S 2 S 1 • So, 1 of the choices gives (c-d)x 0 Pr[cx=dx] ½
September 20, 2004 (c) Piotr Indyk & Charles Leiserson L4.13 Matrix Product Checker Is A×B=C ?

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.