Given a graph with 1,000 vertices, find a Hamiltonian Cycle (visiting each node once):
\text{Search space: } \sim 1000! \approx 4 \times 10^{2567}
Given an ordered list of vertices (v_1, v_2, \dots, v_{1000}):
\text{Verify } (v_i, v_{i+1}) \in E \quad \text{and all } v_i \text{ distinct}
The Core Question
Is finding a needle in a haystack fundamentally harder than recognizing the needle once shown?
All decision problems are formalized as languages over a binary alphabet \Sigma = \{0, 1\}.
Language Formulation
A language L \subseteq \{0, 1\}^* is a set of instances with a “YES” answer: x \in L \iff \text{Problem instance encoded as } x \text{ has answer YES}
Definition (The Class P)
A language L \subseteq \{0, 1\}^* is in \mathbf{P} if there exists a deterministic Turing machine M and a polynomial p(n) such that for all x \in \{0, 1\}^*:
\mathbf{P} = \bigcup_{c \ge 1} \mathbf{DTIME}(n^c)
\mathbf{NP} is often defined as problems where positive answers have short, easily checkable proofs.
Candidate Certificate u
│
▼
Instance x ──►[ Polynomial-Time Verifier V ]──► ACCEPT / REJECT
Definition: NP via Verifiers
A language L \subseteq \{0, 1\}^* is in \mathbf{NP} if there exists a polynomial-time deterministic Turing Machine V (called a verifier) and a polynomial p(n) such that:
Completeness (YES instances): x \in L \implies \exists u \in \{0, 1\}^{\le p(|x|)} \text{ such that } V(x, u) \text{ accepts}
Soundness (NO instances): x \notin L \implies \forall u \in \{0, 1\}^{\le p(|x|)}, \quad V(x, u) \text{ rejects}
Given 3-CNF formula \phi: \phi = (x_1 \lor \overline{x_2} \lor x_3) \land (\overline{x_1} \lor x_4 \lor x_2)
Given graph G and target size k:
Note
Notice the asymmetry: A certificate only needs to prove that a solution exists (x \in L). It does not need to explain why no solution exists (x \notin L).
Historically, NP stands for Non-deterministic Polynomial time.
At each step, the transition function allows multiple choices: \delta: Q \times \Gamma \to \mathcal{P}(Q \times \Gamma \times \{\text{L}, \text{R}\})
Spawns a computation tree of configurations.
Root (Start)
/ \
Path 1 Path 2
/ \ / \
x x Acc x
Definition: NP via NDTMs
L \in \mathbf{NP} if there exists an NDTM N that runs in time at most p(|x|) on all branches and accepts x \iff x \in L.
Theorem
\mathbf{NP}_{\text{verifier}} \equiv \mathbf{NP}_{\text{NDTM}}
How do we mathematically compare the relative difficulty of two problems?
Intuition
If problem A can be easily solved using a subroutine for problem B, then: \text{"Problem } A \text{ is no harder than problem } B\text{"} \quad (A \le B)
Two primary models of polynomial-time reductions:
Algorithm for A:
Step 1: Do work
Step 2: Ask oracle for B?
Step 3: If NO, ask oracle for B again!
Step 4: Invert answer and return
Instance x of A
│
▼
[ Function f: Poly-time ]
│
▼
Instance f(x) of B
Why Karp Reductions for NP?
Karp reductions preserve witness structure and separate \mathbf{NP} from \mathbf{co\text{-}NP}.
x ∈ A ═════════════════════► f(x) ∈ B
x ∉ A ═════════════════════► f(x) ∉ B
Core Properties
With reductions in place, we can identify the hardest problems in \mathbf{NP}.
A language B is NP-hard if: \forall A \in \mathbf{NP}, \quad A \le_p B
A language B is NP-complete (\mathbf{NPC}) if:
If P ≠ NP: If P = NP:
┌────────────────────────┐ ┌────────────────────────┐
│ NP-Hard │ │ │
│ ┌────────────────┐ │ │ │
│ │ NP-Complete │ │ │ │
│ └────────────────┘ │ │ │
│ NP │ │ P = NP = NPC │
│ ┌────────┐ │ │ │
│ │ P │ │ │ │
│ └────────┘ │ │ │
└────────────────────────┘ └────────────────────────┘
The Missing Piece
To prove B is NP-complete, we need to reduce an existing NP-complete problem A \le_p B.
How do we prove the very first NP-complete problem?
CS G526: Advanced Algorithms & ComplexityTulasimohan Molli