I need to multiply two matrix using constant space. Note that the result should be stored at one of the matrix after operation. Printing the result without storing is trivial. Normally any standard algorithm defines a new matrix of the same size which stores all temporary as well as final result. It can be even optimised to use a single array. But cant think of any mechanism to do it in constant space. Intuitively this can be thought of as equivalent as finding out algorithm for multiplying two 2x2 matrix without using temporary variable?
Asked
Active
Viewed 179 times
0
-
Constant space it should be. Space requirement should not increase as the input size increases – user559150 Jul 30 '18 at 13:15
-
In one of the input matrix. Which one does not matter – user559150 Jul 30 '18 at 13:17
-
Please take the [tour] and visit the [help]. Also do not include unrelated tags such as C++ and C. Those are two unrelated languages. – Ron Jul 30 '18 at 13:19
-
@Ron C++ and C are unrelated? I would rather say that each push towards differing usage patterns. – Stéphane Gourichon Jul 30 '18 at 14:05
-
Which language, C or C++? In C++ you can create a Matrix class and use `std::vector` for the arrays. The C language doesn't support `std::vector` and you have to manage the memory yourself, as well as pass the capacity along with the arrays to functions. – Thomas Matthews Jul 30 '18 at 14:06
-
Language is irrelevant. A good algorithmic question, with the likely answer being _you can not_. PS: I don't see the reason to downvote. – user58697 Jul 30 '18 at 19:11
-
Possible duplicate of [Is there an algorithm to multiply square matrices in-place?](https://stackoverflow.com/questions/25450809/is-there-an-algorithm-to-multiply-square-matrices-in-place) – beaker Jul 31 '18 at 19:49