Reducibility and NP Completeness
Reducibility and NP Completeness
Reducibility and NP Completeness
Reducibility and NP
Completeness
Computational Complexity
Theory
Computational Complexity Theory
is the study of how much of a given
resource (such as time, space,
parallelism, algebraic operations,
communication) is required to solve
important problems.
2
Classification of Problems
Q. Which problems will we be able to solve in
practice?
A working definition. [Cobham 1964, Edmonds
1965, Rabin 1966] Those with polynomial-time
algorithms.
Yes Probably no
Shortest path Longest path
Matching 3D-matching
Min cut Max cut
2-SAT 3-SAT
Planar 4-color Planar 3-color
Bipartite vertex cover Vertex cover
4
Intractable Problems
5
Impossible Problems
6
The Halting Problem
7
Complexity Classes
Focus on
Decision problems decision problems
Answer is yes or no
Optimization problems
Answer is a number
Construction problems
Answer is some object (set of vertices, function,
…)
9
Decision problems versus
optimization problems
Finding the maximum sized clique is an
optimization problem
But we can reduce it to a series of decision
problems
Can we find a clique of size 3 (why start at 3??)
Can we find a clique of size 4
Etc
In general in our study of complexity classes,
we will focus on decision problems
P Vs NP
Complexity Class P
FORMAL INFORMAL
Class of languages Class of decision
L, for which there problems that
exists a have polynomial
deterministic
Turing Machine time algorithms
deciding whether i solving them
L, using running
time O(p(|i|)) for
some polynomial p
12
Complexity Class P
13
Verification algorithm
14
Complexity Class NP
15
Complexity Class NP
Problems with polynomial time verification
algorithm and polynomial size certificates
Problem L belongs to the class NP, if there
exists a 2-argument algorithm A, with
A runs in polynomial time
There is a constant d such that for each x, there is a
certificate y with
A(i,c) = true
|c| = O(|i|d)
16
Many problems are in NP
Examples: Hamiltonian Path, Maximum
Independent Set, Satisfiability, Vertex
Cover, …
Al of these have trivial certificates (set of
vertices, truth assignment, …)
17
P NP
18
Reducibility
Reducibility
20
Lemma
21
K-COLORING
A k-coloring of a graph is an assignment of
one color to each vertex such that:
No more than k colors are used
No two adjacent vertices receive the same
color
22
Course Scheduling Problem
23
K-Coloring Problem:
24
Two Different Problems
Science Math
1pm Mon 3pm Fri
Yes!
28
2 Colorable
Given a graph G, how do we
decide if it can be 2-colored?
? ? ? ? ? ?? ?
30
Let’s consider a completely different
problem.
k-CLIQUES
A k-clique is a set of k nodes with all
k(k-1)/2 possible edges between them.
32
This graph contains a 4-clique
33
Given an n-node graph G and a
number k, how can you decide if G
contains a k-clique?
? ? ? ? ? ?? ?
34
OK, how about a slightly different
problem?
INDEPENDENT SET
This graph
contains an
independent
set of size 3.
36
Given an n-node graph G and a number
k, how can you decide if G contains an
independent set of size k?
INSPIRATION:
? ? ? ? ? ?? ?
37
One more completely different problem
Combinational Circuits
39
Logic Gates
Not And Or
40
Example Circuit
41
CIRCUIT-SATISFIABILITY
(decision version)
42
CIRCUIT-SATISFIABILITY
(search version)
43
Satisfiable Circuit Example
44
Satisfiable?
No!
45
Given a circuit, is it
satisfiable?
PERSPIRATION: Try out all 2n
assignments
INSPIRATION:
? ? ? ? ? ?? ?
46
We have seen 4 problems:
coloring, clique,
independent set, and
circuit SAT.
48
Complement Of G
49
Example
G G*
3-Clique
Independent set of size 3
50
Reduction
51
Or what if you have an
Oracle?
or·a·cle
52
Let G be an n-node graph.
<G,k>
<G*, k>
BUILD:
Indep. GIVEN:
Set Clique
Oracle Oracle
COSC 3101B, PROF. J. ELDER
53
Let G be an n-node graph.
<G,k>
<G*, k>
BUILD:
GIVEN:
Clique
Indep.
Oracle
COSC 3101B, PROF. J. ELDER
54 Set
Oracle
Thus, we can quickly
reduce clique problem
to an independent set
problem and vice versa.
A language L is NP-complete, if
1. L NP
2. For every L’ NP: L’ P L
A language L is NP-hard, if
1. For every L’ NP: L’ P L
NP-hardness sometimes also used as term for
problems that are not a decision problem, and
for problems that are ‘harder than NP’
57
What does it mean to be
NP-complete?
Evidence that it is (very probably) hard to
find an algorithm that solves the problem
Always
Exact
In polynomial time
58
CNF-Satisfiability
59
Cook-Levin theorem
Satisfiability is NP-complete
Most well known is Cook’s proof, using Turing
machine characterization of NP.
60
Proving that problems are
NP-complete
Proving problems NP-
complete
Lemma
1. Let L’ P L and let L’ be NP-complete. Then L is
NP-hard.
2. Let L’ P L and let L’ be NP-complete, and L NP.
Then L is NP-complete.
62
3-Sat
3-Sat is CNF-Satisfiability, but each clause has
exactly three literals
Lemma: CNF-Satisfiability P 3-Sat
Clauses with one or two literals:
Use two extra variables p and q
Replace 2-literal clause (x or y) by (x or y or p) and (x or
y or not(p))
Similarly, replace 1-literal clause by 4 clauses
Clauses with more than three literals:
Repeat until no such clauses
For (l1 or l2 or … lr) add new variable t and take as
replacement clauses (l1 or l2 or t) and (not(t) or l3 or … or
lr)
63
3-Sat is NP-complete
Membership in NP
Reduction
3-Sat is important starting problem for many NP-
completeness proofs
64
Clique
65
Reduction for Clique
Clause: {x1,not(x2),x3}
One vertex per
x1 not(x2) x3
literal per clause
Edges between
vertices in different x1
clauses, except …
edges between xi x2
and not(xi) not(x3)
If m clauses, look
Clause: {x1,x2,not(x3)}
for clique of size m
66
Correctness
67
Independent set
68
Independent set is NP-
complete
In NP.
NP-hard: transform from
Clique.
W is a clique in G, if and
only if W is an independent
set in the complement of G
(there is an edge in Gc iff. there is no edge in G).
69
How do I write down this
proof?
Theorem. Independent Set is NP-complete.
Proof: The problem belongs to NP: as
certificates, we use sets of vertices; we can
check in polynomial time for a set that it is a
clique, and that its size is at least k.
To show NP-hardness, we use a reduction
from Clique. Let (G,k) be an input to the
clique problem. Transform this to (Gc,k) with
Gc the complement of G. As G has a clique
with at least k vertices, if and only if Gc has
an independent set with k vertices, this is a
correct transformation. The transformation
can clearly be carried out in polynomial time.
QED
70
Vertex Cover
= vertex cover
71
Vertex cover is NP-complete
In NP.
NP-hard: transform from independent set.
W is a vertex cover in G, if and only if V-W is an
independent set in G.
72
P=NP?
73