computational complexity
Complexity Classes (P vs NP)
You should know: big o notation, turing machines
Overview
Complexity theory classifies decidable problems not by whether they CAN be solved, but by how much time or space an algorithm needs as a function of input size. The most famous open question in computer science — whether P equals NP — asks whether every problem whose solution can be quickly VERIFIED can also be quickly FOUND. It's one of the seven Clay Millennium Prize Problems, with a $1 million reward for its resolution.
Intuition
Solving a jigsaw puzzle can take a long time, but CHECKING that a completed puzzle is correct is fast — just look at it. P vs NP asks: is there always a fast (polynomial-time) way to solve any problem whose solutions can be fast-checked? For problems like sorting, the answer is yes (P). For problems like the Traveling Salesman Problem, no efficient solving method is known — only efficient checking — and most computer scientists believe none exists (P ≠ NP), though this remains unproven.
Formal Definition
The core complexity classes:
Equivalent 'verifier' characterization of NP
Notation
| Notation | Meaning |
|---|---|
| Problems solvable in polynomial time | |
| Problems verifiable in polynomial time | |
| The hardest problems in NP — every NP problem reduces to them in polynomial time |
Properties
P is a subset of NP
Example: Anything solvable quickly is also checkable quickly (just re-solve it).
NP-completeness
P=NP consequence
Applications
Worked Examples
Checking a filled grid against the rules takes time proportional to the number of cells — polynomial. Finding a valid filling, in the worst case, may require searching exponentially many candidate assignments.
Answer: Verification is fast (P); solving is NP-complete for the generalized n²×n² version.
Practice Problems
If someone proved P = NP tomorrow, what would that mean for modern cryptography?
A delivery company wants the shortest route visiting 30 cities exactly once (the Traveling Salesman Problem). Why can't they just check every possible route, and how does this relate to NP-hardness?
A password has 10 characters from a 90-symbol set. Brute-forcing it is 90¹⁰ attempts. Verifying a guessed password is instant. Which complexity idea does this illustrate?
A completed Sudoku can be CHECKED for validity quickly, but SOLVING a large blank one seems hard. This 'easy to verify, hard to solve' pattern is the defining feature of:
Common Mistakes
Believing NP stands for 'not polynomial'.
NP stands for 'nondeterministic polynomial time' — it does NOT mean a problem takes non-polynomial time; it means a solution can be verified in polynomial time (and P is itself a subset of NP).
Assuming P ≠ NP has been proven.
It's widely believed but remains an open problem — one of the most famous unsolved questions in mathematics and computer science.
Quiz
Flashcards
Historical Background
The classes P and NP were formalized in the early 1970s. Stephen Cook's 1971 paper introduced NP-completeness and proved the Boolean satisfiability problem (SAT) is NP-complete — the Cook-Levin theorem (independently discovered by Leonid Levin). Richard Karp's 1972 paper showed 21 other important problems (including Traveling Salesman) are also NP-complete, revealing that an enormous range of practical problems are all equally hard, in a precise sense.
- 1971
Stephen Cook proves SAT is NP-complete (Cook-Levin theorem)
Stephen Cook
- 1972
Richard Karp shows 21 further problems are NP-complete
Richard Karp
- 2000
The Clay Mathematics Institute lists P vs NP as one of seven Millennium Prize Problems
Summary
- P: solvable in polynomial time. NP: solutions verifiable in polynomial time.
- P ⊆ NP always; whether P = NP is a famous open problem (Millennium Prize).
- NP-complete problems are the hardest in NP — solving one quickly would solve all of NP quickly.
- Most practitioners believe P ≠ NP, motivating heuristics/approximations for NP-complete problems in practice.
Mathematics