Complexity Classes • story mode

Which problems are easy, hard, or impossible to handle?

This page builds the idea step by step: everyday questions → solve vs verify → P / NP / NP-Complete / NP-Hard → reductions and SAT to Vertex Cover.

Real-life examples first Interactive Venn diagram SAT → Vertex Cover
Learning map
1.Not all questions behave the same way.
2.Some are easier to verify than to solve.
3.That gap leads to complexity classes.
4.Reductions transfer hardness.
Start with intuition

Not all problems are the same

Some questions are easy to answer directly. Some are hard to solve but easy to check. Some may be so general that no algorithm can solve them in every case.

Decision-style question: “Do you have a calculator in your room?”
Verification-style question: “Is this Sudoku solution correct?”
Construction-style question: “Create an exam timetable with no clashes.”
Deep limit question: “Can one algorithm always predict the future exactly?”
Big idea: complexity theory compares the effort needed to find an answer, check an answer, and sometimes asks whether a general solution is even possible.
📦

Do you have a pen in your room?

Answer type: YES / NO

If someone shows you the pen, verification is immediate. If not, you may keep searching.

🧩

Solve this Sudoku

Finding a full solution can take a lot of trial and backtracking.

This feels very different from simply checking a completed grid.

Check whether this Sudoku is correct

Now the task becomes structured: scan rows, columns, and boxes.

This is the exact gap that leads toward NP.

🗓️

Make an exam timetable

A valid schedule must satisfy many constraints at once.

But checking whether a given timetable has clashes is much easier.

🚗

Find the best route through all cities

Optimization problems quickly become huge as cities grow.

A proposed route can be evaluated much faster than searching all possibilities.

🔮

Can an algorithm predict everything?

This pushes students to think about the limits of computation itself.

Complexity is about difficulty; some questions also touch computability limits.

A simple progression

Step 1

Ask a question

Is there a pen? Is this timetable valid? Is this route short enough?

Step 2

Search for an answer

Sometimes search is tiny. Sometimes possibilities explode.

Step 3

Verify a candidate

Given a proposed answer, constraints may be checked quickly.

Step 4

Classify the problem

That is where P, NP, NP-Complete, and NP-Hard enter.

Left side

Solve the problem

Start from scratch and construct an answer.

Sudoku

Fill every blank correctly. Many branches may need to be explored.

Exam timetable

Assign all courses to slots while satisfying every clash constraint.

Hamiltonian cycle / route planning

Construct a valid cycle or route, not just check one.

Right side

Verify a proposed answer

Someone gives a candidate. You only need to test whether it works.

Sudoku

Check rows, columns, and sub-grids for duplicates.

Exam timetable

Scan all student pairs or conflict edges for clashes.

Route / cycle

Check whether all required cities or vertices appear correctly and whether the cost limit is met.

The key teaching idea

Hard to solve

You may need to search among many possibilities.

Easy to verify

Once a candidate is given, checking can be much faster.

Takeaway: many important problems are not known to be easy to solve, but their proposed solutions can be checked efficiently. This intuition is exactly why the class NP matters.

Mini comparison

Find from scratchBuild a valid answer yourself
Check a candidateConfirm whether a proposed answer is correct
Decision versionConvert the task into YES / NO form
Example

Instead of asking “Find the shortest tour”, ask “Is there a tour of length ≤ 100?” That YES / NO version fits more naturally into complexity classes.

Interactive centerpiece

Explore the relationship between P, NP, NP-Complete, and NP-Hard

Hover or click a region. Then click the example chips below to see where they belong.

How these classes are related

This diagram compares efficiently solvable problems, efficiently verifiable problems, and the hardest well-known decision problems.

Click a region to explore
NP solutions can be verified efficiently NP-Hard extends beyond NP NP-C NP ∩ NP-Hard P P lies inside NP. NP-Complete fills the exact overlap of NP and NP-Hard. NP-Hard also extends beyond NP.
Legend
P: efficiently solvable
NP: efficiently verifiable
NP-Complete: exact overlap of NP and NP-Hard
NP-Hard: at least as hard as NP
Reading the diagram
P ⊆ NP, so every problem in P can also be verified efficiently.
NP-Complete = NP ∩ NP-Hard, so the full overlap is filled by NP-C.
NP-Hard continues outside NP, so not every NP-Hard problem belongs to NP.
Open question: Is P = NP? This is one of the biggest unsolved problems in computer science, and it is also one of the Clay Mathematics Institute’s Millennium Prize Problems.
Example chips
Problem transfer

Reductions explain why NP-Complete problems matter

A reduction transforms one problem into another in polynomial time. If a known hard problem can be converted into a new problem, the new problem must also be hard. "The conversion from A to B takes polynomial time"

A ≤p B

“A reduces to B” means: if you can solve B efficiently, then you can also solve A efficiently.

To prove B is hard

Reduce a known hard problem A → B.

Common mistake

Students often reverse the arrow. The direction matters.

Cook’s Theorem: SAT was the first NP-Complete problem. That means every problem in NP can be polynomially reduced to SAT.
SAT → Vertex Cover

The classroom pattern for 3-SAT reduction

Variable gadget

For each variable, create a pair such as x and ¬x. The cover will choose one side from each pair.

Clause gadget

Each 3-literal clause becomes a triangle. To cover all its internal edges, the cover chooses 2 vertices from that clause gadget.

Final size

If there are l variables and c clauses, then the target size is:

k = l + 2c

Mini interactive counter

Move the sliders to see how the target cover size changes for a 3-SAT style reduction.

Required cover size
10
k = l + 2c