LearnViz CompSci
Home / Learn / Theory & Discrete Math / NP-Completeness

Advanced Topic 37 of 51 Theory & Discrete Math

NP-Completeness

Hardest problems in NP to which all NP reduces.

How it works

A problem is NP-complete if it is in NP and every problem in NP reduces to it in polynomial time, so it is among the hardest problems in NP. If any NP-complete problem had a polynomial-time algorithm, then P would equal NP. Classic NP-complete problems include SAT, 3-SAT, clique, vertex cover, Hamiltonian cycle, traveling salesman in decision form, subset sum, knapsack and graph coloring. Proofs use reductions from a known NP-complete problem.

Step-by-step walkthrough

  1. A problem is NP-complete if it is in NP.
  2. And every problem in NP reduces to it in polynomial time.
  3. So a fast algorithm for one gives a fast algorithm for all.
  4. Examples: SAT, 3-coloring, Traveling Salesman decision version.
  5. They are the hardest problems in NP.

Where it is used

Recognizing NP-completeness tells engineers not to search for an exact efficient algorithm for all instances and to use approximation, heuristics, parameterized or special-case algorithms or SAT solvers.

Common pitfall

Proving NP-hardness by reducing in the wrong direction is the standard error. Verify membership in NP as well as hardness. NP-complete is a worst-case notion: many real instances are solved quickly. Pseudo-polynomial algorithms for problems like knapsack do not contradict hardness. Reduce from a problem similar in structure.

Where it fits in the course

NP-Completeness is topic 37 of 51 in Theory & Discrete Math, rated Advanced. It follows Class NP. The next topic is Cook-Levin Theorem.

Practice and explore

How to study this topic

  1. Read the explanation above and restate the definition in your own words.
  2. Open the interactive lesson and answer its mini quiz.
  3. Read the common pitfall, then write a short example that avoids it.
  4. Check your understanding in the Theory & Discrete Math quiz, and revisit the topic if you miss a question.

Frequently asked questions

What is NP-Completeness?
Hardest problems in NP to which all NP reduces. It belongs to Theory & Discrete Math and is an advanced-level topic.
Where do people use NP-Completeness?
Recognizing NP-completeness tells engineers not to search for an exact efficient algorithm for all instances and to use approximation, heuristics, parameterized or special-case algorithms or SAT solvers.
What is the most common mistake with NP-Completeness?
Proving NP-hardness by reducing in the wrong direction is the standard error.
What should I learn before this topic?
Start with Class NP, the topic just before it in Theory & Discrete Math.
How can I practice it?
Answer the mini quiz in the interactive lesson, then take the Theory & Discrete Math quiz.
Is NP-Completeness hard to learn?
It is an Advanced topic. Expect to read the explanation more than once and to connect it with earlier topics. Working through a small example by hand helps most.
How long does it take to learn NP-Completeness?
Most learners can read the explanation and finish the interactive lesson in under an hour. Fluency comes from applying the idea, so plan a few short practice sessions with the quiz.
Which topics are related to NP-Completeness?
Class NP, Cook-Levin Theorem, Class P are closely connected. The full list is in the related topics section of this page.
What should I study after NP-Completeness?
Continue with Cook-Levin Theorem, the next topic in Theory & Discrete Math.

Related topics