Reductions: Complexity ©D.Moshkovitz
Reductions: Complexity ©D.Moshkovitz
Complexity 1
©D.Moshkovitz
Motivation
• Reductions are our main tool for
comparison between problems.
Complexity 2
©D.Moshkovitz
Introduction
• Objectives:
– To formalize the notion of “reductions”.
• Overview:
– Karp reductions
– HAMPATH p HAMCYCLE
– Closeness under reductions
– Cook reductions
– Completeness
Complexity 3
©D.Moshkovitz
Reductions – Concept
IF problem A can be efficiently translated to problem B…
A p B
Complexity 4
©D.Moshkovitz
SIP 250
Reductions – Formal
Definition
I.e – there exists a polynomial time TM which
halts with f(w) on its tape when given input w.
A B
* - A * - B
* *
Complexity 6
©D.Moshkovitz
Reductions and Algorithms
polynomial time algorithm for A
polynomial time
algorithm for B
f(w) f(w)B
w f ? wA
?
Complexity 7
©D.Moshkovitz
How to Reduce?
1. Construct f.
2. Show f is polynomial time
computable.
3. Prove f is a reduction, i.e show:
1. If wA then f(w)B
2. If f(w)B then wA
Complexity 8
©D.Moshkovitz
Terminology
• The type of reductions we’ve just
described is also called:
– Polynomial-time mapping reduction
– Polynomial-time many-one reduction
– Polynomial-time Karp reduction
• We’ll always refer to such reductions
unless otherwise specified.
Complexity 9
©D.Moshkovitz
Example
• To demonstrate a reduction, we’ll revisit
the example we gave in the introduction.
• We’ll rephrase and formalize the seating
and tour problems
• And demonstrate a slightly different
reduction between them.
Complexity 10
©D.Moshkovitz
Hamiltonian Path
Instance: a directed graph G=(V,E) and two
vertices stV.
Problem: To decide if there exists a path
from s to t, which goes through each node
once.
In the version presented in the introduction
we asked for some path, without specifying
the start and end vertices.
Complexity 11
©D.Moshkovitz
Hamiltonian Cycle
Instance: a directed graph G=(V,E).
Problem: To decide if there exists a simple
cycle in the graph which goes through each
node exactly once.
Complexity 12
©D.Moshkovitz
HAMPATH p HAMCYCLE
f( <G=(V,E),s,t> ) = <G’=(V{u},E{(u,s),(t,u)})>
s s
t p t
Complexity 13
©D.Moshkovitz
Correctness
• (Completeness) If there exists a
Hamiltonian path (v0=s,v1,…,vn=t) in the
original graph, then (u,v0=s,v1,…,vn=t,u)
is a Hamiltonian cycle in the new
graph.
Complexity 14
©D.Moshkovitz
Correctness
• (Soundness) (u,s) and (t,u) must be in
any Hamiltonian cycle in the
constructed graph, thus removing u
yields a Hamiltonian path from s to t.
Complexity 15
©D.Moshkovitz
How to Reduce?
1. Construct f.
2. Show f is polynomial time easy to
verify
computable.
3. Prove f is a reduction, i.e show:
1. If wHAMPATH then
f(w)HAMCYCLE
2. If f(w)HAMCYCLE then
wHAMPATH
Complexity 16
©D.Moshkovitz
Closeness Under Reductions
Definition: A complexity class C is
closed under reductions if, whenever
L is reducible to L’ and L’C, then L is
also in C.
L’ C
L
Complexity 17
©D.Moshkovitz
Observation
Theorem: P, NP, PSPACE and EXPTIME
are closed under polynomial-time Karp
reductions.
Proof: Filling in the exact details is left
to the reader. (See sketch)
Complexity 18
©D.Moshkovitz
Other Types of Reductions
• Cook Reduction: Use an efficient “black
box” (procedure) that decides B, to
construct a polynomial-time machine which
decides A.
polynomial
time algorithm
for B
polynomial time
algorithm for A
Complexity 21
©D.Moshkovitz
Cook reduction of
HAMCYCLE to HAMPATH.
• For each edge (u,v)E,
– if there’s a Hamiltonian path from v to u
in the graph where (u,v) is removed,
output ‘YES’, exit
• Output ‘NO’
HAMPATH
Make oracle
sure it’s
efficient!
Complexity 22
©D.Moshkovitz
How do Cook and Karp
Reductions Differ?
• Cook reductions allow us to call the
procedure many times (instead of 1).
• When Karp reducing, we must output
the answer of the procedure.
Complexity 23
©D.Moshkovitz
On the Relation Between
Cook and Karp Reductions
• Observation: Karp reductions are
special cases of Cook reductions.
Complexity 24
©D.Moshkovitz
Food for Thought…
Complexity 25
©D.Moshkovitz
Completeness
Definition: Let C be a complexity class
and let L be a language. We say L is
C-Complete if:
1. L is in C
2. For every language AC, A is reducible
to L.
Complexity 26
©D.Moshkovitz
C-Complete Languages
hardness
C-Complete
Complexity 27
©D.Moshkovitz
Observation
Theorem: If two classes C and C’ are both
closed under reductions (of some specific
type) and there is a language L which is
complete for both C and C’, then C=C’.
Proof: W.l.o.g we’ll only show CC’. All
languages in C are reducible to L. Since C’ is
closed under reductions, it follows that
CC’.
Complexity 28
©D.Moshkovitz
Corollary
If any NP-Complete problem is in P,
then P=NP.
Complexity 29
©D.Moshkovitz
Summary
• In this lecture we’ve introduced many
types of reductions:
– Cook/Karp reductions
– Polynomial-time reductions
• We’ve defined the notion of completeness
• And seen how it can help us prove equality
of complexity classes.
• Nevertheless, we are still not convinced
complete languages even exist.
Complexity 30
©D.Moshkovitz