Question

In: Computer Science

In your own words describe the ‘knapsack problem’. Further, compare and contrast the use of a...

In your own words describe the ‘knapsack problem’. Further, compare and contrast the use of a brute force and a dynamic programming algorithm to solve this problem in terms of the advantage and disadvantages of each. An analysis of the asymptotic complexity of each is required as part of this assignment.

Solutions

Expert Solution

Knapsack problem is described as :-

Given a set of n items I1, I2,....,In with weight w1, w2,...,wn and values v1,v2,....,vn and a knapsack of capacity C, our goal is to carry as much item as possible in knapsack within capacity C such that sum of value of items within Knapsack is maximized.

While Brute force approach try to check for all possible set of combination of items and hence there are 2n possible ways of inserting items and Brute force method check for all possibility.

On the other hand dynamic programming approach build the solution over smaller set of items and then extend the solution over larger set of items. Thus if KNAP(m, C1) is optimal solution of wet of items from index 1 to m with knapsack capacity C1 then using this solution for KNAP(m, C1+1) and KNAP(m+1,C1) is build and hence finally KNAP(n, C) is the desired solution.

Both dynamic programing and Brute force technique will give optimal solution.

Dynamic programing build the solution in time complexity O(nC) while brute force algorithm will build solution in time O(n2n).

Advantage of Dynamic programing over brute force is that former is faster when C <2n.

Disadvantage of dynamic programing is then it will be slower if C > 2n.

Please comment for any clarification .


Related Solutions

Please no plagiarism and must be in your own words (800) Compare and contrast the use...
Please no plagiarism and must be in your own words (800) Compare and contrast the use of R vs Python and identify the pros and cons of each. Provide an example of both programming languages with coding examples as well as your experience in using one or both programming languages in professional or personal work. If you have no experience with either language, please discuss how you foresee using either/both of these languages in visualizing data when analyzing big data.  
In your own words compare and contrast these character, Louise Mallard (The Story of an Hour)....
In your own words compare and contrast these character, Louise Mallard (The Story of an Hour). Emily Grierson (A Rose for Emily). and Tessie Hutchinson (The Lottery).
In your own words, compare and contrast the real rate of return, the nominal rate of...
In your own words, compare and contrast the real rate of return, the nominal rate of return, and the ex ante nominal rate of return, using either real-life examples or hypothetical examples.
Describe and discuss in your own words adolescent sexuality. Use own words please
Describe and discuss in your own words adolescent sexuality. Use own words please
In your own words, compare and contrast the concepts "health system" and "healthcare system". Provide at...
In your own words, compare and contrast the concepts "health system" and "healthcare system". Provide at least three points of contrast. Develop a table to display your points. Give examples to support your response.
Refer to Section 6-5b - Styles of Leadership In your own words, compare and contrast the...
Refer to Section 6-5b - Styles of Leadership In your own words, compare and contrast the pros and cons of Autocratic, Participative, and Entrepreneurial leadership styles. Which leadership style would you most enjoy working under? Which leadership style most reflects your style as a leader? Do you have any stories or thoughts from experiences working under a leader that was very Autocratic, Participative, or Entrepreneurial? Did it change your outlook on this type of leadership style?
In 75-100 words (your own, that is) compare & contrast the 3 "schools of thought" covered...
In 75-100 words (your own, that is) compare & contrast the 3 "schools of thought" covered "in class", the handout/outline, the lecture that goes with it & any other resource you might find. (For example, do they emphasize the demand or supply side of the economy; short-run or long-run; government intervention; et al.)
In your own words, describe the problem solving strategy you would use to find an unknown...
In your own words, describe the problem solving strategy you would use to find an unknown force in a mechanical system
In your own words, compare and contrast the ways in which demographers track both continuously growing
In your own words, compare and contrast the ways in which demographers track both continuously growing (e.g. humans) and discretely growing (e.g. most bird species) populations of organisms considering the exponential and geometric growth models that they have developed. How are these 2 different types of populations similar and how are they different in terms of: how they are surveyed, their yearly population #’s patterns, their population growth dynamics, . . .?
In your own words, compare and contrast the purposes of each type of t-test (single, independent,...
In your own words, compare and contrast the purposes of each type of t-test (single, independent, and repeated). Under what conditions/circumstances should you use each type? Include in your discussion the types of samples, comparisons, variance, pooled variance, matched-pair, individual differences, # of samples involved, etc. This is not a simple question and requires a comprehensive response to cover all aspects. As it states above, the responses should be mostly in your own words, but you can cite sources to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT