![]() Note that if we were to "cheat", we could represent $W$ using $W$ bits if we used a unary encoding. The main difference is that $W$ represents a number in the input, while $n$ represents "the number of things". We can represent the number $n$ using $\log n$ bits, but we can't represent $n$ things using $\log n$ bits. ![]() However, (coming back to your example about sorting) an instance for sorting consists of $n$ elements to be sorted, and representing these takes at least $n$ bits (and probably a bit more, since the elements themselves are probably bigger than $1$ bit each). This makes $nW$ not polynomial in the size of the instance, since $W$ is exponential in $\log W$. ![]() Each number is represented with $\log W$ bits, and there are $n$ numbers, so the size of the instance is $n\log W$. Ignoring the values of the items for the moment (and considering only their weights), the input of the knapsack problem is $n$ numbers $\leq W$. ![]() This is where the argument about $\log W$ comes in. However, we usually consider the running time of an algorithm as a function of the size of the input. When we say polynomial or exponential, we mean polynomial or exponential in some variable.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |