Pseudo-polynomial time should not be confused with Quasi-polynomial time.
In computational complexity theory, a numeric algorithm runs in pseudo-polynomial time if its running time is a polynomial in the numeric value of the input (the largest integer present in the input)—but not necessarily in the length of the input (the number of bits required to represent it), which is the case for polynomial time algorithms.[1]
In general, the numeric value of the input is exponential in the input length, which is why a pseudo-polynomial time algorithm does not necessarily run in polynomial time with respect to the input length.
An NP-complete problem with known pseudo-polynomial time algorithms is called weakly NP-complete.An NP-complete problem is called strongly NP-complete if it is proven that it cannot be solved by a pseudo-polynomial time algorithm unless . The strong/weak kinds of NP-hardness are defined analogously.
Consider the problem of testing whether a number n is prime, by naively checking whether no number in divides
n
log(n)
Contrast this algorithm with a true polynomial numeric algorithm—say, the straightforward algorithm for addition: Adding two 9-digit numbers takes around 9 simple steps, and in general the algorithm is truly linear in the length of the input. Compared with the actual numbers being added (in the billions), the algorithm could be called "pseudo-logarithmic time", though such a term is not standard. Thus, adding 300-digit numbers is not impractical. Similarly, long division is quadratic: an m-digit number can be divided by a n-digit number in
O(mn)
In the case of primality, it turns out there is a different algorithm for testing whether n is prime (discovered in 2002) that runs in time
O((log{n})6)
In the knapsack problem, we are given
n
wi
vi
W
maximize
n | |
\sum | |
i=1 |
vixi
subject to
n | |
\sum | |
i=1 |
wixi\leqW
xi\in\{0,1\}
O(nW)
W
logW
Although the notion of pseudo-polynomial time is used almost exclusively for numeric problems, the concept can be generalized:The function m is pseudo-polynomial ifm(n) is no greater than a polynomial function of the problem size n and an additional property of the input, k(n). (Presumably, k is chosen to be something relevant to the problem.)This makes numeric polynomial problems a special case by taking k to be the numeric value of the input.
The distinction between the value of a number and its length is one of encoding: if numeric inputs are always encoded in unary, then pseudo-polynomial would coincide with polynomial.