|
|
|
|
|
by 0xc0der
657 days ago
|
|
I have been recently thinking about the NP-complete class of problems particularly the knapsack problem (it is easy to understand and attack). And I think it is really solvable in polynomial time. I actually tried and posted my solution here.
https://news.ycombinator.com/item?id=41341608
a bit of feedback would be really helpful. |
|
For a counterexample, imagine you have a ton of items that have a weight of 10^-20 and value of 1, and a single item that has the weight of whatever is the capacity of the knapsack (so it’s only thing that fits if it’s inserted to the knapsack) and the value of +infinity.
All items have their cost ≈ 0, so whether you fit all of the “light but valueless” items or the single “heavy but extremely valuable” item depends on how you sort when costs are equal.
An improved heuristic would take the value into account more than just having it as a factor, but it’s not easy to design.
I would recommend finding an open course on algorithm design and analysis and going through the lessons while trying to extrapolate approaches to problems instead of just solutions to them.