Ex - 2
Ex - 2
P1 = A * (F - H)
P2 = (A + B) * H
P3 = (C + D) * E
P4 = D * (G - E)
P5 = (A + D) * (E + H)
P6 = (B - D) * (G + H)
P7 = (A - C) * (E + F)
o These products are then used to compute the four submatrices of the
result matrix CCC:
C11 = P5 + P4 - P2+ P6
C12 = P1 + P2
C21 = P3 + P4
C22 = P1 + P5 - P3 - P7
o The recursion stops when the matrices are reduced to a size of 1×1. At
this point, a simple multiplication is performed.
PSEUDOCODE :
Function split(matrix):
row, col = dimensions of matrix
row2, col2 = row // 2, col // 2
Return matrix[:row2, :col2], matrix[:row2, col2:],
matrix[row2:, :col2], matrix[row2:, col2:]
p1 = strassen(a, f - h)
p2 = strassen(a + b, h)
p3 = strassen(c + d, e)
p4 = strassen(d, g - e)
p5 = strassen(a + d, e + h)
p6 = strassen(b - d, g + h)
p7 = strassen(a - c, e + f)
c11 = p5 + p4 - p2 + p6
c12 = p1 + p2
c21 = p3 + p4
c22 = p1 + p5 - p3 - p7
Return c
Matrix A = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14,
15, 16]]
Matrix B = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14,
15, 16]]
Result Matrix C = strassen(A, B)
Print C
Print execution time