5

When analyzing square matrix multiplication runtimes, I understand that the runtimes are

T(N) = 8T(N/2) + O(N^2)

for the naive divide-and-conquer method, and

T(N) = 7T(N/2) + O(N^2)

for Strassen's method.

Why is N divided by 2 and not 4?

How I understand it, the coefficient of T(N/2) (8 for naive, 7 for Strassen) is the number of recursions that each level introduces, or the growth rate of subproblems. The divisor is the factor of reduction of the problem. The O(N^2) addend is the runtime of each particular recurrence node.

If the naive algorithm and Strassen's method are both dividing the output matrix into N/2 x N/2 matrices where N is the number of rows and columns, isn't the problem being reduced by a factor of 4 and not 2, since at each level we are solving the problem for 4 smaller matrices?

Below is an image for the naive method that I obtained from GeeksforGeeks:

Naive method image

cadaniluk
  • 15,027
  • 2
  • 39
  • 67
L Lin
  • 53
  • 3
  • 4
    Number of elements indeed reduce by 4, but the problem is parametrized by the _size_ of a single dimension of a matrix, which only halves. – Ivan Smirnov Oct 23 '17 at 17:50
  • I think it would greatly improve your question if you presented at least pseudocode and argued according to that. A recurrence is tied to an algorithm, not a problem and you only present the latter. – cadaniluk Sep 25 '18 at 13:55
  • I have to add that I meant $T(n/4)$. – Green Falcon Sep 25 '18 at 13:56
  • @cadaniluk its publicly availabe. Just a simple search! – Green Falcon Sep 25 '18 at 13:58
  • @Media "its publicly availabe. Just a simple search!" Doesn't mean it's part of the question. If the OP were to specifically argue that the subproblems should be divided by 4, the question would become obvious and he would probably figure it out himself. (You can drop the LaTeX markers, it's not supported on Stack Overflow anyway.) – cadaniluk Sep 25 '18 at 14:00

1 Answers1

3

From Introduction to Algorithms, 3rd Edition, p. 77:

Let T(n) be the time to multiply two n x n matrices using this [the naive matrix multiplication] procedure.

n is not the number of elements in any one matrix, it is a dimension. So, since the matrix dimensions are recursively divided in halves, the divisor is 2 and not 4.

cadaniluk
  • 15,027
  • 2
  • 39
  • 67
  • Dear friend thanks for your reply but the question is about the recursion. It is clear that we have 7 calls but why is that T(n/2)? Why it is not divided by 4? At least I meant that. – Green Falcon Sep 25 '18 at 14:17
  • 1
    @Media The argument n in T(n) is a *dimension*. It's width and length of the matrix. Now, you halve both matrices and multiply one n/2 x n/2 matrix by another n/2 x n/2 matrix. Just look at the dimensions. They were *halved*. Again, note that n does not measure the number of elements but the matrix *dimension*. On rereading, I noticed the last part of my answer is a little untidy, I will fix that. – cadaniluk Sep 25 '18 at 14:24