Welcome back.
In the previous video we have seen that in this example which is given to us, we can multiply the three
matrices involved in these two ways.
Over here we are first multiplying the first and second matrix, and the output of this will be multiplied
with the third matrix.
Over here we are first multiplying the second and third matrices, and the output of this and the first
matrix are getting multiplied.
Now let's take a look at the number of multiplications involved in these two ways of multiplying the
three matrices.
Just so that we clearly understand what the question demands from us.
Now, to multiply these two matrices, we know that the number of multiplications involved is 20 into
ten into five.
That's equal to 1000 okay.
And the dimension of this matrix, once these two are multiplied will be 20 into five okay.
So we have a matrix of size 20 into five.
And when we multiply this matrix with this matrix over here the multiplications involved will be 20
into five into 30 okay.
So that would be equal to 3000.
And therefore the total number of multiplications involved is 1000 plus 3000.
Which is equal to 4000.
And again, notice we don't have any multiplications involved to reduce this part to a single matrix
because it's already a single matrix.
And that's why it's just zero.
So we could say that the number of multiplications involved is 1000 plus 3000 plus zero, which is equal
to 4000.
Now what about this way of multiplying the three matrices involved.
So initially we have one matrix.
So there's no multiplication involved to reduce this to a single matrix because it's already a single
matrix.
Now to multiply these two matrices the number of multiplications involved is ten into five into 30,
which is equal to 1500.
And the size of this matrix, once these two are multiplied, would be ten into 30.
Okay.
And to multiply these two matrices, which are of size 20 into ten and ten into 30, the number of multiplications
involved is 20 into ten into 30.
And that's equal to 6000.
So the total number of multiplications involved in the second way would be 1500 plus 6000, which is
equal to 7500.
Now notice over here we just had to do 4000 multiplications.
But in the second way we have to do almost double which is 7500 multiplications.
So in this case this is the most efficient way of multiplying the three matrices which are given to
us.
And we'll have to return this value.
So that would be the expected output.
All right.
So we have thoroughly understood the question at hand.
Now as always remember when you are given a coding interview question, it's very important that you
ask any clarifying questions that you may want to ask.
So a possible question that you could ask in this case is what if I am given an array with just one
element?
Now the issue with this is if there is just one element in the array which is given, you are not able
to form any matrix, right?
You need at least two elements to form a matrix.
And let's say the interviewer replies the array will have at least two elements.
All right.
So we have understood the question.
We've reviewed all that we need to know about matrix multiplication.
And we have also asked clarifying questions in the next video.
Let's build the intuition required to solve this problem.