1
$\begingroup$

Dynamic programming algorithm for Knapsack is stated to have complexity $\mathcal O (nW)$.

However, I've also seen the complexity stated as $\mathcal O (n^2V),ドル where $V=\max v_i$.

(Here $n$ is the number of items and $W$ the weight limit).

I see from the algorithm that the first complexity measure is correct: http://en.wikipedia.org/wiki/Knapsack_problem

Can someone tell me, why the other complexity measure works ?

Raphael
73.3k31 gold badges184 silver badges406 bronze badges
asked Jun 2, 2015 at 13:44
$\endgroup$

1 Answer 1

2
$\begingroup$

The first complexity measure is in terms of the target weight, the second in terms of the heaviest element. Since $W \leq nV$ (or rather, we can assume that $W \leq nV$), the first estimate $O(nW)$ implies the second $O(n^2V)$. So $O(nW)$ is a stronger estimate than $O(n^2V)$.

answered Jun 2, 2015 at 13:51
$\endgroup$
2
  • $\begingroup$ Thank you, excellent answer. Now, the approximation algorithm (with $v_i$ scaled) runs in polynomial size in the input encoded as binary (not a pseudo polynomial), because the size $n$ and the size of the input is polynomially related ? $\endgroup$ Commented Jun 2, 2015 at 13:59
  • $\begingroup$ I have no idea what "the approximation algorithm" is, but I'm sure you can answer your question yourself and don't need my help. $\endgroup$ Commented Jun 2, 2015 at 14:02

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.