P vs NP

The Million Dollar Question

CS305 -- Formal Language Theory & Complexity

$1,000,000 · Unsolved since 1971 · Use ← → to navigate

The Big Picture

We've studied what's computable. Now: among computable problems, which are EFFICIENTLY solvable?

The Computability/Complexity Landscape ======================================== All Problems (Languages) +----------------------------------------------+ | Undecidable (Halting Problem, etc.) | | "No algorithm can solve these -- ever." | | | | +------------------------------------------+| | | Decidable (Computable) || | | "An algorithm EXISTS, but how fast?" || | | || | | +--------------------------------------+|| | | | Efficiently Solvable? ||| | | | THIS is the P vs NP question! ||| | | +--------------------------------------+|| | +------------------------------------------+| +----------------------------------------------+

Analogy: Finding Your Keys

Computability: "Your keys exist somewhere in the universe."
Complexity: "Can you find them before lunch?"

Key Shift in Perspective

In the first half of the course, we asked: "Can this problem be solved at all?"
Now we ask: "Can it be solved FAST ENOUGH to be practical?"

Why This Matters

A problem can be decidable yet completely impractical. An algorithm taking 2n steps on input of size n=1000 would run longer than the age of the universe. "Solvable in theory" is not "solvable in practice."

The central question of complexity theory:

Is finding solutions fundamentally harder than checking them?

Time Complexity

Measuring efficiency as a function of input size n

Polynomial Time (Tractable)

  • O(n) -- Linear
  • O(n log n) -- Linearithmic
  • O(n²) -- Quadratic
  • O(n³) -- Cubic
  • O(nk) -- Polynomial for fixed k

These grow manageably.

Exponential Time (Intractable)

  • O(2n) -- Exponential
  • O(n!) -- Factorial

These EXPLODE.

Why This Matters

At n=100: O(n²) = 10,000 steps (milliseconds).
O(2n) = 1030 steps -- more than the age of the universe in nanoseconds.

Growth Rate Comparison

n = 1
Increase n to see the growth gap emerge.

The Class P

Problems solvable in polynomial time by a deterministic Turing Machine

P = { L | ∃ deterministic TM M and polynomial p(n) such that M decides L in time O(p(n)) }

What "P" Means Intuitively

  • Problems we can actually solve in practice
  • Algorithms that scale to large inputs
  • Time grows at most as some fixed power of input size
  • "Efficiently solvable" = "in P"

Key Idea

P captures the notion of feasible computation. If a problem is in P, we can build practical software to solve it.

Analogy

P problems are like recipes where cooking time is proportional to the number of guests. Double the guests? Maybe quadruple the cooking time. Manageable.

Examples of P Problems

ProblemAlgorithmTime
SortingMerge sortO(n log n)
Shortest PathDijkstraO(V²)
GCDEuclid'sO(log n)
PrimalityAKS (2002)O(n&sup6;)
MatchingEdmonds'O(V³)
2-SATSCC-basedO(V+E)
Graph connectivityBFS/DFSO(V+E)

Note

Being "in P" doesn't mean trivially fast -- O(n100) is technically polynomial but impractical. In practice, most P algorithms are low-degree polynomials.

The Class NP

Problems where solutions can be VERIFIED quickly -- the certificate/verifier definition

NP = { L | ∃ poly-time verifier V s.t. x ∈ L ⇔ ∃ certificate c, |c| ≤ poly(|x|), V(x,c) accepts }

The Two Key Parts

  • Certificate (witness): A proposed solution or "proof" that the answer is YES
  • Verifier: An algorithm that CHECKS the certificate in polynomial time

NP = Nondeterministic Polynomial time, NOT "Non-Polynomial"!

Common Misconception

NP does NOT mean "not solvable in polynomial time." Many NP problems ARE in P! NP means verifiable in polynomial time.

Interactive: Subset Sum Verifier

Set = {3, 7, 1, 8, 4}   Target = 12. Click numbers to build a certificate.

The Asymmetry

Verifying {3,1,8} sums to 12: instant (3 additions).
Finding which subset sums to 12: potentially 2n subsets to check.

NP via Nondeterminism

The equivalent "lucky guessing" definition using Nondeterministic Turing Machines

NTM Branching Tree

Click Step or Auto to build the computation tree.

The "Lucky Guesser" Interpretation

Think of it as a two-phase machine:

Phase 1: GUESS

Nondeterministically "guess" a certificate. Magically picks the right one if it exists.

Phase 2: VERIFY

Deterministically check the guess in polynomial time. This is the verifier.

Analogy: Magic Oracle

A friend with perfect intuition always guesses right. You still double-check their work. If checking is fast (polynomial), the problem is in NP.

Why Definitions Are Equivalent

Certificate-based: "A short proof exists and can be checked quickly."
NTM-based: "A nondeterministic machine can find and verify in poly time."
Each branch = different candidate certificate.

P ⊆ NP

Every problem in P is also in NP -- but is the reverse true?

Why P ⊆ NP

If you can solve a problem in polynomial time, you can certainly verify a solution in polynomial time -- just solve it again and compare!

The Proof (1 line)

Given a P-algorithm for L: build a verifier V(x,c) that ignores c, runs the P-algorithm on x, and accepts iff the algorithm says YES. V runs in poly time, so L ∈ NP.

Interactive Venn Diagram

Showing: P ⊂ NP (most experts believe this)

The Million Dollar Question

We KNOW: P ⊆ NP We DON'T KNOW: Does P = NP ? (everything verifiable is also solvable) Or P ⊊ NP ? (some problems are harder to solve than to verify)

The Stakes

This is one of the Clay Millennium Prize Problems. Solve it (either direction) and win $1,000,000. Open since 1971 -- over 50 years of the brightest minds failing to resolve it.

The Million Dollar Question: P =? NP

Two possible worlds -- click to explore each scenario

Most experts think this is UNLIKELY

If P = NP...

Cryptography breaks. RSA, AES, blockchain -- all gone.
Optimization becomes trivial. Scheduling, logistics, protein folding -- all solvable optimally.
Mathematical proofs become automated. Computers find short proofs of any provable theorem.
AI leaps. Optimal neural network training in poly time.

"If P = NP, then the world would be a profoundly different place... Everyone who could appreciate a symphony would be Mozart." -- Scott Aaronson

Why Most Experts Believe P ≠ NP

Decades of effort by brilliant researchers have failed to find polynomial algorithms for NP-complete problems. It would be astonishing if all that effort missed something. But nobody can PROVE it either way!

Polynomial-Time Reductions

The tool for comparing problem difficulty: A ≤P B

Core Idea

Problem A reduces to problem B (written A ≤P B) if we can transform any instance of A into an instance of B in polynomial time, such that solving B gives us the answer to A.

Polynomial-Time Reduction: A ≤_P B Instance of A Instance of B Solution to B +-----------+ poly +-----------+ solve +-----------+ | | -------> | | -------> | | | "Is x | time | "Is f(x) | B's | YES/NO | | in A?" | f(x) | in B?" | algo | | +-----------+ +-----------+ +-----------+ | | +---------- Same answer! ----------------------+ If B is easy (in P), then A is easy too! If A is hard, then B must be hard too!

Analogy: Language Translation

If you can translate French to English quickly, and you have an English dictionary, then you can look up French words. Reducing French-lookup to English-lookup.

Direction Matters!

A ≤P B means "A is no harder than B" (or "B is at least as hard as A").
Showing a hard problem reduces TO your problem means your problem is hard too!

NP-Completeness

The hardest problems IN NP -- click regions and problems to explore

Definition

A problem is NP-Complete if:

1. It is in NP (solutions can be verified in polynomial time), AND

2. It is NP-Hard (every NP problem reduces to it in poly time)

Click a problem badge or region label to learn more.

Why NP-Complete Problems Are Special

If you find a polynomial algorithm for ANY NP-complete problem, then P = NP. Conversely, if ANY NP-complete problem has no poly-time algorithm, then P ≠ NP. They're the "gatekeepers."

Cook-Levin Theorem (1971)

SAT is NP-complete -- the theorem that launched complexity theory

Theorem

SAT is NP-complete. Boolean Satisfiability was the FIRST problem ever proven NP-complete. Every other NP-completeness proof builds on this.

Proof Sketch (Step Through)

Click Next Step to walk through Cook's proof idea.

Interactive SAT Solver

φ = (x1 ∨ ¬x2 ∨ x3)
(¬x1 ∨ x2)
(¬x1 ∨ ¬x3)
(x2 ∨ x3)
x1
x2
x3

The Difficulty

3 variables = 8 assignments. n variables = 2n. At n=300, more than atoms in the universe.

Challenge: Classify the Problem

For each problem, decide: Is it in P, NP-complete, or NP-hard (not in NP)?

P

NP-Complete

NP-Hard (not in NP)

Click a card, then click a zone to classify it.

NP-Complete Reduction Web

Click edges for reduction details, nodes for connections, or watch the chain cascade

Click any node to explore the reduction web.

Chain of Dominoes

Cook knocked over the first domino (SAT). Karp knocked over 21 more in 1972. Now thousands of NP-complete problems are known. Each needs just ONE reduction from an existing NP-complete problem.

Reduction: 3-SAT → CLIQUE

Step-by-step construction showing how to reduce 3-SAT to the Clique problem

The Construction

Click Next Step to see the 3-SAT to Clique reduction.

Visual: Graph Construction

Key Insight

A k-clique in the constructed graph corresponds to picking one TRUE literal from each clause -- exactly a satisfying assignment!

Challenge: Fix the Reduction

This reduction from Vertex Cover to Set Cover has a bug. Find and fix it!

Buggy Reduction: Vertex Cover ≤P Set Cover

Given graph G=(V,E) and integer k:
1. Universe U = E (the edges)
2. For each vertex v ∈ V, create set Sv = {all vertices adjacent to v}
3. Set cover budget = k
4. G has vertex cover of size k ⇔ (U,S,k) has set cover of size k

What should Sv contain instead? Click the correct fix:

NP-Hard vs NP-Complete

Understanding the crucial distinction

NP-Complete = NP-Hard ∩ NP

NP-Hard

Every NP problem reduces to it. "At least as hard as the hardest NP problems."
Does NOT need to be in NP itself!

NP-Complete

NP-Hard AND in NP. The "sweet spot" -- maximally hard within NP. These are the gatekeepers of P vs NP.

Every NP problem reduces to H: SAT --------\ TSP ---------\ Clique -------+----> H (NP-Hard) Coloring ----/ SubsetSum --/ ...every NP problem If H is ALSO in NP: H is NP-Complete!

NP-Hard Does NOT Mean "in NP"

NP-hard problems can be harder than NP! They might not even be decidable.

Example: The Halting Problem is NP-hard (every NP problem reduces to it) but it's not in NP -- it's not even decidable!

In NP?NP-Hard?
SortingYes (in P)No
SATYesYes (NP-Complete)
TSP DecisionYesYes (NP-Complete)
Halting ProblemNoYes (NP-Hard only)
TSP OptimizationNoYes (NP-Hard only)

Analogy: The Master Lock

An NP-hard problem is a "master lock." Pick this one lock, every other NP lock opens. NP-complete means it's also a lock in the NP building. Some master locks (Halting Problem) aren't even in the building!

Implications: P=NP vs P≠NP

What would each answer mean for the world?

If P = NP

Cryptography BREAKS

RSA, AES, blockchain -- all broken. Attackers decrypt any message, forge any signature. Online banking, HTTPS -- gone.

Optimization Becomes Trivial

Scheduling, logistics, protein folding, chip design -- all solvable optimally in polynomial time.

Mathematical Proofs Automated

Finding proofs is in NP. If P=NP, computers find short proofs of any provable theorem automatically.

"If P = NP... everyone who could appreciate a symphony would be Mozart." -- Scott Aaronson

If P ≠ NP (likely)

Cryptography is Safe

The hardness of certain problems guarantees encryption works. Your online banking is safe.

Fundamental Asymmetry Exists

Creating IS harder than checking. Writing a proof is harder than verifying one. This asymmetry is built into mathematics.

Creativity Has Value

Some tasks require genuine insight that cannot be shortcut by computation.

2019 poll: 88% of complexity theorists expect P ≠ NP.

But nobody can prove it either way!

Coping with NP-Hardness

Your problem is NP-complete. Now what? Don't despair!

1. Approximation Algorithms

Find a solution provably CLOSE to optimal. Vertex Cover: greedy gives ≤ 2x optimal. TSP (metric): Christofides gives ≤ 1.5x optimal.

2. Heuristics & Metaheuristics

Simulated annealing, genetic algorithms, local search. TSP tours for millions of cities found near-optimally in practice.

3. Special Cases

2-SAT is in P. Graph coloring on trees is in P. Your specific inputs might have exploitable structure.

4. Randomized Algorithms

Random assignment satisfies ≥ 7/8 of clauses in MAX-3-SAT on average.

5. Exponential but Practical

Modern SAT solvers handle millions of variables using DPLL, CDCL, unit propagation. Worst case exponential, typical cases fast.

6. Restrict Input Size

If n is small, even O(2n) is fine. Subset Sum with 30 elements? 230 ≈ 109 -- seconds on modern hardware.

Analogy

NP-completeness says "you can't always find the exit in a giant maze quickly." But YOUR maze might have helpful signs, be small, or you might accept an exit that's close enough.

Beyond NP -- The Complexity Hierarchy

NP is just one level in a vast tower of complexity

The Tower (interactive)

Hover over a level to learn more.

Key Classes Beyond NP

coNP

Complements of NP problems. "Can you verify something is NOT the case?"
Example: "Is this formula UNSATISFIABLE?"

PSPACE

Polynomial SPACE, possibly exponential time. Example: Quantified Boolean Formulas (QBF) -- two-player game logic. PSPACE = NPSPACE (Savitch's theorem).

EXPTIME

Exponential time. Generalized chess & checkers are EXPTIME-complete. We KNOW P ≠ EXPTIME!

What We Know vs. Don't Know

P ⊆ NP ⊆ PSPACE ⊆ EXPTIME -- all known.
But we only know P ≠ EXPTIME for certain. Whether P≠NP, NP≠PSPACE are open!

Challenge: Classify the Complexity

Match each problem to its complexity class

Problems

Your Answers

Select a class for each problem, then click Check.

Summary & Cheat Sheet

Everything you need to know about P vs NP on one slide

COMPLEXITY CHEAT SHEET ====================== P: Solvable in poly time (det. TM) Examples: sorting, shortest path, primality, matching, 2-SAT NP: Verifiable in poly time (cert) Examples: SAT, TSP, Clique, Subset Sum, Graph Coloring P ⊆ NP: Always true. NP-Hard: At least as hard as every NP problem. NP-Complete: NP-Hard AND in NP. Examples: SAT, 3-SAT, Clique, Vertex Cover, TSP, Ham. Cycle P =? NP: OPEN. $1M prize. Most believe P ≠ NP.

How to Prove X is NP-Complete

1. Show X is in NP (describe a verifier).
2. Reduce a known NP-complete problem to X.
That's it! Usually reduce from 3-SAT.

RELATIONSHIP MAP (if P ≠ NP) +------------------------------------+ | NP-Hard (may be outside NP) | | +--------------------------------+| | | NP || | | +-------+ +--------------+ || | | | P | | NP-Complete | || | | +-------+ +--------------+ || | +--------------------------------+| +------------------------------------+ KEY REDUCTIONS: SAT -> 3-SAT -> Clique, Ind. Set, Vtx Cover, Subset Sum, 3-Color Ham Cycle -> TSP
IF P = NP: - Crypto breaks, optimization trivial - Proofs automated, world transforms IF P ≠ NP (likely): - Some problems inherently hard - Crypto safe, creativity has value - Use approx, heuristics, special cases

The Big Takeaway

P vs NP asks: is finding solutions fundamentally harder than checking solutions? The most important open question in CS. We believe yes (P≠NP), but proving it remains one of humanity's greatest challenges.

Quiz 1: Core Concepts

Test your understanding of P, NP, and reductions

Q1: Which is NOT in NP?

Q2: If 3-Coloring is solved in O(n5), what follows?

Q3: A ≤P B means:

Q4: Which statement is TRUE?

Quiz 2: Reductions & NP-Completeness

Test your understanding of reductions and proofs

Q1: To prove X is NP-complete, you must:

Q2: Which is NOT a valid strategy for NP-hard problems?

Q3: 2-SAT is in which class?

Q4: Cook-Levin proved SAT is NP-complete by:

Quiz 3: Advanced Complexity

Final challenge on complexity hierarchy and implications

Q1: Which inclusion is PROVEN?

Q2: If P = NP, which would NOT happen?

Q3: PSPACE = NPSPACE because of:

Q4: Why can't current techniques prove P ≠ NP?