Write a function that will accept two integer matrices A and B by reference parameters, and two integers i and j as a value parameter. The function will return an integer m, which is the (i,j)-th coefficient of matrix denoted by A*B (multiplication of A and B). For example, if M = A*B, the function will return m, which is equal to M[i][j].
Explain the time complexity of this function inside of the code as a comment.
FUNCTION:
int func(int i, int j)
{
// A is a matrix with r1 rows and c1 columns
// B is a matrix with r2 rows and c2 columns
// c1 should be equal to r2 for matrix multiplication
// The worst case time complexity is O( n )
// because there is only 1 for loop
int m = 0;
for(int x = 0;x < c1;x++)
{
m += A[i][x] * B[x][j];
}
return m;
}
Get Answers For Free
Most questions answered within 1 hours.