GATE / CS ARCHIVE

GATE CSE 2004 / QUESTION 39

Matrix layout and asymptotic multiplication cost

Algorithms · Asymptotic Analysis & Recurrences · Full GATE CSE 2004 paper

GATE 2004, Q39 2 marks · MCQ
Report issue

Asymptotic Analysis & Recurrences

Question 39, GATE 2004: Matrices M1,M2 are stored in arrays A,B respectively. Each may use row-major or column-major contiguous storage. How does this affect the time complexity of a fixed algorithm computing M1×M2?
Options:
(A) Best when A is row-major and B column-major
(B) Best when both are row-major
(C) Best when both are column-major
(D) Independent of storage scheme
Question 39, GATE 2004: Matrices M1,M2 are stored in arrays A,B respectively. Each may use row-major or column-major contiguous storage. How does this affect the time complexity of a fixed algorithm computing M1×M2?
Options:
(A) Best when A is row-major and B column-major
(B) Best when both are row-major
(C) Best when both are column-major
(D) Independent of storage scheme
Tap to enlarge
Your answer
Answer & solution

Answer: D under a unit-cost RAM model (no official key was published)

1. Changing row-major to column-major storage changes the address formula, not the number of arithmetic operations or constant-time element accesses. Thus asymptotic running time for a fixed multiplication algorithm is independent of the layout, D.

2. For the usual i,j,k loop order, A-row-major/B-column-major can improve locality and elapsed time, but that is a cache-performance distinction rather than an asymptotic RAM-operation count.

3. Teaching check: For an r×c row-major array, address(i,j) uses ic+j; column-major uses jr+i. Both formulas take constant time under a unit-cost RAM model. Cache misses may differ dramatically, but that does not by itself alter a fixed algorithm’s asymptotic arithmetic/access count.

Original paper, page 5