SlideShare a Scribd company logo
1 of 6
Implementation Of Strassens's Algorithm
#include<stdio.h>
void main()
{
int i,j, r1,c1, r2, c2, a[50][50], b[50][50], c[50][50], p1,p2,p3,p4,p5,p6,p7;
printf("nxn matrix using Strassen's multiplication");
printf("nEnter row size of matrix A:t");
scanf("%d", &r1);
printf("Enter column size of matrix A:t");
scanf("%d", &c1);
printf("nEnter row size of matrix B:t");
scanf("%d", &r2);
printf("Enter column size of matrix B:t");
scanf("%d", &c2);
if(c1!=r2)
{
printf("Invalid matrix size! Exiting...n");
return ;
}
printf("Enter elements for matrix A:n");
for(i=1;i<=r1;i++)
{
for(j=1;j<=c1;j++)
{
scanf("%d", &a[i][j]);
}
}
printf("nEnter elements of matrix B:n");
for(i=1;i<=r2;i++)
{
for(j=1;j<=c2;j++)
{
scanf("%d", &b[i][j]);
}
}
printf("MATRIX A:n");
for(i=1;i<=r1;i++)
{
printf("n");
for(j=1;j<=c1;j++)
{
printf("%dt", a[i][j]);
}
}
printf("nMATRIX B:n");
for(i=1;i<=r2;i++)
{
printf("n");
for(j=1;j<=c2;j++)
{
printf("%dt", b[i][j]);
}
}
p1= (a[1][1]+a[2][2])*(b[1][1]+b[2][2]);
p2= (a[2][1]+a[2][2])*b[1][1];
p3= a[1][1]*(b[1][2]-b[2][2]);
p4= a[2][2]*(b[2][1]-b[1][1]);
p5= (a[1][1]+a[1][2])*b[2][2];
p6= (a[2][1]-a[1][1])*(b[1][1]+b[1][2]);
p7= (a[1][2]-a[2][2])*(b[2][1]+b[2][2]);
c[1][1]=p1+p4-p5+p7;
c[1][2]=p3+p5;
c[2][1]=p2+p4;
c[2][2]=p1+p3-p2+p6;
printf("nThe matrix C is:n");
for(i=1;i<=r1;i++)
{
printf("n");
for(j=1;j<=c2;j++)
{ printf("%dt", c[i][j]);
}
}
}
Output
Strassen's Multiplication Algorithm
P1 = (A11+ A22)(B11+B22)
P2 = (A21 + A22) * B11
P3 = A11 * (B12 - B22)
P4 = A22 * (B21 - B11)
P5 = (A11 + A12) * B22
P6 = (A21 - A11) * (B11 + B12)
P7 = (A12 - A22) * (B21 + B22)
C11 = P1 + P4 - P5 + P7
C12 = P3 + P5
C21 = P2 + P4
C22 = P1 + P3 - P2 + P6
Where C is :
Introduction:
Strassens's Multiplication
The Strassen’s method of matrix multiplication is a typical divide and conquer algorithm. We’ve
seen so far some divide and conquer algorithms like merge sort and the Karatsuba’s fast
multiplication of large numbers. However let’s get again on what’s behind the divide and
conquer approach.
Unlike the dynamic programming where we “expand” the solutions of sub-problems in order to
get the final solution, here we are talking more on joining sub-solutions together. These solutions
of some sub-problems of the general problem are equal and their merge is somehow well
defined.

More Related Content

What's hot (20)

C programming BY Mazedur
C programming BY MazedurC programming BY Mazedur
C programming BY Mazedur
 
Bcsl 033 data and file structures lab s5-2
Bcsl 033 data and file structures lab s5-2Bcsl 033 data and file structures lab s5-2
Bcsl 033 data and file structures lab s5-2
 
Bcsl 033 data and file structures lab s2-2
Bcsl 033 data and file structures lab s2-2Bcsl 033 data and file structures lab s2-2
Bcsl 033 data and file structures lab s2-2
 
C program to check leap year
C program to check leap year C program to check leap year
C program to check leap year
 
Implement a queue using two stacks.
Implement a queue using two stacks.Implement a queue using two stacks.
Implement a queue using two stacks.
 
Bcsl 033 data and file structures lab s3-3
Bcsl 033 data and file structures lab s3-3Bcsl 033 data and file structures lab s3-3
Bcsl 033 data and file structures lab s3-3
 
Computer programing w
Computer programing wComputer programing w
Computer programing w
 
Najmul
Najmul  Najmul
Najmul
 
Progr3
Progr3Progr3
Progr3
 
Program for pyramid
Program for pyramidProgram for pyramid
Program for pyramid
 
Loop control structure
Loop control structureLoop control structure
Loop control structure
 
C workshop day 6
C workshop day 6C workshop day 6
C workshop day 6
 
LAB PROGRAMS SARASWATHI RAMALINGAM
LAB PROGRAMS SARASWATHI RAMALINGAMLAB PROGRAMS SARASWATHI RAMALINGAM
LAB PROGRAMS SARASWATHI RAMALINGAM
 
week-8x
week-8xweek-8x
week-8x
 
week-1x
week-1xweek-1x
week-1x
 
C programs Set 2
C programs Set 2C programs Set 2
C programs Set 2
 
Spiral array
Spiral arraySpiral array
Spiral array
 
Shan
ShanShan
Shan
 
Session06 functions
Session06 functionsSession06 functions
Session06 functions
 
C file
C fileC file
C file
 

Viewers also liked

Packet switching
Packet switchingPacket switching
Packet switchingVikash Dhal
 
Life of Phong: Photo Diary
Life of Phong: Photo DiaryLife of Phong: Photo Diary
Life of Phong: Photo DiaryPhonggggg
 
Mc edwards assignment 9.4
Mc edwards assignment 9.4Mc edwards assignment 9.4
Mc edwards assignment 9.4TayMcEdwards
 
Photo journal
Photo journalPhoto journal
Photo journalPhonggggg
 
File handling in c
File handling in c File handling in c
File handling in c Vikash Dhal
 
RSpec: Feature specs as checklist
RSpec: Feature specs as checklistRSpec: Feature specs as checklist
RSpec: Feature specs as checklistEdward Fox
 
Avoiding conflict and litigation with hmrc
Avoiding conflict and litigation with hmrcAvoiding conflict and litigation with hmrc
Avoiding conflict and litigation with hmrcIndia inc
 
Atomic Designにまつわるエトセトラ
Atomic DesignにまつわるエトセトラAtomic Designにまつわるエトセトラ
Atomic DesignにまつわるエトセトラEdward Fox
 
Panel discussion - Property v Luxury assets - what should and what will india...
Panel discussion - Property v Luxury assets - what should and what will india...Panel discussion - Property v Luxury assets - what should and what will india...
Panel discussion - Property v Luxury assets - what should and what will india...India inc
 
Panel discussion- Preferred offshore hubs for Indians
Panel discussion- Preferred offshore hubs for IndiansPanel discussion- Preferred offshore hubs for Indians
Panel discussion- Preferred offshore hubs for IndiansIndia inc
 
Pannel discussion - protecting, planning & giving - tips & trends
Pannel discussion - protecting, planning & giving - tips & trendsPannel discussion - protecting, planning & giving - tips & trends
Pannel discussion - protecting, planning & giving - tips & trendsIndia inc
 
Panel discussion-what are indian family offices doing globally? Managing Indi...
Panel discussion-what are indian family offices doing globally? Managing Indi...Panel discussion-what are indian family offices doing globally? Managing Indi...
Panel discussion-what are indian family offices doing globally? Managing Indi...India inc
 
Preprocessor directives
Preprocessor directivesPreprocessor directives
Preprocessor directivesVikash Dhal
 
Strinng Classes in c++
Strinng Classes in c++Strinng Classes in c++
Strinng Classes in c++Vikash Dhal
 

Viewers also liked (16)

Packet switching
Packet switchingPacket switching
Packet switching
 
Life of Phong: Photo Diary
Life of Phong: Photo DiaryLife of Phong: Photo Diary
Life of Phong: Photo Diary
 
Mc edwards assignment 9.4
Mc edwards assignment 9.4Mc edwards assignment 9.4
Mc edwards assignment 9.4
 
Photo journal
Photo journalPhoto journal
Photo journal
 
File handling in c
File handling in c File handling in c
File handling in c
 
C fundamentals
C fundamentalsC fundamentals
C fundamentals
 
RSpec: Feature specs as checklist
RSpec: Feature specs as checklistRSpec: Feature specs as checklist
RSpec: Feature specs as checklist
 
Raid
RaidRaid
Raid
 
Avoiding conflict and litigation with hmrc
Avoiding conflict and litigation with hmrcAvoiding conflict and litigation with hmrc
Avoiding conflict and litigation with hmrc
 
Atomic Designにまつわるエトセトラ
Atomic DesignにまつわるエトセトラAtomic Designにまつわるエトセトラ
Atomic Designにまつわるエトセトラ
 
Panel discussion - Property v Luxury assets - what should and what will india...
Panel discussion - Property v Luxury assets - what should and what will india...Panel discussion - Property v Luxury assets - what should and what will india...
Panel discussion - Property v Luxury assets - what should and what will india...
 
Panel discussion- Preferred offshore hubs for Indians
Panel discussion- Preferred offshore hubs for IndiansPanel discussion- Preferred offshore hubs for Indians
Panel discussion- Preferred offshore hubs for Indians
 
Pannel discussion - protecting, planning & giving - tips & trends
Pannel discussion - protecting, planning & giving - tips & trendsPannel discussion - protecting, planning & giving - tips & trends
Pannel discussion - protecting, planning & giving - tips & trends
 
Panel discussion-what are indian family offices doing globally? Managing Indi...
Panel discussion-what are indian family offices doing globally? Managing Indi...Panel discussion-what are indian family offices doing globally? Managing Indi...
Panel discussion-what are indian family offices doing globally? Managing Indi...
 
Preprocessor directives
Preprocessor directivesPreprocessor directives
Preprocessor directives
 
Strinng Classes in c++
Strinng Classes in c++Strinng Classes in c++
Strinng Classes in c++
 

Similar to Implementation of strassens

All important c programby makhan kumbhkar
All important c programby makhan kumbhkarAll important c programby makhan kumbhkar
All important c programby makhan kumbhkarsandeep kumbhkar
 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solutionAzhar Javed
 
Unit 3 Input Output.pptx
Unit 3 Input Output.pptxUnit 3 Input Output.pptx
Unit 3 Input Output.pptxPrecise Mya
 
Introduction to Basic C programming 02
Introduction to Basic C programming 02Introduction to Basic C programming 02
Introduction to Basic C programming 02Wingston
 
LET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERSLET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERSKavyaSharma65
 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020vrgokila
 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using CBilal Mirza
 
C basics
C basicsC basics
C basicsMSc CST
 
Data Structure in C Programming Language
Data Structure in C Programming LanguageData Structure in C Programming Language
Data Structure in C Programming LanguageArkadeep Dey
 
C programming function
C  programming functionC  programming function
C programming functionargusacademy
 

Similar to Implementation of strassens (20)

All important c programby makhan kumbhkar
All important c programby makhan kumbhkarAll important c programby makhan kumbhkar
All important c programby makhan kumbhkar
 
C lab manaual
C lab manaualC lab manaual
C lab manaual
 
Arrays
ArraysArrays
Arrays
 
C Programming lab
C Programming labC Programming lab
C Programming lab
 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
 
Unit 3 Input Output.pptx
Unit 3 Input Output.pptxUnit 3 Input Output.pptx
Unit 3 Input Output.pptx
 
C Programming Exam problems & Solution by sazzad hossain
C Programming Exam problems & Solution by sazzad hossainC Programming Exam problems & Solution by sazzad hossain
C Programming Exam problems & Solution by sazzad hossain
 
Introduction to Basic C programming 02
Introduction to Basic C programming 02Introduction to Basic C programming 02
Introduction to Basic C programming 02
 
C-programs
C-programsC-programs
C-programs
 
C programms
C programmsC programms
C programms
 
ADA FILE
ADA FILEADA FILE
ADA FILE
 
SaraPIC
SaraPICSaraPIC
SaraPIC
 
LET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERSLET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERS
 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020
 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using C
 
C Programming Example
C Programming ExampleC Programming Example
C Programming Example
 
C basics
C basicsC basics
C basics
 
Data Structure in C Programming Language
Data Structure in C Programming LanguageData Structure in C Programming Language
Data Structure in C Programming Language
 
C programming function
C  programming functionC  programming function
C programming function
 
VTU Data Structures Lab Manual
VTU Data Structures Lab ManualVTU Data Structures Lab Manual
VTU Data Structures Lab Manual
 

Implementation of strassens

  • 1. Implementation Of Strassens's Algorithm #include<stdio.h> void main() { int i,j, r1,c1, r2, c2, a[50][50], b[50][50], c[50][50], p1,p2,p3,p4,p5,p6,p7; printf("nxn matrix using Strassen's multiplication"); printf("nEnter row size of matrix A:t"); scanf("%d", &r1); printf("Enter column size of matrix A:t"); scanf("%d", &c1); printf("nEnter row size of matrix B:t"); scanf("%d", &r2); printf("Enter column size of matrix B:t"); scanf("%d", &c2); if(c1!=r2) { printf("Invalid matrix size! Exiting...n"); return ; } printf("Enter elements for matrix A:n"); for(i=1;i<=r1;i++) { for(j=1;j<=c1;j++)
  • 2. { scanf("%d", &a[i][j]); } } printf("nEnter elements of matrix B:n"); for(i=1;i<=r2;i++) { for(j=1;j<=c2;j++) { scanf("%d", &b[i][j]); } } printf("MATRIX A:n"); for(i=1;i<=r1;i++) { printf("n"); for(j=1;j<=c1;j++) { printf("%dt", a[i][j]); } } printf("nMATRIX B:n"); for(i=1;i<=r2;i++)
  • 3. { printf("n"); for(j=1;j<=c2;j++) { printf("%dt", b[i][j]); } } p1= (a[1][1]+a[2][2])*(b[1][1]+b[2][2]); p2= (a[2][1]+a[2][2])*b[1][1]; p3= a[1][1]*(b[1][2]-b[2][2]); p4= a[2][2]*(b[2][1]-b[1][1]); p5= (a[1][1]+a[1][2])*b[2][2]; p6= (a[2][1]-a[1][1])*(b[1][1]+b[1][2]); p7= (a[1][2]-a[2][2])*(b[2][1]+b[2][2]); c[1][1]=p1+p4-p5+p7; c[1][2]=p3+p5; c[2][1]=p2+p4; c[2][2]=p1+p3-p2+p6; printf("nThe matrix C is:n"); for(i=1;i<=r1;i++) { printf("n"); for(j=1;j<=c2;j++) { printf("%dt", c[i][j]);
  • 5. Strassen's Multiplication Algorithm P1 = (A11+ A22)(B11+B22) P2 = (A21 + A22) * B11 P3 = A11 * (B12 - B22) P4 = A22 * (B21 - B11) P5 = (A11 + A12) * B22 P6 = (A21 - A11) * (B11 + B12) P7 = (A12 - A22) * (B21 + B22) C11 = P1 + P4 - P5 + P7 C12 = P3 + P5 C21 = P2 + P4 C22 = P1 + P3 - P2 + P6 Where C is :
  • 6. Introduction: Strassens's Multiplication The Strassen’s method of matrix multiplication is a typical divide and conquer algorithm. We’ve seen so far some divide and conquer algorithms like merge sort and the Karatsuba’s fast multiplication of large numbers. However let’s get again on what’s behind the divide and conquer approach. Unlike the dynamic programming where we “expand” the solutions of sub-problems in order to get the final solution, here we are talking more on joining sub-solutions together. These solutions of some sub-problems of the general problem are equal and their merge is somehow well defined.