Professional Documents
Culture Documents
02
Total Marks: 20
Instructions
Please read the following instructions carefully before submitting assignment:
It should be clear that your assignment will not get any credit (zero marks) if:
o
The assignment is copied (from other student or ditto copy from any other
source).
Objective
Submission
You are required to submit your solution through LMS as MS Word document.
Problem Statement:
Consider the following four matrices A1, A2, A3, and A4 along with their dimensions.
A1 = 4*3
A2 = 3*2
A3 = 2*3
A4 = 3*5
Questions:
1. Determine the optimal multiplication order for above matrices A1, A2, A3, and A4
using Dynamic Programming approach.
Answer:
four matrices A1, A2, A3, and A4 along with their dimensions.
A1 = 4*3
A2 = 3*2
A3 = 2*3
A4 = 3*5
Four Mtrices
m[1, 1]
m[1,2]
m[2,2]
m[2,3]
m[3,3]
m[3,4]
m[4,4]
(43)
A2
(32)
A3
(23)
A4
(35)
P0 4
P1 3
P2 2
P3 3
P4 5
We will compute the entries of the m matrix starting with the base condition. We first fill that
main
diagonal:
0
0
0
0
Next, we compute the entries in the first super diagonal, i.e., the diagonal above the main
diagonal:
m[1, 2] = m[1, 1] +m[2, 2] + p0 p1 p2 = 0 + 0 + 4 3 2 = 24
m[2, 3] = m[2, 2] +m[3, 3] + p1 p2 p3 = 0 + 0 + 3 2 3 = 18
m[3, 4] = m[3, 3] +m[4, 4] + p2 p3 p4 = 0 + 0 + 2 3 5 = 30
The matrix m now looks as follows:
0
24
0
18
0
30
0
We now proceed to the second super diagonal. This time, however, we will need to try two
possible
values for k. For example, there are two possible splits for computing m[1, 3]; we will choose
the split
that yields the minimum:
m[1, 3] = m[1, 1] +m[2, 3] + p0 p1 p3 = 0 + 18 + 4 3 3 = 54
m[1, 3] = m[1, 2] +m[3, 3] + p0 p2 p3 = 24 + 0 + 4 2 3 = 48
the minimum m[1, 3] = 48 occurs with k = 2
18
60
30
0
We repeat the process for the remaining diagonals. However, the number of possible splits
(values of k)
increases:
m[1, 4] = m[1, 1] +m[2, 4] + p0 p1 p4 = 0 + 60 + 4 3 5 = 120
m[1, 4] = m[1, 2] +m[3, 4] + p0 p2 p4 = 24 + 30 + 4 2 5 = 94
m[1, 4] = m[1, 3] +m[4, 4] + p0 p3 p4 = 48 + 0 + 4 3 5 = 108
minimum m[1, 4] = 94 at k = 2
The matrix m at this stage is:
0
24
48
94
0
18
60
30
0
3
0
3
0
A1
A2 A3
A4