Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Dynamic Programming ( DP ) can provide optimal solution of the knapsack problem. In DP , we compute the solutions to the smaller problems and

Dynamic Programming (DP) can provide optimal solution of the knapsack problem. In DP, we compute the solutions to the smaller problems and store them in a table, to be reused later repeatedly to solve a larger problem.
For the knapsack problem given in Fig. 1, a typical DP table is shown below. We start with 0 items and 0 capacity of the knapsack and keep increasing them along rows and columns respectively. The first non-zero row is constructed assuming that only item 1 is available, while the next row assumes that items 1 and 2 are available, and so on. Similarly, the first non-zero column is filled assuming that the knapsack capacity is only 1 Kg, and so on.
Construct the DP table for the problem given in Fig. 1. Then use backtracking technique learned in the class, starting from the last cell, to determine which items shall be placed in the knapsack.
Solution:
Capacity (Kg)
Number of items 0123456789101112131415
00000000000000000
10000000000044444
20222222222246666
30224444444446688
40234555555556789
50234101213141515151515151515 solve in java
image text in transcribed

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

How To Build A Million Dollar Database

Authors: Michelle Bergquist

1st Edition

0615246842, 978-0615246840

More Books

Students also viewed these Databases questions

Question

Solve the following 1,4 3 2TT 5x- 1+ (15 x) dx 5X

Answered: 1 week ago