Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to show that the problem below, also known as the Knapstack Problem, is in NP (non-deterministic polynomial time). Where should I start?

Given $n$ items numbered $1$ through $n$ so that $i^{th}$ item has weight $w_i$ and value $v_i$, determine whether it is possible to select some of these items with total weight at most $W$ and total value at least $V$.

share|cite|improve this question
Knapsack is clearly in NP, since we can guess what items to take and then verify in polynomial time if this is a correct solution according to our requirements. – user12205 Oct 12 '11 at 7:16

Loosely speaking, being in NP means it's possible to verify any proposed solution efficiently. If someone proposes a selection of items, all you have to do to verify the proposal is to add up the weights and see you get at most $W$, and add up the values and see you get at least $V$.

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.