ProgrammingHard

For a matrix of size n x n with n = 500, which algorithm is correct and fast enough within 1 second for C multiplication?

  1. A. Naive loops with four nested levels, about 6 x 10^10 steps
  2. B. Naive triple loop, about 1.25 x 10^8 multiply-adds
  3. C. Recursive exponent loops that repeat each product n times, about 10^12 steps
  4. D. Multiplying every pair of rows, about 5 x 10^10 steps

Correct answer: B. Naive triple loop, about 1.25 x 10^8 multiply-adds

The standard triple loop does n^3 = 1.25 x 10^8 multiply-adds, which fits comfortably in a second in C. Any O(n^4) scheme gives about 6 x 10^10, far too slow.

More C Programming questions

Exams that ask this topic