Homework Problems with Solutions - Algorithm Design and Analysis | CISC 621, Assignments of Computer Science

Material Type: Assignment; Class: Algorithm Design and Analysis; Subject: Computer/Information Sciences; University: University of Delaware; Term: Fall 2003;

Typology: Assignments

Pre 2010

Uploaded on 09/02/2009

koofers-user-ozw-1
koofers-user-ozw-1 🇺🇸

9 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Homework Problem V Solution
CISC 621 – Fall 2003
Problem A (CLRS 28.2-2)
How would you modify Strassen’s algorithm to multiply n x n matrices in which n is not
an exact power of 2? Show that the resulting algorithm runs in time
Θ
(nlg7).
Strassen’s algorithm can be applied to n x n matrix multiplications where n is not an
exact power of 2 by padding the operands with 0’s. Let m = 2k such that 2k - 1 < n < 2k (m
equals 2lgn). Create m x m matrices A’ and B’ by padding A and B respectively.
Applying Strassen’s algorithm, the resulting matrices C’, A’ and B’ appear as follows,
where C’ is the matrix product of A’ and B’:
To obtain the product, we simply extract the matrix C from C’.
The runtime for this method is Θ(mlg7). Since 2k – 1 < n, it follows that m < 2n. Therefore,
the runtime becomes Θ((2n)lg7) = Θ(2 lg7 n lg7) = Θ(n lg7).
Problem B (CLRS 28.2-3)
What is the largest k such that if you can multiply 3 x 3 matrices using k multiplications,
then you can multiply n x n matrices in time o(nlg7)? What would the running time of this
algorithm be?
Strassen’s algorithm takes the approach of a recursive multiply with a base condition of
2x2 matrices. We are asked to apply an algorithm using a base condition of a 3x3 matrix
and told it will take k multiplications.
Consider the comparative recursions:
Strassen: T(n) = 7T(n/2) + Θ(n2)
3x3: T(n) = kT(n/3) + Θ(n2)
As the hint points out, case 1 of the Master Theorem applies and the recursive term
dominates. Concentrating on the 3x3 recursion, we want to solve for k such that the
number of multiplies will be less than nlg7. We do so as follows:
Θ(nlg7) Θ(nlog[3]k), so
pf2

Partial preview of the text

Download Homework Problems with Solutions - Algorithm Design and Analysis | CISC 621 and more Assignments Computer Science in PDF only on Docsity!

Homework Problem V Solution CISC 621 – Fall 2003 Problem A (CLRS 28.2-2) How would you modify Strassen’s algorithm to multiply n x n matrices in which n is not an exact power of 2? Show that the resulting algorithm runs in time Θ (n lg7 ). Strassen’s algorithm can be applied to n x n matrix multiplications where n is not an exact power of 2 by padding the operands with 0’s. Let m = 2 k^ such that 2 k^ - 1^ < n < 2 k^ ( m equals 2lg n ). Create m x m matrices A’ and B’ by padding A and B respectively. Applying Strassen’s algorithm, the resulting matrices C’ , A’ and B’ appear as follows, where C’ is the matrix product of A’ and B’ : To obtain the product, we simply extract the matrix C from C’. The runtime for this method is Θ( m lg7). Since 2 k^ – 1^ < n , it follows that m < 2 n. Therefore, the runtime becomes Θ((2 n) lg7) = Θ(2 lg7^ ⋅ n lg7) = Θ( n lg7). Problem B (CLRS 28.2-3) What is the largest k such that if you can multiply 3 x 3 matrices using k multiplications, then you can multiply n x n matrices in time o(nlg7)? What would the running time of this algorithm be? Strassen’s algorithm takes the approach of a recursive multiply with a base condition of 2x2 matrices. We are asked to apply an algorithm using a base condition of a 3x3 matrix and told it will take k multiplications. Consider the comparative recursions: Strassen: T( n ) = 7T( n /2) + Θ( n^2 ) 3x3: T( n ) = k T( n /3) + Θ( n^2 ) As the hint points out, case 1 of the Master Theorem applies and the recursive term dominates. Concentrating on the 3x3 recursion, we want to solve for k such that the number of multiplies will be less than n lg7. We do so as follows: Θ( n lg7) ≥ Θ( n log[3] k ), so

n lg7≥ n log[3] k lg7 ≥ log 3 k Utilizing maple as suggested to solve for k we find that 21.8499 ≥ k. Therefore the largest k possible, while still doing better than o (n lg7 ) using this 3x3 method is 21. Plugging 21 back into the recurrence and solving using case 1 of the Master Theorem provides us with a running time of: Θ( n log3) ≈ Θ( n 2.7712)