Skip to content

Commit 1aadef4

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent a928ebd commit 1aadef4

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

divide_and_conquer/strassen_matrix_multiplication.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,15 @@ def actual_strassen(matrix_a: list, matrix_b: list) -> list:
7575
"""
7676
Recursive function to calculate the product of two matrices, using the Strassen
7777
Algorithm. It only supports square matrices of any size that is a power of 2.
78-
78+
7979
Strassen's algorithm reduces the number of recursive multiplications needed to
8080
multiply two n x n matrices from the 8 required by the naive divide-and-conquer
8181
approach down to 7, at the cost of a few extra matrix additions/subtractions
8282
(which are cheaper, O(n^2), operations). Each matrix is split into four
8383
(n/2) x (n/2) quadrants, 7 products of quadrant combinations are computed
8484
recursively, and those products are combined with additions/subtractions to
8585
form the four quadrants of the result.
86-
86+
8787
Time complexity: O(n^log2(7)) ~= O(n^2.807), an improvement over the O(n^3) of
8888
the standard/naive matrix multiplication algorithm.
8989
Space complexity: O(n^2) for storing the intermediate quadrant matrices, plus
@@ -125,7 +125,7 @@ def strassen(matrix1: list, matrix2: list) -> list:
125125
until they are square matrices whose dimension is a power of 2 (required
126126
by the divide-and-conquer recursion in actual_strassen), performs the
127127
multiplication, then trims the padding back off the result.
128-
128+
129129
>>> strassen([[2,1,3],[3,4,6],[1,4,2],[7,6,7]], [[4,2,3,4],[2,1,1,1],[8,6,4,2]])
130130
[[34, 23, 19, 15], [68, 46, 37, 28], [28, 18, 15, 12], [96, 62, 55, 48]]
131131
>>> strassen([[3,7,5,6,9],[1,5,3,7,8],[1,4,4,5,7]], [[2,4],[5,2],[1,7],[5,5],[7,8]])

0 commit comments

Comments
 (0)