Question

Consider the integer knapsack problem. Give a recursive algorithm (call it Find-Optimal-Subset) that finds the optimal...

Consider the integer knapsack problem. Give a recursive algorithm (call it Find-Optimal-Subset) that finds the optimal subset of items through post-processing, that is, after filling in the memorization table to find the maximum total value of the optimal subset of items. (The algorithm we studied in class finds only the maximum total value, not the actual optimal subset of items.) Hint: Trace back through the array M[0..n,0..W] following the optimal structure.

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

The dynamic programming algorithm for kanapsack is given below:

knapsack(v, x, n, y)

FOR x = 0 TO y
DO c[0, x] = 0
FOR i=1 to n
DO c[i, 0] = 0
FOR x=1 TO y
DO IF xi ≤ x
THEN IF vi + c[i-1, x-xi]
THEN c[i, x] = vi + c[i-1, x-xi]
ELSE c[i, x] = c[i-1, x]
ELSE
c[i, x] = c[i-1, x]

We can see that from the table items to take can be deduced, starting at c[n. x] and where the optimal value came from tracing backward to that.
If c[i, x] = c[i-1, x] item i is not part of the solution, and the tracing will be continue with c[i-1, x]. Otherwise item i is part of the solution, and tracing will be continue with c[i-1, x-y].

θ(nx) time is taken by the dynamic knapsack algorithm, and the space taken is θ(nx) times to fill the table, which has (n +1).(x +1) entries in it, each of them required θ(1) computation times. To trace the solution O(n) times is required, it's only because the process of tracing starts in row n of the table and will be moving up 1 row at a time. (at every step).

Add a comment
Know the answer?
Add Answer to:
Consider the integer knapsack problem. Give a recursive algorithm (call it Find-Optimal-Subset) that finds the optimal...
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
  • [Recursive Cost] [ALGORITHM] Improving Efficiency PLEASE explain in DETAIL the following question in detail. The algorithm...

    [Recursive Cost] [ALGORITHM] Improving Efficiency PLEASE explain in DETAIL the following question in detail. The algorithm is also given below. Thank You! 1.a) Define recursively the worst case cost Kn of the Knapsack function for n items. Remember that you need to provide both the base case and the recurrence relation. Also do not forget to include the cost of the function Worth in your cost. Justify your answer (i.e. explain what each component of the formula represents). [5points] 1.b)  Use...

  • Consider the following greedy algorithm for the knapsack problem: each time we pick the item with...

    Consider the following greedy algorithm for the knapsack problem: each time we pick the item with the highest value to weight ratio to the bag. Skip items that will make the total weight exceeded the capacity of the bag. Find a counterexample to show that this approach will not work, and the result could be 100 times worse than the optimal solution. That is, construct a table of set of items with weight and values and find a bag capacity...

  • Make a program using Java that asks the user to input an integer "size". That integer...

    Make a program using Java that asks the user to input an integer "size". That integer makes and prints out an evenly spaced, size by size 2D array (ex: 7 should make an index of 0-6 for col and rows). The array must be filled with random positive integers less than 100. Then, using recursion, find a "peak" and print out its number and location. (A peak is basically a number that is bigger than all of its "neighbors" (above,...

  • This is an assignment for my algorithm class which I have written the code partially and...

    This is an assignment for my algorithm class which I have written the code partially and only need to complete it by adding a time function that calculates the average running time. We could use any programming language we want so I am using C++. I am including the instruction and my partial code below. Thank you! Implement linearSearch(a,key) and binarySearch( a,key)functions. Part A.In this part we will calculate theaverage-case running time of each function.1.Request the user to enter a...

  • CMPS 12B Introduction to Data Structures Programming Assignment 2 In this project, you will write...

    can i get some help with this program CMPS 12B Introduction to Data Structures Programming Assignment 2 In this project, you will write a Java program that uses recursion to find all solutions to the n-Queens problem, for 1 Sns 15. (Students who took CMPS 12A from me worked on an iterative, non-recursive approach to this same problem. You can see it at https://classes.soe.ucsc.edu/cmps012a/Spring l8/pa5.pdf.) Begin by reading the Wikipcdia article on the Eight Queens puzzle at: http://en.wikipedia.org/wiki/Eight queens_puzzle In...

  • Can you please help me with creating this Java Code using the following pseudocode? Make Change C...

    Can you please help me with creating this Java Code using the following pseudocode? Make Change Calculator (100 points + 5 ex.cr.)                                                                                                                                  2019 In this program (closely related to the change calculator done as the prior assignment) you will make “change for a dollar” using the most efficient set of coins possible. In Part A you will give the fewest quarters, dimes, nickels, and pennies possible (i.e., without regard to any ‘limits’ on coin counts), but in Part B you...

  • Lab Exercise #15 Assignment Overview This lab exercise provides practice with Pandas data analysis library. Data...

    Lab Exercise #15 Assignment Overview This lab exercise provides practice with Pandas data analysis library. Data Files We provide three comma-separated-value file, scores.csv , college_scorecard.csv, and mpg.csv. The first file is list of a few students and their exam grades. The second file includes data from 1996 through 2016 for all undergraduate degree-granting institutions of higher education. The data about the institution will help the students to make decision about the institution for their higher education such as student completion,...

  • Edit a C program based on the surface code(which is after the question's instruction.) that will...

    Edit a C program based on the surface code(which is after the question's instruction.) that will implement a customer waiting list that might be used by a restaurant. Use the base code to finish the project. When people want to be seated in the restaurant, they give their name and group size to the host/hostess and then wait until those in front of them have been seated. The program must use a linked list to implement the queue-like data structure....

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
ADVERTISEMENT