Question

**Knapsack Problem**

This exercise is due Tuesday, May 14. It has to be turned in on time in order to get participation credit. I'll come into class and go over the solution right away. Then I will collect your work on the exercise. Be ready to turn it in at that time.

- Fill out the table for the knapsack problem, where the objects, weights, and values are as given, and the overall weight limit is 10.
- Next, circle the entries in the table that are used when backtracking to find objects to use in the solution.
- Then list the object numbers that can be used for an optimal solution.
- Also list the weights and values of those objects.
- Verify that the values of your solution objects add up to the optimal number in the last row and column in the table.
- Verify that the sum of the weights of your solution the objects is not more than the overall weight limit of 10.

Weight Capacity ----->

obj

# wt val | 0 1 2 3 4 5 6 7 8 9 10

_________________________________________________________

0 0 0 | 0 0 0 0 0 0 0 0 0 0 0

1 4 5 | 0

2 3 4 | 0

3 5 7 | 0

4 3 2 | 0

**Here is a filled-out table for a similar problem:**

Total Weight ----->

obj

# wt val | 0 1 2 3 4 5 6 7

_____________________________________________

0 0 0 | 0 0 0 0 0 0 0 0

1 1 2 | 0 2 2 2 2 2 2 2

2 4 9 | 0 2 2 2 9 11 11 11

3 3 7 | 0 2 2 7 9 11 11 16

4 2 3 | 0 2 3 7 9 11 12 16

Let me know in class if you have questions about how such problems are solved. The algorithm is covered in section 6.4.

Step 1

Instructions for completing the table:

- Enter 0 where objects and weights are zero.
- For each row assume there are only that objects are present as the current row. That means for row 2 there is only 1 object to be considered. And, for row 3, there are only objects 1, 2 and 3.
- Similarly, for columns, assume the knapsack only has the limit specified in the column. That means for the column, the knapsack can carry a maximum weight of 4 only.
- Use backtracking to find maximum possible value in the maximum limit of the knapsack.
- Consider the weight that has more value than the one with less value.

Step 2

The complete table:

Step 3

Starting with row 1, the knapsack can only have object 1 with weight 4 and value 5. Next, object 1 and 2 has a maximum weight of 7 and value 9. So, at the 7th column in the table the value will be 9. Moving on to the next row, the object 3 has a weight of 5 and value 7.

Now, by backtracking, in row 3 and column 7, the value of objects 1 and 2 combined (9) is greater than the value of object 3 (7). Hence, it will ...

Tagged in

Q: How do you convert 172.16.20.55 to binary format?

A: 172.16.20.55 represents IP address in decimal format. In order to convert it into binary format we n...

Q: How do I check if a binary number is a multiple of 16 by using bit shifting?

A: Approach: Result = (((n >>4) << 4) == n). First we shift the 4 bit right then we shift t...

Q: 2. Write a program called ListOddNumbers that prints the below (there is a single space between each...

A: Solution: 2. The below program is written in Java language to display the odd number between 1 and 5...

Q: Write a program called Convert, which converts an ASCII code to its equivalentcharacter. 1) Create a...

A: Java codeimport java.util.Scanner; public class Convert{public static void main(String[] args) {Scan...

Q: Programming in C language.

A: Note:The below program has been complied and run in "repl.it" online complier.

Q: what is the best test strategy for any ERP system?

A: ERP stands for Enterprise resource planning is a software used for business process management. It a...

Q: Associate each of the following concepts with one of the languages we covered (pseudo code,FORTRAN, ...

A: Associating languages with given concepts:ALGOL 60: Pass by nameALGOL 60: Pass by valueFORTRAN: Assi...

Q: import java.util.*;public class TestAverage {public static void main(String[] args) {int test1, test...

A: Click to see the answer

Q: A Maze Room : In this lab, we will make a maze game. The maze is based on Linked Lists. Instead of h...

A: For class Room, implement the setter and getter methods by assign and returning values respectively....

Sorry about that. What wasn’t helpful?