Pseudo-polynomial time
In computational complexity theory, a numeric algorithm runs in pseudo-polynomial time if its running time is polynomial in the numeric value of the input (which is exponential in the length of the input -- its number of digits).
An Example
Consider the problem of testing whether a number n is prime, by naively checking whether no number in {2,3,...,n/2} divides n evenly. This approach can take up to n/2-1 divisions, which is indeed linear in n but not in the size of n. For example, the number n = 2,000,000,000 would require approximately 1 billion divisions, even though the length of n is only 10 digits. Moreover one can easily write down an input (say, a 300-digit number) for which this algorithm is impractical. Since computational complexity measures difficulty with respect to the length of the (encoded) input, this naive algorithm is actually exponential. It is, however, pseudo-polynomial time.
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 steps (see Big O notation.)
In the case of primality, it turns out there is a different algorithm for testing whether n is prime (discovered in 2002) which runs in time .
Ramifications
If a problem is in P, then it per force has a pseudo-polynomial time algorithm. But NP-Complete problems may also have pseudo-polynomial time algorithms (for example, the Knapsack problem). Garey and Johnson write:
A pseudo-polynomial-time algorithm … will display 'exponential behavior' only when confronted with instances containing 'exponentially large' numbers, [which] might be rare for the application we are interested in. If so, this type of algorithm might serve our purposes almost as well as a polynomial time algorithm.
(where by "exponentially large numbers", they mean "numbers with many digits"). On the other hand, some NP-complete problems remain NP-complete even when their numeric parameters are polynomially bounded in their size. Such problems are called Strongly NP-complete.
Generalizing to non-numeric problems
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 if m(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 problems a special case by taking k to be the number of (binary) digits 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.
References
- M. R. Garey and D. S. Johnson. Computers and Intractability: A Guide to the Theory of NP-Completeness. W.H. Freeman and Company, 1979.