🖨️ Printing Instructions:
Press
Ctrl/Cmd + P
and select "Save as PDF".
1
P, NP, and the Limits of Computation
2
Learning Goals
Understand the classes P and NP.
Learn the Verifier definition of NP.
Explore the P vs NP question.
3
Computational Models
4
Algorithm vs Problem
Problem
: A general question to be answered (e.g., Sorting).
Algorithm
: A specific procedure to solve a problem (e.g., Quicksort).
Instance
: A specific input (e.g., [3,1,2]).
5
Decision Problems
Problems with a YES/NO answer.
Optimization problems can be cast as Decision problems.
Opt: Find min path length.
Dec: Is there a path of length $\le K$?
If we can solve Dec efficiently, we can usually solve Opt efficiently (Binary Search on K).
6
The Class P
7
Polynomial Time
Algorithm $A$ runs in polynomial time if $T(n) = O(n^k)$.
Class P
: Set of decision problems solvable by a deterministic algorithm in Polynomial Time.
Roughly corresponds to "Efficiently Solvable".
8
Examples of P
Binary Search.
Sorting
Minimum Spanning Tree (Kruskal).
Shortest Path (Dijkstra).
9
The Class NP
10
Nondeterminism from standard view
Original Def: Solvable by a
Nondeterministic
Turing Machine in Polynomial Time.
Imagine a machine that can branch into parallel universes at every step.
It says YES if
any
branch leads to Accept.
Not physically realizable.
11
Verifier Definition (Standard)
Class NP
: Set of decision problems where a 'Yes' instance has a certificate (proof) that can be
verified
in Polynomial Time.
Note: We don't need to find and verify NO instances efficiently.
NP = "Nondeterministic Polynomial" (Not "Non-Polynomial"!).
12
Example: Hamiltonian Cycle
Dec: Does graph G have a simple cycle interacting all V?
Is it in NP?
Yes. The Certificate is the sequence of vertices.
Verification: Check if edges exist, check if all V visited, check if simple.
Takes $O(n)$, which is poly.
13
Example: Sudoku
Is there a valid filling?
Certificate: The filled board.
Verification: Check rows, cols, boxes.
Takes polynomial time. In NP.
14
Example: Factoring
Input: M, k. Is there a factor $f$ of M such that $1 < f < k$?
Certificate: The factor $f$.
Verifier: Division check. $O(poly \log M)$.
In NP.
15
P vs NP
16
Interactive Demo
🚀 Interactive Demo:
p_vs_np_demo.html
17
Relationship
Any problem in P is also in NP.
Proof: If we can solve it in poly time, we can verify it in poly time (ignore certificate, just run solver).
So $P \subseteq NP$.
18
The Big Question
Is $P = NP$?
Can every problem with an easily verifiable solution also be SOLVED easily?
Most believe
No
.
Why? Finding a proof seems harder than checking one.
Example: Writing a symphony vs Appreciating one.
19
Millennium Prize
Clay Math Institute offers $1,000,000 for proof.
Biggest open problem in CS.
20
Class EXP
21
Exponential Time
Problems solvable in $O(2^{n^k})$.
We know $P \subseteq NP \subseteq EXP$.
We know $P \neq EXP$.
So strict inequality must exist somewhere in the chain.
22
Co-NP
23
Definition
Problems where 'NO' instances can be efficiently verified.
Complement of NP problems.
Example: Tautology (Is formula always true?).
No-Certificate: A counter-example (assignment making it false).
24
Relationship
Is $NP = Co-NP$?
Unknown. Most think No.
If $P=NP$, then $NP=Co-NP$ (since P is closed under complement).
25
Examples Comparison
26
Shortest Path vs Longest Path
Shortest Path: P.
Longest Path (Simple): NP (related to Hamiltonian Path).
27
Eulerian vs Hamiltonian
Eulerian Tour (Use every edge): P (Degree checks).
Hamiltonian Cycle (Use every vertex): NP.
28
2-SAT vs 3-SAT
2-SAT: $(x_1 \lor x_2) \land (\neg x_1 \lor x_3)$. P (Linear).
3-SAT: $(x_1 \lor x_2 \lor x_3)$. NP.
29
Practice Problems
30
Problem 1
Is Sorting in P?
Yes.
$O(n \log n)$ is polynomial in $n$.
31
Problem 2
Is 0/1 Knapsack in P?
Careful! It is $O(nW)$.
W can be $2^b$ where $b$ is bits.
Not in P (unless P=NP).
It is "Pseudo-Polynomial".
32
Problem 3
Show that if $P=NP$, then we can break RSA encryption.
RSA relies on Factoring being hard.
Factoring is in NP (Decision version).
If $P=NP$, Factoring is in P.
We can factor large keys efficiently.
33
Common Pitfalls & Anti-Patterns
34
Watch Out For...
Confusing NP with 'Non-Polynomial' (NP means Nondeterministic Polynomial).
Assuming NP-hard problems cannot be solved (they can, just not efficiently).
Forgetting that P ⊆ NP (all P problems are also in NP).
35
Lecture Summary
P
: Problems with polynomial-time algorithms.
NP
: Problems with polynomial-time verifiable certificates.
The
P vs NP
problem asks whether every problem with a quickly verifiable solution can be quickly solved.
EXP
and
Co-NP
are other important complexity classes.
36
Supplementary Resources
🚀 Interactive Demo:
p_vs_np_demo.html
🚀 Interactive Demo:
handout.html