1 answer

Dynamic programming

Question:

(a) Give a dynamicprogramming solution to the 0-1 knapsack problem that runs in O(nW)time, where n is the number of items and W is the maximum weight ofitems thatthe thief can put in the knapsack.
(b) Apply your algorithm to the problem when n = 4, W = 10, thevalue of items are v1 = 20, v2 = 60, v3 = 80, v4 = 100, and theweight items are w1 = 2, w2 = 4, w3 =5, w4 = 7.

Answers

A)0-1 Knapsack Problem (Dynamic-programmingsolution)
Given
A dynamic programming solution to the 0-1 knapsackproblem that runs in O(nW) time, where n is a number of items and Wis the maximum weightof items that the thief can put in hisknapsack. Hint: for i in [0..n] and u in [0..W], letV[i,u] be the maximum value that the thief couldsteal assumingthat he may selected only among the first I objects and that he hasa knapsack of size u.So we have to dothepseudocodefor a dynamic programming algorithm to solve thisproblem. our algorithm need not determine the actual items tobe stolen, just the maximumvalue.
The dynamic programming solution to the 0/1 knapsack is similar innature to the Longest Common Subsequence problem, and others indynamicprogramming. A table is created, representing thechoice of items (in ascending order of weights w1εwn), and agradually increasing size ofknapsack, w. The first row isinitialized to 0, as the knapsack cannot hold any items.

Thefirst column is initialized to 0, as there are noitems to put inthe knapsack. The cells are calculated using thefollowing formul
Algorithm Dynamic 1/0 Knapsack
Input: Two sequences of v = <v1,âεvn> and w= <w1âεwn>, n (number of items), W (maximumweight)
Output: the optimal value of the knapsack (not the actualitems)
for w = 0 to W do
V[0,w] = 0
end-for
for i = 1 to n do
V[i,0] = 0
for w = 1 to W do
if wi ï‚ε w then
if vi + V[i-1,w-wi] > V[i-1,w] then
V[i,w] = vi + V[i-1,w-wi]
else
V[i,w] = V[i-1,w]
end-if
else
V[i,w] = V[i-1,w]
end-if
end-for
end-for
return V[n,W]

b)
The following example has the values and weights given below, witha knapsack capacity of 5. For those cells in whichwiÂ>Âw, thevalue to the left is taken,represented by the  symbol. For the cellsin which wiÂï‚£Âw areassigned the maximum of the itemvalue vi (taking the item)plus the V table one column to the left and ui rows up (thecalculated value of the items in a knapsack made smaller by vibytaking the item), and the value to the left (not taking theitem).


i
Value (vi)
Weight (wi)
1
60
1
2
100
2
3
120
3

Knapsack capacity (w)

Item 1
(v1 = 20, w1 = 2)
Item 2
(v2 = 60, w2 = 4)
Item 3
(v3 = 80, w3 = 5)
Item 4(v4=100,w4=7)0
0
0
0
0
1
0
max(60+0,0) = 60
 60
 60
2
0
max(60+0,0) = 60
max(100+0,60) = 100
 100
3
0
max(60+0,0) = 60
max(100+60,60) = 160
max(120+0,160) = 160
4
0
max(60+0,0) = 60
max(100+60,60) = 160
max(120+60,160) = 180
5
0
max(60+0,0) = 60
max(100+60,60) = 160
max(120+100,160) = 220ITS HELPFUL TO YOU.........
.

Similar Solved Questions

1 answer
8. A health record has been subpoenaed and a court order accompanies it. The physician has...
8. A health record has been subpoenaed and a court order accompanies it. The physician has removed important parts of the record. You know that this information is missing. The office sends you to court as the keeper of the record. You must testify about the completeness of the record. What are you ...
1 answer
A. It is 2016, you've just graduated college, and you are contemplating your lifetime budget. You...
a. It is 2016, you've just graduated college, and you are contemplating your lifetime budget. You think your general pre-retirement living expenses will average around $50,000 a year. For the next 8 years, you will rent an apartment for $16,000 a year (assume end-of-period payments). At the end ...
1 answer
The following table gives the joint probability distribution between employment status and college graduation among those...
The following table gives the joint probability distribution between employment status and college graduation among those either employed or looking for work (unemployed) in the working age U.S. population Unemployed (Y-0) 0.0426 0.0103 0.0529 Employed Non-college grads (X- 0) College grads (X= 1) T...
1 answer
#6. The level of lead in the blood was determined for a sample of 152 male and 86 female hazardous- waste workers resulting in mean t standard error of 5.5 t 0.3 for the men and 3.8 ± 0.2 for the...
#6. The level of lead in the blood was determined for a sample of 152 male and 86 female hazardous- waste workers resulting in mean t standard error of 5.5 t 0.3 for the men and 3.8 ± 0.2 for the women. (a) Provide a 92% CI on the difference between the true average blood levels for male and ...
1 answer
Express f in terms of unit step functions. fo) 1- 3 t-(t-1)2(t-1)-T(t-4) O t2(t-4) O t-1+...
Express f in terms of unit step functions. fo) 1- 3 t-(t-1)2(t-1)-T(t-4) O t2(t-4) O t-1+ (t-4) O ti(t-1) _ (t-1)- (t-4) Find f(t) and Xset f(t). (Enter your answer in terms of s.) Xiet f(t))...
1 answer
Dr. Burke, a urologist, performs a destruction of a penile lesion of a patient. Are all...
Dr. Burke, a urologist, performs a destruction of a penile lesion of a patient. Are all destruction codes the same? if not, state what the differences are based on....
1 answer
Distributions Worksheet At the organizational meeting of AID, Inc., Ashley, Ian, and Dallas, acting in their...
Distributions Worksheet At the organizational meeting of AID, Inc., Ashley, Ian, and Dallas, acting in their capacity as the Board of Directors, approved the issuance of 1,000 shares of $1 par common stock to each of them at a price of $5 per share (for a total issuance of 3,000 shares). Each of the...
1 answer
[0/2 Points) DETAILS PREVIOUS ANSWERS LARCOLALG10 1.3.055. MY NOTES ASK YOUR TEACHER PRACTICE ANOTHER A nursery...
[0/2 Points) DETAILS PREVIOUS ANSWERS LARCOLALG10 1.3.055. MY NOTES ASK YOUR TEACHER PRACTICE ANOTHER A nursery has 560,000 of inventory in dogwood trees and red maple trees. The profit on a dogwood tree and the profit on a red maple trees 1. The profit for the entire stock 201. How much invested in...
1 answer
Weygandt, Accounting Principles, 12e Question S ZUMBRUNN COMPANY Income Statement For the Year Ended December 31,...
Weygandt, Accounting Principles, 12e Question S ZUMBRUNN COMPANY Income Statement For the Year Ended December 31, 2017 Service revenue Operating expenses, excluding depreciation Depreciation expense Loss on disposal of equipment Income before income taxes Income tax expense Net income 54,500 26,000 ...
1 answer
Question 28 (4 points) A plant operates on Just-in-Time/lean principles. The total production requirements for next...
Question 28 (4 points) A plant operates on Just-in-Time/lean principles. The total production requirements for next three days are 3000 units of X, 300 units of Y, and 1200 units of Z. Assume that the plant has enough capacity to produce all of the units within the three-day period. Which one of the...
1 answer
Please do a-e if possible, you may use matlab too. 1. (20 points) Design an FIR...
Please do a-e if possible, you may use matlab too. 1. (20 points) Design an FIR bandstop filter with low cutoff frequency fi = 3565 Hz high cutoff frequency fn = 7325 Hz sampling rate fsampling = 22000 Hz length N=17 Blackman window. (a) Find the unscaled impulse response hBs(k) of the filter for 0...
1 answer
/3 y13 6. Suppose that a firm has a production function given by: q-Ks a) Derive...
/3 y13 6. Suppose that a firm has a production function given by: q-Ks a) Derive the conditional factor demands. b) Derive the cost function. c) Derive the supply function. d) Derive the input demand functions....
1 answer
Will rate lifesaver the right answer.. thank you
QuestionDetails:A narrow U-shaped glass tube withopen ends is filled with 25.0 of oil (of specific gravity 0.800) and25.0 of water on opposite sides, with abarrierseparating the liquids.What would the heights be if theoil's density were much less than that of water?So far, I know that water...
1 answer
Provide mechanism type ne sono Et3N (cat) sto se H20 Ph Ph1
Provide mechanism type ne sono Et3N (cat) sto se H20 Ph Ph1...
1 answer
Vino Veritas Company, a U.S.-based importer of wines and spirits, placed an order with a French...
Vino Veritas Company, a U.S.-based importer of wines and spirits, placed an order with a French supplier for 2,200 cases of wine at a price of 260 euros per case. The total purchase price is 572,000 euros. Relevant exchange rates for the euro are as follows: Date Spot Rate Forward Rate to October...
1 answer
I am told to create a fillArray method that will read integers from the file "data.txt"...
I am told to create a fillArray method that will read integers from the file "data.txt" and store them in the array. I'm told to assume that the file has no more than 100 items in it. This is what I have so far: public void fillArray() { int curVal;    Scanner input = null; try...