Witty Timmy II

Timmy is now given two n × n n \times n matrices to multiply using the schoolbook algorithm. Which complexity best describes the process?

O ( n 3 ) O(n^3) O ( n ) O(n) O ( n 2.5 ) O(n^{2.5}) O ( lg ( n ) ) O(\lg(n)) O ( n 2 ) O(n^2)

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

2 solutions

First, we notice that the output vector consists of n 2 n^2 entries, each of which is a dot product of two vectors of n n components.

Since computing the dot product of two vectors require summing over all n n corresponding pairs of components, this task is O ( n ) O(n) .

Doing an O ( n ) O(n) task O ( n 2 ) O(n^2) times takes time in O ( n 3 ) O(n^3)

Actually, one can use Strassen's Algorithm for faster multiplication.

Moderator note:

Great! Thanks for sharing about Strassen's Algorithm.

Zeeshan Ali
Jan 30, 2016

Here is the algorithm for multiplication of two square matrices of same order r × c r \times c with r = c = n r=c=n

1
2
3
4
5
for i=1 to n
   for j=1 to n    
     c[i][j]=0
     for k=1 to n
         c[i][j] = c[i][j]+a[i][k]*b[k][j]

The time complexity is O ( n 3 ) O(n^3) ..

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...