Chapter5-2-DivideConquer

And analysis of algorithms chapter 4 c sum d0 15

Info iconThis preview shows page 1. Sign up to view the full content.

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

Unformatted text preview: d half is the c1 = (a1 + a0) * (b1 + b0) – (c2 + c0) is the product of the sum is of the a’s halves and the sum of the b’s halves minus the sum of c2 andesign.and Analysis of Algorithms – Chapter 4 c sum D0 15 Multiplication of large integers a c =c210n + c110n/2 + c0, where c2 = a1 * b1 is the product of their first half is the c0 = a0 * b0 is the product of their second half is the c1 = (a1 + a0) * (b1 + b0) – (c2 + c0) is the product of is the sum of the a’s halves and the sum of the b’s halves minus the sum of c2 and c0 halves Multiplication of n-digit numbers requires three Multiplication multiplications of n/2-digit numbers multiplications Design and Analysis of Algorithms – Chapter 4 16 Multiplication of large integers a M(n) = 3M(n/2) for n>1, M(1) = 1 a M(n) ≈ n1.585 M(n) Design and Analysis of Algorithms – Chapter 4 17 Matrix multiplication (brute force] - - - - - = - multiplication: Θ(n3) addition: Θ(n3) Design and Analysis of Algorithms – Chapter 4 18 Matrix multiplication Matrix (divide-conquer recursive algorithm] A, B: n by n matrices; Aij, Bij: n/2 by n/2 matrices, where i, j ∈ {0, 1} recurrence relations: multiplication: M(n) = ? addition: A(n) = ? Design and Analysis of Algorithms – Chapter 4 19 Matrix multiplication (divideconquer] conquer] C00 C 10 C01 A00 A01 B00 B01 = A * B C11 10 A11 10 B11 A00 * B00 + A01 * B10 A00 * B01 + A01 * B11 = A10 * B00 + A11 * B10 A10 * B01 + A11 * B11 A, B: n by n matrices; Aij, Bij: n/2 by n/2 matrices, where i, j ∈ {0, 1} multiplication: Θ(n3) addition: Θ(n3) Design and Analysis of Algorithms – Chapter 4 20 Strassen’s matrix multiplication C00 C 10 C01 A00 A01 B00 B01 = A * B C11 10 A11 10 B11 M3 + M5 M 1 + M 4− M 5 + M 7 = M2 + M4 M1 + M 3 − M 2 + M 6 M1=(A00+A11)*(B00+B11) M2=(A10+A11)*B00 recurrence relations: M3=A00*(B01-B11) multiplication: M(n) = ? M4=A11*(B10-B00) addition: A(n) = ? M5=(A00+A01)*B11 M6=(A10-A00)*(B00+B01) M7=(A01-A11)*(B10+B11) of Algorithms – Chapter 4 Design and Analysis 21 Strassen’s matrix multiplication C00 C 10 C01 A00 A01 B00 B01 = A * B C11 10 A11 10 B11 M3 + M5 M 1 + M 4− M 5 + M 7 = M2 + M4 M1 + M 3 − M 2 + M 6 M1=(A00+A11)*(B00+B11) M2=(A10+A11)*B00 M(n) ≈ Θ(n2.807) M3=A00*(B01-B11) A(n) ≈ Θ(n2.807) M4=A11*(B10-B00) M5=(A00+A01)*B11 M6=(A10-A00)*(B00+B01) M7=(A01-A11)*(B10+B11) of Algorithms – Chapter 4 Design and Analysis 22 In-Class Exercise In-Class a Given a sorted array of distinct integers A[1… n], you want to find out whether there is an n], index i for which A[i] = i. Given a dive-andindex conquer algorithm that runs in time O(logn). conquer Design and Analysis of Algorithms – Chapter 4 23...
View Full Document

Ask a homework question - tutors are online