Applying NP-Completeness

Gregory M. Kapfhammer

December 1, 2025

Learning objectives

Learning Objectives for Theoretical Machines

  • CS-204-1: Use both intuitive analysis and theoretical proof techniques to correctly distinguish between problems that are tractable, intractable, and uncomputable.
  • CS-204-2: Correctly use one or more variants of the Turing machine (TM) abstraction to both describe and analyze the solution to a computational problem.
  • CS-204-3: Correctly use one or more variants of the finite state machine (FSM) abstraction to describe and analyze the solution to a computational problem.
  • CS-204-4: Use a formal proof technique to correctly classify a problem according to whether or not it is in the P, NP, NP-Hard, and/or NP-Complete complexity class(es).
  • CS-204-5: Apply insights from theoretical proofs concerning the limits of either program feasibility or complexity to the implementation of both correct and efficient real-world Python programs.

Review from last week

  • Polyreductions: Compare problem difficulty via transformations
  • Three conditions: pos→pos, neg→neg, and polytime
  • SAT problems: CircuitSAT, SAT, and 3-SAT are fundamental
  • Polyequivalence: \(F \equiv_P G\) means equal difficulty
  • Proof technique: Describe transformation, verify conditions
  • This chapter: NP-completeness builds on these ideas!

Polyreductions are the foundation of complexity theory: they let us prove that problems are equally hard and establish a hierarchy of difficulty. Now, we’ll use these tools to identify the “hardest” problems in NP!

NP-completeness shows most “hard” problems are “equally hard”!

NP-completeness helps with learning objectives CS-204-1 and CS-204-4. We will define a profound class of problems that are equally hard and believed to be intractable. This chapter introduces the most famous open problem in computer science: “P versus NP”. As proofgrammers, let’s explore the hardest problems in NP and understand why they all have the same fundamental difficulty!

Recall definitions of P, NP, and Expo

  • P: Decision problems solvable in polynomial time
  • NP: Decision problems with polytime verification (= NPoly)
  • Expo: Decision problems solvable in exponential time
  • Remember: We restrict to decision problems in this chapter

Key relationships: We know P \(\subseteq\) NP \(\subseteq\) Expo, but are these proper subsets? This is perhaps the most famous open question in computer science!

P versus NP: the most famous open problem

  • The question: Does P = NP?
  • Million dollar prize: Clay Mathematics Institute offers $1M!
  • What it means: The key open question is “can every problem with polytime verification be solved in polytime?”
  • Current belief: P \(\neq\) NP (verification is easier than solving)
  • No proof yet: Despite decades of effort by brilliant researchers

P versus NP shapes modern cryptography: if P = NP, most encryption schemes would be broken! Security depends on problems being hard to solve but easy to verify.

Is there anything in NP but not in P?

  • Middle region”: This is where NP-complete problems live, if P \(\neq\) NP
  • Question: Are there any computational problems in this region?
  • Belief: Yes, thousands of problems are in NP but not in P

Intuitively grasp the P versus NP problem

  • Introduce different ways to explain the problem
  • Give different ways to ask the same question
  • Try to understand visually and mathematically
  • Hopefully, one approach will resonate with you!

Try to grasp “P versus NP” debate

  • One understanding: If P = NP, the classes are identical
  • Alternative view: If P \(\neq\) NP, there’s a “gap” between them
  • Key insight: We don’t know which view is correct!
  • Reminders about this definition:
    • Focus is on complexity class of decision problems
    • P: problems solvable in polynomial time
    • NP: problems verifiable in polynomial time

Alternative view of P versus NP

  • Scenario 1: P = NP is unlikely but possible
  • Scenario 2: P \(\neq\) NP is widely believed
  • Importance: This affects cryptography, optimization, and much more
  • Deep insight: Verification might be fundamentally easier than solving
  • Don’t forget the “middle group” from the prior diagram!

Determinism versus nondeterminism view

  • In P: Solvable with polytime, deterministic program
  • In NP: Solvable with polytime, nondeterministic program
  • P versus NP: Does nondeterminism provide exponential speedup?
  • Belief: Nondeterminism is fundamentally more powerful
  • Implication: Parallel search beats sequential search

Nondeterminism captures parallel search: nondeterministic programs can explore all possibilities simultaneously. The question is whether this provides exponential speedup over deterministic search!

Tree-based interpretation

  • Deterministic: Must search tree sequentially
  • Nondeterministic: Can explore all branches simultaneously
  • P = NP would mean: Sequential search is as good as parallel search
  • P \(\neq\) NP would mean: Parallel search provides exponential speedup
  • Let’s revisit a computational tree to understand this further!

Computation tree visualization

  • Tree structure: Each branch represents a possible solution path
  • Nondeterministic advantage: Explore all paths at once
  • Deterministic limitation: Must try paths one at a time
  • Question: Can deterministic programs simulate this efficiently?

Another tree-based view

  • If the answer was yes, then P = NP!
  • Looking ahead:
    • Next, we’ll define NP-completeness
    • Show how NP-complete problems are the “hardest” in NP
    • Thousands of problems are polyequivalent to:
      • CircuitSAT, SAT, or 3-SAT
      • UHC or DHC
    • We can define a group of problems that are all “equally hard”

So many polyequivalent problems!

  • Polyequivalence: Problems with bidirectional polyreductions
  • Examples: DHC, UHC, TSPD, CircuitSAT, SAT, 3-SAT
  • Meaning: These problems are “equally hard”
  • Ignoring: Polynomial factors in running time
  • Thousands more: Many other problems at this same hardness level

Polyequivalence creates hardness classes: if you can solve one problem efficiently, you can solve them all efficiently. This creates the foundation for NP-completeness!

Many problems are polyequivalent

  • Claim: These problems are all polyequivalent
  • Can be proved: But we didn’t prove all reductions
  • Equal difficulty: If we ignore polynomial factors
  • Thousands known: Many other problems at this level
  • Next: Define this class as NP-complete

NP-complete problems are the “hardest” in NP

  • Classical definition: NP-complete means all NP problems polyreduce to it
  • Key property: These are the “hardest problems in NP”
  • Must be in NP: The problem itself is in NP
  • Universal target: Every NP problem reduces to it
  • Implication: Solving one solves them all!

NP-complete captures “maximum hardness” in NP: these are the problems that are at least as hard as every other problem in NP. If we could solve one NP-complete problem in polynomial time, we could solve all NP problems in polynomial time! See the benefit?

Classical definition of NP-complete

  • Two conditions: Must be in NP and all NP problems reduce to it
  • Example: DHC is NP-complete (although we haven’t proved it yet)
  • Surprising fact: All NP problems polyreduce to DHC!
  • This is strange but true: One problem captures all of NP
  • However, let’s start with the Cook-Levin theorem!

Cook-Levin theorem: SAT is NP-complete

  • Historic result: Proved in 1970s by Cook and Levin
  • Main claim: All NP problems polyreduce to SAT
  • Implication: SAT is NP-complete
  • Game changer: Led to easier definition of NP-completeness
  • Foundation: Starting point for proving other problems NP-complete

Cook-Levin theorem “opened the floodgates”: once we know one problem is NP-complete, we can prove others are NP-complete by reducing from it. Many results follow!

Definition using SAT

  • Because of Cook-Levin: We can use SAT as a starting point
  • Easier definition: Just reduce from SAT instead of all NP problems
  • Exercise: Why is this definition equivalent to the “classical one”?
  • However, a more general definition is actually possible!

Nothing special about SAT in the definition!

  • Generalization: Can use any NP-complete problem
  • Key insight: Once one problem is NP-complete, use it as base
  • Chain of reductions: Build web of NP-complete problems
  • Practical approach: Reduce from problem most similar to yours
  • All equivalent: Any NP-complete problem works as starting point

NP-completeness is transitive: \(A\) is NP-complete and \(A \leq_P B\) and \(B \in\) NP, then \(B\) is NP-complete. We now build a web of NP-complete problems!

General definition using any NP-complete problem

  • Replace SAT: Use any known NP-complete problem \(C\)
  • Exercise: Why is this definition equivalent to earlier ones?
  • Flexibility: Choose reduction source that’s most convenient

Polyequivalence definition

  • Definition: NP-complete problem is polyequivalent to any NP-complete problem; note that this moves in both directions!
  • Polyequivalence: Bidirectional reductions between problems
  • Key insight: All NP-complete problems are equally hard
  • Implication: Solving one solves them all
  • Elegant: Captures the essence of NP-completeness

Grasp P versus NP

  • P = NP: Every NP-complete problem is in P
  • P \(\neq\) NP: No NP-complete problem is in P
  • Key insight: Focus on one NP-complete problem
  • Practical: Solve SAT efficiently and you solve everything!
  • Equivalence: All NP-complete problems rise or fall together

P versus NP becomes concrete: instead of asking about all NP problems, just ask whether any single NP-complete problem is in P. They all have the same fate!

First reformulation of P versus NP

  • P = NP: Equivalent to saying every NP-complete problem is in P
  • P \(\neq\) NP: Equivalent to saying no NP-complete problem is in P
  • Simplified question: Focus on NP-complete problems

Second reformulation of P versus NP

  • Alternative phrasing: Uses specific NP-complete problem
  • Same question: Different way to express P versus NP
  • All equivalent: Various formulations, one open problem

Revisit the diagram

  • Visual representation: Shows the question graphically
  • Middle region question: Are there any computational problems here?
  • Exercise: Why are these definitions equivalent to earlier ones?

NP-hard means “as hard as NP-complete”

  • NP-hard definition: All NP problems polyreduce to it
  • Key difference: Problem itself might not be in NP
  • Could be harder: Outside NP entirely
  • For problems in NP: NP-hard and NP-complete are equivalent
  • Examples: Nondecision variants of NP-complete problems

NP-hard is more general than NP-complete: NP-complete problems must be in NP, but NP-hard don’t have that requirement. So NP-hard is “at least as hard as NP-complete”!

Definition of NP-hard

  • Key property: All NP problems polyreduce to it
  • Not necessarily in NP: Problem could be “outside NP”
  • Relationship: For problems in NP, NP-hard = NP-complete
  • Examples: Nondecision TSP, nondecision UHC, nondecision SAT

Complexity classes

  • P: Polynomial-time solvable
  • NP: Polynomial-time verifiable
  • NP-complete: Hardest problems in NP
  • NP-hard: At least as hard as NP-complete
  • Expo: Exponential-time solvable
  • Open question: Relationships between classes

Understanding the hierarchy: P \(\subseteq\) NP \(\subseteq\) Expo is known, but whether these are proper subsets is still open. NP-complete and NP-hard problems are believed to be intractable but (as of yet) there is no formal proof!

Decision problem summary

  • Restriction: This diagram applies to decision problems only
  • Relationships: Shows how classes relate to each other
  • NP-complete: At the “boundary” between P and NP
  • What would happen if we could prove that TSP was in P?

Nondecision problem summary

  • Broader view: Includes optimization and search problems
  • NP-hard region: Contains problems outside NP
  • Complete picture: Shows full complexity landscape

What if P = NP?

  • Revolutionary: Would transform cryptography, optimization, AI
  • Cryptography broken: Most encryption relies on P \(\neq\) NP
  • Optimization solved: Traveling salesman, scheduling, packing
  • Scientific discovery: Drug design and protein folding
  • Unlikely: Most researchers believe P \(\neq\) NP
  • Deep insight: Verification seems fundamentally easier than solving

P = NP would be revolutionary but is considered unlikely: the asymmetry between solving and verification seems fundamental: verifying is easier than solving. Most cryptography depends on this asymmetry!

NP-completeness is very widespread!

  • Thousands known: NP-complete problems from diverse areas
  • Computer science: MaxClique, MaxCut, DeadlockAvoidance
  • Applied math: IntegerProgramming, TaskAssignment
  • Pure math: QuadraticDiophantineEquation
  • Biology: MultipleSequenceAlignment
  • Key insight: Fundamental hardness appears everywhere

NP-completeness spans all of science and engineering: from scheduling to circuit design to biology, the same fundamental hardness appears!

The web of NP-completeness

  • Arrows: Represent polyreductions between problems
  • Solid black: Reductions we proved in this book
  • Dotted: Reductions from other sources
  • Grey: Follow from NP-completeness of CircuitSAT

Proof techniques for NP-completeness

  • Standard approach: Two steps to prove NP-completeness
    • Step 1: Show problem is in NP (give polytime verifier)
    • Step 2: Reduce from known NP-complete problem
  • Choose wisely: Pick reduction source similar to your problem
  • Verify: Pos→pos, neg→neg, polytime

Template for NP-completeness proofs: (1) construct polytime verifier, (2) describe polyreduction from known NP-complete problem, (3) verify all three reduction conditions. Unless necessary, follow this template every time!

Good and bad news!

  • Many NP-complete: But some problems are intermediate
    • Examples: Factor, DiscreteLog (in NP, not known to be in P or NP-complete)
  • Some are actually in P: Don’t assume all hard-looking problems are NP-complete
    • Examples: IsPrime, MinCut, ShortestPath, LinearProgramming
  • Approximation: Some NP-hard problems can be approximated efficiently
    • Examples: TSP, TaskAssignment have good approximation algorithms
  • Real-world solvable: Some NP-hard problems can be solved for real-world inputs
    • Example: SAT solvers work well in practice despite worst-case hardness

NP-completeness is not the end of the story: even if a problem is NP-complete, there are many techniques for dealing with it in practice. Approximation, heuristics, and special cases can make “intractable” problems tractable!

Key insights for proofgrammers

  • P versus NP: Most famous open problem in computer science
  • NP-complete: Hardest problems in NP, all equally hard
  • NP-hard: At least as hard as NP-complete
  • Cook-Levin: SAT is NP-complete, starting point for all others
  • Widespread: Thousands of NP-complete problems across all fields
  • Proof technique: Show NP, then polyreduce from NP-complete problem
  • Practical impact: Guides algorithm design and cryptography

NP-completeness is the “crown jewel” of complexity theory: it shows that thousands of diverse problems all have the same fundamental difficulty. As proofgrammers, understanding NP-completeness helps us recognize intractable problems and guides us toward practical solutions!