java - Naive matrix multiplication improvement -


my cs teacher asked "add small change" code make run time complexity of n3 - n2 instead of normal n3. cannot life of me figure out , wondering if happened know. don't think talking strassens method. when looked @ it, maybe take advantage of fact cares square (diagonal) matrix.

void multiply(int n, int a[][], int b[][], int c[][]) {     (int = 0; < n; i++)     {         (int j = 0; j < n; j++)         {             c[i][j] = 0;             (int k = 0; k < n; k++)             {                 c[i][j] += a[i][k]*b[k][j];             }         }     } } 

you cannot achieve matrix multiplication in o(n2). however, can improve complexity o(n3). in linear algebra, there algorithms strasens algorithm reduces time complexity o(n2.807) reducing number of multiplications required each 2x2 sub-matrix 8 7.

coppersmith winograd algorithm fastest known matrix multiplication algorithm best time complexity o(n2.3729).


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -