11

Three N*N matrices A,B,C are given. C is the same as the product of A and B except that exactly one element is wrong. The naive algorithm to find it out requires N^3 time. Can we do faster than that?

helloflash
  • 2,457
  • 2
  • 15
  • 19
user2249675
  • 464
  • 3
  • 13

1 Answers1

12

Take a vector v = (1 1 1 1 ... 1)T, and calculate: u = Cv - A(Bv).

u is equal to (C-AB)v, and therefore it will have zeroes in all elements except one. The index of this element corresponds to the row index where C is different from AB. The value of the element (a) is the value of the nonzero element in C-AB.

To find the column index, you can repeat this with the vector v2 = (1 2 3 4 ... n)T. Now the value of the nonzero element is ac, where a is the value we calculated before and c is the column index.

Since we only do a few matrix*vector multiplications, the running time is O(n^2).

interjay
  • 107,303
  • 21
  • 270
  • 254