Question: Consider the following two algorithms that navely compute the sum and product of two n x n matrices. product(A,B): sum (A,B): for i= [0,
Consider the following two algorithms that navely compute the sum and product of two n x n matrices. product(A,B): sum (A,B): for i= [0, n): for j [0, n): for i = [0,n): C[i,j] A[i, j]+ Bli, j] end for end for return C = for j = [0, n): C[i,j] = add{A[i, k] B[k,j] : ke [0, n)} end for end for return C Assuming that adding and multiplying matrix elements can be carried out in O(1) time, and add will add the elements of a set 5 in O(S) time: (a) Give an asymptotic upper bound, in terms of n, for the running time of sum. (b) Give an asymptotic upper bound, in terms of n, for the running time of product. (2 marks) (2 marks)
Step by Step Solution
3.35 Rating (167 Votes )
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
