Lecture #1, day 1, 1/12/98
1. Matrix Multiplication
1.1 Naive method
The naive method for doing matrix multiplication is the method typically taught
in math class. Multipy 2 matrices A*B = C by setting Cij = åk = 1nAikBkj . The number of multiplications
and additions is O(n3)
1.2 Slightly less Naive method
Divide the matrices into submatrices, multiply the submatrices, then recombine
the resulting matrices.
[
| ] * |
é ê
ë
|
|
| |
ù ú
û
|
= |
é ê
ë
|
|
| |
ù ú
û
|
- avoids thrashing the cache, but otherwise has the same time complexity
1.3 Strassen's algorithm
Strassen's algorithm starts by subdividing the matrices in the same manner as
the slightly less naive method, but then uses a different series of manipulations
to construct the result matrix with only 7 recursive calls, instead of the 8
used in the slightly less naive method. Complexities:
- Addition: A(n) = 18[(n2)/ 4]+7A(n/2) with A(1) = 0 . Solution: A(n) = 6nlog27
- Multiplication: M(n) = 7M(n/2) with M(1) = 1 . Solution: M(n) = nlog27
One important note is that the constant 6 in A(n) for Strassen's algorithm is much
larger than the constant 1 in A(n) for the naive algorithms. This means there is
some size of matrix s.t. forall larger matrix multiplications strassen should
be used and for all smaller matrices, one of the naive methods should be used.
File translated from TEX by TTH, version 1.30.
|