What is NP-completeness?

Stephen M. Walker II · Co-Founder / CEO

What is NP-completeness?

NP-completeness describes a class of computational problems that are easy to verify but believed to be hard to solve. A problem is NP-complete if it satisfies two properties:

  1. It is in NP, meaning any proposed solution can be checked for correctness in polynomial time.
  2. Every other problem in NP can be reduced to it in polynomial time, so an efficient algorithm for one NP-complete problem would yield an efficient algorithm for all of them.

Examples of NP-complete problems include the Traveling Salesman Problem (decision version), the Boolean Satisfiability Problem (SAT), the Knapsack Problem, the Hamiltonian Cycle Problem, and the Subset Sum Problem.

No polynomial-time algorithm is known for any NP-complete problem. Whether one exists is the P vs. NP question, one of the most important open problems in computer science. In practice, NP-complete problems are addressed with heuristic methods and approximation algorithms that trade optimality for a solution in reasonable time.

What is the difference between NP-complete and NP-hard problems?

An NP-hard problem is at least as hard as the hardest problems in NP: formally, a problem X is NP-hard if some NP-complete problem Y is reducible to X in polynomial time. Unlike NP-complete problems, NP-hard problems don't have to be in NP themselves, so their solutions may not be verifiable in polynomial time.

Examples of NP-hard problems include the Traveling Salesman Problem (optimization version), the Knapsack Problem, and the Steiner Tree Problem.

What are some examples of NP-complete problems?

  • Boolean Satisfiability Problem (SAT) — finding a truth assignment that satisfies a given propositional formula in conjunctive normal form.
  • Knapsack Problem (decision version) — determining whether items can be chosen, subject to a budget constraint, to reach at least a target value.
  • Hamiltonian Path Problem — finding a path that visits every vertex of a graph exactly once.
  • Travelling Salesman Problem (decision version) — determining whether a tour visiting every city exists within a given length.
  • Subgraph Isomorphism Problem — determining if a graph G is isomorphic to a subgraph of another graph H.
  • Subset Sum Problem — finding a subset of a given set that sums to a given target value.
  • Clique Problem — finding the largest set of vertices in a graph that form a complete subgraph.
  • Vertex Cover Problem — finding the minimum set of vertices in a graph that covers all edges.

Can AI methods help with NP-complete problems?

AI and machine learning methods can produce good approximate solutions to some NP-complete problems, but they don't change the underlying complexity result: no known method, AI-based or otherwise, solves NP-complete problems exactly in polynomial time for all inputs. Approaches used in research include:

  • Constraint satisfaction — searching for an assignment that satisfies a system of constraints.
  • Graph neural networks (GNNs) — trained to predict near-optimal solutions to combinatorial problems such as the decision variant of the Traveling Salesman Problem. These models learn heuristics from data and can generalize to somewhat larger instances, but they produce approximations, not guaranteed optimal or verified-correct solutions.
  • Evolutionary methods — genetic algorithms and related techniques that evolve a population of candidate solutions, adjusting the weights of a neural network's connections across generations to improve fitness.
  • Reinforcement learning — trial-and-error search that learns a policy for constructing solutions, used experimentally on problems like TSP and job-shop scheduling.

These methods can be faster or more practical than brute-force search on specific problem instances, and they can improve with training. Their limitations include high computational cost, no optimality guarantees, and inconsistent generalization outside the distribution of problems they were trained on.

Traditional (non-AI) methods remain widely used alongside these approaches, including integer programming, branch-and-bound, and classical approximation and heuristic algorithms. Which method works best depends on the specific problem and the resources available.


FAQs

Why are NP-complete problems considered intractable?

Because no known algorithm solves them in polynomial time in the general case; solving them exactly typically requires exponential time as input size grows. Computer scientists rely on heuristics or approximation algorithms to get usable results in practice.

What is the significance of polynomial-time reduction?

Polynomial-time reduction transforms one problem into another using only polynomial-time work. It is the tool used to prove NP-completeness: if a known NP-complete problem reduces to a new problem in polynomial time, the new problem is NP-complete too.

Is there a known way to solve NP-complete problems efficiently?

No. Whether a polynomial-time algorithm exists for NP-complete problems is the P vs. NP problem, still unresolved. Specific instances can sometimes be solved quickly, but no general efficient method is known.

What strategies are used when no polynomial-time solution exists?

Common strategies include heuristic algorithms that find good (not necessarily optimal) solutions quickly, exponential-time algorithms for small inputs, specialized polynomial-time algorithms for restricted cases, and polynomial-time reductions used to relate problems and study their structure.

More terms

Continue exploring the glossary.

Learn how teams define, measure, and improve LLM systems.

Glossary term

What are the ethical implications of artificial intelligence?

The ethical implications of artificial intelligence include addressing issues such as bias and discrimination in AI systems, safeguarding privacy and data ownership, upholding human rights in decision-making processes, managing potential unemployment and economic inequality caused by automation, ensuring safety and security of AI systems, and fostering a culture of responsibility and accountability.
Read term

Glossary term

What is a Turing machine?

A Turing machine is a mathematical model of computation that was first proposed by the mathematician Alan Turing in 1936. It's an abstract machine that manipulates symbols on a strip of tape according to a table of rules. Despite its simplicity, a Turing machine is capable of simulating any computer algorithm, no matter how complex.
Read term

It's time to build

Collaborate with your team on reliable Generative AI features.
Want expert guidance? Book a 1:1 onboarding session from your dashboard.

Talk to sales