Professional Documents
Culture Documents
MC170401669
Q#1: Consider the following five matrices A, B, C, D and E along with their dimensions;
A B C D E
(6×5) (5×1) (1×7) (7×4) (4×2)
Determine the Optimal Multiplication Order for above matrices using Dynamic Programming approach
and also present the sequence (i.e. optimal order) in Binary Tree.
=0+0+6.5.1
=30
=0+0+5.1.7
=35
=0+0+1.7.4
=28
=0+0+7.4.2=56
0 30
0 35
0 28
0 56
0
Now we will compute the second super diagonal. We will need two possible values for K but we wii
choose the minimum value.
= 0+35+6.5.7 = 245
= 30+0+6.1.7 = 72
= 0+28+5.1.4 = 48
= 35+0+4.1.7 = 63
For m [C, E]
= 0+56+1.7.4 = 84
0 30 72
0 35 48
0 28 36
0 56
0
The values of k will increases:
=30+28+6.1.7
=100
=72+0+6.7.4
=240
m [B, E] = 0+36+5.1.2
=46
= 35+56+5.7.2 = 161
=48+0+5.4.2 = 88
Minimum m [B, E] = 46 at K =3
0 30 72 100
0 35 48 46
0 28 36
0 56
0
=0+46+6.5.2 = 106
= 30+36+6.1.2 = 78
m [A, E] = m [ A, C] + m [D, E] + P0. P3. P5
= 72+56+6.7.2 =212
=100+0+6.4.2 =148
Minimum m [A, E] = 78 at K= 3
0 30 72 100 78
0 0 35 48 46
0 0 0 28 36
0 0 0 0 56
0 0 0 0 0
0 1 5 8 10
0 0 2 6 9
0 0 0 3 7
0 0 0 0 4
0 0 0 0 0
0 1 1 3 3
0 0 2 3 3
0 0 0 3 3
0 0 0 0 4
0 0 0 0 0
Multiplying the five matrices and the optimal order for multiplication is
((A(BC)) (DE))
1 4
D E
A 2
B C
Q#2:
A) List down In and Out- Degrees of vertices of the given directed graph.
A) How many cycles are there in the given directed graph, list all of them. Further, is there
any Hamiltonian cycle in it (yes/no)?
ANS: there are five cycles in the given directed graph.
A A
A B
A C
B C
C B
No, this graph is not Hamiltonian, because there is no vertex visits exactly once.