0% found this document useful (0 votes)
35 views

Foundations of Algorithms Assignment 3 Chinmay Kulkarni (ck1166)

This document discusses Strassen's matrix multiplication algorithm and its analysis. It begins by working through an example of Strassen's algorithm to multiply two matrices of size 2x2. It then provides pseudocode for Strassen's algorithm and discusses how it can be applied to matrices of any size n by padding with zeros. Finally, it analyzes the running time of Strassen's algorithm, showing that it runs in O(n^2.807) time, an improvement over the O(n^3) time of standard matrix multiplication.

Uploaded by

Chinmay Kulkarni
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views

Foundations of Algorithms Assignment 3 Chinmay Kulkarni (ck1166)

This document discusses Strassen's matrix multiplication algorithm and its analysis. It begins by working through an example of Strassen's algorithm to multiply two matrices of size 2x2. It then provides pseudocode for Strassen's algorithm and discusses how it can be applied to matrices of any size n by padding with zeros. Finally, it analyzes the running time of Strassen's algorithm, showing that it runs in O(n^2.807) time, an improvement over the O(n^3) time of standard matrix multiplication.

Uploaded by

Chinmay Kulkarni
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Foundations of Algorithms Assignment 3

Chinmay Kulkarni(ck1166)

1.a.

[ 1

3]

[6

8]

[ 7

5]

[4

2]

by Strassens Algorithm

Let,
[ A

B]

[E

F]

[ C

D]

[G

H]

P1= A(F-H) =1(8-2) =6


P2= H(A+B) = 2(1+3) =8
P3= E(C+D) = 6(7+5) =72
P4= D(G-E) = 5(4-6) =-10
P5= (A+D) (E+H) = (6) (8) = 48
P6= (B-D) (G+H) = (-2) (6) = -12
P7= (A-C) (E+F) = (-6) (14) = -84

[ P6+P5+P4-P2
[ P3+P4

[ -12+48-10-8
[ 72-10

[18

14]

[62

66]

P1+P2 ]
P1+P5-P3-P7]

6+8

6+48-72+84]

b. Strassens Algorithm pseudocode:

strassens_algo(A,B):
divide matrix A in sub-matrices A11,A12,A21,A22
divide matrix B in sub-matrices B11,B12,B21,B22

P1 A11*(B12-B22)
P2 (A11+A12) * (B22)
P3 (A21+A22) * (B11)
P4 (A22) * (B21-B11)
P5 (A11+A22) * (B11+B22)
P6 (A12-A22) * (B21+B22)
P7 (B21-B11) * (B11+B12)

C11 P5 + P4 - P2 + P6
C12 P1 + P2
C21 P3 + P4
C22 P5 + P1 - P3 - P7

Combine sub-matrices C11, C12, C21, C22 to C


Return C

c. Suppose we have square matrix of order n x n, where n is not 2 k


We can apply Strassens Algorithm in following way:

Let n<2k
We can pad (2k-n) rows and columns with 0s to the original matrix so that overall order of the
matrix can be changed to some power of 2 ie n x n ,where n=2 k.
Now we can apply Strassens algorithm to the matrix. Therefore the resulting algorithm will run in
(nlg 7).

d. suppose, x = a + ib and y = c + id

now we want to perform x*y with 3 multiplications,

Let P= (a+b) * (c+d)


Q= a*c
R= b*d
x*y can be performed with the help of these 3 multiplications
(Q-R) + i(P Q - R)

2.a (n+1)/2 =n/2

Suppose (n+1)/2 =n/2=k,

n/2=k
k (n+1)/2 < k+1
2k n+1 < 2k+2
2k-1 n < 2k+1

----------------(1)

(n+1)/2 =k
k n/2 < k+1
2k n < 2k+2

-----------------(2)

When we compare (1) and (2), we get an intersection between 2 inequalities


2k n <2k+1
Hence we can say that LHS=RHS.

b. n/2+1=(n+1)/2

suppose n/2+1=(n+1)/2=k
n/2+1=k
n/2= k 1

k-1 n/2 <k


2k-2 n < 2k

--------------------(1)

(n+1)/2=k
k< (n+1)/2 k+1
2k < n+1 2k+2
2k-1 < n 2k+1

-----------------------(2)

When we compare (1) and (2), we get an intersection between 2 inequalities


2k+1 < n < 2k
Hence we can say that LHS=RHS

c. T (1) = 0 and T(n) = T(n/2) + T((n/2) + n


D(n)= T(n+1) - T(n)
D (1) = T (2) T (1)
= [ T (2/2) + T ( (2/2) + 2] [T (1/2) + T ((1/2) + 1]
= [1+1+2] - [0+1+1]
=2
D(n)= [T((n+1)/2) + T((n+1)/2) + n+1] [T(n/2) + T((n/2) + n]
= [T((n+1)/2) - T(n/2)] + T((n+1)/2) + n+1- T((n/2) - n
= D(n/2 )+ T((n+1)/2) + n+1- T((n/2) - n
= D(n/2 )+ T((n+1)/2) + n+1- T((n+1)/2) n
= D(n/2 )+1
d.

by strong induction prove for n>=1, D(n)= lg n+2,

base step :
for n=1,
D(1)= lg 1+2
= 0+2
=2
It holds true
Inductive step:
Let k be any integer k >= 1, suppose it is true for 1ik, ie D(i) is true,
Now we have to show that D(k+1) is true. That is D(k+1) = lg (k+1)+2
As we know that D(k)= D(k/2) +1
For D(k+1) = D((k+1))+1
= [ lg (k+1) +1]+1

( T(n)=T(n/2)+1 then T(n)=(lg

n)+1)
=lg (k+1) +2
Hence proved.

e. T(n) T (1) =

n-1

k=1 D(k)

Taking RHS,
=

n-1

k=1 D(k)

n-1

k=1T(k+1) T(k)

n-1

k=1T(k+1) -

n-1

k=1T(k)

= [T(2)+ T(2)+ T(3)+.+ T((n-1)+T((n-1)+1)] [T(1)+ T(2)+


T(n-1)]
= [T(2)+ T(2)+ T(3)+.+ T((n-1)+T((n)] [T(1)+ T(2)+ T(n-1)]
= [T(n) T(1)]
Hence proved.
As we know that D(k) =lg k +2
Therefore,
T(n) T (1) =

n-1

k=1lg k +2

f. T(n)= n-1k=1lg k +2 running time is O(n log n),

T(n)= n-1k=1lg k + n-1k=12


= n-1k=1lg k +2(n-1)
= (lg 1+lg 2+lg 3+..lg (n-1)+lg n) + 2(n-1) -lg n
= (lg 1+ lg 2+ lg 3.. lg (n-1)+ lg n)+2(n-1) -lg n
= (lg (n!))+2(n-1) -lg n
As we know that lg (n!) = O(n log n),
= O(n log n)+O(n)
Therefore,
The overall expression will run in O(n log n).

You might also like