Answer:
Follows are the code to this question:
MATRIX_CHAIN_MULTIPLY(A,s,i,j)//defining a method MATRIX_CHAIN_MULTIPLY that accepts 4 parameters
if(i == j)//use if block to check i and j value is equal
return A[i]//return array values
if(j == i+1)//use another if block to check j value is equal to incrementing value of i
return A[i]*A[j];//return multiplication of array
else//defining else block
x1 = MATRIX_CHAIN_MULTIPLY(A,s,i,S[i,j])//x1 variable to call above method
x2 = MATRIX_CHAIN_MULTIPLY(A,s,S[i,j]+1,j)//x2 variable to call above method
return B1*B2//return multiplication of method holding value
Step-by-step explanation:
Please find the attached file of the complete question:
In the code, a method "MATRIX_CHAIN_MULTIPLY" is declared, which accepts parameters and uses a conditional statement to check value, which can be defined as follows:
- In the first, if block, it checks the variable "i and j" value that is equal if it is true it will return an array.
- In the second if it checks variable j value is equal to incrementing the value of i, if this is true it will return multiplication of array.
- In the else block two-variable "x1, x2" is used that calls the above method and returns its multiplicating value.