Question

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 value, such that, this approach picks a set of items of total value W to put in bag, while it is possible to pick items that are of value >= 100W.

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

Weight : 1 1000     20 30 40 9

Values: 10 9000    10 10 10 1

Capacity of knapsack = 1000

Consider the above weight value pair. I've sorted according to value by weight ratio. If we use 0/1 knapsack approach, we would get Profit = 9000 because we will pick second item i.e. weight = 1000.

If we use greedy fractional knapsack approach, we still get profit 10+(999/1000)*9000 = 9001

In your greedy approach, we select first item, capacity become 999 so we can't select second item so skip it. Now we have capacity to select all items so take them. Total profit = 10 + 10 + 10 + 10 + 1 = 41 = W

we can see that 9000> 200*W. So in this example, your greedy approach fail.

There are examples in which selecting more value/weight ratio item can result in poor solution like the above.

Add a comment
Know the answer?
Add Answer to:
Consider the following greedy algorithm for the knapsack problem: each time we pick the item with...
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
  • "Greedy, but Better": Given a knapsack problem with a weight capacity C, and n items, and...

    "Greedy, but Better": Given a knapsack problem with a weight capacity C, and n items, and each item has a weight W[1:n] and monetary value P[1:n]. You have to determine which items to take so that the total weight is C, and the total value (profit) is maximized. In this case we are considering an integer problem, so you can either take an item, or not take an item, you cannot take it fractionally. If you recall, the greedy algorithm...

  • There is no known Greedy strategy that is optimal for solving the 0/1 Knapsack problem. For...

    There is no known Greedy strategy that is optimal for solving the 0/1 Knapsack problem. For each of the following strategies give a counterexample, i.e. descibe an instance where that strategy will fail to produce an optimal result. (a) Lightest item first. (b)Most valuable item first. (c)Item with the best value to weight ratio first.

  • For given capacity of knapsack W and n items {i1,i2,...,in} with its own value {v1,v2,...,vn} and...

    For given capacity of knapsack W and n items {i1,i2,...,in} with its own value {v1,v2,...,vn} and weight {w1,w2,...,wn}, find a greedy algorithm that solves fractional knapsack problem, and prove its correctness. And, if you naively use the greedy algorithm to solve 0-1 knapsack problem with no repetition, then the greedy algorithm does not ensure an optimal solution anymore. Give an example that a solution from the greedy algorithm is not an optimal solution for 0-1 knapsack problem.

  • 5) (10 pts) Greedy Algorithms The 0-1 Knapsack problem is as follows: you are given a...

    5) (10 pts) Greedy Algorithms The 0-1 Knapsack problem is as follows: you are given a list of items, each item has an integer weight and integer value. The goal of the problem is to choose a subset of the items which have a sum of weights less than or equal to a given W with a maximal sum of values. For example, if we had the following five items (each in the form (weight, value)): 11(6, 13), 2(4, 10),...

  • Recall that in the "Knapsack Problem", there are n items having respective values V1..n) and weights...

    Recall that in the "Knapsack Problem", there are n items having respective values V1..n) and weights W1..n), all greater than 0 and one needs to maximize the total value of the subset of the items placed in the knapsack limited by a weight capacity of W In the 0-1 Knapsack Problem, each item must be either be included or excluded in its entirety, in light of the fact that this problem is to be "NP-Complete", how can one solve the...

  • 1. Fractional Knapsack Problem Algorithm Which best describes the tightest range of the number of items...

    1. Fractional Knapsack Problem Algorithm Which best describes the tightest range of the number of items with only fractional inclusion (i.e. not entirely included or excluded) in the knapsack? (Let n denote the number of items for possible inclusion.) A) At least 0 items and at most n items B) At least 1 items and at most n items C) Exactly n items D) At least 0 items and at most n-1 items E) At least 1 items and at...

  • solution is required in pseudo code please. 2 Knapsack Problem În al Knapsack problem. given n items(11-12. . . ....

    solution is required in pseudo code please. 2 Knapsack Problem În al Knapsack problem. given n items(11-12. . . . . 1"} with weight {w1·W2. . . . . ux) and value (n 2, .., nJ, the goal is to select a combination of items such that the total value V is maximized and the total weight is less or equal to a given capacity In this question, we will consider two different ways to represent a solution to the...

  • 2 Knapsack Problem In a Knapsack problem, given n items {11, I2, -.., In} with weight {wi, w2, -.., wn) and value fvi,...

    2 Knapsack Problem In a Knapsack problem, given n items {11, I2, -.., In} with weight {wi, w2, -.., wn) and value fvi, v2, ..., vn], the goal is to select a combination of items such that the total value V is maximized and the total weight is less or equal to a given capacity W. Tt i=1 In this question, we will consider two different ways to represent a solution to the Knapsack problem using an array with size...

  • Local Search Knapsack 0-1

    Design a local search algorithm for the 0-1 knapsack problem. Assume there are n items x1 ... xn each with weight wi and value vi. The knapsack can have at most one of each item and the total weight cannot exceed W. You want to maximize the total value in the knapsack.Question 1: (7 points) Show the psuedocode/explanation for your algorithm.Question 2. (3 points) Is it guaranteed to find an optimal solution? Justify your answer.

  • a) Implement the bottom-up dynamic programming algorithm for the knapsack problem in python. The program should...

    a) Implement the bottom-up dynamic programming algorithm for the knapsack problem in python. The program should read inputs from a file called “data.txt”, and the output will be written to screen, indicating the optimal subset(s). b) For the bottom-up dynamic programming algorithm, prove that its time efficiency is in Θ(nW), its space efficiency is in Θ(nW) and the time needed to find the composition of an optimal subset from a filled dynamic programming table is in O(n). Consider the following...

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