CSFG
English Deutsch Beta Español Beta język polski (2.6.0)
Chapters Curriculum Guides Appendices

Complexity and Tractability
12.4. Polynomial Time and Non-polynomial Time

Complexity and Tractability

  • 12.1. What's the big picture?
  • 12.2. Best, Worst, and Average Case Complexity
  • 12.3. Asymptotic Complexity (Big-O Notation)
  • 12.4. Polynomial Time and Non-polynomial Time
    • Tractability
    • NP-complete
    • Heuristics and approximation algorithms
    • What if we find that P=NP?
  • 12.5. Tractability
  • 12.6. The Travelling Salesperson Problem
  • 12.7. Bin packing problem
  • 12.8. Other intractable problems
  • 12.9. The whole story!
  • 12.10. Further reading

Computer scientists often draw a line between algorithms that require exponential time (that is, they are or worse), and those that require polynomial time, which require times like , , and so on including things like and . The latter ones are referred to as “polynomial time”, since the amount of time they take is proportional to a polynomial. Those that are or worse are sometimes loosely referred to as “non-polynomial”, although “exponential” or “superpolynomial” is probably a better description.

What is the exponent in an "exponential"? Curiosity

The word "exponential" is often used inaccurately in casual use, often to refer to something that grows quickly. But the real meaning of "exponential" is that it has in the exponent, such as , , or even (which is similar to ). This means that , or even is not not exponential, since is not in the exponent. They grow quite quickly as increases, but they are nothing like as bad as .

12.4.1.

Tractability

Polynomial time algorithms are generally referred to as “tractable”, because chances are a powerful enough computer will be able to run them in a reasonable time, even if is fairly big. Exponential (or non-polynomial) time algorithms are generally referred to as “intractable”, because even if the algorithm runs fast enough for a given value of , it will probably be too slow if increases by just a small amount. Of course, some polynomial time algorithms are also too slow to use, but it’s a simple distinction that usually provides a good warning if things are going to get out of hand.

12.4.2.

NP-complete

NP-complete is a term for a huge set of problems that we just can’t seem to find tractable algorithms for, and yet if we find a solution for one of them, we know how to get a fast solution for all of them. Finding out if one of these solutions exists is considered one of the biggest questions in computer science, and there’s even a $1,000,000 prize for finding a solution (it’s one of the “Millenium Prize Problems”). Examples of these problems include TSP, bin-packing and the knapsack problem.

The “NP” in the name stands for “non-deterministic polynomial-time”, which means that it’s part of a class of problems that could be solved by a “non-deterministic” machine (these don’t exist in reality) in polynomial time (that is, a tractable amount of time). In reality, computer scientists have only found exponential time algorithms for them (which are loosely referred to as using non-polynomial time).

The “complete” in NP-complete mainly means that any algorithm for one NP-complete problem can be converted to another in polynomial time, so if a fast algorithm for one is discovered, then we have instantly found a polynomial time algorithm for all of them.

12.4.3.

Heuristics and approximation algorithms

Because many of the NP-complete problems solve important real world problems (like reducing the amount of fuel used for deliveries, or loading aeroplanes optimally), we need to use heuristics or approximation algorithms that don’t necessarily find the best solution, but at least find a fairly good solution in a reasonable amount of time. For example, for the TSP, the “nearest neighbour” heuristic can work reasonably well - it just chooses the nearest unvisited location at each step. This typically gives a solution about 25% worse than the optimal one, but it runs in polynomial time. Another example is for bin-packing, where a heuristic “next-fit” algorithm just puts an item in the first bin that has space for it. It can run in O(n) time, but it might use up to about twice as many bins as an optimal algorithm.

12.4.4.

What if we find that P=NP?

While it seems unlikely, it is possible that someone will find a polynomial time algorithm for an NP-complete problem, in which case we’ll have one for all NP-complete problems! This might seem positive, since we can then optimal decisions about things like transport and timetabling, but one interesting social consequence of this is that it also means that cryptographic methods relying on the algorithms to take exponential time may now be useless. In fact, a solution to any NP-complete problem would be like the discovery of nuclear fission - it is both an incredible benefit, and a huge threat! There’s a thriller movie) that imagines a group solving the TSP problem, and the consequences.

Previous:
Asymptotic Complexity (Big-O Notation)
Next:
Tractability

Looking for something for primary schools? Check out CS Unplugged.

The Computer Science Field Guide is an online interactive resource for high school students learning about computer science.

Useful Links

  • About
  • Chapters
  • Interactives
  • Curriculum Guides

Community

  • Twitter
  • YouTube
  • GitHub

Help

  • Search
  • Glossary
  • Feedback

Switch to student mode

English | Deutsch | Español | język polski (2.6.0)

The Computer Science Field Guide material is open source on GitHub, and this website's content is shared under a Creative Commons Attribution-ShareAlike 4.0 International license. The Computer Science Field Guide is a project by the Computer Science Education Research Group at the University of Canterbury, New Zealand. Icons provided generously by icons8.

3.16.0

This definition is not available in English, sorry!