complexity-theory

Definition

Pseudo-polynomial time complexity

Pseudo-polynomial time complexity is a time complexity that is polynomial in the encoded input length and in the numeric values of selected integer parameters, but not necessarily polynomial in the bit-lengths of those parameters.

Formally, fix an encoding of instances. For an instance , let

be its encoded input length. Let be numeric parameters of , such as capacities, targets, or total weights. An algorithm runs in pseudo-polynomial time if there is a polynomial such that, for every instance ,

This differs from ordinary polynomial time, which requires fixed constants such that

for every instance . In pseudo-polynomial time, the bound may depend polynomially on numeric values that can be exponentially larger than their encoded bit-lengths.

Equivalently, if

then . Thus a runtime polynomial in may be exponential in when the parameters are given in binary encoding.

Encoding

The distinction matters because binary encoding is compact. If is a numeric field of an instance , define its bit-length by

A runtime is polynomial in and , but it is not necessarily polynomial in and , because

Thus

up to constant factors in the exponent.

If the same numeric input were written in unary, then the length of the encoding of would be . Under that encoding, an algorithm would be polynomial in the input length. This is why pseudo-polynomial time is often described as polynomial time under unary encoding.

Consequences

Pseudo-polynomial algorithms explain the difference between weakly NP-hard and strongly NP-hard problems.

A weakly NP-hard problem may admit a pseudo-polynomial algorithm. Its hardness comes from the possibility that numeric values are exponentially large compared with their binary encodings.

A strongly NP-hard problem cannot admit a pseudo-polynomial algorithm unless . Its hardness remains even when numeric values are polynomially bounded in the input size.

Non-example

An algorithm with runtime

is ordinary polynomial time with respect to the binary input length, because is the size of the binary representation of . It is not merely pseudo-polynomial.

Examples

Subset sum

The subset sum problem with numbers and target has a dynamic programming algorithm with runtime

This is pseudo-polynomial. It is polynomial in the number of items and in the target value , but it can be exponential in the bit-length of the target.

Knapsack

The knapsack problem has dynamic programming algorithms with runtimes such as

where is the capacity, or

where is a bound on total value. These bounds are pseudo-polynomial because and are numeric magnitudes, not encoding lengths.