NPC

The Theory of
NP-Completeness
2012/11/6
1




P: the class of problems which can be solved
by a deterministic polynomial algorithm.
NP : the class of decision problem which can
be solved by a non-deterministic polynomial
algorithm.
NP-hard: the class of problems to which every
NP problem reduces.
NP-complete (NPC): the class of problems
which are NP-hard and belong to NP.
Nondeterministic algorithms


A nondeterministic algorithm
is an algorithm consisting of
two phases: guessing (or
choice) and checking.
Furthermore, it is assumed
that a nondeterministic
algorithm always makes a
correct guessing.
3
Nondeterministic algorithms


Machines for running nondeterministic
algorithms do not exist and they would
never exist in reality. (They can only be
made by allowing unbounded parallelism in
computation.) (Quantum computation may be
an approximation.)
Nondeterministic algorithms are useful
only because they will help us define a
class of problems: NP problems
4
NP (Nondeterministic
Polynomial) algorithm

If the checking stage of a
nondeterministic algorithm is
of polynomial time-complexity,
then this algorithm is called an
NP (nondeterministic
polynomial) algorithm.
5
NP problem


If a decision problem can be solved by a
NP algorithm, this problem is called an
NP (nondeterministic polynomial)
problem.
NP problems : must be decision
problems
6
Decision problems



The solution is simply “Yes” or “No”.
Optimization problem : harder
Decision problem
: easier
E.g. the traveling salesperson problem


Optimization version:
Find the shortest tour (cycle)
Decision version:
Is there a tour whose total length is less than or
equal to a constant C ?
7
Decision version of sorting

Given a1, a2,…, an and c, is there a
permutation of ais ( a1, a2 , … ,an )
such that∣a2–a1∣+∣a3–a2∣+ … +∣an–an∣<
1
C?
8
Decision vs Original Version

We consider decision version problem D
rather than the original problem O

because we are addressing the lower
bound of a problem

and D ∝ O
9
To express Nondeterministic Algorithm
by three special commands



Choice(S) : arbitrarily chooses one of
the elements in set S at one step
Failure : an unsuccessful completion
Success : a successful completion
10
Example:
Nondeterministic searching Algorithm
input: n elements and a target element x
output: success if x is found among the n elements;
failure, otherwise.
j ← choice(1 : n) /* guess
if A(j) = x then success /* check
else failure

A nondeterministic algorithm terminates

unsuccessfully iff there exist no set of choices leading
to a success signal.
The time required for choice(1 : n) is O(1).
11
Relationship Between NP and P
It is known PNP.
However, it is not known whether P=NP or
whether P is a proper subset of NP
It is believed NP is much larger than P







We cannot find a polynomial-time algorithm for many NP
problems. (Those NP problems may or may not in P.)
But, no NP problem is proved to have exponential lower
bound. (No NP problem has been proved to be not in P.)
So, “does P = NP?” is still an open question!
Cook tried to answer the question by proposing
NPC.
12
NP-hard

A problem X is NP-hard if
every NP problem
(polynomially) reduces to X.
13
NP-complete (NPC)
A problem X is NP-complete
(NPC) if X∈NP and every NP
problem (polynomially)
reduces to X.
 So, X  NPC
if XNP-hard and XNP

14
Cook’s Theorem (1971)





Prof. Cook
Toronto U.
Receiving Turing Award (1982)
Discussing difficult problems whose
worst case lower bound seems to be in
the order of an exponential function
The problems are called NP-complete
(NPC) Problems
15
Cook’s Theorem (1971)
NP = P iff SAT  P
 That is, NP = P iff the satisfiability
(SAT) problem is a P problem
 SAT is NP-complete
 It is the first NP-complete problem
 Every NP problem reduces to SAT

16
SAT is NP-complete





Every NP problem can be solved by an NP
algorithm
Every NP algorithm can be transformed in
polynomial time to an SAT problem
Such that the SAT problem is satisfiable iff
the answer for the original NP problem is “yes”
That is, every NP problem  SAT
SAT is NP-complete
17
Proof of NP-Completeness



To show that X is NP-complete
(I) Prove that X is an NP problem
(II) Prove that  Y  NPC, Y  X
 X  NPC
Why ?
Transitive property of polynomial-time reduction
18
Karp
Dr. R. Karp showed several NPC
problems, such as 3-STA, node
(vertex) cover, and Hamiltonian
cycle problems, etc.
 Dr. Karp received Turing Award in
1985

19
NP-Completeness Proof: Reduction
All NP
problems
SAT
Clique
Vertex
Cover
3-SAT
Chromatic Number
Dominating
Set
20
NP-Completeness
“NP-complete problems”: the hardest
problems in NP
Interesting property




If any one NP-complete problem can be
solved in polynomial time, then every
problem in NP can also be solved in
polynomial time (i.e., P=NP)
Many believe P≠NP
21
Importance of NP-Completeness



NP-complete problems: considered
“intractable”
Important for algorithm designers &
engineers
Suppose you have a problem to solve




Your colleagues have spent a lot of time to solve
it exactly but in vain
See whether you can prove that it is NP-complete
If yes, then spend your time developing an
approximation (heuristic) algorithm
Many natural problems can be NP-complete
22
Some concepts




Up to now, none of the NPC problems can be
solved by a deterministic polynomial time
algorithm in the worst case.
It does not seem to have any polynomial time
algorithm to solve the NPC problems.
The lower bound of any NPC problem seems
to be in the order of an exponential function.
The theory of NP-completeness always
considers the worst case.
23
Caution !
If a problem is NP-complete, its
special cases may or may not
be
of
exponential
timecomplexity.
 We consider worst case lower
bound in NP-complete.

24
Even harder problems:
Undecidable Problems



They cannot be solved by guessing
and checking.
They are even more difficult than NP
problems.
E.G.: Halting problem: Given an
arbitrary program with an arbitrary
input data (the number of input cases
is infinite), will the program terminate
or not?
It is not NP
 It is NP-hard (SAT Halting problem)

25
Some known NPC problems










SAT problem
3SAT problem
0/1 knapsack problem
Traveling salesperson problem
Partition problem
Art gallery problem
Clique problem
Vertex Cover problem
Dominating Set problem
Chromatic Coloring problem
26
The satisfiability (SAT) problem




Def : Given a Boolean formula, determine whether
this formula is satisfiable or not.
A literal (Boolean variable): xi or -xi
A clause (disjunction of variables): ci  x1 v x2 v -x3
A formula : conjunctive normal form
C1& c2 & … & cm
27
NPC Problems
•
•
SAT: Give a Boolean expression
(formula) in CNF (conjunctive normal
form), determine if it is satisfiable.
3SAT: Give a Boolean expression in CNF
such that each clause has exactly 3
variables (literals), determine if it is
satisfiable.
28
The satisfiability (SAT) problem

The satisfiability problem

The logical formula :
x1 v x2 v x3
& - x1
& - x2
the assignment :
x1 ← F , x2 ← F , x3 ← T
will make the above formula true
(-x1, -x2 , x3) represents
x1 ← F , x2 ← F , x3 ← T
29
The satisfiability problem


If there is at least one assignment which
satisfies a formula, then we say that this
formula is satisfiable; otherwise, it is
unsatisfiable.
An unsatisfiable formula :
x1 v x2
& x1 v -x2
& -x1 v x2
& -x1 v -x2
30
Resolution principle
Let formula F=
c1 : -x1 v -x2 v x3
c2 : x1 v x4
 c3 : -x2 v x3 v x4 (resolvent)
x1 cannot satisfy
c1 and c2 at the
same time, so it
is deleted to deduce
a resolvent of c1 and
c2. This is called the
resolution principle .
31
Satisfiable

If no new clauses can be deduced
 satisfiable
-x1 v -x2 v x3
x1
x2
(1) & (2)
-x2 v x3
(4) & (3)
x3
(1) & (3)
-x1 v x3
(1)
(2)
(3)
(4)
(5)
(6)
32
Unsatisfiable
If an empty clause is deduced
 unsatisfiable

- x1 v -x2 v x3
x1 v -x2
x2
- x3
 deduce
(1) & (2)
-x2 v x3
(4) & (5)
-x2
(6) & (3)
□
(1)
(2)
(3)
(4)
(5)
(6)
(7)
33
Nondeterministic SAT

Guessing
Checking
for i = 1 to n do
xi ← choice( true, false )
if E(x1, x2, … ,xn) is true
then success
else failure
34
Proof of Cook’s Theory


Dr. Cook Prove the theory by showing
that all instances of each NP algorithm
can reduce to the SAT problem.
Below, we show a simple example that
the NP searching algorithm reduces to
the SAT problem.
35
The NP searching algorithm
reduces to the SAT problem



Does there exist a number in { x(1),
x(2), …, x(n) }, which is equal to 7?
For example, assume n = 2
The algorithm becomes:
36
The NP searching algorithm
reduces to SAT
i=1 v i=2
& i=1 → i≠2
& i=2 → i≠1
& x(1)=7 & i=1
& x(2)=7 & i=2
& x(1)≠7 & i=1
& x(2)≠7 & i=2
& FAILURE
& SUCCESS
→ SUCCESS
→ SUCCESS
→ FAILURE
→ FAILURE
→ -SUCCESS
(Guarantees a successful termination when it is possible)
& x(1)=7 (Input Data)
& x(2)≠7
37
The NP searching algorithm
reduces to SAT

CNF (conjunctive normal form) :
i=1 v i=2
i≠1 v i≠2
x(1)≠7 v i≠1 v SUCCESS
x(2)≠7 v i≠2 v SUCCESS
x(1)=7 v i≠1 v FAILURE
x(2)=7 v i≠2 v FAILURE
-FAILURE v -SUCCESS
SUCCESS
x(1)=7
x(2)≠7
(1)
(2)
(3)
(4)
(5)
(6)
(7)
(8)
(9)
(10)
38
The NP searching algorithm
reduces to SAT

Satisfiable at the following assignment :
i=1
i≠2
SUCCESS
-FAILURE
x(1)=7
x(2)≠7
satisfying
satisfying
satisfying
satisfying
satisfying
satisfying
(1)
(2), (4) and (6)
(3), (4) and (8)
(7)
(5) and (9)
(4) and (10)
39
The NP searching algorithm
reduces to SAT

Searching for 7, but x(1)7, x(2)7
CNF :
i=1
v
i=2
i1
v
i2
x(1)7
v i1
v
x(2)7
v i2
v
x(1)=7
v i1
v
x(2)=7
v i2
v
SUCCESS
-SUCCESS v -FAILURE
x(1)  7
x(2)  7
SUCCESS
SUCCESS
FAILURE
FAILURE
(1)
(2)
(3)
(4)
(5)
(6)
(7)
(8)
(9)
(10)
40
The NP searching algorithm
reduces to SAT

Apply resolution principle :
(9) & (5)
(10) & (6)
(7) & (8)
(13) & (11)
(13) & (12)
(14) & (1)
(15) & (16)
i1 v FAILURE
i2 v FAILURE
-FAILURE
i1
i2
i=2
□
(11)
(12)
(13)
(14)
(15)
(11)
(17)
We get an empty clause  unsatisfiable
 7 does not exit in x(1) or x(2).
41
Searching in CNF with inputs

Searching for 7, where x(1)=7, x(2)=7
CNF :
i=1
v
i=2
i1
v
i2
x(1)7
v
i1
v
x(2)7
v
i2
v
x(1)=7
v
i1
v
x(2)=7
v
i2
v
SUCCESS
-SUCCESS v -FAILURE
x(1)=7
x(2)=7
SUCCESS
SUCCESS
FAILURE
FAILURE
(1)
(2)
(3)
(4)
(5)
(6)
(7)
(8)
(9)
(10)
42
0/1 Knapsack problem
Profit
P1
P2
P3
P4
P5
P6
P7
P8
10
5
1
9
3
4
11
17
3
3
10
1
9
22
15
Weight 7

Given M (weight limit) and P, is there is a
solution with a profit larger than P?
This is an NPC problem.
43
Traveling salesperson problem


Given: A set of n planar points and a
value L
Find: Is there a closed tour which
includes all points exactly once such
that its total length is less than L?
This is an NPC problem.
44
Partition problem


Given: A set of positive integers S
Find: Is there a partition of S1 and S2 such
that S1S2=, S1S2=S, iS1i=iS2 i
(partition S into S1 and S2 such that element
sum of S1 is equal to that of S2)
e.g. S={1, 7, 10, 9, 5, 8, 3, 13}



S1={1, 10, 9, 8}
S2={7, 5, 3, 13}
This problem is NP-complete.
45
Art gallery problem:
*Given a constant C, is there a guard placement
such that the number of guards is less than C
and every wall is monitored?
*This is an NPC problem.
46
NPC Problems

CLIQUE(k): Does G=(V,E) contain a clique
of size k?
Definition:
 A clique in a graph is a set of vertices such
that any pair of vertices are joined by en
edge.
47
NPC Problems

Vertex Cover(k): Given a graph G=(V, E)
and an integer k, does G have a vertex
cover with k vertices?
Definition:
 A vertex cover of G=(V, E) is V’V such that
every edge in E is incident to some vV’.
50
NPC Problems
Dominating Set(k): Given a graph G=(V,
E) and an integer k, does G have a
dominating set of size k ?
Definition:
 A dominating set D of G=(V, E) is DV
such that every vV is either in D or
adjacent to at least one vertex of D.

53
NPC Problems
Chromatic Coloring(k): Given a graph
G=(V, E) and an integer k, does G have
a coloring for k
Definition
•

A coloring of a graph G=(V, E) is a function
f : V  { 1, 2, 3,…, k }  if (u, v)  E, then
f(u)f(v).
56
Q&A
57