In computer science, a polynomial-time algorithm is generally speaking an algorithm whose running time is upper-bounded by some polynomial function of the input size. The definition naturally depends on the computational model, which determines how the running time is measured, and how the input size is measured. Two prominent computational models are the Turing-machine model and the arithmetic model. A strongly-polynomial time algorithm is polynomial in both models, whereas a weakly-polynomial time algorithm is polynomial only in the Turing machine model.
The difference between strongly- and weakly-polynomial time is when the inputs to the algorithms consist of integer or rational numbers. It is particularly common in optimization.
Two common computational models are the Turing-machine model and the arithmetic model:
Some algorithms run in polynomial time in one model but not in the other one. For example:
2n | |
2 |
However, if an algorithm runs in polynomial time in the arithmetic model, and in addition, the binary length of all inputs, outputs, and intermediate values is polynomial in the number of input values, then it is always polynomial-time in the Turing model. Such an algorithm is said to run in strongly polynomial time.
Strongly polynomial time is defined in the arithmetic model of computation. In this model of computation the basic arithmetic operations (addition, subtraction, multiplication, division, and comparison) take a unit time step to perform, regardless of the sizes of the operands. The algorithm runs in strongly polynomial time if:
Any algorithm with these two properties can be converted to a polynomial time algorithm by replacing the arithmetic operations by suitable algorithms for performing the arithmetic operations on a Turing machine. The second condition is strictly necessary: given the integer
2n
2n | |
2 |
2n | |
2 |
2n
However, for the first condition, there are algorithms that run in a number of Turing machine steps bounded by a polynomial in the length of binary-encoded input, but do not take a number of arithmetic operations bounded by a polynomial in the number of input numbers. The Euclidean algorithm for computing the greatest common divisor of two integers is one example. Given two integers
a
b
O(loga+logb)
O(loga+logb)
a
b
An algorithm that runs in polynomial time but that is not strongly polynomial is said to run in weakly polynomial time.[1] A well-known example of a problem for which a weakly polynomial-time algorithm is known, but is not known to admit a strongly polynomial-time algorithm, is linear programming. Weakly polynomial time should not be confused with pseudo-polynomial time, which depends on the magnitudes of values in the problem instead of the lengths and is not truly polynomial time.
In order to specify the arithmetic model, there are several ways to define the division operation. The outcome of dividing an integer a by another integer b could be one of:
In all versions, strongly-polynomial-time implies polynomial-time in the Turing model.