Question

Apply the top-down (i.e., memory function) dynamic programming algorithm to the following instance of the knapsack problem. Input your results in the table shown below. For empty cells, input a single minus sign (-) into the cell.

item weight value 1 3 $25 2 2 $20 3 1 $15 14 4 $40 5 5 $50 and capacity W = 6.

Warning: When filling in the table below with your answers, be sure to type the number in each cell, with no decimal points or leading zeros or spaces. For example, if a cell should contain a value of 0, just type "0" and not "0.0" or "00" or " 0". Likewise, if a cell should contain a value of 5, just type "5" and not "5.0" or "05" or "05.0." For this problem, if you add a leading zero or a decimal, Canvas will mark answers as incorrect (even if they're numerically equal to the correct answer). Remember, to indicate a cell is empty, type one single minus sign: "-".

Answer: capacity 1 2 3 4 5 6 lo 10 1 2 3 4 5

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Sol)

If take V as a table, i and j as a row and column value then the value of

V[i, j] = max{ v[ i-1, j ] , v[ i-1 , j - w[ i ] + p[ i ] }

here, w[ i ] = weight of an object i

p[ i ] = profit/value of an object i

Initially we dont include any object, no profit will be gained so, we fill the first row with all zeros.

then calculate the value of each cell by using above formula.

Value(p) weight(w) i

capacity( j )

0 1 2 3 4 5 6
0 0 0 0 0 0 0 0
25 3 1 0 0 0 25 25 25 25
20 2 2 0 0 20 25 25 45 45
15 1 3 0 15 20 35 40 45 60
40 4 4 0 15 20 35 40 55 60
50 5 5 0 15 20 35 40 55 65

So, the answer table is :

i

capacity( j )

0 1 2 3 4 5 6
0 0 0 0 0 0 0 0
1 0 0 0 25 25 25 25
2 0 0 20 25 25 45 45
3 0 15 20 35 40 45 60
4 0 15 20 35 40 55 60
5 0 15 20 35 40 55 65

If we want to know which items are included in the bag

we start with maximum profit 65, 65 is generated in 5th row itself, so we include item 5

then we substract value of item5(50) from 65.

65 - 50 = 15.

15 is generated in 3rd row so we include item 3.

then we substract value of item3(15) from 15.

we get 0, no item is there, so we stop the process.

so, only item3 and item 5 (00101) will be included in the bag to get maximum profit value.

Add a comment
Know the answer?
Add Answer to:
Apply the top-down (i.e., memory function) dynamic programming algorithm to the following instance of the knapsack...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1. Apply the dynamic programming algorithm discussed in class to solve the knapsack problem. (10 points)...

    1. Apply the dynamic programming algorithm discussed in class to solve the knapsack problem. (10 points) a. Show the completed table. b. Which items are included in the final configuration of the knapsack? c. What is the maximum value that can fit in the knapsack using a configuration of these items? item 1 2. 3 4 weight 3 2 value $25 $20 $15 1 capacity W = 6. 4 5 $40 $50 5

  • Write an algorithm that uses dynamic program to find a solution to the knapsack problem. The...

    Write an algorithm that uses dynamic program to find a solution to the knapsack problem. The input is the capacity of the knapsack then each row of the table of values and weights. The output is the resulting maximum value of the items that can be put in the knapsack. Code submitted in C++ Sample Input 1: 11 1 1 6 2 18 5 22 6 28 7 Sample Output 1: 40 Sample Input 2: 8 15 1 10 5...

  • 3. Apply the dynamic programming algorithm discussed in class to solve the knapsack problem. (20 points)...

    3. Apply the dynamic programming algorithm discussed in class to solve the knapsack problem. (20 points) a. Show the completed table. b. Which items are included in the final configuration of the knapsack? c. What is the maximum value that can fit in the knapsack using a configuration of these items? Item 1 weighs 2 pounds and is worth $9.00 Item 2 weighs 3 pounds and is worth $12.00 Item 3 weighs 5 pounds and is worth $14.00 Item 4...

  • ALGORITHM Given the following Knapsack problem instance and its DP solution: 1 2 3 4 5...

    ALGORITHM Given the following Knapsack problem instance and its DP solution: 1 2 3 4 5 weight value To 10 10 10 10 item1 1 10 item2 | 2 17 item3 11 11 21 21 28 28 item4 15 0 11 121 121 128 36 According to the solution table, the maximum item value that we can achieve 36. By reconstructing the solution, we know that the following items {1,3,4} are included in the solution. Carefully, fill in the following...

  • Haloo , i have java program , Java Program , dynamic program Given a knapsack with capacity B∈N and -n- objects with profits p0, ..., p n-1 and weights w0, ..., wn-1. It is also necessary to find a su...

    Haloo , i have java program , Java Program , dynamic program Given a knapsack with capacity B∈N and -n- objects with profits p0, ..., p n-1 and weights w0, ..., wn-1. It is also necessary to find a subset I ⊆ {0, ..., n-1} such that the profit of the selected objects is maximized without exceeding the capacity. However, we have another limitation: the number of objects must not exceed a given k ∈ N Example: For the items...

  • Algorithm and computing system(Python) What is dynamic programming? Why does it usually work faster? Using the...

    Algorithm and computing system(Python) What is dynamic programming? Why does it usually work faster? Using the dynamic programming solution for the knapsack problem, compute a solution to this knapsack problem: Weight          value 2                     16 3                     19 4                     23 5                     28 total number of items = 4 capacity of the knapsack = 7 Suppose that the similarity between an object O and 6 other objects in the database A,B,C,D,E and F are as follows: sim(A,O) = 0.1 sim(B,O) = 0.3 sim(C,O)...

  • Please explain step by step, thank you so much! 0-1 Knapsack (N=6, W=10) Item Weight Value...

    Please explain step by step, thank you so much! 0-1 Knapsack (N=6, W=10) Item Weight Value (lb) ($) 8 1 0 10 Weight limit w(lb) 4 5 6 7 2 2 2 2 2 2 3 2 #2 2 1 2 43 33 3 w #3 0 2 3 3 #4 56 w 2 a #6 7. (10%) (Cont.) Unbounded Knapsack Problem (1-Dim Dynamic Programming) Weight limit w 0 : 6 Weight limit w F(w) 7 Unbounded Knapsack (N=6, W=10)...

  • Sequential Search Algorithm Python Programming Objectives ---------- * sequential search - design, analyze, implement, test, time...

    Sequential Search Algorithm Python Programming Objectives ---------- * sequential search - design, analyze, implement, test, time * continue practicing previously learned skills: algorithm analysis, graphing with theoretical prediction curves Implementation -------------- Write a function named sequential_search. It must have two parameters, a list to search and a value to search for. It must return either the index of the value within the list or -1 if the value is not found in the list. Your search function should NOT print...

  • I need this using C++. In this project, you will implement the dynamic programming-based solution to...

    I need this using C++. In this project, you will implement the dynamic programming-based solution to find the longest common subsequence (LCS) of two sequences. Your inputs will be the two sequences (as Strings) and the outputs are the longest common subsequence (printed as a String) and the final matrix (printed as a two-dimensional array) depicting the length of the longest common subsequences (as shown in the slides) for all possible subsequences of the two input sequences. The two input...

  • In terms of the programming language required, the algorithm needs to be written in pseudocode Dynamic Programming Cons...

    In terms of the programming language required, the algorithm needs to be written in pseudocode Dynamic Programming Consider the following problem based on the transformation of a sequence (or collection) of coloured disks Assume that you have a very large collection of disks, each with an integer value representing the disk colour from the range [0, c. For example, the colour mapping might be 0-red. 1-yellow, 2-blue, 3-pink. , c-black For a given sequence of coloured disks e.g., ( 0,1,2,3,4...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT