0% found this document useful (0 votes)
107 views

608 34 PDF

1. The document discusses NP-completeness and polynomial-time solvable problems. It defines abstract and concrete problems and describes how problems can be encoded as binary strings. 2. Key points covered include defining decision problems as functions mapping instances to yes/no solutions, and how optimization problems can be recast as decision problems by setting bounds. 3. The complexity class P is defined as problems solvable by a polynomial-time algorithm. It is shown that if a problem is accepted by a polynomial-time algorithm, it can also be decided by one.

Uploaded by

seetarampandey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
107 views

608 34 PDF

1. The document discusses NP-completeness and polynomial-time solvable problems. It defines abstract and concrete problems and describes how problems can be encoded as binary strings. 2. Key points covered include defining decision problems as functions mapping instances to yes/no solutions, and how optimization problems can be recast as decision problems by setting bounds. 3. The complexity class P is defined as problems solvable by a polynomial-time algorithm. It is shown that if a problem is accepted by a polynomial-time algorithm, it can also be decided by one.

Uploaded by

seetarampandey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 75

Chapter 34 1

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

A given problem instance may have more than one solution or


may have no solutions at all
A solution to the shortest path problem is a sequence of vertices
in the graph
Chapter 34 3

For the moment suppose we restrict our attention to decision type


problems: those having yes/no solutions.
XXDecision type problems can be viewed as functions that map
the instance set I to the solution set {0, 1}.
Example: Consider the path related problem for a given two
vertices u and v in an unweighted graph G = (V, E), and a
non-negative integer k.
Is there a path from u to v with at most k edges?
Optimization problems are problems whose objective is to
minimize or maximize a quantity
Optimization problems can be recast as decision problems by
setting a bound on the solution. For example, is there a solution
X to the problem such that X < BOUND.
Chapter 34 4

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

Given the above properties, a reasonable encoding scheme will


have little impact on whether a given problem is tractable or
non-tractable
A concrete problem is a decision problem that takes an instance
set that consists of binary strings
An algorithm solves a concrete problem in time O(T (n)) if when
it is provided a problem instance I of length n = |I|, the
algorithm can produce the solution in at most O(T (n)).
A concrete problem is polynomial-time solvable, if there exists an
algorithm to solve in time O(nk ) for some constant k.
the complexity class P is the set of concrete decision problems
that are solvable in polynomial time.
Given an abstract decision problem, the encoding e : I → {0, 1}∗
can be used to induce a related concrete decision problem
A function f : {0, 1}∗ → {0, 1}∗ is polynomial-time computable if
Chapter 34 6

there exists a polynomial time algorithm A that, given any input


x ∈ {0, 1}∗ , produces the output f (x).
Chapter 34 7

Lemma 34.1: Let Q be an abstract decision problem on an


instance set I, and let e1 and e2 be polynomially related encoding
on I. Then e1 (Q) ∈ P iff e2 (Q) ∈ P
proof of 34.1:
We need to prove one direction since the other is symmetric
Assume that e1 (Q) ∈ P . Thus it can be solved in O(nk ) from
some constant k
Also since e1 and e2 are polynomially related, then the encoding
e1 (i) can be computed from e2 (i) in time O(nc ) for some constant
c, where n = |e2 (i)|. Observe that an output cannot be larger
than the running time.
To solve the problem e2 (Q), on e2 (i)
XX1. compute e1 (i): takes O(nc )
XX2. Solve e1 (Q): takes O(|e1 (i)|k ) = O(nck )
Chapter 34 8

A formal language framework


An Alphabet Σ: is a finite set of symbols.
A language L over Σ is any set of strings made up of symbols
from Σ.
: the empty string
∅: the empty language
Σ∗ : the language of all strings over Σ
For example if Σ = {0, 1} then
{0, 1}∗ = {, 0, 1, 00, 01, 10, 11, 000, ...}
Every language over Σ is subset of Σ∗
The complement of a language L is L = Σ∗ \ L
The concatenation of two languages L1 and L2 is the language
L = {x1 x2 | x1 ∈ L1 and x2 ∈ L2 }
Chapter 34 9

Let Lk be the language obtained by concatenating L to itself k


times. Then the closure of a language L is
L∗ = {} ∪ L1 ∪ L2 ∪ L3 ∪ ...
Union and intersections of languages follow their definition from
set theory
Chapter 34 10

Defining a problem in terms of language


The set of instances of any decision problem Q is the set Σ∗ where
Σ = {0, 1}
We can view Q as the language L over Σ = {0, 1}, where
L = {x ∈ Σ∗ | Q(x) = 1}
Example: The decision path problem has the corresponding
language PATH = {< G, u, v, k > |G = (V, E) is an undirected
graph, u, v ∈ V, k ≥ 0 is an integer, and there exists a path from u
to v in G whose length is at most k}
Sometimes the same name is used for the decision problem as well
as the language underlying it
An algorithm accepts a string x ∈ {0, 1}∗ if, given input x, the
algorithm outputs A(x) = 1
The language accepted by an algorithm A is the set
L = {x ∈ {0, 1}∗ | A(x) = 1}
Chapter 34 11

Similarly, an algorithm A rejects a string x ∈ {0, 1}∗ if given input


x, the algorithm outputs A(x) = 0
The algorithm may not necessarily reject all the string x ∈ L (for
example it might loop forever without generating an output, it
may never halt)
A language L is decided by an algorithm if every binary string in
L is accepted by A and every string not in L is rejected by A
A language is accepted in polynomial time by an algorithm A if
there exists a constant k such that every length-n string x ∈ L,
the algorithm accepts x in time O(nk )
A language is decided in polynomial time by an algorithm A if
there exists a constant k such that for every length-n string
x ∈ {0, 1}∗ , the algorithm decides x in time O(nk ) (where k is a
constant)
complexity class is a set of languages for which membership is
determined by some complexity measure
Chapter 34 12

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

Theorem 34.2: P = {L| L is accepted by a polynomial-time


algorithm}
Proof of Lemma 34.2

The class of languages decided by polynomial-time algorithms is a


subset of the class of languages accepted by polynomial time
algorithms
Thus we need to show that if L is accepted by a polynomial time
algorithm it is also decided by a polynomial time algorithm
Let L be such language accepted by a polynomial-time algorithm
A, use simulation techniques to generate a polynomial-time
algorithm A0 that decides L
Because A accepts L in O(nk ) there exists a constant c such that
A accepts L in c · nk steps
Let T = cnk . The algorithm A0 simulates the action of A for the
Chapter 34 14

period T and at the end of the period, if x is accepted by A, then


x is also accepted by A0 .
If at the end of period T , x is not accepted by A then A0 rejects x
Chapter 34 15

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

The Hamiltonian cycles is an example of a problem for which we


know of no polynomial decision time algorithm
However, given a certificate, verification is easy

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

How can an algorithm decide the Language HAM-CYCLE?


Given an instance < G >, one possible decision algorithm lists all
permutations of the vertices and checks each permutation to see if
there is a hamiltonian path.

The number m of vertices is Ω( n) where n = | < G > | is the
length of the encoding of G
There are m! permutations of the vertices. Thus the running time
√ √
is Ω(m!) = Ω( n!) = Ω(2 n )
This is non-polynomial and the hamiltonian cycle is NP-complete
Chapter 34 18

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

Thus a proof that a hamiltonian cycle exists in a graph can be


verified in polynomial time
A verification algorithm is defined as a two argument algorithm
A, where one argument is the input string x and the other is a
binary string y called cerificate
The algorithm A verifies an input string x if there exists a
certificate y such that A(x, y) = 1
The language verified by the verification algorithm A is
L = {x ∈ {0, 1}∗ | there exists y ∈ {0, 1}∗ such that A(x, y) = 1}
An algorithm A verifies a language L if for any string x ∈ L, there
is a certificate y that A can use to prove that x ∈ L
Also, for any string x 6∈ L, there must be no certificate y for which
A(x, y) = 1
Chapter 34 20

The complexity class NP


The complexity class NP is the class of languages that can be
verified by an polynomial time algorithm
A language L belongs to NP if and only if there exists a two input
polynomial time algorithm A and constant c such that
L = {x ∈ {0, 1}∗ | there exists a certificate y with |y| = O(|x|c )
such that A(x, y) = 1}
The above algorithm A verifies the language L in polynomial time
We know that HAM-CYCLE∈ N P
Also if there is an algorithm that decides L in polynomial time,
then it is possible to construct an algorithm that verifies L in
polynomial time
Thus P ⊆ N P
We dont know whether P = NP
Chapter 34 21

Intuition suggests that P 6= N P , thus there are problems in N P


that are not in P
Chapter 34 22

Is the class NP closed under complement? That is, does L ∈ N P


==>L ∈ N P ?
Let co − N P be the set of languages L such thatL ∈ N P
We don’t know if N P =co − N P
Since P is closed under complement, it follows that
P ⊆ N P ∩ co − N P
We also don’t know if P =N P ∩ co − N P
or
We don’t know if there is a language in N P ∩ co − N P \ P
There are four possible scenarios
Chapter 34 23

NP-completeness and reducibility


The existence of the NP-complete class gives researchers a reason
to think that P 6= N P
The NP-complete class satisfies the following property: if one
NP-complete problem can be solved in polynomial time then every
problem in NP has a polynomial time solution (i.e. P = NP)
No polynomial time algorithm has been discovered for any
NP-complete problem
The language HAM-CYCLE is NP-complete.
Chapter 34 24

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

Lemma 34.3 if L1 , L2 ∈ {0, 1}∗ are languages such that


L1 ≤p L2 , then L2 ∈ P implies that L1 ∈ P
Proof: Let A2 be a polynomial time algorithm that decides L2
Let F be a polynomial time reduction algorithm that computes
the reduction function f
We will construct an algorithm A1 that decides L1 in polynomial
time
For a given input x ∈ {0, 1}∗ , the algorithm A1 uses F to
transform x into f (x)
The algorithm A1 then uses A2 to decide whether f (x) ∈ L2
Chapter 34 26

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

Research into the P 6= N P problem concentrates on NP-complete


problems Most researchers believe that P 6= N P

It is possible for a researcher to come-up with a polynomial time


algorithm that solves an NP-complete problem.
Thus proving that P = NP
No polynomial time algorithm for any NP-complete problem has
been discovered
Thus, we will use proof of NP-completeness as a good measure for
intractability
Chapter 34 29

Example of NP-complete Problem:


Circuit satisfiability
A truth assignment for a boolean combination circuit is a set of
boolean input values.
One-output boolean combinational circuit is satisfiable if it has a
satisfying assignment.
A satisfying assignment: a truth assignment that causes the
output of the circuit to be “1”
The first circuit (see example pg 989) generates “1” when
x1 = 1, x2 = 1 and x3 = 0. Thus it is satisfiable.
The second circuit is unsatisfiable. No assignment values of x1 , x2 ,
and x3 causes the circuit to produce “1” (it always produces “0”).
Chapter 34 30

The circuit satisfiability problem is,


Given a boolean combinational circuit composed of AND, OR,
and NOT gates, is it satisfiable?
Encoding: a graph-like encoding that maps any given circuit C
into a binary string < C > whose length is not much larger than
the circuit itself.
CIRCUIT-SAT = {< C >: C is a satisfiable boolean combinational
circuit}
Importance of the problem in computer-aided hardware design. If
a circuit always produces “zero” we can eliminate it
Given a circuit C we can try all input combinations to determine
whether it is satisfiable or not.
If there are k inputs, this means checking 2k configurations
(non-polynomial)
Chapter 34 31

There is a strong evidence that there is no polynomial time


algorithm for that circuit-satisfiability problem
In fact circuit-satisfiability is NP-complete
Chapter 34 32

Lemma 34.5: The circuit-satisfiability problem belongs to the


class NP
Proof:
Construct a polynomial time algorithm A, with two inputs that
can verity CIRCUIT-SAT
One input is the encoding of the circuit C and the other input is
the certificate corresponding to an assignment of the wires in C
For each gate in the circuit check that the value provided by the
certificate on the output wire is correctly computed as function of
the values on the input wires
Whenever a circuit is satisfiable, there is a certificate whose length
is polynomial in the size of C and that causes A to output “1”
Whenever a circuit is unsatisfiable, there is no certificate that can
make A believe that the circuit is satisfiable
Chapter 34 33

The second part of the proof is to show that CIRCUIT-SAT is


NP-hard. That is every language in NP is polynomial-time
reducible to CIRCUIT-SAT (property of the definition of NP
completeness)
Sketch the proof based on the workings of a computer hardware
A computer program is a sequence of instructions stored in the
computer memory
A program counter (PC) is a special memory location that points
to the instruction to be executed next.
At any point in the execution of a program, the entire state of the
computation is stored in memory
The memory also includes storage space for bookkeeping
A particular state of the computer memory is called a
configuration
Chapter 34 34

The execution of one instruction is viewed as the mapping from


one memory configuration to another memory configuration
The computer hardware that can accomplish this mapping can be
implemented as a boolean combinational circuit (denote it by M –
see figure pg 992)
Chapter 34 35

Lemma 34.6: The circuit-satisfiability problem is NP hard


Proof:
Let L be any language in NP
We will describe a polynomial-time function F computing a
function f that maps every binary string x to a circuit C = f (x)
such that x ∈ L iff C ∈ CIRCUIT-SAT
Since L ∈ N P , there must be an algorithm A that verifies L in
polynomial time
The algorithm F will use the two-input algorithm A to compute
the reduction f
Let T (n) denote the worst case running time of A on a length n
input string
T (n) = O(nk ) where k ≥ 1
Chapter 34 36

Each configuration includes, the program for A, the program


counter (PC), the auxiliary machine state, the input x, the
certificate y, and the working storage
Starting with configuration c0 , each configuration ci is mapped to
a configuration ci+1 using the combination circuit M
The output of the algorithm A (0 or 1) is written in a specific
location of the working storage when A finishes execution
If the algorithm runs at most T (n) steps, the output appears in
the working storage in cT (n)
The reduction algorithm F constructs a single combinational
circuit that generates all the configurations generated by an initial
configuration c0
The basic idea is to paste together T (n) copies of the circuit M
The output of the ith circuit is feedback to the input of the
(i + 1)st circuit
Chapter 34 37

Given an input x the algorithm F must compute a circuit


C = f (x) that is satisfiable iff there exists a certificate y such that
A(x, y) = 1
When F obtains an input x, it computes n = |x| and constructs a
combinational circuit C 0 consisting of T (n) copies of M
The input to C 0 is the initial configuration c0
The output of C 0 is the configuration cT (n)
The circuit C that computes F corresponds to a modification of
C0
The inputs of C 0 corresponding to the program for A, the initial
PC, the input x and the initial memory configuration are directly
hardwired to these known values
The only remaining input is the certificate y
All outputs to the circuit are ignored, except for the bit of cT (n)
corresponding the output of A
Chapter 34 38

The circuit C as constructed above, computes C(y) = A(x, y) for


any input y of length O(nk )
The reduction algorithm F , when provided with an input x
computes such a circuit C
We need to prove
XX1. F correctly computes a reduction function f (i.e. C is
satisfiable iff there exists a certificate y such that A(x, y) = 1)
and
XX2. F runs in polynomial time
To show (1) ==>Suppose that there exists a certificate y of
length O(nk ) such that A(x, y) = 1
If we apply the bits of y to the inputs of C, the output of
C(y) = A(x, y) = 1
Thus if a certificate exists, then C is satisfiable
==>Suppose C is satisfiable Thus there exists an input y such
Chapter 34 39

that C(y) = 1 Therefore, A(x, y) = 1


F correctly computes a reduction function
Chapter 34 40

To show (2), that is to show F runs in polynomial time Let n = |x|


The number of bits required to represent a configuration is
polynomial in n
The program A is constant in size, independent of the input x
The length of the input x is n
The length of the certificate y is O(nk )
Since the algorithm runs in at most O(nk ) steps, the amount of
working storage is at most O(nk )
We assume that this memory is contiguous
The combinational circuit M implementing the computer
hardware has polynomial size in the length of the configuration
i.e. polynomial in n
Chapter 34 41

The circuit C consists of at most t = O(nk ) copies of M , thus it


has size polynomial in n The construction of C from x can be
accomplished in polynomial time (using F ), since each step of the
construction takes polynomial time
Chapter 34 42

The language CIRCUIT-SAT is therefore at least as hard as any


language in NP, and since it belongs to NP, it is NP-complete.
Theorem 34.7: The circuit-satisfiability problem is NP-complete
Proof:
Lemmas 34.5, 34.6 and the definitions of NP-completeness.
Chapter 34 43

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

To prove that a language L is NP-complete


1. Prove L ∈ N P
2. Select a known NP-complete language L0 (a good choice of L0
can make the proof very easy)
3. Describe an algorithm that computes a function f mapping
every instance of L0 to an instance of L
4. Prove that the function f satisfies x ∈ L0 if and only if
f (x) ∈ L for all x ∈ {0, 1}∗
5. Prove that the algorithm computing f runs in polynomial time
CIRCUIT-SAT is NP-complete, thus it can be used for L0
Chapter 34 45

Formula satisfiability: determine whether a boolean formula is


satisfiable.
The problem is formulated in terms of the language SAT
An instance of SAT is a boolean formula ∆ composed of
1. boolean variables: x1 , x2 , ...
2. boolean connectives: any boolean function with one or two
inputs and one output such as
XX∧ : AND
XX∨ : OR
XX¬ : NOT
XX→: Implication
XX↔: if and only if
3. parentheses
Chapter 34 46

A truth assignment for a boolean formula ∆ is a set of values for


the variables of ∆
A satisfying assignment for a boolean formula ∆ is a truth
assignment that causes ∆ to evaluate to 1
A formula with a satisfying assignment is a satisfiable formula
The satisfiable problem asks whether a boolean formula is
satisfiable
That is, SAT = {< ∆ > such that ∆ is a satisfiable boolean
formula}
Example
XXLet

∆ = ((x1 → x2 ) ∨ ¬((¬x1 ↔ x3 ) ∨ x4 )) ∧ ¬x2

∆ has the satisfying assignment x1 = 0, x2 = 0, x3 = 1, and x4 = 1


Thus ∆ belongs to SAT
Chapter 34 47

If we evaluate every combination of inputs to find out if a formula


is satisfiable or not we will end up with a NON-POLYNOMIAL
algorithm.
There are 2n possible configurations for n variables.
Chapter 34 48

Theorem 34.9: Satisfiability of boolean formulas is NP-complete


Proof: two parts
1. SAT ∈ NP
2. CIRCUIT-SAT ≤p SAT
By Lemma 34.8, the two parts will conclude the proof that SAT is
NP- complete.
Part 1: A certificate consisting of a satisfying assignment for a
boolean formula ∆ can be verified in polynomial time
The verifying algorithm replaces each variable in the formula by
its value
The expression ∆ is then evaluated
This algorithm is doable in polynomial time
If the expression evaluates to 1 then ∆ is satisfiable
Chapter 34 49

Part 2: Any instance of circuit satisfiability can be reduced in


polynomial time to formula satisfiability
We can use induction to express any boolean combinational circuit
as a boolean formula write an expression for each gate inductively
combine all the expressions problem: this is not polynomial time.
Shared subexpressions can cause the size of the expression to grow
exponentially think of a circuit that has feedback
We need a polynomial time reduction algorithm
Chapter 34 50

Each wire is labeled with a variable xi


The operation of a gate can be expressed in terms of the variables
corresponding to the input wires
example: x10 ↔ (x7 ∧ x8 ∧ x9 ))
The formula for ∆ consists of the “product” (AND) of all terms
describing the gates (AND of output with the conjunction of the
clauses) For the circuit (pg 998) we have:
∆ = x10 ∧ (x4 ↔ x3 )
∧ (x5 ↔ (x1 ∨ x2 ))
∧ (x6 ↔ ¬x4 )
∧ (x7 ↔ (x1 ∧ x2 ∧ x4 ))
∧ (x8 ↔ (x5 ∨ x6 ))
∧ (x9 ↔ (x6 ∨ x7 ))
∧ (x10 ↔ (x7 ∧ x8 ∧ x9 ))
Chapter 34 51

This transformation is polynomial time


Chapter 34 52

The circuit C is satisfiable exactly when the formula ∆ is


satisfiable
If C has a satisfying assignment, each wire has a well defined
value and the output of the circuit is 1
The assignment of wire values to variables in ∆ makes each term
in ∆ evaluate to “1”
Thus, the product of all the terms will evaluate to “1”
Conversely, if there is an assignment that causes ∆ to evaluate to
“1”, the circuit C is satisfiable
Use the values of the input wires as a satisfying assignment for
the circuit
Chapter 34 53

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

(x1 ∨ ¬x1 ∨ ¬x2 ) ∧ (x3 ∨ x2 ∨ x4 ) ∧ (¬x1 ∨ ¬x3 ∨ ¬x4 )

3-CNF-SAT asks whether a boolean formula in 3-CNF is


satisfiable.
Chapter 34 54

Theorem 34.10: Satisfiability of boolean formulas in 3-CNF is


NP- complete
Proof: two parts
1. 3-CNF-SAT ∈ NP (similar to the argument showing that SAT
∈ NP )
2. SAT ≤p 3-CNF-SAT
By Lemma 34.8 the two parts will conclude the proof that SAT is
NP- complete.
Part 2: Any instance of formula satisfiability can be reduced in
polynomial time to 3-CNF satisfiability
The reduction algorithm that will express instances of SAT into
instances of 3-CNF-SAT consists of 3 steps
In the first step we construct a parse tree for the boolean formula

Chapter 34 55

Example: given the formula

∆ = ((x1 → x2 ) ∨ ¬((¬x1 ↔ x3 ) ∨ x4 )) ∧ ¬x2

see figure pg 1000

The leaves of the parse tree are literals


The nodes are boolean connectives
For clauses with more than two literals use associativity to apply
parenthesis around the subexpression so that each node has at
most two children
We use a similar approach to the one used in the proof of theorem
34.9
Chapter 34 56

Label each internal node with a variable yi rewrite the original


formula using the new variables

∆0 = y1 ∧ (y1 ↔ (y2 ∧ ¬x2 ))


∧ (y2 ↔ (y3 ∨ y4 ))
∧ (y3 ↔ (x1 → x2 )
∧ (y4 ↔ ¬y5 )
∧ (y5 ↔ (y6 ∨ x4 ))
∧ (y6 ↔ (¬x1 ↔ x3 ))

All the clauses ∆0i in ∆0 have at most three literals


There are two additional requirements
XXeach clause has to be an OR of literals (step 2)
XXalso each clause has to have exactly three literals (step 3)
Chapter 34 57

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

In DNF form (SUM of products) we can write

¬∆01 = (y1 ∧y2 ∧x2 )∨(y1 ∧¬y2 ∧x2 )∨(y1 ∧¬y2 ∧¬x2 )∨(¬y1 ∧y2 ∧¬x2 )

XXApply DeMorgan’s law we get ∆00 0


1 which is equivalent to ∆1
but it is in CNF form
XX∆001 =
(¬y1 ∨ ¬y2 ∨ x2 ) ∧ (¬y1 ∨ y2 ∨ ¬x2 ) ∧ (¬y1 ∨ y2 ∨ x2 ) ∧ (y1 ∨ ¬y2 ∨ x2 )
The conjunction ∆00 of all ∆00
i is a CNF formula equivalent to ∆0 .

Furthermore each clause has at most three literals.


Chapter 34 59

Step 3: make each clause consist of exactly three literals and


construct the final formula ∆000
1

XXintroduce two new variables p and q


XXif a given clause of ∆00 has three literals then include it “as is”
in ∆000
XXif a given clause of ∆00 has two literals, Ci = (l1 ∨ l2 ), then
rewrite Ci = (l1 ∨ l2 ∨ p) ∧ (l1 ∨ l2 ∨ ¬p)
XXif a given clause of ∆00 has one literal, Cj = l1 , then rewrite
Cj = (l1 ∨ p ∨ q) ∧ (l1 ∨ p ∨ ¬q) ∧ (l1 ∨ ¬p ∨ q) ∧ (l1 ∨ ¬p ∨ ¬q)
We can show that the 3-CNF formula ∆000 is satisfiable iff ∆ is
satisfiable
Since each step in the transformation produces a formula that is
equivalent to ∆
Chapter 34 60

We must also show that the reduction can be done in polynomial


time
Constructing ∆0 from ∆ introduces at most 1 variable and 1
clause per connective operation
Constructing ∆00 from ∆0 introduces at most 8 clauses for each
clause in ∆0
Constructing ∆000 from ∆00 introduces at most 4 clauses for each
clause in ∆00
Thus each construction can be done in polynomial time
Chapter 34 61

NP-complete Problems
see figure pg 1004

The Clique Problem


A Clique in an undirected graph G = (V, E) is a subset V 0 ⊆ V ,
such that each pair of vertices is connected by an edge in E
In other words a clique is a complete subgraph of G
CLIQUE = {< G, k > |G is a graph with a clique of size k vertices}
Chapter 34 62

Theorem 34.11: The clique problem is NP-complete.


proof Part 1: Clique ∈ N P : Find a polynomial time verification
algorithm for a graph G = (V, E), we use the set V 0 as a
certificate it is easy to verify in polynomial time that all the
vertices of V 0 form a complete graph
Part 2: Clique is NP-hard: 3-CNF-SAT ≤p CLIQUE
Let ∆ = C1 ∧ C2 ∧ ... ∧ Ck in 3-CNF
Each clause Cr = l1r ∨ l2r ∨ l3r
A graph G = (V, E) is constructed as follows: For each
Cr = l1r ∨ l2r ∨ l3r in ∆ place three corresponding vertices v1r , v2r , v3r
in V There is an edge between two vertices vir and vjs
XX1. if vir and vjs are in different triplets (i.e. r 6= s)
XX2. lir is not the complement of ljs
Chapter 34 63

Example: Let
∆ = (x1 ∨ ¬x2 ∨ ¬x3 ) ∧ (¬x1 ∨ x2 ∨ x3 ) ∧ (x1 ∨ x2 ∨ x3 )

see figure

We have to show that the transformation is a reduction.


Chapter 34 64

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

Part 2: Vertex-cover is NP-hard: Clique ≤p Vertex-cover


Given an undirected graph G = (V, E), the complement of G is
G = (V, E), where E = {(u, v) such that (u, v) 6∈ E}
G contains all the edges that are not in G
Given G = (V, E), the reduction algorithm proceeds as follows:
XXCompute G (polynomial time)
XXThe output of the reduction algorithm is the instance
< G, |V | − k >
Chapter 34 68

We need to show that the transformation is a reduction. That is


the graph G has a clique of size k if and only if the graph G has a
vertex-cover of size |V | − k
==>
Assume that G has a clique V 0 ⊆ V with |V 0 | = k. Claim that
V \ V 0 is a vertex-cover for G.
Let (u,v) be any edge on E
(u, v) 6∈ E, thus at least one of u or v 6∈ V 0 (every pair of vertices
in V 0 is connected by an edge in E )
Therefore at least one of u or v ∈ V \ V 0
Thus the edge (u, v) is covered by V \ V 0
The choice of (u,v) was arbitrary, thus the set V \ V 0 (with size
|V | − k) forms a vertex-cover for G
Chapter 34 69

<==
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

The Hamiltonian-Cycle Problem


Theorem 34.13 : The hamiltonian-cycle problem is
NP-complete.
Chapter 34 71

Traveling Salesman Problem


Closely related to the hamiltonian cycle problem
The salesman would like to visit each city and return to the
starting city–a tour i.e. a hamiltonian cycle
XXvisit each city exactly once
There is an integer cost c(i, j) corresponding to the trip form city
i to city j
The salesman would like to make tour whose total cost is
minimum
TSP = {< G, c, k > such that G = (V, E) is a complete graph c is
a function from V × V → Z, k ∈ Z and G has a traveling salesman
tour with cost at most k}
Theorem 34.14: The traveling salesman problem is
NP-complete.
Chapter 34 72

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

G has a hamiltonian cycle if and only if G0 has a tour of cost at


most “0”
==>
Suppose G has a hamiltonian cycle h
Each edge in h belongs to E and has cost “0” in G0
Sum of all edges in h is “0”
<==
Assume G0 has a tour h0 with total cost at most 0
Since the edges in E 0 cost either “1”or “0”
The cost of the tour h0 is exactly “0”
Therefore h0 contains only edges in E
Thus h is a hamiltonian cycle in G
Chapter 34 75

The Subset-Sum Problem


Given a set S ⊂ N and a target t ∈ N
Is there a subset S 0 ⊆ S whose element add up to t?
example:

S = {1, 4, 16, 64, 256, 1040, 1041, 1093, 1284, 1344}

and t = 3758, then the subset

S 0 = {1, 4, 16, 64, 256, 1040, 1093, 1284}

is a solution.
SUBSET-SUM = {< S, t > | there exists a subset S 0 ⊆ S such
P
that t = s∈S 0 s}

You might also like