LearnViz CompSci
Home / Learn / Theory & Discrete Math / Class NP

Advanced Topic 36 of 51 Theory & Discrete Math

Class NP

Problems whose solutions can be verified quickly.

How it works

Class NP consists of decision problems for which a proposed solution can be verified in polynomial time by a deterministic algorithm, equivalently solvable in polynomial time by a nondeterministic Turing machine. Examples include satisfiability, graph coloring, clique, subset sum, the Hamiltonian cycle and factoring in its decision form. Every problem in P is in NP, and the famous open question is whether the reverse holds. A certificate is the evidence, such as an assignment or a path, that the verifier checks.

Step-by-step walkthrough

  1. NP problems have solutions that can be checked in polynomial time.
  2. Sudoku: given a filled grid, checking is easy.
  3. Solving from scratch may take much longer, nobody knows.
  4. Every problem in P is also in NP.

Where it is used

NP captures many practical search and optimization problems in scheduling, routing, design and verification. Solvers use heuristics, SAT and SMT engines and approximation.

Common pitfall

NP does not stand for not polynomial but nondeterministic polynomial time. A problem being in NP says nothing about being hard; it includes all of P. Checking a certificate is easy, finding one may not be. Complement problems, such as proving unsatisfiability, may not be in NP, which leads to the class co-NP. Always specify the decision version.

Where it fits in the course

Class NP is topic 36 of 51 in Theory & Discrete Math, rated Advanced. It follows Class P. The next topic is NP-Completeness.

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 Class NP?
Problems whose solutions can be verified quickly. It belongs to Theory & Discrete Math and is an advanced-level topic.
Where do people use Class NP?
NP captures many practical search and optimization problems in scheduling, routing, design and verification.
What is the most common mistake with Class NP?
NP does not stand for not polynomial but nondeterministic polynomial time.
What should I learn before this topic?
Start with Class P, 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 Class NP 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 Class NP?
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 Class NP?
Class P, NP-Completeness, Complexity Classes are closely connected. The full list is in the related topics section of this page.
What should I study after Class NP?
Continue with NP-Completeness, the next topic in Theory & Discrete Math.

Related topics