Fast Convolution; Strassen s Method

Size: px
Start display at page:

Download "Fast Convolution; Strassen s Method"

Transcription

1 Fast Convolution; Strassen s Method 1 Fast Convolution reduction to subquadratic time polynomial evaluation at complex roots of unity interpolation via evaluation at complex roots of unity 2 The Master Method to Solve Recurrences a recursive matrix-matrix multiplication the master method 3 Strassen s method the steps in the method reduction to subcubic time CS 401/MCS 401 Lecture 9 Computer Algorithms I Jan Verschelde, 9 July 2018 Computer Algorithms I (CS 401/MCS 401) Fast Convolution; Strassen s Method L-9 9 July / 40

2 Fast Convolution; Strassen s Method 1 Fast Convolution reduction to subquadratic time polynomial evaluation at complex roots of unity interpolation via evaluation at complex roots of unity 2 The Master Method to Solve Recurrences a recursive matrix-matrix multiplication the master method 3 Strassen s method the steps in the method reduction to subcubic time Computer Algorithms I (CS 401/MCS 401) Fast Convolution; Strassen s Method L-9 9 July / 40

3 computing convolutions Input: a = (a 0, a 1,..., a n 1 ), b = (b 0, b 1,..., b n 1 ). Output: c = a b, the convolution of a with b. Example: n = 4, consider: a 0 b 0 a 0 b 1 a 0 b 2 a 0 b 3 a 1 b 0 a 1 b 1 a 1 b 2 a 1 b 3 a 2 b 0 a 2 b 1 a 2 b 2 a 2 b 3 + a 3 b 0 a 3 b 1 a 3 b 2 a 3 b 3 c 0 c 1 c 2 c 3 c 4 c 5 c 6 The general formula for the k-th coefficient in the convolution: c k = min(n 1,k) i=max(0,k n+1) a k i b i. Computer Algorithms I (CS 401/MCS 401) Fast Convolution; Strassen s Method L-9 9 July / 40

4 applying divide and conquer View the input a = (a 0, a 1,..., a n 1 ) and b = (b 0, b 1,..., b n 1 ) as coefficients of polynomials A(x) and B(x) respectively. Compute c = a b by polynomial evaluation and interpolation: 1 Choose 2n values x 1, x 2,..., x 2n. Evaluating A and B at those values gives A(x 1 ), A(x 2 ),..., A(x 2n ), B(x 1 ), B(x 2 ),..., B(x 2n ). 2 Multiply the 2n evaluations: C(x j ) = A(x j ) B(x j ), j = 1, 2,..., 2n. Evaluation commutes with computing the product of A and B. 3 Because the degree of C is 2n 1, C has 2n 1 coefficients, which can be recovered from the 2n 1 values C(x 1 ), C(x 2 ),..., C(x 2n ) by polynomial interpolation. Steps 2 runs in O(n), but step 1 and 3 are both O(n 2 ), for any x i. Computer Algorithms I (CS 401/MCS 401) Fast Convolution; Strassen s Method L-9 9 July / 40

5 Lagrange interpolation Given are n interpolation points (x i, f i ), i = 0, 1,..., n, where for all i j: x i x j. The Lagrange interpolating polynomial has the form p(x) = l 0 (x)f 0 + l 1 (x)f (x 1 ) + + l n (x)f n, where l i (x j ) = { 1 if i = j 0 if i j l i (x) = n j = 0 j i ( x xj x i x j ). In this form, we have that p(x i ) = f i, i = 0, 1,..., n. Exercise 1: Write a pseudo description for the computation of p(x). Prove that the algorithm to compute p(x) runs in O(n 2 ) time. Computer Algorithms I (CS 401/MCS 401) Fast Convolution; Strassen s Method L-9 9 July / 40

6 Fast Convolution; Strassen s Method 1 Fast Convolution reduction to subquadratic time polynomial evaluation at complex roots of unity interpolation via evaluation at complex roots of unity 2 The Master Method to Solve Recurrences a recursive matrix-matrix multiplication the master method 3 Strassen s method the steps in the method reduction to subcubic time Computer Algorithms I (CS 401/MCS 401) Fast Convolution; Strassen s Method L-9 9 July / 40

7 complex roots of unity Consider the 8-th complex roots of unity: ω 1 = e 2π/8 = cos(2π/8) + sin(2π/8)i, i = 1, ω k = e 2kπ/8, k = 0, 1,..., 7. Let θ = 2π/8: ω 2 ω 3 ω 1 ω 4 θ ω 0 ω 5 ω 6 ω 7 Computer Algorithms I (CS 401/MCS 401) Fast Convolution; Strassen s Method L-9 9 July / 40

8 an exercise Exercise 2: For n > 0, show that the squares of the 2n complex roots of unity are the n complex roots of unity of x n 1. Computer Algorithms I (CS 401/MCS 401) Fast Convolution; Strassen s Method L-9 9 July / 40

9 evaluation at complex roots of unity A(x) = a 0 + a 1 x + a 2 x 2 + a 3 x 3 + a 4 x 4 + a 5 x 5 + a 6 x 6 + a 7 x 7 = a 0 + a 2 x 2 + a 4 x 4 + a 6 x 6 + a 1 x + a 3 x 3 + a 5 x 5 + a 7 x 7 = a 0 + a 2 x 2 + a 4 x 4 + a 6 x 6 + x(a 1 + a 3 x 2 + a 5 x 4 + a 7 x 6 ) A even (z) = a 0 + a 2 z + a 4 z 2 + a 6 z 3 A odd (z) = a 1 + a 3 z + a 5 z 2 + a 7 z 3 We have thus A(x) = A even (x 2 ) + x A odd (x 2 ). Consider: A(ω 0 ) = A even (ω 0 ) + ω 0 A odd (ω 0 ) A(ω 1 ) = A even (ω 2 ) + ω 1 A odd (ω 2 ) A(ω 2 ) = A even (ω 4 ) + ω 2 A odd (ω 4 ) A(ω 3 ) = A even (ω 6 ) + ω 3 A odd (ω 6 ) A(ω 4 ) = A even (ω 0 ) + ω 4 A odd (ω 0 ), as (ω 4 ) 2 = e 2 (2 4π/8) = ω 0 A(ω 5 ) = A even (ω 2 ) + ω 5 A odd (ω 2 ), as (ω 5 ) 2 = e 2 (2 5π/8) = ω 2 A(ω 6 ) = A even (ω 4 ) + ω 6 A odd (ω 4 ), as (ω 6 ) 2 = e 2 (2 6π/8) = ω 4 A(ω 7 ) = A even (ω 6 ) + ω 7 A odd (ω 6 ), as (ω 7 ) 2 = e 2 (2 7π/8) = ω 6 Computer Algorithms I (CS 401/MCS 401) Fast Convolution; Strassen s Method L-9 9 July / 40

10 deriving a recurrence The evaluation of A(x) at 2n points is reduced to 1 evaluation of A even (x) at ω 0, ω 2,..., ω 2n 2, 2 evaluation of A odd (x) at ω 0, ω 2,..., ω 2n 2, 3 n sums of A even (ω 0 ) + ω 0 A odd (ω 0 ) A even (ω 1 ) + ω 1 A odd (ω 1 )..., A even (ω 2n 2 ) + ω n 1 A odd (ω 2n 2 ) 4 n sums of A even (ω 0 ) + ω n A odd (ω 0 ) A even (ω 1 ) + ω n 1 A odd (ω 1 )..., A even (ω 2n 2 ) + ω 2n 1 A odd (ω 2n 2 ) Denote by T (2n) the time to evaluate A(x) at the 2n roots of unity. We have T (2n) 2T (n) + O(n) because 1 the size of A even (x) is n, 2 the size of A odd (x) is n, 3 taking n sums is O(n), 4 taking n sums is O(n). Computer Algorithms I (CS 401/MCS 401) Fast Convolution; Strassen s Method L-9 9 July / 40

11 O(n log(n)) time The recurrence T (2n) 2T (n) + O(n) is equivalent to T (n) 2T (n/2) + O(n). So the following theorem applies: Theorem If T (n) 2T (n/2) + c 1 n and T (2) c 2, for positive constants c 1 and c 2, then T (n) is O(n log(n)). Computer Algorithms I (CS 401/MCS 401) Fast Convolution; Strassen s Method L-9 9 July / 40

12 Fast Convolution; Strassen s Method 1 Fast Convolution reduction to subquadratic time polynomial evaluation at complex roots of unity interpolation via evaluation at complex roots of unity 2 The Master Method to Solve Recurrences a recursive matrix-matrix multiplication the master method 3 Strassen s method the steps in the method reduction to subcubic time Computer Algorithms I (CS 401/MCS 401) Fast Convolution; Strassen s Method L-9 9 July / 40

13 a property of complex roots of unity Consider: ( ) x 2n 1 = (x 1) x 2n x + 1. For any ω, a complex root of unity: ω 2n 1 = 0. Consider ω 1: x 1 0, as ω satisfies x 2n 1 = 0, we must have that the other factor x 2n x + 1 = 0. Because ω 2n 1 = 0, we then have for ω 1: ω 2n ω + 1 = 0. For ω = 1, substitute 1 in ω 2n ω + 1 = 1 } + {{ } = 2n. 2n To conclude: ω 2n ω + 1 = { 0 if ω 1, 2n if ω = 1. Computer Algorithms I (CS 401/MCS 401) Fast Convolution; Strassen s Method L-9 9 July / 40

14 interpolation by evaluation Given C(ω 0 ), C(ω 1 ), C(ω 2 ), C(ω 3 ), C(ω 4 ), C(ω 5 ), C(ω 6 ), C(ω 7 ), we want to compute coefficients c 0, c 1, c 2, c 3, c 4, c 5, c 6, c 7 of C(x) = c 0 + c 1 x + c 2 x 2 + c 3 x 3 + c 4 x 4 + c 5 x 5 + c 6 x 6 + c 7 x 7. D(x) = C(ω 0 )+C(ω 1 )x +C(ω 2 )x 2 +C(ω 3 )x 3 +C(ω 4 )x 4 +C(ω 5 )x 5 +C(ω 6 )x 6 +C(ω 7 )x 7 = (c 0 + c 1 ω 0 + c 2 ω c 3ω c 4ω c 5ω c 0ω c 7ω 7 0 )1 + (c 0 + c 1 ω 1 + c 2 ω c 3ω c 4ω c 5ω c 1ω c 7ω 7 1 )x + (c 0 + c 1 ω 2 + c 2 ω c 3ω c 4ω c 5ω c 2ω c 7ω 7 2 )x 2 + (c 0 + c 1 ω 3 + c 2 ω c 3ω c 4ω c 5ω c 3ω c 7ω 7 3 )x 3 + (c 0 + c 1 ω 4 + c 2 ω c 3ω c 4ω c 5ω c 4ω c 7ω 7 4 )x 4 + (c 0 + c 1 ω 5 + c 2 ω c 3ω c 4ω c 5 ω c 5ω c 7ω 7 5)x 5 + (c 0 + c 1 ω 6 + c 2 ω c 3ω c 4ω c 5ω c 6ω c 7ω 7 6 )x 6 + (c 0 + c 1 ω 7 + c 2 ω c 3 ω c 4ω c 5 ω c 7ω c 7ω 7 7)x 7 Computer Algorithms I (CS 401/MCS 401) Fast Convolution; Strassen s Method L-9 9 July / 40

15 rearranging the coefficients D(x) = (c 0 + c 1 ω 0 + c 2 ω c 3ω c 4ω c 5ω c 0ω c 7ω 7 0 )1 + (c 0 + c 1 ω 1 + c 2 ω c 3ω c 4ω c 5ω c 1ω c 7ω 7 1 )x + (c 0 + c 1 ω 2 + c 2 ω c 3ω c 4ω c 5ω c 2ω c 7ω 7 2 )x 2 + (c 0 + c 1 ω 3 + c 2 ω c 3ω c 4ω c 5ω c 3ω c 7ω 7 3 )x 3 + (c 0 + c 1 ω 4 + c 2 ω c 3ω c 4ω c 5ω c 4ω c 7ω 7 4 )x 4 + (c 0 + c 1 ω 5 + c 2 ω c 3ω c 4ω c 5 ω c 5ω c 7ω 7 5)x 5 + (c 0 + c 1 ω 6 + c 2 ω c 3ω c 4ω c 5ω c 6ω c 7ω 7 6 )x 6 + (c 0 + c 1 ω 7 + c 2 ω c 3 ω c 4ω c 5 ω c 7ω c 7ω 7 7)x 7 = ( 1 + x + x 2 + x 3 + x 4 + x 5 + x 6 + x 7 )c 0 + (ω 0 + ω 1 x + ω 2 x 2 + ω 3 x 3 + ω 4 x 4 + ω 5 x 5 + ω 6 x 6 + ω 7 x 7 )c 1 + (ω0 2 + ω2 1 x + ω2 2 x 2 + ω3 2 x 3 + ω4 2 x 4 + ω5x ω6 2 x 6 + ω7x 2 7 )c 2 + (ω0 3 + ω3 1 x + ω3 2 x 2 + ω3 3 x 3 + ω4 3 x 4 + ω5 3 x 5 + ω6 3 x 6 + ω7 3 x 7 )c 3 + (ω0 4 + ω4 1 x + ω4 2 x 2 + ω3 4 x 3 + ω4 4 x 4 + ω5x ω6 4 x 6 + ω7x 4 7 )c 4 + (ω0 5 + ω5 1 x + ω5 2 x 2 + ω3 5 x 3 + ω4 5 x 4 + ω5 5 x 5 + ω6 5 x 6 + ω7 5 x 7 )c 5 + (ω0 6 + ω6 1 x + ω6 2 x 2 + ω3 6 x 3 + ω4 6 x 4 + ω5 6 x 5 + ω6 6 x 6 + ω7 6 x 7 )c 6 + (ω0 7 + ω7 1 x + ω7 2 x 2 + ω3 7 x 3 + ω4 7 x 4 + ω5x ω6 7 x 6 + ω7x 7 7 )c 7 Computer Algorithms I (CS 401/MCS 401) Fast Convolution; Strassen s Method L-9 9 July / 40

16 simplifying the powers of the roots of unity D(x) = ( 1 + x + x 2 + x 3 + x 4 + x 5 + x 6 + x 7 )c 0 + (ω 0 + ω 1 x + ω 2 x 2 + ω 3 x 3 + ω 4 x 4 + ω 5 x 5 + ω 6 x 6 + ω 7 x 7 )c 1 + (ω0 2 + ω2 1 x + ω2 2 x 2 + ω3 2 x 3 + ω4 2 x 4 + ω5x ω6 2 x 6 + ω7x 2 7 )c 2 + (ω0 3 + ω3 1 x + ω3 2 x 2 + ω3 3 x 3 + ω4 3 x 4 + ω5 3 x 5 + ω6 3 x 6 + ω7 3 x 7 )c 3 + (ω0 4 + ω4 1 x + ω4 2 x 2 + ω3 4 x 3 + ω4 4 x 4 + ω5x ω6 4 x 6 + ω7x 4 7 )c 4 + (ω0 5 + ω5 1 x + ω5 2 x 2 + ω3 5 x 3 + ω4 5 x 4 + ω5 5 x 5 + ω6 5 x 6 + ω7 5 x 7 )c 5 + (ω0 6 + ω6 1 x + ω6 2 x 2 + ω3 6 x 3 + ω4 6 x 4 + ω5 6 x 5 + ω6 6 x 6 + ω7 6 x 7 )c 6 + (ω0 7 + ω7 1 x + ω7 2 x 2 + ω3 7 x 3 + ω4 7 x 4 + ω5x ω6 7 x 6 + ω7x 7 7 )c 7 = (1 + x + x 2 + x 3 + x 4 + x 5 + x 6 + x 7 )c 0 + (1 + ω 1 x + ω 2 x 2 + ω 3 x 3 + ω 4 x 4 + ω 5 x 5 + ω 6 x 6 + ω 7 x 7 )c 1 + (1 + ω 2 x + ω 4 x 2 + ω 6 x 3 + 1x 4 + ω 2 x 5 + ω 4 x 6 + ω 6 x 7 )c 2 + (1 + ω 3 x + ω 6 x 2 + ω 1 x 3 + ω 4 x 4 + ω 7 x 5 + ω 2 x 6 + ω 5 x 7 )c 3 + (1 + ω 4 x + 1x 2 + ω 4 x 3 + 1x 4 + ω 4 x 5 + 1x 6 + ω 4 x 7 )c 4 + (1 + ω 5 x + ω 2 x 2 + ω 7 x 3 + ω 4 x 4 + ω 1 x 5 + ω 6 x 6 + ω 3 x 7 )c 5 + (1 + ω 6 x + ω 4 x 2 + ω 2 x 3 + 1x 4 + ω 6 x 5 + ω 4 x 6 + ω 2 x 7 )c 6 + (1 + ω 7 x + ω 6 x 2 + ω 5 x 3 + ω 4 x 4 + ω 3 x 5 + ω 2 x 6 + ω 1 x 7 )c 7 Computer Algorithms I (CS 401/MCS 401) Fast Convolution; Strassen s Method L-9 9 July / 40

17 simplifying more: ω k = ω1 k, ωj k = ωk j 1 = ω k j mod 2n 1 D(x) = (1 + x + x 2 + x 3 + x 4 + x 5 + x 6 + x 7 )c 0 + (1 + ω 1 x + ω 2 x 2 + ω 3 x 3 + ω 4 x 4 + ω 5 x 5 + ω 6 x 6 + ω 7 x 7 )c 1 + (1 + ω 2 x + ω 4 x 2 + ω 6 x 3 + 1x 4 + ω 2 x 5 + ω 4 x 6 + ω 6 x 7 )c 2 + (1 + ω 3 x + ω 6 x 2 + ω 1 x 3 + ω 4 x 4 + ω 7 x 5 + ω 2 x 6 + ω 5 x 7 )c 3 + (1 + ω 4 x + 1x 2 + ω 4 x 3 + 1x 4 + ω 4 x 5 + 1x 6 + ω 4 x 7 )c 4 + (1 + ω 5 x + ω 2 x 2 + ω 7 x 3 + ω 4 x 4 + ω 1 x 5 + ω 6 x 6 + ω 3 x 7 )c 5 + (1 + ω 6 x + ω 4 x 2 + ω 2 x 3 + 1x 4 + ω 6 x 5 + ω 4 x 6 + ω 2 x 7 )c 6 + (1 + ω 7 x + ω 6 x 2 + ω 5 x 3 + ω 4 x 4 + ω 3 x 5 + ω 2 x 6 + ω 1 x 7 )c 7 = (1 + x + x 2 + x 3 + x 4 + x 5 + x 6 + x 7 )c 0 + (1 + ω 1 x + ω1 2 x 2 + ω1 3 x 3 + ω1 4 x 4 + ω1 5 x 5 + ω1 6 x 6 + ω1 7 x 7 )c 1 + (1 + ω 2 x + ω2 2 x 2 + ω2 3 x 3 + ω2 4 x 4 + ω2 5 x 5 + ω2 6 x 6 + ω2 7 x 7 )c 2 + (1 + ω 3 x + ω3 2 x 2 + ω3 3 x 3 + ω3 4 x 4 + ω3 5 x 5 + ω3 6 x 6 + ω3 7 x 7 )c 3 + (1 + ω 4 x + ω4 2 x 2 + ω4 3 x 3 + ω4 4 x 4 + ω4 5 x 5 + ω4 6 x 6 + ω4 7 x 7 )c 4 + (1 + ω 5 x + ω5x ω5 3 x 3 + ω5x ω5 5 x 5 + ω5 6 x 6 + ω5x 7 7 )c 5 + (1 + ω 6 x + ω6 2 x 2 + ω6 3 x 3 + ω6 4 x 4 + ω6 5 x 5 + ω6 6 x 6 + ω6 7 x 7 )c 6 + (1 + ω 7 x + ω7x ω7 3 x 3 + ω7x ω7 5 x 5 + ω7 6 x 6 + ω7x 7 7 )c 7 Computer Algorithms I (CS 401/MCS 401) Fast Convolution; Strassen s Method L-9 9 July / 40

18 evaluation at the roots of unity D(x) = (1 + x + x 2 + x 3 + x 4 + x 5 + x 6 + x 7 )c 0 + (1 + ω 1 x + ω1 2 x 2 + ω1 3 x 3 + ω1 4 x 4 + ω1 5 x 5 + ω1 6 x 6 + ω1 7 x 7 )c 1 + (1 + ω 2 x + ω2 2 x 2 + ω2 3 x 3 + ω2 4 x 4 + ω2 5 x 5 + ω2 6 x 6 + ω2 7 x 7 )c 2 + (1 + ω 3 x + ω3 2 x 2 + ω3 3 x 3 + ω3 4 x 4 + ω3 5 x 5 + ω3 6 x 6 + ω3 7 x 7 )c 3 + (1 + ω 4 x + ω4 2 x 2 + ω4 3 x 3 + ω4 4 x 4 + ω4 5 x 5 + ω4 6 x 6 + ω4 7 x 7 )c 4 + (1 + ω 5 x + ω5x ω5 3 x 3 + ω5x ω5 5 x 5 + ω5 6 x 6 + ω5x 7 7 )c 5 + (1 + ω 6 x + ω6 2 x 2 + ω6 3 x 3 + ω6 4 x 4 + ω6 5 x 5 + ω6 6 x 6 + ω6 7 x 7 )c 6 + (1 + ω 7 x + ω7x ω7 3 x 3 + ω7x ω7 5 x 5 + ω7 6 x 6 + ω7x 7 7 )c 7 { ω 2n 1 0 if ω 1, + + ω + 1 = 2n if ω = 1, D(ω 0 ) = 8c 0 D(ω 1 ) = 8c 7 D(ω 2 ) = 8c 6 D(ω implies 3 ) = 8c 5 D(ω 4 ) = 8c 4 D(ω 5 ) = 8c 3 D(ω 6 ) = 8c 2 D(ω 7 ) = 8c 1 Computer Algorithms I (CS 401/MCS 401) Fast Convolution; Strassen s Method L-9 9 July / 40

19 the general form of interpolation by evaluation Let D(x) = Then D(ω j ) = 2n 1 k=0 2n 1 C(ω k )x k = k=0 2n 1 l=0 ( 2n 1 l=0 c l ω l k 2n 1 k=0 ) ( 2n 1 c l ω l k l=0 2n 1 ω k j = l=0 ) x k. ( 2n 1 c l k=0 2n 1 ( 2n 1 ) and D(ω j ) = c l e (2πi/2n)(k l+j k) = k=0 l=0 ω l k ωk j ), ( 2n 1 c l k=0 ω l+j k ). ω 2n ω + 1 = { 0 if ω 1, 2n if ω = 1, implies D(ω k ) = 2n c 2n k, for k = 0, 1,..., 2n 1. Or equivalently, c k = D(ω 2n k). 2n Computer Algorithms I (CS 401/MCS 401) Fast Convolution; Strassen s Method L-9 9 July / 40

20 a recursive step 3 For D(x) = 2n 1 k=0 C(ω k )x k, we have c k = D(ω 2n k), k = 0, 1,..., 2n 1. 2n We evaluate a polynomial at complex roots of unity, so the same recurrence T (2n) T (n) + O(n) applies and we obtain a subquadratic, O(n log(n)) algorithm to compute the coefficients of the convolution. Theorem For a = (a 0, a 1,..., a n 1 ) and b = (b 0, b 1,..., b n 1 ), the convolution c = a b can be computed in O(n log(n)) time. The algorithm using the complex roots of unity is known as the Fast Fourier Transform, abbreviated as FFT. Computer Algorithms I (CS 401/MCS 401) Fast Convolution; Strassen s Method L-9 9 July / 40

21 reformulate step 3 with matrices Exercise 3: The computation of the coefficients of C on slide #17 from the values C(x 0 ), C(x 1 ),..., C(x 2n 1 ) can be expressed as a matrix-vector product: 1 The input of this product are the coefficients of C, and 2 the output are the values C(x 0 ), C(x 1 ),..., C(x 2n 1 ). Write the matrix and its inverse for n = 4 and n = 8. Does the structure of the matrix show the reduction to subquadratic time? Computer Algorithms I (CS 401/MCS 401) Fast Convolution; Strassen s Method L-9 9 July / 40

22 Fast Convolution; Strassen s Method 1 Fast Convolution reduction to subquadratic time polynomial evaluation at complex roots of unity interpolation via evaluation at complex roots of unity 2 The Master Method to Solve Recurrences a recursive matrix-matrix multiplication the master method 3 Strassen s method the steps in the method reduction to subcubic time Computer Algorithms I (CS 401/MCS 401) Fast Convolution; Strassen s Method L-9 9 July / 40

23 a recursive matrix-matrix multiplication Given are two n-by-n matrices A and B, we want to compute their product C = A B. Partition each matrix into four n/2-by-n/2-matrices: [ ] [ ] [ A11 A A = 12 B11 B, B = 12 C11 C, C = 12 A 21 A 22 B 21 B 22 C 21 C 22 ]. Then the product of A and B is [ ] [ C11 C 12 A11 B = 11 + A 12 B 21 A 11 B 12 + A 12 B 22 C 21 C 22 A 21 B 11 + A 22 B 21 A 21 B 12 + A 22 B 22 ]. One matrix multiplication A B on an n-by-n matrix is replaced by 8 matrix multiplications on n/2-by-n/2 matrices, and 4 additions of n/2-by-n/2 matrices. Computer Algorithms I (CS 401/MCS 401) Fast Convolution; Strassen s Method L-9 9 July / 40

24 setting up the recurrence Let T (n) be the time to multiply two n-by-n matrices. The base case for the recursion is n = 1: c 11 = a 11 b 11, which runs in Θ(1), constant time. For n > 1: [ C11 C 12 C 21 C 22 ] [ A11 B = 11 + A 12 B 21 A 11 B 12 + A 12 B 22 A 21 B 11 + A 22 B 21 A 21 B 12 + A 22 B 22 ]. The addition of two matrices of dimension n costs Θ(n 2 ). Thus, we have the recurrence: T (n) = 8T (n/2) + Θ(n 2 ), for n > 1. Computer Algorithms I (CS 401/MCS 401) Fast Convolution; Strassen s Method L-9 9 July / 40

25 Fast Convolution; Strassen s Method 1 Fast Convolution reduction to subquadratic time polynomial evaluation at complex roots of unity interpolation via evaluation at complex roots of unity 2 The Master Method to Solve Recurrences a recursive matrix-matrix multiplication the master method 3 Strassen s method the steps in the method reduction to subcubic time Computer Algorithms I (CS 401/MCS 401) Fast Convolution; Strassen s Method L-9 9 July / 40

26 Theorem (the master theorem) The recurrence relation T (n) = at (n/b) + f (n), a 1, b > 1, some function f has the following bounds: 1 If f (n) is O(n log b (a) ɛ ) for some constant ɛ > 0, then T (n) is Θ(n log b (a) ). 2 If f (n) is Θ(n log b (a) ), then T (n) is Θ(n log b (a) log 2 (n)). 3 If f (n) is Ω(n log b (a)+ɛ ), for some constant ɛ > 0, and a f (n/b) c f (n), for some constant c < 1 and n N, then T (n) is Θ(f (n)). Computer Algorithms I (CS 401/MCS 401) Fast Convolution; Strassen s Method L-9 9 July / 40

27 interpretation of the theorem Recall: the recurrence T (n) = at (n/b) + f (n) defines a tree of depth log b (n) with L = n log b (a) leaves. Three cases: 1 f grows no faster than L: f is O(n log b (a) ) 2 f grows at the same rate as L: f is Θ(n log b (a) ) 3 f grows at least as fast as L: f is Ω(n log b (a) ) Relating f (n) to L, we find that T (n) depends on L. Second case: f is Θ(L) T (n) is Θ(L log 2 (n)). Note: depth log b (n) = log 2 (n)/ log 2 (b) is Θ(log 2 (n)). Computer Algorithms I (CS 401/MCS 401) Fast Convolution; Strassen s Method L-9 9 July / 40

28 an illustration: merge sort The merge sort algorithm has a recurrence T (n) = 2T (n/2) + Θ(n), where a = 2, b = 2, and f (n) = Θ(n). The number of leaves: L = n log b (a) = n log 2 (2) = n, so case 2 of the theorem applies: 2 If f (n) is Θ(n log b (a) ), then T (n) is Θ(n log b (a) log 2 (n)). Therefore: T (n) is O(n log 2 (n)). Computer Algorithms I (CS 401/MCS 401) Fast Convolution; Strassen s Method L-9 9 July / 40

29 applied to recursive matrix-matrix multiplication The recursive matrix-matrix multiplication has the recurrence T (n) = 8T (n/2) + Θ(n 2 ), where a = 8, b = 2, and f (n) = Θ(n 2 ). Compute n log b (a) = n log 2 (8) = n 3, so case 1 of the theorem applies: 1 If f (n) is O(n log b (a) ɛ ) for some constant ɛ > 0, then T (n) is Θ(n log b (a) ). Take ɛ = 1. Therefore: T (n) is O(n 3 ). Computer Algorithms I (CS 401/MCS 401) Fast Convolution; Strassen s Method L-9 9 July / 40

30 applying the master method Exercise 4: Use the master method to give a tight asymptotic bound on the recurrence T (n) = 2T (n/4) + n. Computer Algorithms I (CS 401/MCS 401) Fast Convolution; Strassen s Method L-9 9 July / 40

31 Fast Convolution; Strassen s Method 1 Fast Convolution reduction to subquadratic time polynomial evaluation at complex roots of unity interpolation via evaluation at complex roots of unity 2 The Master Method to Solve Recurrences a recursive matrix-matrix multiplication the master method 3 Strassen s method the steps in the method reduction to subcubic time Computer Algorithms I (CS 401/MCS 401) Fast Convolution; Strassen s Method L-9 9 July / 40

32 steps 1 and 2 of Strassen s method Given are two n-by-n matrices A and B, we want to compute their product C = A B. 1 Partition each matrix into four n/2-by-n/2-matrices: ] [ C11 C, C = 12 C 21 C 22 [ A11 A A = 12 A 21 A 22 ] [ B11 B, B = 12 B 21 B 22 2 Make the following 10 matrices S 1 = B 12 B 22, S 2 = A 11 + A 12, S 3 = A 21 + A 22, S 4 = B 21 B 11, S 5 = A 11 + A 22, S 6 = B 11 + B 22, S 7 = A 12 A 22, S 8 = B 21 + B 22, S 9 = A 11 A 21, S 10 = B 11 + B 12. This steps takes Θ(n 2 ) time. ]. Computer Algorithms I (CS 401/MCS 401) Fast Convolution; Strassen s Method L-9 9 July / 40

33 steps 3 and 4 of Strassen s method 3 Multiply seven times n/2-by-n/2 matrices: P 1 = A 11 S 1 = A 11 B 12 A 11 B 22, P 2 = S 2 B 22 = A 11 B 22 + A 12 B 22, P 3 = S 3 B 11 = A 21 B 11 + A 22 B 11, P 4 = A 22 S 4 = A 22 B 21 A 22 B 11, P 5 = S 5 S 6 = A 11 B 11 + A 11 B 22 + A 22 B 11 + A 22 B 22, P 6 = S 7 S 8 = A 12 B 21 + A 12 B 22 A 22 B 21 A 22 B 22, P 7 = S 9 S 10 = A 11 B 11 + A 11 B 12 A 12 B 11 A 21 B Construct the matrices in the product C: C 11 = P 5 + P 4 P 2 + P 6, C 12 = P 1 + P 2, C 21 = P 3 + P 4, C 22 = P 5 + P 1 P 3 P 7. Computer Algorithms I (CS 401/MCS 401) Fast Convolution; Strassen s Method L-9 9 July / 40

34 verifying correctness for C 12 Strassen s method defines C 12 = P 1 + P 2, with With direct verication: P 1 = A 11 S 1 = A 11 B 12 A 11 B 22, P 2 = S 2 B 22 = A 11 B 22 + A 12 B 22, A 11 B 12 A 11 B 22 + A 11 B 22 + A 12 B 22 A 11 B 12 + A 12 B 22 Indeed, we computed earlier: C 12 = A 11 B 12 + A 12 B 22. Computer Algorithms I (CS 401/MCS 401) Fast Convolution; Strassen s Method L-9 9 July / 40

35 verifying correctness for C 21 Strassen s method defines C 21 = P 3 + P 4, with With direct verification: P 3 = S 3 B 11 = A 21 B 11 + A 22 B 11, P 4 = A 22 S 4 = A 22 B 21 A 22 B 11, A 21 B 11 + A 22 B 11 + A 22 B 11 + A 22 B 21 A 21 B 11 + A 22 B 21 Indeed, we computed earlier: C 21 = A 21 B 11 + A 22 B 21. Computer Algorithms I (CS 401/MCS 401) Fast Convolution; Strassen s Method L-9 9 July / 40

36 verifying correctness for C 11 Strassen s method defines C 11 = P 5 + P 4 P 2 + P 6, with P 5 = A 11 B 11 + A 11 B 22 + A 22 B 11 + A 22 B 22, P 4 = A 22 B 21 A 22 B 11, P 2 = A 11 B 22 + A 12 B 22, P 6 = A 12 B 21 + A 12 B 22 A 22 B 21 A 22 B 22. With direct verification: A 11 B 11 +A 11 B 22 +A 22 B 11 +A 22 B 22 A 22 B 11 +A 22 B 21 A 11 B 22 +A 12 B 22 + A 22 B 22 A 22 B 21 +A 12 B 22 +A 12 B 21 A 11 B 11 +A 12 B 21 Indeed, we computed earlier: C 11 = A 11 B 11 + A 12 B 21. Computer Algorithms I (CS 401/MCS 401) Fast Convolution; Strassen s Method L-9 9 July / 40

37 verifying correctness for C 22 Strassen s method defines C 22 = P 5 + P 1 P 3 P 7, with P 5 = A 11 B 11 + A 11 B 22 + A 22 B 11 + A 22 B 22, P 1 = A 11 B 12 A 11 B 22, P 3 = A 21 B 11 + A 22 B 11, P 7 = A 11 B 11 + A 11 B 12 A 12 B 11 A 21 B 12. With direct verification: A 11 B 11 +A 11 B 22 +A 22 B 11 +A 22 B 22 A 11 B 22 +A 11 B 12 A 22 B 11 A 21 B 11 + A 11 B 11 A 11 B 12 +A 21 B 11 +A 21 B 12 A 22 B 22 +A 21 B 12 Indeed, we computed earlier: C 22 = A 21 B 12 + A 22 B 22. Computer Algorithms I (CS 401/MCS 401) Fast Convolution; Strassen s Method L-9 9 July / 40

38 Fast Convolution; Strassen s Method 1 Fast Convolution reduction to subquadratic time polynomial evaluation at complex roots of unity interpolation via evaluation at complex roots of unity 2 The Master Method to Solve Recurrences a recursive matrix-matrix multiplication the master method 3 Strassen s method the steps in the method reduction to subcubic time Computer Algorithms I (CS 401/MCS 401) Fast Convolution; Strassen s Method L-9 9 July / 40

39 reduction to subcubic time Let T (n) be the time of Strassen s method. We have the recurrence { θ(1) if n = 1, T (n) = 7T (n/2) + θ(n 2 ) if n > 1. where a = 7, b = 2, and f (n) = Θ(n 2 ). Compute n log b (a) = n log 2 (7), so case 1 of the theorem applies: 1 If f (n) is O(n log b (a) ɛ ) for some constant ɛ > 0, then T (n) is Θ(n log b (a) ). Take ɛ = 0.80, as log 2 (7) Therefore: T (n) is O(n log 2 (7) ) = Θ(n ). Computer Algorithms I (CS 401/MCS 401) Fast Convolution; Strassen s Method L-9 9 July / 40

40 exercises Homework collection on Friday 13 July 2018, at 10AM: 1 Exercise 1 on slide #10 of lecture 7. 2 Exercise 2 on slide #2 of lecture 7. 3 Exercise 1 on slide #9 of lecture 8. 4 Exercise 2 on slide #16 of lecture 8. 5 Exercise 3 on slide #16 of lecture 8. 6 Exercise 4 on slide #28 of lecture 8. 7 Exercise 1 on slide #5 of lecture 9. 8 Exercise 2 on slide #8 of lecture 9. 9 Exercise 3 on slide #20 of lecture Exercise 4 on slide #29 of lecture 9. Computer Algorithms I (CS 401/MCS 401) Fast Convolution; Strassen s Method L-9 9 July / 40

Divide and Conquer algorithms

Divide and Conquer algorithms Divide and Conquer algorithms Another general method for constructing algorithms is given by the Divide and Conquer strategy. We assume that we have a problem with input that can be split into parts in

More information

CS483 Design and Analysis of Algorithms

CS483 Design and Analysis of Algorithms CS483 Design and Analysis of Algorithms Lecture 6-8 Divide and Conquer Algorithms Instructor: Fei Li lifei@cs.gmu.edu with subject: CS483 Office hours: STII, Room 443, Friday 4:00pm - 6:00pm or by appointments

More information

CSE 421 Algorithms. T(n) = at(n/b) + n c. Closest Pair Problem. Divide and Conquer Algorithms. What you really need to know about recurrences

CSE 421 Algorithms. T(n) = at(n/b) + n c. Closest Pair Problem. Divide and Conquer Algorithms. What you really need to know about recurrences CSE 421 Algorithms Richard Anderson Lecture 13 Divide and Conquer What you really need to know about recurrences Work per level changes geometrically with the level Geometrically increasing (x > 1) The

More information

FFT: Fast Polynomial Multiplications

FFT: Fast Polynomial Multiplications FFT: Fast Polynomial Multiplications Jie Wang University of Massachusetts Lowell Department of Computer Science J. Wang (UMass Lowell) FFT: Fast Polynomial Multiplications 1 / 20 Overview So far we have

More information

Divide and Conquer. Arash Rafiey. 27 October, 2016

Divide and Conquer. Arash Rafiey. 27 October, 2016 27 October, 2016 Divide the problem into a number of subproblems Divide the problem into a number of subproblems Conquer the subproblems by solving them recursively or if they are small, there must be

More information

Chapter 5 Divide and Conquer

Chapter 5 Divide and Conquer CMPT 705: Design and Analysis of Algorithms Spring 008 Chapter 5 Divide and Conquer Lecturer: Binay Bhattacharya Scribe: Chris Nell 5.1 Introduction Given a problem P with input size n, P (n), we define

More information

CS 577 Introduction to Algorithms: Strassen s Algorithm and the Master Theorem

CS 577 Introduction to Algorithms: Strassen s Algorithm and the Master Theorem CS 577 Introduction to Algorithms: Jin-Yi Cai University of Wisconsin Madison In the last class, we described InsertionSort and showed that its worst-case running time is Θ(n 2 ). Check Figure 2.2 for

More information

Divide and Conquer: Polynomial Multiplication Version of October 1 / 7, 24201

Divide and Conquer: Polynomial Multiplication Version of October 1 / 7, 24201 Divide and Conquer: Polynomial Multiplication Version of October 7, 2014 Divide and Conquer: Polynomial Multiplication Version of October 1 / 7, 24201 Outline Outline: Introduction The polynomial multiplication

More information

Recurrence Relations

Recurrence Relations Recurrence Relations Analysis Tools S.V. N. (vishy) Vishwanathan University of California, Santa Cruz vishy@ucsc.edu January 15, 2016 S.V. N. Vishwanathan (UCSC) CMPS101 1 / 29 Recurrences Outline 1 Recurrences

More information

Introduction to Algorithms 6.046J/18.401J/SMA5503

Introduction to Algorithms 6.046J/18.401J/SMA5503 Introduction to Algorithms 6.046J/8.40J/SMA5503 Lecture 3 Prof. Piotr Indyk The divide-and-conquer design paradigm. Divide the problem (instance) into subproblems. 2. Conquer the subproblems by solving

More information

Chapter 1 Divide and Conquer Polynomial Multiplication Algorithm Theory WS 2015/16 Fabian Kuhn

Chapter 1 Divide and Conquer Polynomial Multiplication Algorithm Theory WS 2015/16 Fabian Kuhn Chapter 1 Divide and Conquer Polynomial Multiplication Algorithm Theory WS 2015/16 Fabian Kuhn Formulation of the D&C principle Divide-and-conquer method for solving a problem instance of size n: 1. Divide

More information

CSE 548: Analysis of Algorithms. Lecture 4 ( Divide-and-Conquer Algorithms: Polynomial Multiplication )

CSE 548: Analysis of Algorithms. Lecture 4 ( Divide-and-Conquer Algorithms: Polynomial Multiplication ) CSE 548: Analysis of Algorithms Lecture 4 ( Divide-and-Conquer Algorithms: Polynomial Multiplication ) Rezaul A. Chowdhury Department of Computer Science SUNY Stony Brook Spring 2015 Coefficient Representation

More information

Multiplying huge integers using Fourier transforms

Multiplying huge integers using Fourier transforms Fourier transforms October 25, 2007 820348901038490238478324 1739423249728934932894??? integers occurs in many fields of Computational Science: Cryptography Number theory... Traditional approaches to

More information

1 Substitution method

1 Substitution method Recurrence Relations we have discussed asymptotic analysis of algorithms and various properties associated with asymptotic notation. As many algorithms are recursive in nature, it is natural to analyze

More information

Divide and Conquer. Maximum/minimum. Median finding. CS125 Lecture 4 Fall 2016

Divide and Conquer. Maximum/minimum. Median finding. CS125 Lecture 4 Fall 2016 CS125 Lecture 4 Fall 2016 Divide and Conquer We have seen one general paradigm for finding algorithms: the greedy approach. We now consider another general paradigm, known as divide and conquer. We have

More information

Grade 11/12 Math Circles Fall Nov. 5 Recurrences, Part 2

Grade 11/12 Math Circles Fall Nov. 5 Recurrences, Part 2 1 Faculty of Mathematics Waterloo, Ontario Centre for Education in Mathematics and Computing Grade 11/12 Math Circles Fall 2014 - Nov. 5 Recurrences, Part 2 Running time of algorithms In computer science,

More information

COMP Analysis of Algorithms & Data Structures

COMP Analysis of Algorithms & Data Structures COMP 3170 - Analysis of Algorithms & Data Structures Shahin Kamali Lecture 5 - Jan. 12, 2018 CLRS 1.1, 1.2, 2.2, 3.1, 4.3, 4.5 University of Manitoba Picture is from the cover of the textbook CLRS. 1 /

More information

Chapter 1 Divide and Conquer Algorithm Theory WS 2016/17 Fabian Kuhn

Chapter 1 Divide and Conquer Algorithm Theory WS 2016/17 Fabian Kuhn Chapter 1 Divide and Conquer Algorithm Theory WS 2016/17 Fabian Kuhn Formulation of the D&C principle Divide-and-conquer method for solving a problem instance of size n: 1. Divide n c: Solve the problem

More information

CS483 Design and Analysis of Algorithms

CS483 Design and Analysis of Algorithms CS483 Design and Analysis of Algorithms Chapter 2 Divide and Conquer Algorithms Instructor: Fei Li lifei@cs.gmu.edu with subject: CS483 Office hours: Room 5326, Engineering Building, Thursday 4:30pm -

More information

Fast Fourier Transform

Fast Fourier Transform Why Fourier Transform? Fast Fourier Transform Jordi Cortadella and Jordi Petit Department of Computer Science Polynomials: coefficient representation Divide & Conquer Dept. CS, UPC Polynomials: point-value

More information

CMPSCI611: Three Divide-and-Conquer Examples Lecture 2

CMPSCI611: Three Divide-and-Conquer Examples Lecture 2 CMPSCI611: Three Divide-and-Conquer Examples Lecture 2 Last lecture we presented and analyzed Mergesort, a simple divide-and-conquer algorithm. We then stated and proved the Master Theorem, which gives

More information

CMPS 2200 Fall Divide-and-Conquer. Carola Wenk. Slides courtesy of Charles Leiserson with changes and additions by Carola Wenk

CMPS 2200 Fall Divide-and-Conquer. Carola Wenk. Slides courtesy of Charles Leiserson with changes and additions by Carola Wenk CMPS 2200 Fall 2017 Divide-and-Conquer Carola Wenk Slides courtesy of Charles Leiserson with changes and additions by Carola Wenk 1 The divide-and-conquer design paradigm 1. Divide the problem (instance)

More information

Data Structures and Algorithms CMPSC 465

Data Structures and Algorithms CMPSC 465 Data Structures and Algorithms CMPSC 465 LECTURE 9 Solving recurrences Substitution method Adam Smith S. Raskhodnikova and A. Smith; based on slides by E. Demaine and C. Leiserson Review question Draw

More information

Solving recurrences. Frequently showing up when analysing divide&conquer algorithms or, more generally, recursive algorithms.

Solving recurrences. Frequently showing up when analysing divide&conquer algorithms or, more generally, recursive algorithms. Solving recurrences Frequently showing up when analysing divide&conquer algorithms or, more generally, recursive algorithms Example: Merge-Sort(A, p, r) 1: if p < r then 2: q (p + r)/2 3: Merge-Sort(A,

More information

The Divide-and-Conquer Design Paradigm

The Divide-and-Conquer Design Paradigm CS473- Algorithms I Lecture 4 The Divide-and-Conquer Design Paradigm CS473 Lecture 4 1 The Divide-and-Conquer Design Paradigm 1. Divide the problem (instance) into subproblems. 2. Conquer the subproblems

More information

Algorithm efficiency analysis

Algorithm efficiency analysis Algorithm efficiency analysis Mădălina Răschip, Cristian Gaţu Faculty of Computer Science Alexandru Ioan Cuza University of Iaşi, Romania DS 2017/2018 Content Algorithm efficiency analysis Recursive function

More information

Integer multiplication with generalized Fermat primes

Integer multiplication with generalized Fermat primes Integer multiplication with generalized Fermat primes CARAMEL Team, LORIA, University of Lorraine Supervised by: Emmanuel Thomé and Jérémie Detrey Journées nationales du Calcul Formel 2015 (Cluny) November

More information

Analysis of Algorithms I: Asymptotic Notation, Induction, and MergeSort

Analysis of Algorithms I: Asymptotic Notation, Induction, and MergeSort Analysis of Algorithms I: Asymptotic Notation, Induction, and MergeSort Xi Chen Columbia University We continue with two more asymptotic notation: o( ) and ω( ). Let f (n) and g(n) are functions that map

More information

CSCI Honor seminar in algorithms Homework 2 Solution

CSCI Honor seminar in algorithms Homework 2 Solution CSCI 493.55 Honor seminar in algorithms Homework 2 Solution Saad Mneimneh Visiting Professor Hunter College of CUNY Problem 1: Rabin-Karp string matching Consider a binary string s of length n and another

More information

Homework 1 Solutions

Homework 1 Solutions CS3510 Design & Analysis of Algorithms Section A Homework 1 Solutions Released 4pm Friday Sep 8, 2017 This homework has a total of 4 problems on 4 pages. Solutions should be submitted to GradeScope before

More information

Algorithms and Data Structures Strassen s Algorithm. ADS (2017/18) Lecture 4 slide 1

Algorithms and Data Structures Strassen s Algorithm. ADS (2017/18) Lecture 4 slide 1 Algorithms and Data Structures Strassen s Algorithm ADS (2017/18) Lecture 4 slide 1 Tutorials Start in week (week 3) Tutorial allocations are linked from the course webpage http://www.inf.ed.ac.uk/teaching/courses/ads/

More information

The Fast Fourier Transform. Andreas Klappenecker

The Fast Fourier Transform. Andreas Klappenecker The Fast Fourier Transform Andreas Klappenecker Motivation There are few algorithms that had more impact on modern society than the fast Fourier transform and its relatives. The applications of the fast

More information

Divide-and-conquer: Order Statistics. Curs: Fall 2017

Divide-and-conquer: Order Statistics. Curs: Fall 2017 Divide-and-conquer: Order Statistics Curs: Fall 2017 The divide-and-conquer strategy. 1. Break the problem into smaller subproblems, 2. recursively solve each problem, 3. appropriately combine their answers.

More information

Chapter 4 Divide-and-Conquer

Chapter 4 Divide-and-Conquer Chapter 4 Divide-and-Conquer 1 About this lecture (1) Recall the divide-and-conquer paradigm, which we used for merge sort: Divide the problem into a number of subproblems that are smaller instances of

More information

5.6 Convolution and FFT

5.6 Convolution and FFT 5.6 Convolution and FFT Fast Fourier Transform: Applications Applications. Optics, acoustics, quantum physics, telecommunications, control systems, signal processing, speech recognition, data compression,

More information

Algorithm Design and Analysis

Algorithm Design and Analysis Algorithm Design and Analysis LECTURE 14 Divide and Conquer Fast Fourier Transform Sofya Raskhodnikova 10/7/2016 S. Raskhodnikova; based on slides by K. Wayne. 5.6 Convolution and FFT Fast Fourier Transform:

More information

Algorithms and data structures

Algorithms and data structures Algorithms and data structures Amin Coja-Oghlan LFCS Complex numbers Roots of polynomials A polynomial of degree d is a function of the form p(x) = d a i x i with a d 0. i=0 There are at most d numbers

More information

Speedy Maths. David McQuillan

Speedy Maths. David McQuillan Speedy Maths David McQuillan Basic Arithmetic What one needs to be able to do Addition and Subtraction Multiplication and Division Comparison For a number of order 2 n n ~ 100 is general multi precision

More information

Design and Analysis of Algorithms

Design and Analysis of Algorithms Design and Analysis of Algorithms CSE 5311 Lecture 5 Divide and Conquer: Fast Fourier Transform Junzhou Huang, Ph.D. Department of Computer Science and Engineering CSE5311 Design and Analysis of Algorithms

More information

DIVIDE AND CONQUER II

DIVIDE AND CONQUER II DIVIDE AND CONQUER II master theorem integer multiplication matrix multiplication convolution and FFT Lecture slides by Kevin Wayne Copyright 2005 Pearson-Addison Wesley http://www.cs.princeton.edu/~wayne/kleinberg-tardos

More information

Tutorials. Algorithms and Data Structures Strassen s Algorithm. The Master Theorem for solving recurrences. The Master Theorem (cont d)

Tutorials. Algorithms and Data Structures Strassen s Algorithm. The Master Theorem for solving recurrences. The Master Theorem (cont d) DS 2018/19 Lecture 4 slide 3 DS 2018/19 Lecture 4 slide 4 Tutorials lgorithms and Data Structures Strassen s lgorithm Start in week week 3 Tutorial allocations are linked from the course webpage http://www.inf.ed.ac.uk/teaching/courses/ads/

More information

Asymptotic Analysis and Recurrences

Asymptotic Analysis and Recurrences Appendix A Asymptotic Analysis and Recurrences A.1 Overview We discuss the notion of asymptotic analysis and introduce O, Ω, Θ, and o notation. We then turn to the topic of recurrences, discussing several

More information

The Fast Fourier Transform: A Brief Overview. with Applications. Petros Kondylis. Petros Kondylis. December 4, 2014

The Fast Fourier Transform: A Brief Overview. with Applications. Petros Kondylis. Petros Kondylis. December 4, 2014 December 4, 2014 Timeline Researcher Date Length of Sequence Application CF Gauss 1805 Any Composite Integer Interpolation of orbits of celestial bodies F Carlini 1828 12 Harmonic Analysis of Barometric

More information

Divide-and-conquer algorithm

Divide-and-conquer algorithm Divide-and-conquer algorithm IDEA: n n matrix = 2 2 matrix of (n/2) (n/2) submatrices: r=ae+bg s=af+bh t =ce+dh u=cf+dg r t s u = a c e g September 15, 2004 Introduction to Algorithms L3.31 b d C = A B

More information

The Master Theorem for solving recurrences. Algorithms and Data Structures Strassen s Algorithm. Tutorials. The Master Theorem (cont d)

The Master Theorem for solving recurrences. Algorithms and Data Structures Strassen s Algorithm. Tutorials. The Master Theorem (cont d) The Master Theorem for solving recurrences lgorithms and Data Structures Strassen s lgorithm 23rd September, 2014 Theorem Let n 0 N, k N 0 and a, b R with a > 0 and b > 1, and let T : N R satisfy the following

More information

A SUMMARY OF RECURSION SOLVING TECHNIQUES

A SUMMARY OF RECURSION SOLVING TECHNIQUES A SUMMARY OF RECURSION SOLVING TECHNIQUES KIMMO ERIKSSON, KTH These notes are meant to be a complement to the material on recursion solving techniques in the textbook Discrete Mathematics by Biggs. In

More information

CSE548, AMS542: Analysis of Algorithms, Fall 2017 Date: October 11. In-Class Midterm. ( 7:05 PM 8:20 PM : 75 Minutes )

CSE548, AMS542: Analysis of Algorithms, Fall 2017 Date: October 11. In-Class Midterm. ( 7:05 PM 8:20 PM : 75 Minutes ) CSE548, AMS542: Analysis of Algorithms, Fall 2017 Date: October 11 In-Class Midterm ( 7:05 PM 8:20 PM : 75 Minutes ) This exam will account for either 15% or 30% of your overall grade depending on your

More information

Find an Element x in an Unsorted Array

Find an Element x in an Unsorted Array Find an Element x in an Unsorted Array What if we try to find a lower bound for the case where the array is not necessarily sorted? J.-L. De Carufel (U. of O.) Design & Analysis of Algorithms Fall 2017

More information

Mid-term Exam Answers and Final Exam Study Guide CIS 675 Summer 2010

Mid-term Exam Answers and Final Exam Study Guide CIS 675 Summer 2010 Mid-term Exam Answers and Final Exam Study Guide CIS 675 Summer 2010 Midterm Problem 1: Recall that for two functions g : N N + and h : N N +, h = Θ(g) iff for some positive integer N and positive real

More information

What we have learned What is algorithm Why study algorithm The time and space efficiency of algorithm The analysis framework of time efficiency Asympt

What we have learned What is algorithm Why study algorithm The time and space efficiency of algorithm The analysis framework of time efficiency Asympt Lecture 3 The Analysis of Recursive Algorithm Efficiency What we have learned What is algorithm Why study algorithm The time and space efficiency of algorithm The analysis framework of time efficiency

More information

Divide and conquer. Philip II of Macedon

Divide and conquer. Philip II of Macedon Divide and conquer Philip II of Macedon Divide and conquer 1) Divide your problem into subproblems 2) Solve the subproblems recursively, that is, run the same algorithm on the subproblems (when the subproblems

More information

Cubic Splines; Bézier Curves

Cubic Splines; Bézier Curves Cubic Splines; Bézier Curves 1 Cubic Splines piecewise approximation with cubic polynomials conditions on the coefficients of the splines 2 Bézier Curves computer-aided design and manufacturing MCS 471

More information

Class Note #14. In this class, we studied an algorithm for integer multiplication, which. 2 ) to θ(n

Class Note #14. In this class, we studied an algorithm for integer multiplication, which. 2 ) to θ(n Class Note #14 Date: 03/01/2006 [Overall Information] In this class, we studied an algorithm for integer multiplication, which improved the running time from θ(n 2 ) to θ(n 1.59 ). We then used some of

More information

COMP 382: Reasoning about algorithms

COMP 382: Reasoning about algorithms Fall 2014 Unit 4: Basics of complexity analysis Correctness and efficiency So far, we have talked about correctness and termination of algorithms What about efficiency? Running time of an algorithm For

More information

The divide-and-conquer strategy solves a problem by: 1. Breaking it into subproblems that are themselves smaller instances of the same type of problem

The divide-and-conquer strategy solves a problem by: 1. Breaking it into subproblems that are themselves smaller instances of the same type of problem Chapter 2. Divide-and-conquer algorithms The divide-and-conquer strategy solves a problem by: 1. Breaking it into subproblems that are themselves smaller instances of the same type of problem. 2. Recursively

More information

Analysis of Multithreaded Algorithms

Analysis of Multithreaded Algorithms Analysis of Multithreaded Algorithms Marc Moreno Maza University of Western Ontario, London, Ontario (Canada) CS 4435 - CS 9624 (Moreno Maza) Analysis of Multithreaded Algorithms CS 4435 - CS 9624 1 /

More information

Divide and Conquer Strategy

Divide and Conquer Strategy Divide and Conquer Strategy Algorithm design is more an art, less so a science. There are a few useful strategies, but no guarantee to succeed. We will discuss: Divide and Conquer, Greedy, Dynamic Programming.

More information

CSCI 3110 Assignment 6 Solutions

CSCI 3110 Assignment 6 Solutions CSCI 3110 Assignment 6 Solutions December 5, 2012 2.4 (4 pts) Suppose you are choosing between the following three algorithms: 1. Algorithm A solves problems by dividing them into five subproblems of half

More information

CSE 613: Parallel Programming. Lectures ( Analyzing Divide-and-Conquer Algorithms )

CSE 613: Parallel Programming. Lectures ( Analyzing Divide-and-Conquer Algorithms ) CSE 613: Parallel Programming Lectures 13 14 ( Analyzing Divide-and-Conquer Algorithms ) Rezaul A. Chowdhury Department of Computer Science SUNY Stony Brook Spring 2015 A Useful Recurrence Consider the

More information

Taking Stock. IE170: Algorithms in Systems Engineering: Lecture 3. Θ Notation. Comparing Algorithms

Taking Stock. IE170: Algorithms in Systems Engineering: Lecture 3. Θ Notation. Comparing Algorithms Taking Stock IE170: Algorithms in Systems Engineering: Lecture 3 Jeff Linderoth Department of Industrial and Systems Engineering Lehigh University January 19, 2007 Last Time Lots of funky math Playing

More information

Algorithm Analysis Recurrence Relation. Chung-Ang University, Jaesung Lee

Algorithm Analysis Recurrence Relation. Chung-Ang University, Jaesung Lee Algorithm Analysis Recurrence Relation Chung-Ang University, Jaesung Lee Recursion 2 Recursion 3 Recursion in Real-world Fibonacci sequence = + Initial conditions: = 0 and = 1. = + = + = + 0, 1, 1, 2,

More information

CS 470/570 Divide-and-Conquer. Format of Divide-and-Conquer algorithms: Master Recurrence Theorem (simpler version)

CS 470/570 Divide-and-Conquer. Format of Divide-and-Conquer algorithms: Master Recurrence Theorem (simpler version) CS 470/570 Divide-and-Conquer Format of Divide-and-Conquer algorithms: Divide: Split the array or list into smaller pieces Conquer: Solve the same problem recursively on smaller pieces Combine: Build the

More information

Data Structures and Algorithms CSE 465

Data Structures and Algorithms CSE 465 Data Structures and Algorithms CSE 465 LECTURE 3 Asymptotic Notation O-, Ω-, Θ-, o-, ω-notation Divide and Conquer Merge Sort Binary Search Sofya Raskhodnikova and Adam Smith /5/0 Review Questions If input

More information

COE428 Notes Week 4 (Week of Jan 30, 2017)

COE428 Notes Week 4 (Week of Jan 30, 2017) COE428 Lecture Notes: Week 4 1 of 9 COE428 Notes Week 4 (Week of Jan 30, 2017) Table of Contents Announcements...2 Answers to last week's questions...2 Review...3 Big-O, Big-Omega and Big-Theta analysis

More information

Chapter 2. Recurrence Relations. Divide and Conquer. Divide and Conquer Strategy. Another Example: Merge Sort. Merge Sort Example. Merge Sort Example

Chapter 2. Recurrence Relations. Divide and Conquer. Divide and Conquer Strategy. Another Example: Merge Sort. Merge Sort Example. Merge Sort Example Recurrence Relations Chapter 2 Divide and Conquer Equation or an inequality that describes a function by its values on smaller inputs. Recurrence relations arise when we analyze the running time of iterative

More information

data structures and algorithms lecture 2

data structures and algorithms lecture 2 data structures and algorithms 2018 09 06 lecture 2 recall: insertion sort Algorithm insertionsort(a, n): for j := 2 to n do key := A[j] i := j 1 while i 1 and A[i] > key do A[i + 1] := A[i] i := i 1 A[i

More information

CS 231: Algorithmic Problem Solving

CS 231: Algorithmic Problem Solving CS 231: Algorithmic Problem Solving Naomi Nishimura Module 4 Date of this version: June 11, 2018 WARNING: Drafts of slides are made available prior to lecture for your convenience. After lecture, slides

More information

Legendre s Equation. PHYS Southern Illinois University. October 18, 2016

Legendre s Equation. PHYS Southern Illinois University. October 18, 2016 Legendre s Equation PHYS 500 - Southern Illinois University October 18, 2016 PHYS 500 - Southern Illinois University Legendre s Equation October 18, 2016 1 / 11 Legendre s Equation Recall We are trying

More information

CS 4407 Algorithms Lecture 2: Iterative and Divide and Conquer Algorithms

CS 4407 Algorithms Lecture 2: Iterative and Divide and Conquer Algorithms CS 4407 Algorithms Lecture 2: Iterative and Divide and Conquer Algorithms Prof. Gregory Provan Department of Computer Science University College Cork 1 Lecture Outline CS 4407, Algorithms Growth Functions

More information

Divide & Conquer. CS 320, Fall Dr. Geri Georg, Instructor CS320 Div&Conq 1

Divide & Conquer. CS 320, Fall Dr. Geri Georg, Instructor CS320 Div&Conq 1 Divide & Conquer CS 320, Fall 2017 Dr. Geri Georg, Instructor georg@colostate.edu CS320 Div&Conq 1 Strategy 1. Divide the problem up into equal sized sub problems 2. Solve the sub problems recursively

More information

Divide and Conquer. Andreas Klappenecker. [based on slides by Prof. Welch]

Divide and Conquer. Andreas Klappenecker. [based on slides by Prof. Welch] Divide and Conquer Andreas Klappenecker [based on slides by Prof. Welch] Divide and Conquer Paradigm An important general technique for designing algorithms: divide problem into subproblems recursively

More information

Recursion. Algorithms and Data Structures. (c) Marcin Sydow. Introduction. Linear 2nd-order Equations. Important 3 Cases. Quicksort Average Complexity

Recursion. Algorithms and Data Structures. (c) Marcin Sydow. Introduction. Linear 2nd-order Equations. Important 3 Cases. Quicksort Average Complexity Recursion Topics covered by this lecture: Recursion: Fibonacci numbers, Hanoi Towers,... cases of recursive equations (with proofs) QuickSort (Proof) Recursion e.g.: n! = (n 1)!n Mathematics: recurrent

More information

Analysis of Algorithms - Using Asymptotic Bounds -

Analysis of Algorithms - Using Asymptotic Bounds - Analysis of Algorithms - Using Asymptotic Bounds - Andreas Ermedahl MRTC (Mälardalens Real-Time Research Center) andreas.ermedahl@mdh.se Autumn 004 Rehersal: Asymptotic bounds Gives running time bounds

More information

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Asymptotic Analysis, recurrences Date: 9/7/17

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Asymptotic Analysis, recurrences Date: 9/7/17 601.433/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Asymptotic Analysis, recurrences Date: 9/7/17 2.1 Notes Homework 1 will be released today, and is due a week from today by the beginning

More information

CS711008Z Algorithm Design and Analysis

CS711008Z Algorithm Design and Analysis CS711008Z Algorithm Design and Analysis Lecture 5 FFT and Divide and Conquer Dongbo Bu Institute of Computing Technology Chinese Academy of Sciences, Beijing, China 1 / 56 Outline DFT: evaluate a polynomial

More information

Problem Set 1 Solutions

Problem Set 1 Solutions Introduction to Algorithms September 24, 2004 Massachusetts Institute of Technology 6.046J/18.410J Professors Piotr Indyk and Charles E. Leiserson Handout 7 Problem Set 1 Solutions Exercise 1-1. Do Exercise

More information

Divide-and-Conquer. Reading: CLRS Sections 2.3, 4.1, 4.2, 4.3, 28.2, CSE 6331 Algorithms Steve Lai

Divide-and-Conquer. Reading: CLRS Sections 2.3, 4.1, 4.2, 4.3, 28.2, CSE 6331 Algorithms Steve Lai Divide-and-Conquer Reading: CLRS Sections 2.3, 4.1, 4.2, 4.3, 28.2, 33.4. CSE 6331 Algorithms Steve Lai Divide and Conquer Given an instance x of a prolem, the method works as follows: divide-and-conquer

More information

Design and Analysis of Algorithms

Design and Analysis of Algorithms CSE 101, Winter 2018 Design and Analysis of Algorithms Lecture 4: Divide and Conquer (I) Class URL: http://vlsicad.ucsd.edu/courses/cse101-w18/ Divide and Conquer ( DQ ) First paradigm or framework DQ(S)

More information

NAME (1 pt): SID (1 pt): TA (1 pt): Name of Neighbor to your left (1 pt): Name of Neighbor to your right (1 pt):

NAME (1 pt): SID (1 pt): TA (1 pt): Name of Neighbor to your left (1 pt): Name of Neighbor to your right (1 pt): CS 170 First Midterm 26 Feb 2010 NAME (1 pt): SID (1 pt): TA (1 pt): Name of Neighbor to your left (1 pt): Name of Neighbor to your right (1 pt): Instructions: This is a closed book, closed calculator,

More information

CS 161 Summer 2009 Homework #2 Sample Solutions

CS 161 Summer 2009 Homework #2 Sample Solutions CS 161 Summer 2009 Homework #2 Sample Solutions Regrade Policy: If you believe an error has been made in the grading of your homework, you may resubmit it for a regrade. If the error consists of more than

More information

Methods for solving recurrences

Methods for solving recurrences Methods for solving recurrences Analyzing the complexity of mergesort The merge function Consider the following implementation: 1 int merge ( int v1, int n1, int v, int n ) { 3 int r = malloc ( ( n1+n

More information

Computational Complexity

Computational Complexity Computational Complexity S. V. N. Vishwanathan, Pinar Yanardag January 8, 016 1 Computational Complexity: What, Why, and How? Intuitively an algorithm is a well defined computational procedure that takes

More information

CPS 616 DIVIDE-AND-CONQUER 6-1

CPS 616 DIVIDE-AND-CONQUER 6-1 CPS 616 DIVIDE-AND-CONQUER 6-1 DIVIDE-AND-CONQUER Approach 1. Divide instance of problem into two or more smaller instances 2. Solve smaller instances recursively 3. Obtain solution to original (larger)

More information

A design paradigm. Divide and conquer: (When) does decomposing a problem into smaller parts help? 09/09/ EECS 3101

A design paradigm. Divide and conquer: (When) does decomposing a problem into smaller parts help? 09/09/ EECS 3101 A design paradigm Divide and conquer: (When) does decomposing a problem into smaller parts help? 09/09/17 112 Multiplying complex numbers (from Jeff Edmonds slides) INPUT: Two pairs of integers, (a,b),

More information

The divide-and-conquer strategy solves a problem by: Chapter 2. Divide-and-conquer algorithms. Multiplication

The divide-and-conquer strategy solves a problem by: Chapter 2. Divide-and-conquer algorithms. Multiplication The divide-and-conquer strategy solves a problem by: Chapter 2 Divide-and-conquer algorithms 1 Breaking it into subproblems that are themselves smaller instances of the same type of problem 2 Recursively

More information

Fast Polynomial Multiplication

Fast Polynomial Multiplication Fast Polynomial Multiplication Marc Moreno Maza CS 9652, October 4, 2017 Plan Primitive roots of unity The discrete Fourier transform Convolution of polynomials The fast Fourier transform Fast convolution

More information

1 Quick Sort LECTURE 7. OHSU/OGI (Winter 2009) ANALYSIS AND DESIGN OF ALGORITHMS

1 Quick Sort LECTURE 7. OHSU/OGI (Winter 2009) ANALYSIS AND DESIGN OF ALGORITHMS OHSU/OGI (Winter 2009) CS532 ANALYSIS AND DESIGN OF ALGORITHMS LECTURE 7 1 Quick Sort QuickSort 1 is a classic example of divide and conquer. The hard work is to rearrange the elements of the array A[1..n]

More information

CS60020: Foundations of Algorithm Design and Machine Learning. Sourangshu Bhattacharya

CS60020: Foundations of Algorithm Design and Machine Learning. Sourangshu Bhattacharya CS60020: Foundations of Algorithm Design and Machine Learning Sourangshu Bhattacharya Matrix multiplication September 14, 2005 L2.27 Standard algorithm for i 1 to n do for j 1 ton do c ij 0 for k 1 to

More information

COMP Analysis of Algorithms & Data Structures

COMP Analysis of Algorithms & Data Structures COMP 3170 - Analysis of Algorithms & Data Structures Shahin Kamali Lecture 4 - Jan. 10, 2018 CLRS 1.1, 1.2, 2.2, 3.1, 4.3, 4.5 University of Manitoba Picture is from the cover of the textbook CLRS. 1 /

More information

Lecture 3. Big-O notation, more recurrences!!

Lecture 3. Big-O notation, more recurrences!! Lecture 3 Big-O notation, more recurrences!! Announcements! HW1 is posted! (Due Friday) See Piazza for a list of HW clarifications First recitation section was this morning, there s another tomorrow (same

More information

Problem Set 2 Solutions

Problem Set 2 Solutions Introduction to Algorithms October 1, 2004 Massachusetts Institute of Technology 6.046J/18.410J Professors Piotr Indyk and Charles E. Leiserson Handout 9 Problem Set 2 Solutions Reading: Chapters 5-9,

More information

CSE 613: Parallel Programming. Lecture 8 ( Analyzing Divide-and-Conquer Algorithms )

CSE 613: Parallel Programming. Lecture 8 ( Analyzing Divide-and-Conquer Algorithms ) CSE 613: Parallel Programming Lecture 8 ( Analyzing Divide-and-Conquer Algorithms ) Rezaul A. Chowdhury Department of Computer Science SUNY Stony Brook Spring 2012 A Useful Recurrence Consider the following

More information

CS S Lecture 5 January 29, 2019

CS S Lecture 5 January 29, 2019 CS 6363.005.19S Lecture 5 January 29, 2019 Main topics are #divide-and-conquer with #fast_fourier_transforms. Prelude Homework 1 is due Tuesday, February 5th. I hope you ve at least looked at it by now!

More information

Data Structures and Algorithms Chapter 3

Data Structures and Algorithms Chapter 3 Data Structures and Algorithms Chapter 3 1. Divide and conquer 2. Merge sort, repeated substitutions 3. Tiling 4. Recurrences Recurrences Running times of algorithms with recursive calls can be described

More information

COMP Analysis of Algorithms & Data Structures

COMP Analysis of Algorithms & Data Structures COMP 3170 - Analysis of Algorithms & Data Structures Shahin Kamali Lecture 4 - Jan. 14, 2019 CLRS 1.1, 1.2, 2.2, 3.1, 4.3, 4.5 University of Manitoba Picture is from the cover of the textbook CLRS. COMP

More information

V. Adamchik 1. Recurrences. Victor Adamchik Fall of 2005

V. Adamchik 1. Recurrences. Victor Adamchik Fall of 2005 V. Adamchi Recurrences Victor Adamchi Fall of 00 Plan Multiple roots. More on multiple roots. Inhomogeneous equations 3. Divide-and-conquer recurrences In the previous lecture we have showed that if the

More information

When we use asymptotic notation within an expression, the asymptotic notation is shorthand for an unspecified function satisfying the relation:

When we use asymptotic notation within an expression, the asymptotic notation is shorthand for an unspecified function satisfying the relation: CS 124 Section #1 Big-Oh, the Master Theorem, and MergeSort 1/29/2018 1 Big-Oh Notation 1.1 Definition Big-Oh notation is a way to describe the rate of growth of functions. In CS, we use it to describe

More information

In-Class Soln 1. CS 361, Lecture 4. Today s Outline. In-Class Soln 2

In-Class Soln 1. CS 361, Lecture 4. Today s Outline. In-Class Soln 2 In-Class Soln 1 Let f(n) be an always positive function and let g(n) = f(n) log n. Show that f(n) = o(g(n)) CS 361, Lecture 4 Jared Saia University of New Mexico For any positive constant c, we want to

More information

CS 4407 Algorithms Lecture 3: Iterative and Divide and Conquer Algorithms

CS 4407 Algorithms Lecture 3: Iterative and Divide and Conquer Algorithms CS 4407 Algorithms Lecture 3: Iterative and Divide and Conquer Algorithms Prof. Gregory Provan Department of Computer Science University College Cork 1 Lecture Outline CS 4407, Algorithms Growth Functions

More information

CPSC 518 Introduction to Computer Algebra Asymptotically Fast Integer Multiplication

CPSC 518 Introduction to Computer Algebra Asymptotically Fast Integer Multiplication CPSC 518 Introduction to Computer Algebra Asymptotically Fast Integer Multiplication 1 Introduction We have now seen that the Fast Fourier Transform can be applied to perform polynomial multiplication

More information