1 / 16

Intro to Computer Algorithms Lecture 9

Intro to Computer Algorithms Lecture 9. Phillip G. Bradford Computer Science University of Alabama. Announcements. Advisory Board’s Industrial Talk Series http://www.cs.ua.edu/9IndustrialSeries.shtm Coop Interview Days: Oct 14th and 15th Signup begins on 22 nd of September

jhowerton
Download Presentation

Intro to Computer Algorithms Lecture 9

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. Intro to Computer Algorithms Lecture 9 Phillip G. Bradford Computer Science University of Alabama

  2. Announcements • Advisory Board’s Industrial Talk Series • http://www.cs.ua.edu/9IndustrialSeries.shtm • Coop Interview Days: Oct 14th and 15th • Signup begins on 22nd of September • At least 40 firms looking for coop students!

  3. ACM announces Movie Night When and Where: Thursday, September 25, 2003 6:30 pm in room 119 EE EVERYONE IS INVITED!!!! The Movie will be Office Space We will have subway platters No Admission fee If you have any questions, go to our newly updated website and post them on the forum: http://www.studentacm.org

  4. Outline • Integer Multiplication • Fast Integer Multiplication • Matrix Multiplication • Start Strassen’s Algorithm

  5. Integer Multiplication • Cost of multiplying two n-digit integers • Basic Grade-School Algorithm • 23 = 2*101 + 3*100 = a1*101 + a0*100 • 14 = 1*101 + 4*100 = b1*101 + b0*100 • (a1 + a0)*(b1 + b0) • Or (a1*b1 + a1*b0) + (a0*b1 + a0*b0 ) • Consider the product of • an*10n + … + a0*100 • bn*10n + … + b0*100 • What does this cost? • O(n2) digit multiplication operations

  6. Integer Multiplication • Can we do any better? • 23 = 2*101 + 3*100 • 14 = 1*101 + 4*100 • 23*14 = (2*1)102 + (3*1+2*4)101 + (3*4)100 • Four multiplications • Powers of 10 can be done via shifting

  7. Integer Multiplication • Note: (3*1)+(2*4) = (2+3)*(1+4) –(2*1)-(3*4) • Because: (a1+a0)*(b1+b0) = a1b1+a1b0+a0b1+a0b0 • Focus on: a1b0+a0b1 both times 101 • Subtract off a1b1+ a0b0 • We must compute a1b1+ a0b0 anyway!

  8. Integer Multiplication • Can we generalize this? • Let a = a1*101 + a0*100 • And b = b1*101 + b0*100 • C = a*b = c2102 + c1101 + c0100 • Where c2 = a1*b1 and c0 = a0b0 • Therefore c1 = (a1+a0)*(b1+b0) – (c2 + c0)

  9. Fast Integer Multiplication • Divide-and-Conquer generalization! • Conceptual Example • Let A1 = a10*1010 + … + a5105 • And A0 = a4104 + … + a0100 • So, Letting A1 A1/105 and B1 B1/105 • Gives A = A1*105 + A0 • Likewise for B = B1*105 + B0 • Thus, A*B = (A1*105 + A0)*(B1*105 + B0)

  10. Fast Integer Multiplication • In general, giving • A*B = A1*B110n + (A1*B0+A0*B1)10n/2 + A0*B0 • For the time being, say n is a power of 2 • Do this with 3 multiplications instead of 4: • A*B = C2*10n + C110n/2 + C0 • Where C2 = A1*B1 and C0 = A0*B0 • And C1 = (A1+A0)*(B1+B0) – (C2 + C0)

  11. Fast Integer Multiplication • Convince me this works! • Recurrence… • Fundamental operation is multiplication • What does this cost? • T(n) = 3T(n/2) for n > 1 • T(1) = 1. • Can we use the Master Theorem?

  12. Fast Integer Multiplication • Solve T(n) by backward substitution • Let n = 2k • Then T(2k) = 3iT(2k-i) • Thus, T(n) = 3k for n = 2k. • Since, k = log2n • It must be that T(n) = 3log2n • Using a^{logb c} = c^{logb a} • T(n) = nlog23 = O(n1.585)

  13. Fast Integer Multiplication • How can we prove • a^{logb c} = c^{logb a} ? • Brassard & Bratley’s simulations

  14. Matrix Multiplication • Grade School Algorithm • M and N, say n-by-n matrices • Output P • For i1 to n do • For j1 to n do • P[i,j]  0 • For k 1 to n do • P[i,j]  P[i,j] + M[i,k]*N[k,j]

  15. Matrix Multiplication • Cost? • O(n3) • Can we do better?

  16. Strassen’s Algorithm • Cost O(n2.807)

More Related