ArticleslgStudy

computer science

Pseudo-polynomial time

Pseudo-polynomial time is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Pseudo-polynomial time rather than just read about it. In short: In computational complexity theory, a numeric algorithm runs in pseudo-polynomial time if its running time is bounded from above by a polynomial function of the two variables: the numeric value of the input (the largest integer present in the input) and the length of the input (the number of bits required to represent it). In general, using a positional number system, the numeric value of the input is exponential in…

Key takeaways

  • Pseudo-polynomial time belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Pseudo-polynomial time to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Pseudo-polynomial time from memory before moving on to harder problems.

Reference excerpt

In computational complexity theory, a numeric algorithm runs in pseudo-polynomial time if its running time is bounded from above by a polynomial function of the two variables: the numeric value of the input (the largest integer present in the input) and the length of the input (the number of bits required to represent it). In general, using a positional number system, 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. The distinction between the value of a number and its length is due to positional encoding; if numeric inputs are instead encoded in unary then the length and value are the same. 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 P = NP. The strong/weak kinds of NP-hardness are defined analogously.

Examples

Primality testing Consider solving the problem of testing whether a number n is prime by naively checking whether a number in { 2 , 3 , … , n } {\displaystyle \{2,3,\dots ,{\sqrt {n}}\}} divides n {\displaystyle n} evenly. This approach can take up to n − 1 {\displaystyle {\sqrt {n}}-1} divisions, which is sub-linear in the value of n but exponential in the length of n (which is about log ⁡ ( n ) {\displaystyle \log(n)} ). For example, a number n slightly less than 10,000,000,000 would require up to approximately 100,000 divisions, even though the length of n is only 11 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 O ( m n ) {\displaystyle O(mn)} 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) that runs in time O ( ( log ⁡ n ) 6 ) {\displaystyle O((\log {n})^{6})} .

Knapsack problem In the knapsack problem, we are given n {\displaystyle n} items with weight w i {\displaystyle w_{i}} and value v i {\displaystyle v_{i}} , along with a maximum weight capacity of a knapsack W {\displaystyle W} . The goal is to solve the following optimization problem; informally, what's the best way to fit the items into the knapsack to maximize value?

maximize ∑ i = 1 n v i x i {\displaystyle \sum _{i=1}^{n}v_{i}x_{i}}

subject to ∑ i = 1 n w i x i ≤ W {\displaystyle \sum _{i=1}^{n}w_{i}x_{i}\leq W} and x i ∈ { 0 , 1 } {\displaystyle x_{i}\in \{0,1\}} . Solving this problem is NP-hard, so a polynomial time algorithm is impossible unless P = NP. However, an O ( n W ) {\displaystyle O(nW)} time algorithm is possible using dynamic programming; since the number W {\displaystyle W} only needs log ⁡ W {\displaystyle \log W} bits to describe, this algorithm runs in pseudo-polynomial time.

Strong and weak NP-hardness vs. strong and weak polynomial-time algorithms Assuming P ≠ NP, the following are true for computational problems on integers:

If a problem is weakly NP-hard, then it does not have a weakly polynomial time algorithm (polynomial in the number of integers and the number of bits in the largest integer), but it may have a pseudopolynomial time algorithm (polynomial in the number of integers and the magnitude of the largest integer). An example is the partition problem. Both weak NP-hardness and weak polynomial-time correspond to encoding the input integers in binary coding. If a problem is strongly NP-hard, then it does not even have a pseudo-polynomial time algorithm. It also does not have a fully-polynomial time approximation scheme. An example is the 3-partition problem. Both strong NP-hardness and pseudo-polynomial time correspond to encoding the input integers in unary coding.

See also Strongly NP-complete Quasi-polynomial time

References

Worked examples

Example 1 — a first encounter with Pseudo-polynomial time

Start with the simplest possible case. Write down what Pseudo-polynomial time claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Pseudo-polynomial time before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Pseudo-polynomial time ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Pseudo-polynomial time

In research
Pseudo-polynomial time appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Pseudo-polynomial time in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Pseudo-polynomial time is common in secondary-school and first-year university syllabi. It links to neighbouring topics Analysis of algorithms, Complexity classes, Computational complexity theory, so understanding it makes those chapters shorter.
In everyday life
Look for Pseudo-polynomial time outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Pseudo-polynomial time” →

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Pseudo-polynomial time in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Pseudo-polynomial time means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Pseudo-polynomial time out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Pseudo-polynomial time in simple terms?

In computational complexity theory, a numeric algorithm runs in pseudo-polynomial time if its running time is bounded from above by a polynomial function of the two variables: the numeric value of the input (the largest integer present in the input) and the length of the input (the number of bits r…

Why does Pseudo-polynomial time matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Pseudo-polynomial time?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Pseudo-polynomial time.

Tags

  • Analysis of algorithms
  • Complexity classes
  • Computational complexity theory
  • Pseudo-polynomial time algorithms

Keep exploring