Question: Determine the time efficiency of the MFKnapsack recursive algorithm listed below. ALGORITHM MFKnapsack (i, j ) //Implements the memory function method for the knapsack problem

Determine the time efficiency of the MFKnapsack recursive algorithm listed below.

ALGORITHM MFKnapsack(i, j )

//Implements the memory function method for the knapsack problem

//Input: A nonnegative integer i indicating the number of the first

// items being considered and a nonnegative integer j indicating

// the knapsack capacity //Output: The value of an optimal feasible subset of the first i items //Note: Uses as global variables input arrays Weights[1..n], Values[1..n], //and table F [0..n, 0..W ] whose entries are initialized with ?1s except for //row 0 and column 0 initialized with 0s if F [i, j ] < 0

if j < Weights[i] value ? MFKnapsack(i ? 1, j )

else

value ? max(MFKnapsack(i ? 1, j ),

Values[i] + MFKnapsack(i ? 1, j ? Weights[i]))

F[i,j]?value

return F [i, j ]

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!