Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This exercise is to gain an hands - on understanding of implementing a Dynamic Programming algorithm from the recursive formulation. Consider the 0 / 1

This exercise is to gain an hands-on understanding of implementing a Dynamic Programming
algorithm from the recursive formulation. Consider the 0/1 Knapsack problem and the recursive
formulation developed in Section 6.6. Your pseudocodes and implementations below should
faithfully follow this recursive formulation.
1. Give pseudocode for a DP algorithm (i.e., iterative, bottom-up).
2. Give pseudocode for a recursive (i.e., top-down) algorithm. Your recursive algorithm should
have two versions: the first one, without memoization and the second, with memoization.
That is, you should give two different pseudocodes, one for each version.
3. Implement all your pseudocodes in Python (preferred) or C++(less preferred).
4. Run all your algorithms on the following input for the knapsack problem. Let the number
of items, n =20 and let knapsack capacity be m =200. Each of the item gets a random
integer weight from 1 to 100. Run at least 10 instances of the above input, where in each
instance n and m are the same, but the weights of the items are newly generated randomly
in each instance.
5. Compare the run times of the three implementations (one iterative and the two recursive)
on all the inputs. Present your results in a table.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions