I have implemented the following code for the strassen algorithm http://www.sanfoundry.com/java-program-strassen-algorithm/. It works for most matrices including 2x2 and 4x4 matrices but fails for 3x3 matrices. Any ideas why and how can I fix it?
Asked
Active
Viewed 4,203 times
-3
-
1Show the relevant code fragment. – Norbert Bicsi Jan 29 '18 at 04:57
-
2You need to add a [mcve], which would include code _in the question itself_, not a link. – 1201ProgramAlarm Jan 29 '18 at 05:21
-
@1201ProgramAlarm code is too big enter here – Shaheem Khan Jan 29 '18 at 05:29
-
Which is why we emphasize _minimal_ – Passer By Jan 29 '18 at 05:50
1 Answers
2
Look at the way Strassen works. It works by divide and conquer. You didn't post your code but it probably has to do with trying to divide a 3x3 matrix into 4 submatrices which can't be done. You can pad the 3x3 with zeros to create a matrix with dimensions which can be split or just use basic matrix mult.
Also, Strassen and recursive MM algs need a base case in which it goes to regular matrix multiplication because Strassen is only practical for larger matrices. Depends on your system but my laptop needs matrices larger than 256x256 for Strassen to see an improvement.

kreitz
- 58
- 6