Two matrices and are to be stored in arrays and 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 will be
View worked solution
Answer: D
The time complexity of an algorithm refers to the asymptotic number of basic operations (such as additions and multiplications) it performs as a function of the input size.
For multiplying two matrices and using the standard matrix multiplication algorithm:
- The number of scalar multiplications required is .
- The number of scalar additions required is .
This count of operations depends solely on the mathematical definition of matrix multiplication and is completely independent of how the matrices are laid out in memory (whether in row-major or column-major order).
Note on Cache Performance:
While the physical execution time (wall-clock time) can be influenced by cache locality—where accessing in row-major and in column-major order minimizes cache misses—the theoretical asymptotic time complexity remains regardless of the storage scheme.
Therefore, the time complexity is independent of the storage scheme.
Free practice · Your answers on this page are not saved.
