1
00:00:00,140 --> 00:00:01,160
Welcome back.

2
00:00:01,190 --> 00:00:07,490
In the previous video we have seen that in this example which is given to us, we can multiply the three

3
00:00:07,490 --> 00:00:10,130
matrices involved in these two ways.

4
00:00:10,160 --> 00:00:17,090
Over here we are first multiplying the first and second matrix, and the output of this will be multiplied

5
00:00:17,090 --> 00:00:18,440
with the third matrix.

6
00:00:18,470 --> 00:00:25,850
Over here we are first multiplying the second and third matrices, and the output of this and the first

7
00:00:25,850 --> 00:00:27,710
matrix are getting multiplied.

8
00:00:27,740 --> 00:00:33,560
Now let's take a look at the number of multiplications involved in these two ways of multiplying the

9
00:00:33,560 --> 00:00:34,430
three matrices.

10
00:00:34,430 --> 00:00:38,570
Just so that we clearly understand what the question demands from us.

11
00:00:38,600 --> 00:00:45,530
Now, to multiply these two matrices, we know that the number of multiplications involved is 20 into

12
00:00:45,530 --> 00:00:46,790
ten into five.

13
00:00:46,790 --> 00:00:49,610
That's equal to 1000 okay.

14
00:00:49,610 --> 00:00:57,560
And the dimension of this matrix, once these two are multiplied will be 20 into five okay.

15
00:00:57,560 --> 00:01:00,950
So we have a matrix of size 20 into five.

16
00:01:00,950 --> 00:01:08,120
And when we multiply this matrix with this matrix over here the multiplications involved will be 20

17
00:01:08,120 --> 00:01:10,340
into five into 30 okay.

18
00:01:10,340 --> 00:01:12,860
So that would be equal to 3000.

19
00:01:12,860 --> 00:01:19,970
And therefore the total number of multiplications involved is 1000 plus 3000.

20
00:01:20,780 --> 00:01:22,760
Which is equal to 4000.

21
00:01:22,760 --> 00:01:29,180
And again, notice we don't have any multiplications involved to reduce this part to a single matrix

22
00:01:29,180 --> 00:01:31,130
because it's already a single matrix.

23
00:01:31,130 --> 00:01:32,660
And that's why it's just zero.

24
00:01:32,660 --> 00:01:39,860
So we could say that the number of multiplications involved is 1000 plus 3000 plus zero, which is equal

25
00:01:39,860 --> 00:01:40,970
to 4000.

26
00:01:40,970 --> 00:01:44,870
Now what about this way of multiplying the three matrices involved.

27
00:01:44,870 --> 00:01:47,030
So initially we have one matrix.

28
00:01:47,030 --> 00:01:52,730
So there's no multiplication involved to reduce this to a single matrix because it's already a single

29
00:01:52,730 --> 00:01:53,300
matrix.

30
00:01:53,300 --> 00:02:00,530
Now to multiply these two matrices the number of multiplications involved is ten into five into 30,

31
00:02:00,530 --> 00:02:02,900
which is equal to 1500.

32
00:02:02,900 --> 00:02:09,020
And the size of this matrix, once these two are multiplied, would be ten into 30.

33
00:02:09,140 --> 00:02:09,800
Okay.

34
00:02:09,800 --> 00:02:17,870
And to multiply these two matrices, which are of size 20 into ten and ten into 30, the number of multiplications

35
00:02:17,870 --> 00:02:20,840
involved is 20 into ten into 30.

36
00:02:21,440 --> 00:02:23,930
And that's equal to 6000.

37
00:02:23,930 --> 00:02:31,670
So the total number of multiplications involved in the second way would be 1500 plus 6000, which is

38
00:02:31,670 --> 00:02:34,010
equal to 7500.

39
00:02:34,010 --> 00:02:38,090
Now notice over here we just had to do 4000 multiplications.

40
00:02:38,090 --> 00:02:44,240
But in the second way we have to do almost double which is 7500 multiplications.

41
00:02:44,240 --> 00:02:50,780
So in this case this is the most efficient way of multiplying the three matrices which are given to

42
00:02:50,780 --> 00:02:51,080
us.

43
00:02:51,080 --> 00:02:53,420
And we'll have to return this value.

44
00:02:53,420 --> 00:02:55,520
So that would be the expected output.

45
00:02:55,520 --> 00:02:55,970
All right.

46
00:02:55,970 --> 00:02:59,420
So we have thoroughly understood the question at hand.

47
00:02:59,420 --> 00:03:06,080
Now as always remember when you are given a coding interview question, it's very important that you

48
00:03:06,080 --> 00:03:09,440
ask any clarifying questions that you may want to ask.

49
00:03:09,440 --> 00:03:16,340
So a possible question that you could ask in this case is what if I am given an array with just one

50
00:03:16,340 --> 00:03:16,880
element?

51
00:03:16,880 --> 00:03:22,430
Now the issue with this is if there is just one element in the array which is given, you are not able

52
00:03:22,430 --> 00:03:23,840
to form any matrix, right?

53
00:03:23,840 --> 00:03:26,960
You need at least two elements to form a matrix.

54
00:03:26,960 --> 00:03:32,900
And let's say the interviewer replies the array will have at least two elements.

55
00:03:33,260 --> 00:03:33,860
All right.

56
00:03:33,860 --> 00:03:35,600
So we have understood the question.

57
00:03:35,600 --> 00:03:39,770
We've reviewed all that we need to know about matrix multiplication.

58
00:03:39,770 --> 00:03:43,640
And we have also asked clarifying questions in the next video.

59
00:03:43,640 --> 00:03:47,660
Let's build the intuition required to solve this problem.
