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
Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 2 images
- Incidence Table 1 A 1 -1 B 0 0 C 0 -1 0 D 0 0 1 E 0 0 0 0 0 -1 -1 For Items 18-22, refer to the incidence table on the previous page 20. The vertex with the highest degree is A. Vertex A C. Vertex C B. Vertex B D. Vertex D 21. What is the diameter of the graph? A. 1 C. 3 B. 2 D. 4 22. Which of the following statements is/are true? A. Edge E1 is incident from A B. Edge E1 is incident from B C. Edge E1 is incident from both A and B D. None of the above E1 1 -1 E2 E3 E4 0 1 0 -1 E5 0 0 1 -1 E6 0 1 0 0 E7 0 0 0 1 E8 0 0 0 20-22 1 0arrow_forwardThe for construct is a kind of loop that iteratively processes a sequence of items. So long as there are things to process, it will continue to operate. In your opinion, how true is this statement?arrow_forwardDemonstrate Recursion Assignment Instructions Overview The programs we’ve discussed so far are generally structured as methods that call one another in a hierarchical manner. For some problems, it’s useful to have a method call itself—this is known as a recursive method. Such a method can call itself either directly or indirectly through another method. Recursion is an important topic discussed at length in upper-level computer-science courses. Instructions Write a recursive method printArray() that displays all the elements in an array of integers, separated by spaces. The array must be 100 elements in size and filled using a for loop and a random number generator. The pseudo-code for this is as follows: //Instantiate an integer array of size 100 //fill the array For (int i=0; i<array.length; i++) Array[i] = random number between 1 and 100 inclusive printArray(integer array); For this assignment make sure that your screen shots show your program running and that your runtime…arrow_forward
- Personal project Q5. This question is concerned with the design and analysis of recursive algorithms. You are given a problem statement as shown below. This problem is concerned with performing calculations on a sequence A of real numbers. Whilst this could be done using a conventional loop-based approach, your answer must be developed using a recursive algorithm. No marks will be given if your answer uses loops. FindAverageAndProduct(a1, ...., an) such that n > 1 Input: A sequence of real values A = (a1, ...., an) Output:, A 2-tuple (average, product) containing the average (average) of all the values and the product (product) of all the values of the elements in A. Your recursive algorithm should use a single recursive structure to find the average and product values, and should not use two separate instances of a recursive design. You should not employ any global variables. (a) Produce a pseudo code design for a recursive algorithm to solve this problem. (b) Draw a call-stack…arrow_forwardPersonal project Q5. This question is concerned with the design and analysis of recursive algorithms. You are given a problem statement as shown below. This problem is concerned with performing calculations on a sequence ? of real numbers. Whilst this could be done using a conventional loop-based approach, your answer must be developed using a recursive algorithm. No marks will be given if your answer uses loops. FindAverageAndProduct(a1, ...., an) such that n > 1 Input: A sequence of real values A = (a1, ..., an) Output:, A 2-tuple (average, product) containing the average (average) of all the values and the product (product) of all the values of the elements in A. Your recursive algorithm should use a single recursive structure to find the average and product values, and should not use two separate instances of a recursive design. You should not employ any global variables. (a) Produce a pseudo code design for a recursive algorithm to solve this problem. (b) Draw a call-stack…arrow_forwardProgram 4 - CCC '07 J1 In the story Goldilocks and the Three Bears, each bear had a bowl of porridge to eat while sitting at his/her favourite chair. What the story didn't tell us is that Goldilocks moved the bowls around on the table, so the bowls were not at the right seats anymore. The bowls can be sorted by weight with the lightest bowl being the Baby Bear's bowl, the medium bowl being the Mama Bear's bowl and the heaviest bowl being the Papa Bear's bowl. Write a program that reads in three weights and prints out the weight of Mama Bear's bowl. You may assume all weights are positive integers less than 100. Sample Input 10 8arrow_forward
- Split blood pressure into systolic and diastolic blood pressure with integer as data type readings and remove the original column. Examine the data and look for predictor columns that are indicator variables, 0 or 1. Convert the data type to Boolean. Using code prepare lists of predictor column names for each data type. Make sure all the predictor columns are included in one and only one list. Print the length of the list of each data type and the sum of the lengths and verify that all predictor variables are accounted for in the lists. Use f-string to align the numbers properly.arrow_forwardA for construct is a loop that goes over a list of objects. Consequently, it runs indefinitely if there are items to process. What do you think about this?arrow_forwardCarl is sitting in a chair that is next to a table. Carl’s cell phone is on top of the table. Your task is to direct Carl to pick up his cell phone. Does the solution to this problem require a repetition structure? If so, what needs to be repeated?arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education