a) Fill the cost table m and path matrix P for computing the product of following sequence of matrices. Show all the steps of your computation. [6] N = 5, r0 =2, r1 =3,r2 =5, r3 =2, r4 =4, r5 =3, code example

Example: matrix chain multiplication

minimum_multiplication(n: integer; d: array(0..n))
        M: array(1..n, 1..n) := (others => 0);

        for diagonal in 1 .. n-1 loop 
            for i in 1 .. n - diagonal loop 
                j := i + diagonal;

                min := integer'last;
                for k in i .. j-1 loop
                    current := M[i, k] + M[k+1, j] + d(i-1)*d(k)*d(j) 
                    if current < min then
                        min := current
                    end if
                end loop
                M[i, j] := min
            end loop
        end loop

Tags:

Misc Example