Professor Turing

Study guides

What is an NP-complete problem?

Last updated: 2026-11-26

An NP-complete problem is a yes-or-no problem with two properties: a proposed proof of a yes answer can be checked in polynomial time (the problem is in NP), and a polynomial-time algorithm for it would give a polynomial-time algorithm for all problems in NP (the problem is NP-hard). Polynomial time means the running time is bounded by a polynomial in the size of the input.

Start learning No account needed

1. Four names

  • P: decision problems that can be solved in polynomial time.
  • NP: decision problems where, if the answer is yes, there is a proof of it that can be checked in polynomial time. A problem in P is also in NP, because the checker can solve it from scratch.
  • NP-hard: problems where a polynomial-time algorithm would imply P = NP. The definition does not require membership in NP.
  • NP-complete: problems that are both NP-hard and in NP.

Whether P equals NP is an open question. If one NP-complete problem had a polynomial-time algorithm, then all problems in NP would have one.

2. A worked example: checking, searching and reducing

Subset Sum asks: given a list of positive whole numbers and a target, does some selection of them add to the target? Partition asks: can a list be split into two groups with equal sums? Take the list 3, 34, 4, 12, 5, 2 and the target 9. Before reading the output, find a selection yourself. The numbers come from scripts/what-is-an-np-complete-problem-worked-example.py in the Professor Turing repository.

list = 3, 34, 4, 12, 5, 2; target = 9
check the certificate 4, 5: 4 + 5 = 9
selections tried by brute force: 2^6 = 64
selections that add to 9: 4 + 5; 3 + 4 + 2
with 20 numbers: 2^20 = 1,048,576
with 40 numbers: 2^40 = 1,099,511,627,776
reduction: sum S = 60, new numbers t + 1 = 10 and S - t + 1 = 52
new list total = 122, each group needs 61
one split: 4, 5, 52
       and 3, 34, 12, 2, 10
targets 1 to 60: subset exists exactly when the new list splits
table for n = 6, t = 9: 4 bits to write t, 6 x (t + 1) = 60 cells
table for n = 6, t = 1,000,000,000,000: 40 bits to write t, 6 x (t + 1) = 6,000,000,000,006 cells

Checking is short. Handed the certificate 4 and 5, you confirm that both are in the list and add them. That shows the answer is yes, and a check of this kind takes polynomial time for any instance, so Subset Sum is in NP.

Trying all selections grows quickly. A list of n numbers has 2 to the power n selections. This shows that this particular method takes exponential time. It does not show that no polynomial method exists.

3. What a reduction proves

To turn a Subset Sum question into a Partition question, let S be the sum of the list and t the target. A target above S has the answer no, which can be settled at once, so assume t is no larger than S. Add two new numbers, t + 1 and S − t + 1. Here they are 10 and 52, the new total is 122, and each group must reach 61.

The two new numbers add to S + 2, which is more than half of the new total, so an even split puts them in different groups. The group holding S − t + 1 needs exactly t more from the original numbers, here 9. In the other direction, a selection adding to t plus the number S − t + 1 makes S + 1, which is half. So the new list can be split evenly exactly when the original list has a selection adding to t.

The script checks that equivalence for the targets from 1 to 60 on this list. The check illustrates the argument and does not replace the proof. Building the new list means adding up the old one and appending two numbers, so it runs in polynomial time.

The conclusion: a polynomial-time algorithm for Partition would solve Subset Sum in polynomial time, by building the new list and asking about it. Subset Sum is NP-hard, so Partition is NP-hard. A split can also be checked by adding the two groups, so Partition is in NP, and the two facts make it NP-complete.

4. A common mistake: reducing in the wrong direction

To prove that your problem A is NP-hard, reduce a known NP-hard problem to A. Reducing A to a hard problem shows that a method for the hard problem would solve A, which says that A is no harder than it. Easy problems can be reduced to hard ones too, so this direction does not show that A is hard.

A useful check is to say the sentence aloud: "if I could solve A quickly, I could solve the known hard problem quickly." If your construction takes an arbitrary instance of A as its input, it runs the other way.

5. A table method that looks polynomial

Subset Sum has a dynamic programming algorithm that runs in time proportional to n times t. That looks polynomial. But the input size counts the bits needed to write the numbers, and t can be about 2 to the power of its number of bits. In the output, a target of a trillion takes 40 bits to write, while the table has more than 6 trillion cells. An algorithm like this is called pseudo-polynomial, and it does not show that P = NP.

6. Test yourself

Case 1. A classmate says, "Sorting is in NP, so sorting is hard." What is wrong?

Answer to case 1

Membership in NP is not a sign of hardness, since NP contains P. Also, NP is defined for yes-or-no problems, so one would first phrase the question that way, for example "is the k-th smallest item at most v?"

Case 2. You show a polynomial-time reduction from your problem B to Subset Sum. Have you shown that B is NP-hard?

Answer to case 2

No. The reduction shows that B is no harder than Subset Sum. To show hardness, reduce Subset Sum, or another known NP-hard problem, to B.

Case 3. For the list 3, 34, 4, 12, 5, 2 and the target 7, which two numbers does the reduction add, and what must each group of the new list sum to?

Answer to case 3

It adds 7 + 1 = 8 and 60 − 7 + 1 = 54. The new total is 122, so each group must sum to 61, and the group with 54 needs 7, which 3 + 4 or 5 + 2 supplies.

For more practice with proofs, see how to study for discrete math and how to study for a computer science exam.

What the sources found, and their limits

Jeff Erickson, Algorithms, chapter 12, NP-Hardness. It defines P, NP, NP-hard and NP-complete, says a problem in P is also in NP, gives the direction rule for reductions, explains pseudo-polynomial time for Subset Sum, and says Partition can be proved NP-hard by a reduction from Subset Sum. Source: NP-Hardness (PDF), read on 2026-11-25.

University of Nevada, Las Vegas, CSC 456 course handout. It reduces Subset Sum to Partition by adding the two numbers used above (it writes C for the target), proves both directions, and notes that a split is a short certificate. Source: Reduction of Subset Sum to Partition (PDF), read on 2026-11-25.

NIST Dictionary of Algorithms and Data Structures. It defines NP-complete in terms of checking answers with a certificate and of other NP problems being no more than a polynomial factor harder. Source: NP-complete, read on 2026-11-25.

Clay Mathematics Institute. It poses P versus NP as the question of whether a problem whose solutions are easy to check is also easy to solve, and marks it unsolved. Source: P versus NP, read on 2026-11-25.

Limits: selected passages of a textbook chapter, a short course handout, a dictionary entry and an overview page. This page uses informal definitions and leaves out Turing machines. The number list and the self-test cases are ours.

How Professor Turing helps

Professor Turing is a tutor for adults learning any subject, in college or on their own. It asks you questions instead of giving the final answer, does not grade a bare guess, and remembers what you got wrong. No account is needed to start. It's an AI tutor, free to try.

Bring a problem you are trying to prove hard and say which known problem you would reduce from. Its first reply asks what you already know, such as which direction the reduction runs, before it teaches anything. You must be 18 or older, and guest conversations are deleted 7 days after the last activity.

FAQ

Does NP mean not polynomial? No. NP stands for nondeterministic polynomial time. It is the class of decision problems where a yes answer has a proof that can be checked in polynomial time, and it includes the problems in P.

What is the difference between NP-hard and NP-complete? An NP-hard problem is one where a polynomial-time algorithm for it would give one for all problems in NP. An NP-complete problem is NP-hard and also belongs to NP.

Has anyone shown that P is different from NP? The Clay Mathematics Institute listed the question as unsolved when we read its page on 2026-11-25.

Start with what you're working on

Tell the tutor which reduction or definition you are working on and let it ask you the questions.

Start learning No account needed

See also: how to study for discrete math · all study guides