TITLE: Calculating the number of operations in matrix multiplication
QUESTION [20 upvotes]: Is there a formula to calculate the number of multiplications that take place when multiplying 2 matrices? For example
$$\begin{pmatrix}1&2\\3&4\end{pmatrix}
\times
\begin{pmatrix}5&6\\7&8\end{pmatrix} 
=
\text{8 multiplications and 4 additions}
$$

REPLY [8 votes]: I would like to give a simple answer for square, $n$ x $n$ matrices using the standard matrix multiplication algorithm.
Say you have two square matrices $A$ and $B$. Computing element $a_{ij}$ of $AB$ requires taking the dot product of row $i$ in $A$ and column $j$ in B. Computing the dot product requires $n$ multiplications and $n-1$ additions. Since there are $n^2$ elements, the dot product must be computed $n^2$ times. 
Thus the total number of operations is $n^2(n+(n-1))=2n^3-n^2 = O(n^3).$