![]() def strassen_multiplication(A: List], B: List], n_switch= 128) -> List]: Multiplying matrices with sizes the set value, we resort to using the naive algorithm. Instead of base case being, we can set it to. We can optimize the divide-and-conquer algorithm by changing the base case. This might be because of the time it takes to fill in and call the functions in the call stack when we do recursions. * In multiplying small square matrices, I found out that the naive algorithm is the fastest. Important points that I discovered as I was experimenting with the implemented algorithm are the following. Since we have only 7 subproblems, by using Master Theorem, we have which translates to time complexity. Implementing this in pseudo-code, we get something like this: def strassen_multiplication(A: List], B: List]) -> List]: The computations for the 7 subproblems are listed below. Strassen Algorithm ImplementationĪs mentioned in the previous part of this article, the Strassen Algorithm uses 7 subproblems only. This is where Strassen's algorithm comes in. Can we do better than this? Yes! It turns out that we can reduce the number of subproblems in this recursion from 8 to 7. Therefore, the whole matrix multiplication algorithm has time complexity which is the same as the naive algorithm's time complexity. This results in this equation: which implies that the multiplication part alone has. For the multiplication part, we will have to apply Master Theorem. Notice that for each part of submatrix, we are conducting multiplication and addition of matrix. # Colate results for submatrices # Recurse until 1 x 1Ĭ = combine_results(C_00, C_01, C_10, C_11) Implementing this in pseudo-code, def multiply_matrix(A: List], B: List]) -> List]:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |