Question: Considering the DYNAMIC programming algorithm for matrix chain multiplication is the following: (Python code): def MatrixChainOrder(p, n): m = [[0 for x in range(n)] for

Considering the DYNAMIC programming algorithm for matrix chain multiplication is the following:

(Python code):

def MatrixChainOrder(p, n):

m = [[0 for x in range(n)] for x in range(n)]

for i in range(1, n):

m[i][i] = 0

for L in range(2, n):

for i in range(1, n-L+1):

j = i+L-1

m[i][j] = float('inf')

for k in range(i, j):

q = m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j]

if q < m[i][j]:

m[i][j] = q

return m[1][n-1]

How would one tweak it, to change it to a GREEDY algorithm instead?

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 Databases Questions!