Upcoming SlideShare
×

# strassen matrix multiplication algorithm

19,692 views

Published on

it explains matrix multiplication. its algorithm and analysis

Published in: Education
1 Comment
3 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
Your message goes here
• VERY NICE :)

Are you sure you want to  Yes  No
Your message goes here
Views
Total views
19,692
On SlideShare
0
From Embeds
0
Number of Embeds
80
Actions
Shares
0
348
1
Likes
3
Embeds 0
No embeds

No notes for slide

### strassen matrix multiplication algorithm

1. 1. Strassen's Matrix Multiplication Presented by: Ali Mamoon 07-0014
2. 2. Contents  Matrix multiplication  Divide and Conquer  Strassen's idea  Analysis
3. 3. Standard algorithm for i ←1 to n do for j←1 to n do cij←0 for k←1 to n do cij←cij+ aik⋅bkj N C i, j a i ,k bk , j k 1 N N N 3 3 Thus T ( N ) c cN O(N ) i1 j1k 1
4. 4. Divide-and-Conquer  Divide-and conquer is a general algorithm design paradigm:  Divide: divide the input data S in two or more disjoint subsets S1, S2, …  Recur: solve the sub problems recursively  Conquer: combine the solutions for S1, S2, …, into a solution for S  The base case for the recursion are sub problems of constant size  Analysis can be done using recurrence equations
5. 5. Matrix Multiplication through Divide and Conquer Approach
6. 6. Divide-and-conquer algorithm
7. 7. Master theorem
8. 8. Strassen’s idea  Multiply 2×2matrices with only 7 recursive multiplications.  P1= a⋅(f–h) r=P5+ P4–P2+ P6 P2= (a+ b) ⋅h  s=P1+ P2 P3= (c+ d) ⋅e  t=P3+ P4  P4= d⋅(g–e) u=P5+ P1–P3–P7 P5= (a+ d) ⋅(e+ h)  P6= (b–d) ⋅(g+ h)  P7= (a–c) ⋅(e+ f )   Note:  7mults, 18adds/subs.  Note: No reliance on commutative of multiplication!
9. 9. Strassen Algorithm void matmul(int *A, int *B, int *R, int n) { if (n == 1) { (*R) += (*A) * (*B); } else { matmul(A, B, R, n/4); matmul(A, B+(n/4), R+(n/4), n/4); matmul(A+2*(n/4), B, R+2*(n/4), n/4); matmul(A+2*(n/4), B+(n/4), R+3*(n/4), n/4); matmul(A+(n/4), B+2*(n/4), R, n/4); matmul(A+(n/4), B+3*(n/4), R+(n/4), n/4); matmul(A+3*(n/4), B+2*(n/4), R+2*(n/4), n/4); matmul(A+3*(n/4), B+3*(n/4), R+3*(n/4), n/4); Divide matrices in } sub-matrices and recursively multiply sub-matrices
10. 10. Analysis of Strassen's  T(n) = 7T(n/2) + Θ(n2)  nlogba= nlog27≈n2.81  ⇒CASE1⇒T(n) = Θ(nlg7).  The number2.81may not seem much smaller than 3, but because the difference is in the exponent, the impact on running time is significant. In fact, Strassen’s algorithm beats the ordinary algorithm on today’s machines for n≥32or so.  Best to date (of theoretical interest only): Θ(n2.376…)