## Greedy approach to 0-1 Knapsack problem in specific instances

### Remember to vote up questions/answers you find interesting or helpful (requires 15 reputation points)

The 0-1 knapsack problem is known to be NP-complete, and the greedy approach by Dantzig (based on choosing on the basis of density or value/weight) can be shown to be suboptimal using counterexamples. Many of the counterexamples seem to rely on a worst case feature where the weights of the elements are huge and comparable to the capacity of the knapsack. Suppose in a given instance, this is not so i.e. weights of all elements are very small compared to the capacity of the knapsack. In this case, will the greedy algorithm perform optimally (or atleast near optimally for practical purposes)? I apologize for such a qualitative description, and am seeking a precise formulation for the question, and a possible solution.

-

## 2 Answers

I don't think this works.

Suppose you have a counterexample to the greedy heuristic, with a knapsack of size $S$ and all elements of density at most $D$ and weight at most $W$. Now add a large number $N$ of objects of weight $W$ and density $1000D$, and consider a knapsack of size $S+NW$. Clearly the $N$ 'dense' objects are included in the optimal solution, and after adding them you're left with an instance of the previous counterexample. By making $N$ large enough, you can ensure that the weights of all objects are arbitrarily small compared to the size of the knapsack.

-
Your counterexample seems correct. So is there any characterization or property of knapsack instances which makes the simple greedy approach optimal in their cases? – Bratt Jun 3 2011 at 11:57

1
Also, the greedy algorithm's performance here seems near optimal here, as the difference between its solution and the optimal is just the difference in its performance in the much smaller counterexample we started out with. Can this be quantified? – Bratt Jun 3 2011 at 12:07

### You can accept an answer to one of your own questions by clicking the check mark next to it. This awards 15 reputation points to the person who answered and 2 reputation points to you.

As Frederico has already shown, this isn't enough to make the greedy heuristic immune to counterexamples.

It's worth mentioning that there is a simple dynamic programming algorithm for the knapsack problem that can be turned into a polynomial time approximation scheme (PTAS) without much difficulty. This can be found in the book by Papadimtiriou and Steiglitz among other places.

-
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 9, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "github"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "english_confidence": 0.9377966523170471, "perplexity_flag": "head"}