Question: ou are given a sequence of matrices A 0 , A 1 , . . . , A i , . . . , A

ou are given a sequence of matrices A0, A1,..., A i ,..., A n where each matrix A i has
dimensions p i1 p i . Your task is to determine the minimum number of scalar multiplications
needed to multiply the entire sequence of matrices using a divide-and-conquer approach
Input: an array P of size n +1 where P [i] represents the number of rows in matrix A i and
P [i +1] represents the number of columns in matrix A i
Output: The minimum number of scalar multiplications required to multiply the entire chain
of matrices.
Example:
Input: P =[10,30,5,60]
Explanation: you need to multiply 3 matrices A1(1030), A 2(305), A3(560)
There are two possible ways to parenthesize the matrix multiplication:
(A1 A2) A3
First multiply A1(1030) A 2(305), this requires 10305=1500 scalar
multiplications
Then multiply, A3(560), this requires 10560=3000 scalar multiplications
Total Cost: 1500+3000=4500
A 1(A2 A3)
First multiply A2(305) A3(560), this requires 30560=9000 scalar
multiplications
Then multiply, A1(1030), this requires 103060=18000 scalar multi-
plications
Total Cost: 9000+18000=27000
Output: The minimum cost of matrix multiplication is 4500 scalar multiplications cor-
responding to (A1 A2) A

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!