IAE Academy

ISRO CS 2023 Q.45: solution and answer

ISRO 2023 · CSQ.45 · 1 mark · MCQ

The complexity of matrix multiplication of two matrices A and B whose orders are m × n and n × p respectively is

  1. (A)

    O(m × p)

  2. (B)

    O(m × n² × p)

  3. (C)

    O(m × n × p²)

  4. (D)

    O(m × n × p)

See the question in the paper

Answer and solution

ANSWER

The complexity is , option (d).

Official answer: DSource: ISRO's revised and final answer key of 16 February 2024

  1. Let be and be . The product is an matrix.

  2. Each entry is , which takes multiplications and additions, so work per entry.

  3. There are entries, so the total work is multiplications, that is with the standard triple loop (over , , , running to , , respectively).

  4. Option (a), , only counts the entries and ignores the inner sum of length .

  5. Options (b) and (c) square or , which no loop in the algorithm does: each of the three loops runs once over its own range.

  6. So the complexity is , option (d).

KEY IDEA

Count the entries of the result () and multiply by the length of the inner sum for each entry (): three nested loops, each running once over its own dimension.

WATCH OUT FOR

Choosing because the result has entries, forgetting that every entry itself needs a sum of products; or squaring a dimension, which no loop does.

From the ISRO CS 2023 paper. Every question of this paper · The full paper (PDF, ISRO) · All 2 ISRO Complexity questions, with notes