0

How can I find out the time complexity for the brute-force implementation of matrix multiplication for:

  1. Two square matrices ($n \times n$),
  2. Two rectangular matrices ($m \times n$) and ($n \times r$)?
David Richerby
  • 81,689
  • 26
  • 141
  • 235
  • @DavidRicherby I don't see any discernible similarity in your suggestion to this post other than the fact that your post is a general question that could (ostensibly) be applied to any analysis of algorithms post (if it could be applied to any specific post which I don't think it could). – Jared Oct 04 '14 at 07:08
  • 2
    @Jared The very first answer to the question I linked shows you how to calculate the running time of a couple of nested for-loops. Assuming the asker knows how to multiply two matrices, the question is exactly, "How do I calculate the running time of three nested for-loops." – David Richerby Oct 04 '14 at 07:28
  • @DavidRicherby The question is not "How do I calculate the running time of three nested for-loops", it's what is the complexity of matrix multiplication. If you want to contribute then say the following: multiplying an $(m\times n)\times (n \times r)$ is equivalent to finding the run time of three nested loops where the loops are $m$, $n$, and $r$ and explain to the poster why it is such--as I did. – Jared Oct 04 '14 at 07:34
  • 2
    @Jared The question is about "the time complexity for the brute-force implementation of matrix multiplication." Brute-force matrix multiplication is three nested for-loops. We already have an answer on the site that explains in some detail how to do compute the running time of nested for-loops and there is no value in duplicating that. – David Richerby Oct 04 '14 at 08:25
  • @DavidRicherby OK, I believe you when you say that there are better algorithms (above $\mathcal{O}(n^3)$ for computing matrix multiplication. But if you want to help the OP, then you should explain two things: 1) why is brute force approach is essentially $\mathcal{O}(n^3)$ and 2) how can you improve that (not reference some abstract for-loop explanation that doesn't deal with matrix multiplication). – Jared Oct 04 '14 at 08:36
  • 2
    @Jared The question asks about the time complexity of a very specific algorithm. It does not ask for a comparison between that algorithm and other ones. – David Richerby Oct 04 '14 at 08:38
  • @Jared The OP uses "time complexity" where they mean "asymptotic runtime". (Also note that some of your $O$ should be $\Omega$.) – Raphael Oct 04 '14 at 08:42
  • @Raphael I would just like, since you think my answer is so bad, for you to at least point the OP toward your answer in where he can find what he (or she) is looking for...to me that's what is missing here. – Jared Oct 04 '14 at 09:47
  • 1
    @Jared David already did that, and a link to that question is still prominent at the top. The top-voted answer there includes examples for nested loops, and there are several more examples. The naive matrix multiplication algorithm (as stated by the OP) is neither special, nor hard to analyse. (The complexity of the problem matrix multiplication is, of course, open.) – Raphael Oct 04 '14 at 12:52
  • @Jared Also, please be nice. This is a moderator warning. The next time I see you throwing around insults, I'll return a suspension your way. – Raphael Oct 04 '14 at 12:53

0 Answers0