SlideShare a Scribd company logo
1 of 15
Strassen's Matrix Multiplication

Presented by:
Ali Mamoon
07-0014
Contents
 Matrix multiplication
 Divide and Conquer
 Strassen's idea
 Analysis
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
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
Matrix Multiplication through
Divide and Conquer Approach
Divide-and-conquer algorithm
Master theorem
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!
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
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…)

More Related Content

What's hot

Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
Ehtisham Ali
 
how to calclute time complexity of algortihm
how to calclute time complexity of algortihmhow to calclute time complexity of algortihm
how to calclute time complexity of algortihm
Sajid Marwat
 
Sets and disjoint sets union123
Sets and disjoint sets union123Sets and disjoint sets union123
Sets and disjoint sets union123
Ankita Goyal
 
daa-unit-3-greedy method
daa-unit-3-greedy methoddaa-unit-3-greedy method
daa-unit-3-greedy method
hodcsencet
 

What's hot (20)

NP completeness
NP completenessNP completeness
NP completeness
 
Recurrences
RecurrencesRecurrences
Recurrences
 
Divide and Conquer - Part 1
Divide and Conquer - Part 1Divide and Conquer - Part 1
Divide and Conquer - Part 1
 
Master method
Master method Master method
Master method
 
Knapsack Problem
Knapsack ProblemKnapsack Problem
Knapsack Problem
 
Master method theorem
Master method theoremMaster method theorem
Master method theorem
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
 
how to calclute time complexity of algortihm
how to calclute time complexity of algortihmhow to calclute time complexity of algortihm
how to calclute time complexity of algortihm
 
Tsp branch and-bound
Tsp branch and-boundTsp branch and-bound
Tsp branch and-bound
 
Asymptotic notation
Asymptotic notationAsymptotic notation
Asymptotic notation
 
Data Structure and Algorithm - Divide and Conquer
Data Structure and Algorithm - Divide and ConquerData Structure and Algorithm - Divide and Conquer
Data Structure and Algorithm - Divide and Conquer
 
Job sequencing with deadline
Job sequencing with deadlineJob sequencing with deadline
Job sequencing with deadline
 
Optimal binary search tree dynamic programming
Optimal binary search tree   dynamic programmingOptimal binary search tree   dynamic programming
Optimal binary search tree dynamic programming
 
3.8 quicksort
3.8 quicksort3.8 quicksort
3.8 quicksort
 
Np completeness
Np completenessNp completeness
Np completeness
 
Red black tree
Red black treeRed black tree
Red black tree
 
Randomized algorithms ver 1.0
Randomized algorithms ver 1.0Randomized algorithms ver 1.0
Randomized algorithms ver 1.0
 
Sets and disjoint sets union123
Sets and disjoint sets union123Sets and disjoint sets union123
Sets and disjoint sets union123
 
daa-unit-3-greedy method
daa-unit-3-greedy methoddaa-unit-3-greedy method
daa-unit-3-greedy method
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
 

Viewers also liked

Divide and conquer 1
Divide and conquer 1Divide and conquer 1
Divide and conquer 1
Kumar
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
Nikhil Sharma
 
8 queens problem using back tracking
8 queens problem using back tracking8 queens problem using back tracking
8 queens problem using back tracking
Tech_MX
 
lecture 15
lecture 15lecture 15
lecture 15
sajinsc
 
x1 t10 04 maximum & minimum problems (13)
x1 t10 04 maximum & minimum problems (13)x1 t10 04 maximum & minimum problems (13)
x1 t10 04 maximum & minimum problems (13)
Nigel Simmons
 
Alg1 8.2 Substitution Method
Alg1 8.2 Substitution MethodAlg1 8.2 Substitution Method
Alg1 8.2 Substitution Method
Jaqueline Vallejo
 
lecture 26
lecture 26lecture 26
lecture 26
sajinsc
 
Lecture 6-cs648 Randomized Algorithms
Lecture 6-cs648 Randomized AlgorithmsLecture 6-cs648 Randomized Algorithms
Lecture 6-cs648 Randomized Algorithms
Anshul Yadav
 

Viewers also liked (20)

Matrix Multiplication(An example of concurrent programming)
Matrix Multiplication(An example of concurrent programming)Matrix Multiplication(An example of concurrent programming)
Matrix Multiplication(An example of concurrent programming)
 
Matrix multiplication
Matrix multiplicationMatrix multiplication
Matrix multiplication
 
Divide and conquer 1
Divide and conquer 1Divide and conquer 1
Divide and conquer 1
 
Matrix chain multiplication
Matrix chain multiplicationMatrix chain multiplication
Matrix chain multiplication
 
Greedy
GreedyGreedy
Greedy
 
Mergesort
MergesortMergesort
Mergesort
 
Minimum spanning tree
Minimum spanning treeMinimum spanning tree
Minimum spanning tree
 
Quick sort Algorithm Discussion And Analysis
Quick sort Algorithm Discussion And AnalysisQuick sort Algorithm Discussion And Analysis
Quick sort Algorithm Discussion And Analysis
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic Notations
 
8 queens problem using back tracking
8 queens problem using back tracking8 queens problem using back tracking
8 queens problem using back tracking
 
lecture 15
lecture 15lecture 15
lecture 15
 
x1 t10 04 maximum & minimum problems (13)
x1 t10 04 maximum & minimum problems (13)x1 t10 04 maximum & minimum problems (13)
x1 t10 04 maximum & minimum problems (13)
 
21 All Pairs Shortest Path
21 All Pairs Shortest Path21 All Pairs Shortest Path
21 All Pairs Shortest Path
 
Alg1 8.2 Substitution Method
Alg1 8.2 Substitution MethodAlg1 8.2 Substitution Method
Alg1 8.2 Substitution Method
 
Multiplication algorithm
Multiplication algorithmMultiplication algorithm
Multiplication algorithm
 
lecture 26
lecture 26lecture 26
lecture 26
 
Lecture 6-cs648 Randomized Algorithms
Lecture 6-cs648 Randomized AlgorithmsLecture 6-cs648 Randomized Algorithms
Lecture 6-cs648 Randomized Algorithms
 
Lesson 19: Maximum and Minimum Values
Lesson 19: Maximum and Minimum ValuesLesson 19: Maximum and Minimum Values
Lesson 19: Maximum and Minimum Values
 
Unit 3 daa
Unit 3 daaUnit 3 daa
Unit 3 daa
 

Similar to strassen matrix multiplication algorithm

8.-DAA-LECTURE-8-RECURRENCES-AND-ITERATION-METHOD.pdf
8.-DAA-LECTURE-8-RECURRENCES-AND-ITERATION-METHOD.pdf8.-DAA-LECTURE-8-RECURRENCES-AND-ITERATION-METHOD.pdf
8.-DAA-LECTURE-8-RECURRENCES-AND-ITERATION-METHOD.pdf
RishikeshJha33
 
presentation_mergesortquicksort_1458716068_193111.ppt
presentation_mergesortquicksort_1458716068_193111.pptpresentation_mergesortquicksort_1458716068_193111.ppt
presentation_mergesortquicksort_1458716068_193111.ppt
ajiths82
 
Recurrence relationclass 5
Recurrence relationclass 5Recurrence relationclass 5
Recurrence relationclass 5
Kumar
 

Similar to strassen matrix multiplication algorithm (20)

Merge Sort
Merge SortMerge Sort
Merge Sort
 
8.-DAA-LECTURE-8-RECURRENCES-AND-ITERATION-METHOD.pdf
8.-DAA-LECTURE-8-RECURRENCES-AND-ITERATION-METHOD.pdf8.-DAA-LECTURE-8-RECURRENCES-AND-ITERATION-METHOD.pdf
8.-DAA-LECTURE-8-RECURRENCES-AND-ITERATION-METHOD.pdf
 
dynamic programming Rod cutting class
dynamic programming Rod cutting classdynamic programming Rod cutting class
dynamic programming Rod cutting class
 
Mathematics prof
Mathematics profMathematics prof
Mathematics prof
 
algorithm Unit 2
algorithm Unit 2 algorithm Unit 2
algorithm Unit 2
 
Unit 2 in daa
Unit 2 in daaUnit 2 in daa
Unit 2 in daa
 
Asymptotic Notation
Asymptotic NotationAsymptotic Notation
Asymptotic Notation
 
Algorithm.ppt
Algorithm.pptAlgorithm.ppt
Algorithm.ppt
 
factoring
factoringfactoring
factoring
 
Merge sort and quick sort
Merge sort and quick sortMerge sort and quick sort
Merge sort and quick sort
 
presentation_mergesortquicksort_1458716068_193111.ppt
presentation_mergesortquicksort_1458716068_193111.pptpresentation_mergesortquicksort_1458716068_193111.ppt
presentation_mergesortquicksort_1458716068_193111.ppt
 
MergesortQuickSort.ppt
MergesortQuickSort.pptMergesortQuickSort.ppt
MergesortQuickSort.ppt
 
5.2 divede and conquer 03
5.2 divede and conquer 035.2 divede and conquer 03
5.2 divede and conquer 03
 
5.2 divede and conquer 03
5.2 divede and conquer 035.2 divede and conquer 03
5.2 divede and conquer 03
 
Nbvtalkatbzaonencryptionpuzzles
NbvtalkatbzaonencryptionpuzzlesNbvtalkatbzaonencryptionpuzzles
Nbvtalkatbzaonencryptionpuzzles
 
Nbvtalkatbzaonencryptionpuzzles
NbvtalkatbzaonencryptionpuzzlesNbvtalkatbzaonencryptionpuzzles
Nbvtalkatbzaonencryptionpuzzles
 
Recurrence relationclass 5
Recurrence relationclass 5Recurrence relationclass 5
Recurrence relationclass 5
 
Recurrence relation solutions
Recurrence relation solutionsRecurrence relation solutions
Recurrence relation solutions
 
Introduction
IntroductionIntroduction
Introduction
 
Conference ppt
Conference pptConference ppt
Conference ppt
 

Recently uploaded

BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
SoniaTolstoy
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 

Recently uploaded (20)

Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 

strassen matrix multiplication algorithm

  • 1.
  • 3. Contents  Matrix multiplication  Divide and Conquer  Strassen's idea  Analysis
  • 4.
  • 5. 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
  • 6. 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
  • 9.
  • 11.
  • 12. 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!
  • 13.
  • 14. 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
  • 15. 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…)