BITS Pilani
BITS Logo
CS G526: Advanced Algorithms and Complexity

Complexity: P, NP & Reductions

Lecture 25 |2026-10-15
Tulasimohan Molli
BITS Pilani, Hyderabad Campus

Agenda

  1. Finding vs. Checking — The intuitive divide between synthesis and verification.
  2. The Class P — Deterministic polynomial-time tractability.
  3. The Class NP (Definition 1: Verifiers & Certificates) — Checking proofs efficiently.
  4. The Class NP (Definition 2: Non-Deterministic TMs) — Branching computation trees.
  5. Equivalence of the Two NP Definitions — Why certificates \iff NDTMs.
  6. Reductions: Turing vs. Karp — Oracles vs. Many-One polynomial mappings.
  7. NP-Hardness & NP-Completeness — Formal definitions and the P vs. NP enigma.

Finding vs. Checking

Finding (Synthesis)

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}

  • Brute force takes longer than the lifespan of the universe.
  • No known polynomial algorithm.

Checking (Verification)

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}

  • Takes < 1000 edge lookups.
  • Runs in < 1 \text{ ms} on any computer.

The Core Question

Is finding a needle in a haystack fundamentally harder than recognizing the needle once shown?

Languages & Decision Problems

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}

Examples

  • Path: \text{PATH} = \{ \langle G, s, t \rangle \mid \text{there is a path from } s \text{ to } t \text{ in } G \}
  • Primality: \text{PRIME} = \{ \langle n \rangle \mid n \text{ is prime} \}
  • Satisfiability: \text{SAT} = \{ \langle \phi \rangle \mid \phi \text{ is a satisfiable Boolean formula} \}

The Complexity Class P

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\}^*:

  1. x \in L \implies M(x) accepts in at most p(|x|) steps.
  2. x \notin L \implies M(x) rejects in at most p(|x|) steps.

\mathbf{P} = \bigcup_{c \ge 1} \mathbf{DTIME}(n^c)

  • Cobham–Edmonds Thesis: \mathbf{P} represents the class of computationally feasible problems.
  • Closed under complement, union, intersection, concatenation, and polynomial reductions.

The Class NP: Definition 1 (Verifiers)

\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}

Certificates in Action

Problem: 3-SAT

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)

  • Certificate u: An assignment \tau \in \{0, 1\}^n to all variables.
  • Verifier V(\phi, \tau): Plug in \tau, evaluate each clause. Linear time!

Problem: CLIQUE

Given graph G and target size k:

  • Certificate u: A subset of vertices S \subseteq V of size k.
  • Verifier V(G, k, S): Verify |S| = k and test if all \binom{k}{2} pairs have edges in G. O(k^2) time!

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).

The Class NP: Definition 2 (Non-Deterministic TMs)

Historically, NP stands for Non-deterministic Polynomial time.

Non-Deterministic TM (NDTM)

  • 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
  • Acceptance rule: An NDTM accepts x if at least one computation branch reaches an accepting state.

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.

Equivalence of the Two NP Definitions

Theorem

\mathbf{NP}_{\text{verifier}} \equiv \mathbf{NP}_{\text{NDTM}}

(\impliedby) NDTM \to Verifier

  • Suppose NDTM N accepts x in p(|x|) steps.
  • The certificate u is the sequence of non-deterministic choices along the accepting path.
  • The deterministic verifier V(x, u) simply replays these exact choices and verifies acceptance!

(\implies) Verifier \to NDTM

  • Suppose verifier V(x, u) exists.
  • An NDTM N on input x:
    1. Non-deterministically guesses p(|x|) bits to generate certificate u.
    2. Deterministically executes V(x, u).
    3. Accepts iff V(x, u) accepts.

Reductions: Transforming Problems

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:

  1. Cook / Turing Reductions (A \le_T^p B): Oracle reductions.
  2. Karp / Many-One Reductions (A \le_m^p B / A \le_p B): Mapping reductions.

Turing vs. Karp Reductions

Turing Reductions (A \le_T^p B)

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
  • Can query problem B multiple times.
  • Can invert the answer (\text{YES} \leftrightarrow \text{NO}).

Karp Reductions (A \le_p B)

Instance x of A
       │
       ▼
[ Function f: Poly-time ]
       │
       ▼
Instance f(x) of B
  • Single query, no post-processing: x \in A \iff f(x) \in B

Why Karp Reductions for NP?

Karp reductions preserve witness structure and separate \mathbf{NP} from \mathbf{co\text{-}NP}.

Properties of Karp Reductions (A \le_p B)

          x ∈ A   ═════════════════════►  f(x) ∈ B
          x ∉ A   ═════════════════════►  f(x) ∉ B

Core Properties

  1. Polynomial-Time Computable: f(x) can be generated in O(|x|^c) time.
  2. Preservation of Truth:
    • x \in A \implies f(x) \in B (Completeness)
    • x \notin A \implies f(x) \notin B (Soundness)
  3. Transitivity: \text{If } A \le_p B \text{ and } B \le_p C, \quad \text{then } A \le_p C

NP-Hardness & NP-Completeness

With reductions in place, we can identify the hardest problems in \mathbf{NP}.

NP-Hard

A language B is NP-hard if: \forall A \in \mathbf{NP}, \quad A \le_p B

  • Every problem in \mathbf{NP} reduces to B.
  • B is at least as hard as everything in \mathbf{NP}.
  • B does not need to be in \mathbf{NP}.

NP-Complete

A language B is NP-complete (\mathbf{NPC}) if:

  1. B \in \mathbf{NP} (membership)
  2. B is \mathbf{NP}-hard (universal hardness)
  • The kings of \mathbf{NP}.
  • If any NP-complete problem has a polynomial algorithm, then \mathbf{P} = \mathbf{NP}!

The Landscape: P vs. NP

               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?

Summary & Next Steps

Today’s Takeaways

  1. \mathbf{P}: Poly-time solvable deterministically.
  2. \mathbf{NP}: Poly-time verifiable with certificates \equiv Poly-time decidable via NDTMs.
  3. Karp Reductions (A \le_p B): Many-one polynomial mappings that preserve solutions.
  4. \mathbf{NPC}: Hardest problems in \mathbf{NP}.

Coming Up Next (Lecture 25)

  • The Cook–Levin Theorem (Full Lecture):
  • Building the computation tableau of an NDTM.
  • Translating machine states and tape cells into Boolean formulas.
  • Proving that \mathbf{SAT} is unconditionally \mathbf{NP}-complete!