Skip to content
Official PYQ · 2004

GATE CS 2004 Q39 — Asymptotic Worst Case Time and Space Complexity

Explain with AI

Two matrices M1M_1 and M2M_2 are to be stored in arrays AA and BB 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 M1×M2M_1 \times M_2 will be

Choose one option
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 n×nn \times n matrices M1M_1 and M2M_2 using the standard matrix multiplication algorithm:

  • The number of scalar multiplications required is n3n^3.
  • The number of scalar additions required is n2(n−1)n^2(n-1).

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 M1M_1 in row-major and M2M_2 in column-major order minimizes cache misses—the theoretical asymptotic time complexity remains O(n3)O(n^3) 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.

Published
Report a correction
Keep exploringMore Asymptotic Worst Case Time and Space Complexity questions