Recap
cs3102: Theory of Computation
Class 25:
NP-Complete Appetizers
Spring 2010
University of Virginia
David Evans
X
B
A problem/language is
NP-Hard if every problem in
NP can be reduced to it.
To prove B is in NP-Hard,
show that some known
NP-Hard problem can be
reduced to B.
If a problem is in NP and
3SAT ∈ NP-Hard
NP-Hard, it is in NP-Complete.
Today’s Menu
SATisfiability
NP-Hardness
Reduction
Proofs
SAT
Subset Sum
Knapsack
(Pre-)History of P
= NP Question
Is SAT in NP?
SAT is NP-Complete
Yes, the variable assignments are a
polynomial-time verifiable certificate.
Proof: SAT is NP-Complete
Show that if SAT is in P, so is 3SAT.
3SAT
SAT
To prove SAT is in NPHard, show that some
known NP-Hard problem
can be reduced to SAT.
3SAT input
NP
3SAT ∈ NP-Hard
Assume this is already
known
NP
Polynomialtime Input
Transformer
MSAT
Polynomial-time
decider for SAT
Poly-time
Output
Transformer
If we can use MSAT, a polynomial-time decider for SAT to build a polynomialtime decider for 3SAT, this proves that SAT is at least as “hard” as 3SAT.
3SAT output
PS6 is due Tuesday, April 27 (but
don’t wait until then to start PS7!)
A problem/language is in NP, if
there is a certificate that
allows you to verify the
answer in polynomial time.
Proof: SAT is NP-Complete
Subset Sum Language
Identify transform:
3SAT input is a valid
SAT input
MSAT
Polynomial-time
decider for SAT
Identify transform:
SAT output is
correct 3SAT output
3SAT output
3SAT input
Show that if SAT is in P, so is 3SAT.
How many test of SUBSET-SUM do we to solve
the subset sum search problem?
SUBSET-SUM is in NP
Can you order the same appetizer more than once?
SUBSET-SUM is in NP-Hard
Transform Goal
Polynomialtime Input
Transformer
MSS
Polynomial-time
decider for
SUBSET-SUM
Poly-time
Output
Transformer
3SAT output
3SAT input
To finish the proof, we need to describe the transformers!
Variables
Transform Idea
x1
x2
x3
...
xl
x1
x2
x3
...
y1
1
0
0
...
y1
1
0
0
...
z1
1
0
0
...
z1
1
0
0
...
y2
0
1
0
...
y2
0
1
0
...
z2
0
1
0
...
z2
0
1
0
...
...
...
...
...
...
y3
0
0
1
...
z3
0
0
1
...
yl
0
0
0
...
1
...
...
...
...
...
zl
0
0
0
...
1
S
t
Variables
xl
c1
c2
x2
x3
...
y1
1
0
0
...
z1
1
0
0
...
y2
0
1
0
...
z2
0
1
0
...
...
...
...
...
...
yl
0
0
0
...
1
yl
0
0
0
...
zl
0
0
0
...
1
zl
0
0
0
t
1
1
1
...
1
t
1
1
1
x3
S
xl
c1
c2
1
0
0
...
1
0
z1
1
0
0
...
0
1
0
1
0
We need to make at
0
least onezterm
in 1 0
... true!
...
...
...
each clause
2
yl
0
zl
0
t
0
0
0
0
...
0
1
...
1
0
...
...
...
...
...
1
1
...
x2
x3
...
y1
1
0
0
z1
1
0
y2
0
1
c1
c2
...
1
0
0
...
0
1
0
...
0
1
...
1
0
...
...
...
1
...
...
...
1
...
...
...
1
2
1
1
...
...
c3
...
1
1
S
...
1
1
...
c3
...
ck
Clauses
x1
x2
x3
...
c1
c2
y1
1
0
0
...
1
0
ck
...
1
xl
Variables
Doesn’t work: more than one term in a clause can be true!
1
x1
Clauses
y1
y2
S
...
ck
Select true/false for each
x2
...
We need to make at
0
least onezterm
in 1 0
... true!
...
...
...
each clause
Variables
x1
c3
Clauses
x1
Fudge factors
S
Variables
Clauses
xl
c3
...
ck
z1
1
0
0
...
0
1
y2
0
1
0
...
0
1
z2
0
1
0
...
1
0
...
...
...
...
...
...
...
yl
0
0
0
...
1
...
...
zl
0
0
0
...
1
...
...
ff1
1
0
0
...
0
fff1
1
0
0
...
0
ff2
0
1
0
...
0
fff2
0
1
0
...
0
...
0
0
...
...
...
t
1
1
1
...
1
Fudge factors
S
Select true/false for each
Variables
Clauses
x1
x2
x3
...
c1
c2
y1
1
0
0
...
xl
1
0
c3
Variables
...
ck
x1
x2
x3
...
xl
z1
1
0
0
...
0
1
y1
1
0
0
...
y2
0
1
0
...
0
1
z1
1
0
0
...
z2
0
1
0
...
1
0
...
...
...
...
...
...
...
y2
0
1
0
...
yl
0
0
0
...
1
...
...
z2
0
1
0
...
zl
0
0
0
...
1
...
...
y3
0
0
1
...
ff1
1
0
0
...
0
fff1
1
0
0
...
0
z3
0
0
1
...
...
...
...
...
...
yl
0
0
0
...
1
zl
0
0
0
...
1
ff2
0
1
0
...
0
fff2
0
1
0
...
0
...
0
0
...
...
...
3
3
3
3
3
t
1
1
1
...
1
c1
c2
c3
...
Polynomialtime Input
Transformer
MSS
Polynomial-time
decider for
SUBSET-SUM
Identity
3SAT output
3SAT input
3SAT reduces to SUBSET-SUM
Reject
Solutions
involve
multiple
orders of
the same
appetizer.
Knapsack
KNAPSACK is in NP
cl
Polynomialtime Input
Transformer
MSS
Polynomial-time
decider for
KNAPSACK
Output
transformer
Could prove by reducing 3SAT to KNAPSACK.
Any easier way?
Polynomialtime Input
Transformer
MSS
Polynomial-time
decider for
KNAPSACK
Output
transformer
Input Transformation
SUBSET-SUM output
SUBSET-SUM input
Is KNAPSACK in NP-Hard?
Prove by reducing SUBSET-SUM to KNAPSACK
Input Transformation
Chain of Reductions
Every problem in NP
reduces to
3SAT
reduces to
S = { 102.15, 1002.75, 10003.35, 100003.55,
1000004.20, 1000005.80,
100.00, 1000.00,
10000.00,
Opps! Iit was pointed out in100000.00,
class that this doesn’t
work since1000000.00,
the KNAPSACK solver might
include 10x or }
1000000.00
100x of one of the numbers and still get the right sum.
t = 11111115.05 This should be fixable…if you can fix it, a good answer
replaces Problem 5 on PS6.
SUBSET-SUM
reduces to
KNAPSACK
3SAT output
Is KNAPSACK in NP-Hard?
3SAT input
Example
Hints for PS6, Problem 5
History of P = NP
• Prove Genome Assembly is NP-Complete
• Solve this by thinking, not googling
• You can (of course!) do the reduction from any
NP-Complete problem to Genome Assembly
Stephen Cook (US, 1971): The complexity of
theorem proving procedures
Richard Karp (US 1972): List of 21 NP-Complete
problems
– But, some will be easier than others
– Some of the problems described in Sipser are
better choices than ones we have covered in class
Leonid Levin (USSR 1969-73): Universal search
problems
Cook-Levin Theorem: SAT is NP-Complete
(Pre)-History of P=NP
Stephen Cook
Leonid Levin
Princeton, 20 March 1956
Princeton, 20 March 1956
Dear Mr. von Neumann:
Dear Mr. von Neumann:
With the greatest sorrow I have learned of your illness. … I hope and wish for you
that your condition will soon improve even more and that the newest medical
discoveries, if possible, will lead to a complete recovery.
With the greatest sorrow I have learned of your illness. … I hope and wish for you
that your condition will soon improve even more and that the newest medical
discoveries, if possible, will lead to a complete recovery.
Since you now, as I hear, are feeling stronger, I would like to allow myself to write you
about a mathematical problem, of which your opinion would very much interest me:
One can obviously easily construct a Turing machine, which for every formula F in
first order predicate logic and every natural number n, allows one to decide if there
is a proof of F of length n (length = number of symbols). Let ψ(F,n) be the number of
steps the machine requires for this and let ϕ(n) = maxF ψ(F, n). The question is how
fast ϕ(n) grows for an optimal machine. One can show that ϕ(n) ≥ k ⋅ n. If there
really were a machine with ϕ(n) ∼ k ⋅ n (or even ∼ k ⋅ n2), this would have
consequences of the greatest importance. Namely, it would obviously mean that
inspite of the undecidability of the Entscheidungsproblem, the mental work of a
mathematician concerning Yes-or-No questions could be completely replaced by a
machine. After all, one would simply have to choose the natural number n so large
that when the machine does not deliver a result, it makes no sense to think more
about the problem.
Since you now, as I hear, are feeling stronger, I would like to allow myself to write you
about a mathematical problem, of which your opinion would very much interest me:
One can obviously easily construct a Turing machine, which for every formula F in
first order predicate logic and every natural number n, allows one to decide if there
is a proof of F of length n (length = number of symbols). Let ψ(F,n) be the number of
steps the machine requires for this and let ϕ(n) = maxF ψ(F, n). The question is how
fast ϕ(n) grows for an optimal machine. One can show that ϕ(n) ≥ k ⋅ n. If there
really were a machine with ϕ(n) ∼ k ⋅ n (or even ∼ k ⋅ n2), this would have
consequences of the greatest importance. Namely, it would obviously mean that
inspite of the undecidability of the Entscheidungsproblem, the mental work of a
mathematician concerning Yes-or-No questions could be completely replaced by a
machine. After all, one would simply have to choose the natural number n so large
that when the machine does not deliver a result, it makes no sense to think more
about the problem.
Gödel’s 1956 Letter (Translated)
Gödel’s 1956 Letter (Translated)
Has-Short-Proof
Has Short Proof is Decidable
• Try all possible proofs of length ≤ n
– How do we know this is finite?
• For each possible proof, check if it is a valid
proof of F.
– A proof is valid if:
“One can obviously easily construct a Turing machine, which
for every formula F in first order predicate logic and every
natural number n, allows one to decide if there is a proof of
F of length n (length = number of symbols).”
Princeton, 20 March 1956
Dear Mr. von Neumann:
…
One can obviously easily construct a Turing machine,
which for every formula F in first order predicate logic
and every natural number n, allows one to decide if
there is a proof of F of length n (length = number of
symbols). Let ψ(F,n) be the number of steps the machine
requires for this and let ϕ(n) = maxF ψ(F, n). The
question is how fast ϕ(n) grows for an optimal
machine. One can show that ϕ(n) ≥ k ⋅ n. If there really
were a machine with ϕ(n) ∼ k ⋅ n (or even ∼ k ⋅ n2), this
would have consequences of the greatest importance. …
• It starts from the accepted axioms.
• Each step follows a deduction rule (finite set of rules).
• It reaches the statement F.
Princeton, 20 March 1956
Dear Mr. von Neumann:
…
One can obviously easily construct a Turing machine,
which for every formula F in first order predicate logic
andLet’s
every
natural
n, allows
to decide
give
Gödelnumber
the benefit
of theone
doubt,
and if
there
is this
a proof
of F even
of length
number
4, ...)” of
∼knn2, (length
∼kn3, ∼=kn
read
as, “(or
symbols). Let ψ(F,n) be the number of steps the machine
requires for this and let ϕ(n) = maxF ψ(F, n). The
question is how fast ϕ(n) grows for an optimal
machine. One can show that ϕ(n) ≥ k ⋅ n. If there really
were a machine with ϕ(n) ∼ k ⋅ n (or even ∼ k ⋅ n2), this
would have consequences of the greatest importance. …
We’ll continue with this Tuesday…
Charge
NP-Complete problems are everywhere!
Route planning, scheduling courses, matching
medical students, register allocation,
pancakes, sudoko, protein folding, soap
bubbles, March madness, ...
Next week
PS6 is due Tuesday, April 27 (but
don’t wait until then to start PS7!)
– When we want problems to be hard
– Computing with photons and DNA
© Copyright 2026 Paperzz