608 34 PDF
608 34 PDF
NP-Completeness
Polynomial time solvable problems are regarded as tractable
Polynomial are closed under addition, multiplication and
composition. Thus the combination of two or more
Polynomial-time solvable problem is a Polynomial-time solvable
problem.
Definition: An abstract problem Q is a binary relation on a set I
of problem instances and a set S of problem solutions.
Example: Consider the shortest path problem for a given two
vertices in an unweighted graph G = (V, E). An instance of the
shortest path problem is the triplet consisting of a graph G, a
source vertex u and a destination vertex v
Chapter 34 2
Encoding
Before a problem can be solved on a computer, the problem
instances must be encoded.
Example: a familiar encoding for natural numbers is the encoding
that maps {0, 1, 2, 3, 4, ....} to {0, 1, 10, 11, 100, ...}
A reasonable encoding has two properties
XX1. The encoding of an instance I should be concise and not
padded with unnecessary information and symbols
XX2. Numbers occurring in I should be represented in binary (or
some fixed base other than 1)
If two encoding schemes differs in polynomial length from one
another, then an algorithm with polynomial time complexity that
uses one encoding will also have polynomial time complexity if the
other encoding is chosen
Chapter 34 5
definition
The complexity class P is defined as P = {L ⊆ {0, 1}∗ | there
exists an algorithm A that decides L in polynomial time}.
Chapter 34 13
Polynomial-time verification
There are algorithms that verify membership of an algorithm in a
language
For example suppose in the context of the PATH problem we are
given an instance < G, u, v, k > of the decision problem and a
path p from u to v
We can check whether p is at most k edges
We can view p as a certificate that the instance indeed belongs to
PATH
In the case of this problem verifying a given certificate may take
as long as solving the problem. Thus verification does not buy us
much time
Chapter 34 16
Hamiltonian cycles
A hamiltonian cycle of an undirected graph is a simple cycle
that contains each vertex in V
A graph that contains a hamiltonian cycle is called hamiltonian,
otherwise it is non-hamiltonian.
The Hamiltonian-cycle problem: “Does a graph G have a
hamiltonian cycle?” As a formal language:
HAM-CYCLE = {< G > |G is a hamiltonian graph}
Chapter 34 17
verification
XXConsider that you are given a graph that is known to be
hamiltonian and you are also given a hamiltonian cycle for the
graph
XXIt would be easy to verify that the cycle provided is
hamiltonian
XXThis verification can be performed in O(n2 ) where n is the
length of the encoding of G
Chapter 34 19
Reducibility
Intuitively, a problem Q can be reduced to a problem Q0 if any
instance of Q can be rephrased into an instance of Q0
For decision problems, we say that L1 is polynomial-time
reducible to a language L2 , we write L1 ≤p L2 , if there is a
polynomial time computable function f : {0, 1}∗ → {0, 1}∗ such
that for all x ∈ {0, 1}∗ we have x ∈ L1 iff f (x) ∈ L2
f is called the reduction function and the algorithm F that
computes f is called a reduction algorithm
Chapter 34 25
NP-completeness
if L1 ≤p L2 , then L1 is not more than polynomial factor harder
than L2
A language L ∈ {0, 1}∗ is NP-complete if
XX1. L ∈ N P and
XX2. L0 ≤p L for every L0 ∈ N P
If a language satisfies property 2, but not necessarily property 1,
we say that L is NP-hard
NPC denotes the class of NP-complete problems
Chapter 34 27
Theorem 34.4
XX1. If any NP-complete problem is polynomial time solvable
then P = NP
XX2. If any problem in NP is not polynomial time solvable then
all NP-complete problems are not polynomial time solvable
Proof: 1. First property Suppose L ∈ P and L ∈ N P C
For any L0 ∈ N P we have L0 ≤p L (property 2 of
NP-completeness)
Thus L0 ∈ P (Lemma 34.3)
2. Second property
Suppose there exists an L ∈ N P such that L 6∈ P
Let L0 ∈ N P C be any NP-complete language.
Assume that L0 ∈ P (proof by contradiction)
From Lemma 34.3, we have L ≤p L0 . Thus, L ∈ P
Chapter 34 28
NP-completeness proofs
We can show that a given language is NP-complete without
directly reducing every language in NP to the given language
Lemma 34.8: If L is a language such that L0 ≤p L for some
L0 ∈ N P C, then L is NP-hard. Moreover, if L ∈ N P , then
L ∈ NP C
Proof:
L0 is NP-complete
Therefore for all L00 ∈ N P , we have L00 ≤p L0
Let L0 ≤p L
By transitivity for all L00 ∈ N P , we have L00 ≤p L0
Thus L is NP-hard (property 2)
If also L ∈ N P (property 1)
Then L ∈ N P C
Chapter 34 44
3-CNF satisfiability
literal: is the occurrence of a variable or its complement
CNF (conjunctive normal form): a boolean expression is in CNF
form if it is in PRODUCT (AND) of SUMS(OR) a boolean
expression is in 3-CNF if each SUM (sum are also called clauses)
has exactly three literals
Example
Step 2:
For each clause ∆0i we use the truth table to generate the
complement of the clause (¬∆0i ) as a product
For the clause ∆01 = (y1 ↔ (y2 ∧ ¬x2 ))
We have the following truth table
y1 y2 x2 ∆0i
0 0 0 1
0 0 1 1
0 1 0 0
0 1 1 1
1 0 0 0
1 0 1 0
1 1 0 1
1 1 1 0
Chapter 34 58
¬∆01 = (y1 ∧y2 ∧x2 )∨(y1 ∧¬y2 ∧x2 )∨(y1 ∧¬y2 ∧¬x2 )∨(¬y1 ∧y2 ∧¬x2 )
NP-complete Problems
see figure pg 1004
Example: Let
∆ = (x1 ∨ ¬x2 ∨ ¬x3 ) ∧ (¬x1 ∨ x2 ∨ x3 ) ∧ (x1 ∨ x2 ∨ x3 )
see figure
1. <==
Assume that ∆ has a satisfying assignment
Each Cr contains a “true” literal call it lir (with corresponding
vertex vir )
The set of all these true vertices forms V 0
Claim that V 0 forms a clique of size k
Pick any two vertices vir , vjs in V 0 where r 6= s (first property)
Since both are true literals, they cannot be the complement of
each other (second property)
Therefore, there is an edge between vir and vjs
Chapter 34 65
2. ==>
Assume V 0 is a clique of size k of G
No edges in G connect vertices in the same triplet
Therefore V 0 contains only one vertex per triplet
Assign 1 to each literal lir whose corresponding vertex vir is in V 0
Each clause is satisfied
Chapter 34 66
Vertex-Cover Problem
A vertex-cover of an undirected graph G = (V, E) is a subset
V 0 ⊆ V , such that if (u, v) ∈ E, then u ∈ V 0 or v ∈ V 0 (or both)
Vertex-cover = {< G, k > graph G has vertex-cover of size k }
The size of the vertex-cover is the number of vertices in V 0
Theorem 34.12: The vertex-cover problem is NP-complete.
proof:
Part 1: Vertex-cover ∈ NP: Find a polynomial time verification
algorithm
For a graph G = (V, E) and integer k, we use the vertex-cover V 0
has a certificate
It is easy to verify in polynomial time that each edge for each
(u, v) ∈ E either u or v is in V 0
Also the algorithm needs to verify that |V 0 | = k
Chapter 34 67
<==
Assume G has a vertex-cover V 0 ⊆ V where |V 0 | = |V | − k
For all u, v ∈ V , if (u, v) ∈ E, then u ∈ V 0 , or v ∈ V 0 , or both
Thus if u 6∈ V 0 and v 6∈ V 0 , then (u, v) ∈ E
Therefore V \ V 0 is a clique of size |V | − |V 0 | = k
Chapter 34 70
proof
Part 1: TSP ∈ NP: Find a polynomial time verification algorithm
For a graph G = (V, E ), we use as certificate the sequence of n
vertices
The verification algorithm must check if this sequence contains all
the vertices in V
Also, the verification algorithm must sum-up all the costs of the
edges in the tour and check whether it is less than k
Part 2: TSP is NP-hard:
Ham-Cycle ≤p TSP
Let G = (V, E ) be an instance of Ham-Cycle
For the complete graph G0 = (V, E 0 ) where E 0 = {(i, j) such that
i, j ∈ V and i 6= j}
Chapter 34 73
Define c as
0 if (i, j) ∈ E
c(i, j) =
1 if (i, j) 6∈ E
Chapter 34 74
is a solution.
SUBSET-SUM = {< S, t > | there exists a subset S 0 ⊆ S such
P
that t = s∈S 0 s}