Two matrices $M_1$ and $M_2$ are to be stored in arrays $A$ and $B$ respectively. Each array can be stored either in row-major or column-major order in contiguous memory locations. The time complexity of an algorithm to compute $M_1×M_2$ will be
- best if $A$ is in row-major, and $B$ is in column-major order
- best if both are in row-major order
- best if both are in column-major order
- independent of the storage scheme
My Try :
Here time complexity is asked, for each access of array element it will be constant,
So the time complexity will not depend upon storage. If at all program execution time is asked
Can you please explain, does storage scheme matter in multiplication of two matrices ?
The Big-O time complexity is not affected if accessing a single entry is $O(1)$ (which would not be the case for array stored in one-dimensional singly-linked lists, for example). Regarding the constant hidden in the big O, opton 1 might be best because it improves cache performance on typical CPUs of today. So you are right if you consider 4 as correct answer to the question - as asked