❓ Full Lesson · Algorithms
P: Fast to Solve | NP: Fast to Verify
P vs NP

The biggest unsolved question in computer science, in one sentence: if a solution is easy to check, must it also be easy to find? Nobody knows — but the answer would reshape cryptography, optimization, and mathematics itself.

The Core Idea
Two Different Kinds of 'Fast'

P (Polynomial time) is the set of problems that can be solved quickly — in time that grows polynomially with input size (like O(n), O(n²), O(n³)), rather than exponentially. NP (Nondeterministic Polynomial time) is the set of problems where, if someone hands you a proposed solution, you can verify that it's correct quickly — even if finding that solution in the first place might take much longer.

Every problem in P is automatically in NP too — if you can solve something quickly, you can obviously also verify a proposed answer quickly (just solve it yourself and compare). The open question, unsolved since it was formally posed in 1971, is whether the reverse is also true: is every problem whose solution is easy to verify also easy to solve? This is written as the question 'does P = NP?'

💡 Memory Trick
Think of a finished jigsaw puzzle vs. an empty table with scattered pieces. Checking that a completed puzzle is correct takes almost no time — you just look at the picture. Assembling that puzzle from scratch can take vastly longer. P vs NP asks: is there always a clever shortcut that makes assembling exactly as fast as checking, for every possible puzzle — or are some puzzles fundamentally harder to assemble than to verify, no matter how clever your method?
The Key Categories
Where Different Problems Sit
1
P — Easy to Solve
Problems with known polynomial-time algorithms. Sorting a list, finding the shortest path with Dijkstra's algorithm, and checking whether a number is prime are all in P — we have efficient algorithms for all of them.
2
NP — Easy to Verify
Problems where a proposed solution can be checked quickly, even if no fast way to find that solution is known. Sudoku solving is in NP: checking a completed grid for validity is fast, but finding the solution from a mostly-empty grid can require extensive search.
3
NP-Complete — The Hardest Problems in NP
A special subset of NP problems that are all provably 'equally hard' — if you found a fast (polynomial-time) algorithm for any single NP-complete problem, you could adapt it to solve every NP-complete problem quickly, which would prove P = NP. The Traveling Salesman Problem (decision version), Boolean satisfiability (SAT), and graph coloring are classic NP-complete problems.
Example: an efficient SAT solver would immediately imply an efficient solver exists for every NP-complete problem, since they can all be transformed into each other.
4
NP-Hard — At Least as Hard, but Not Necessarily in NP
Problems at least as hard as the hardest NP problems, but which may not themselves be verifiable quickly (so they might not even be in NP). The optimization version of the Traveling Salesman Problem (find the actual shortest route, not just verify if one under a certain length exists) is NP-hard.
Why It Matters
Practical Consequences of the Unsolved Question

Most computer scientists believe P ≠ NP (that some problems really are fundamentally harder to solve than to verify), but this has never been proven — it remains one of the seven Millennium Prize Problems, with a $1 million reward for a correct proof either way. Modern cryptography implicitly relies on P ≠ NP being true: many encryption schemes are secure specifically because certain problems (like factoring large numbers) are believed to be hard to solve quickly, even though verifying a proposed factorization is trivial.

In practice, since NP-hard and NP-complete problems can't currently be solved exactly and efficiently for large inputs, real-world systems use approximation algorithms (which find a 'good enough' answer quickly) or heuristics (rules of thumb that work well in practice without guaranteed optimality) instead of insisting on the perfect solution.

🖥️ Applied Scenario
You're asked to write a route-planning system for a delivery company that must find the absolute shortest route visiting 50 specific delivery addresses exactly once.
1
You recognize this as the Traveling Salesman Problem, which is NP-hard — there is no known algorithm that finds the guaranteed optimal route in polynomial time for large numbers of stops.
2
You calculate that checking every possible route (brute force) for 50 stops would require examining more possible orderings than there are atoms in the observable universe — completely infeasible.
3
Instead of insisting on the mathematically perfect route, you choose an approximation algorithm that guarantees a route within a known percentage of optimal, computed in a practical amount of time.
4
Conclusion: because the problem is NP-hard, you accept a 'good enough, provably bounded' answer rather than searching for an efficient exact solution that current computer science strongly believes doesn't exist.
📌 Exam Application
Exam questions often ask you to classify a described problem as being in P, NP, NP-complete, or NP-hard, and to justify the classification by describing whether a fast verification method exists and whether a fast solving method is known. You may also be asked to explain, in your own words, why proving any single NP-complete problem is in P would prove P = NP for all of them — the answer rests on NP-complete problems all being reducible to one another in polynomial time.
⚠️ Most Common P vs NP Mistakes
The most common mistake is treating 'NP' as if it stood for 'not polynomial' or 'impossible to solve quickly' — NP actually means the solution is verifiable quickly; whether it's also solvable quickly is exactly the open question, not a settled negative. Another frequent error is confusing NP-complete (which requires a problem to also be in NP, i.e., verifiable quickly) with NP-hard (which does not require this) — every NP-complete problem is NP-hard, but not every NP-hard problem is NP-complete.
✓ Quick Self-Test
Can you explain, in one sentence, the difference between a problem being 'easy to solve' and 'easy to verify'? Can you correctly classify a few example problems (sorting, Sudoku, Traveling Salesman) into P, NP, NP-complete, or NP-hard, and justify each classification?
Next Lesson
Amortized Analysis
← All Algorithms Lessons