np-complete, probtems · 180 design and analysis of algorithms f chapter 8 ta some examples in p:...

12
;' CHAPTER 8 {fl llr \+ ,trft, '\tk* {l ritl ilill (a tr $ m. )xity. for the { I I I t l I { t i .. NP-COMPLETE, PROBTEMS Mostalgorithmswehavestudiedsofarhavepolynomial-time,running.times.-thatil,T*: the shortest paths and minimum spanning trees in graphs, sorting of arrays, matrlx multiplication, and so on. All these algorithms are efficient, tecause in each case their time requirement grows as a pol1'nomial funJion (such as n' n' ' o' -'|-1 of the size of the input' This chapter gives a g",,",ul introduction of P, NP and NP-complete problems' We will study the definition und ,ot" classic examples of NP-complete problems' More importantly' we will leam how to show that a problem is not easier than another problem by polynomial-time reduction. Polynomial-time reduction is the ge1ei1.! metlod to prove that a new problem is lr[P: ;;ffi;;:;#;;J*"ln exeuse nol to rind trreoptimal solu1ion. As we encounter more NP- 4ilffi;'p-blems, *e wittriarn some genera'l techniques for reductions' Polynomial-time algorithms can be considered tractable (easy or not so difficult) for the l'Tr1iffii"Jir"or"- which has a running time of say o(nk) (ror rarge value of k) can be called intractable (difficult), there ur" \r"ry few practical problems with such orders of polynomial complexity. i ,-- r :.. -^r-.'^^*:-r +. . For reasonable models of computation, a problem that can be solved in polynomial time tn one model can also be solved in polynomial time on another' o The class of poiyr,o-ia-time solvable problems has nice closure properties (since polynomials are closed under addition' multiplication' etc') 8.1 P, NP, and NP-complete Somehow we believe that an efficient algorithm should run in polynomial time, that is, O(nk) fot input size r and some constant k. consequently, problems that can be solved in polynomial time are treated as "easy" p.oUf"rr, (although k canie arbitrarily large)' and we use P to denote the set of polynomial-timl-solvable problems' Here is the formal definition: P: the set of problems that can be solved in polynomial time'

Upload: others

Post on 08-Aug-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: NP-COMPLETE, PROBTEMS · 180 Design and Analysis of Algorithms F Chapter 8 ta Some examples in P: Finding the shortest-path in a graph between two vertices such that the surn of the

;'CHAPTER 8

{flllr

\+

,trft,

'\tk*{l

ritl

ilill

(a

tr

$

m.

)xity.

for the

{IIIt

lI{

t

i

.. NP-COMPLETE, PROBTEMS

Mostalgorithmswehavestudiedsofarhavepolynomial-time,running.times.-thatil,T*:the shortest paths and minimum spanning trees in graphs, sorting of arrays, matrlx

multiplication, and so on. All these algorithms are efficient, tecause in each case their time

requirement grows as a pol1'nomial funJion (such as n' n' '

o' -'|-1

of the size of the input'

This chapter gives a g",,",ul introduction of P, NP and NP-complete problems' We will

study the definition und ,ot" classic examples of NP-complete problems' More importantly' we

will leam how to show that a problem is not easier than another problem by polynomial-time

reduction. Polynomial-time reduction is the ge1ei1.! metlod to prove that a new problem is lr[P:

;;ffi;;:;#;;J*"ln exeuse nol to rind trreoptimal solu1ion. As we encounter more NP-

4ilffi;'p-blems, *e wittriarn some genera'l techniques for reductions'

Polynomial-time algorithms can be considered tractable (easy or not so difficult) for the

l'Tr1iffii"Jir"or"- which has a running time of say o(nk) (ror rarge value of k) can be

called intractable (difficult), there ur" \r"ry few practical problems with such orders of

polynomial complexity. i ,-- r :.. -^r-.'^^*:-r +.

. For reasonable models of computation, a problem that can be solved in polynomial time tn

one model can also be solved in polynomial time on another'

o The class of poiyr,o-ia-time solvable problems has nice closure properties (since

polynomials are closed under addition' multiplication' etc')

8.1 P, NP, and NP-complete

Somehow we believe that an efficient algorithm should run in polynomial time, that is, O(nk) fot

input size r and some constant k. consequently, problems that can be solved in polynomial time

are treated as "easy" p.oUf"rr, (although k canie arbitrarily large)' and we use P to denote the

set of polynomial-timl-solvable problems' Here is the formal definition:

P: the set of problems that can be solved in polynomial time'

Page 2: NP-COMPLETE, PROBTEMS · 180 Design and Analysis of Algorithms F Chapter 8 ta Some examples in P: Finding the shortest-path in a graph between two vertices such that the surn of the

180 Design and Analysis of Algorithms

F

Chapter 8

taSome examples in P:

Finding the shortest-path in a graph between two vertices such that the surn of the

weights of its constituent edges is minimized.Testing whether given number is prime.Finding the maximum element in a given array.

Some problems that we can not solve in polynomial time so far:

(1) Faitorization: given n andm, determine whether n has any prime factors less than z.For exarnple, let n : 324 and m : 5. 324 is the product of the prime factors 2 x 2 x 3 x 3

x 3 x 3 : iz x34.2 and3 are prime factors less than 5.

(2) Polynomial Identities Testing: determining whether a given multivariate polynomial is

identically equal to 0. For example, consiJer a polynomial in two variables x andy: x3f+ xy - 10. Forx :2 andy: 1, the value of this polynomial is 0' Hence,

(3) Graph Coloring: givenk,determine whether a graph has a t vertex coloring.

The problems that can not be solved in polynomial time so far*.are considered as "hard"

problems. For the "haqd" problems, if (say by guessing) we are given a solution for a problem,

we may be able to iheck whether the solution is correct very efficiently (i.e. in polynomial

time). This leads to the definition of NP problems:

d.IP: the set of problems for which the "yes" answer (with a certificate - that is, a solution)

,fcan be verified in polynomial time. NP stands for "Ngry-{eterministic Polynomial t!me'I.---. -.

ehe quick observation is that any problem in P is also in NP, because we can verifr its answer

d,y soivilg the problem (and so do not even need a certificate). On the other hand, many "hard"

pioblems mentioned above are also in NP: although we do not have a polynomial-time

algorithm for it, we can verifu a solution in polynomial time. To understand the relation betweenp and NP, it is useful to have a "hardest" problem in NP. Here comes the definition for NP-

completeness:

. A problem is NP-complete if (l) it is in NP; and (2) if it can be solved in polynomial time,

I th"n any problem in NP can be solved in polynomial time.I"/ Generally NP-complete (NPC) problems are considered as the "hard" problems. The interesting

/ tfrire is ihat *. n"rr"r say NPC problems can not be solved in polynomial time in the formal/ A"firrition, because we do not have a proof for it. Instead, we use the second property in the

definition to link all the NPC problems together: any NPC problem is at least not easier than any

other NPC problem. The technique to show that a problem A is not easier than another problem

B is Polvnomial-time Reduction, which willbe shown in next section.

#aiii-iffi#*"A"rtption (and our belief), the relation of P, NP and NPC problems are

shown in Figure 8.1. Note that we do not know for sure whether NP or NPC problems are

polynomial-time-solvable. This is the most famous open problem in theoretical computer

sciince, and the Clay Mathematics Instihrte of Cambridge, Massachusetts, USAoffers a million

dollar for its solution.

' we almost believe that they can never be solved in polynomial time...

(1)

(2)(3)

i

il;li

i

l,

l

Ii

h

ll{i

I'

I

li

!

It is imporalgorithms for Ito believe thaiapproximation :of this is the Tsolve TSP thenreason to havelooking problencomplete.

8.1.1 Examp

Before giving e:problem determiquestions requiriyes-or-no questity without remairus to determine Iyes or no.

Traveling SalesrA Hamiltonian cexactly once. Op,Hamiltonian Cycthere exist a Ham

Subset Sum:The input is a pcOptimization Prosubset sum? Deci

Knapsack ProbhThis is a generali;is a positive intes.profitsp1, p2,..., f

Page 3: NP-COMPLETE, PROBTEMS · 180 Design and Analysis of Algorithms F Chapter 8 ta Some examples in P: Finding the shortest-path in a graph between two vertices such that the surn of the

NP-CompleteProblems 181q*r

fr'!tlr

'fll!,,,\[w

[3

tt,

\

rlll.

ilil&

less than ru.

2x2x3 x3

olynomial isx andy: x31?

]d as "hard"r a problem,polynomial

, a solution)rl time".

y its answernany "hard"nomial-timeion betweenion for NP-

romial time,

: interestingL the formalperty in theier than anyrer problem

roblems are'oblems areI computerrs a million

Figure 8.1: What we think the world looks like.. ' q -

It is important to know the rudiments of NP-completeness for anyone to design "sound"

algorithms for problems. If one can establish a problem as NP-complete, there is strong reason

to- believe thai it is intractable. We would then do better by trying to design a good

approximation algorithm rather than searching endlessly seeking an exact solution' An example

#tnir is the Traveling Salesman Problem (TSP), which is intractable. A practical strategy to

solve TSP therefore would be to design a good approxirnation algorithm' Another important

,"uron to have good familiarity with NP-completeness is many natural interesting and safe-

looking problemi that on the surface seem no harder than sorting or searching, are in fact NP-

complete.

8.1.1 Examples of some Intractable Protllems

Before giving examples on intractable problems, let us deltne a decision problem' A decision

proOt"i d"tJr*ines ihether or not there exists a decision procedure or algorithm for a class S of

questions requiring a Boolean value (i.e., a true or false, or yes or no)' These are also known as

y".-or-no qulrtiorri. For example, the decision problem for the class of questions "Does ':r divide

y without remainder?" is decidable because there exists a mechanical procedure, which allows

us to determine for any x andy whether the answer for "Does x divide y without remainder?" is

yes or no.

Traveling Salesman Problem:A ltamittinian cycle in an undirected graph is a simple cycle that passes through every r'ertex

exactly once. Opiimi zationProblem: Given a complete, weighted graph, find a minimum-weight

Hamiltonian Cycle. Decision Problem: Given a complete, weighted graph and an integer h does

there exist a Hamiltonian cycle with total weight at most k'

Subset Sum:The input is a positive integer c and n objects whose vdlues are positive integers x1, 'Y2,"', xn'

Optimization Pioblem: aming all subsets of objects with sum at most C, what is the largest

subset sum? Decision probleml Is there a subset of objects whose values add up to exactly C?

Knapsack Problem:Thisis a gereralizatio, of the subset sum problern. Consider a knapsack of capacity C where C

is a positive integer and n objects with positive integer weights wb w2,..-, wn and positive integer

p.ofttrp,, p2,..., pn. Optimization Problern: Find the largest total profit of any subset of the

dlv

ltH

["'t tl

rl

"I

l:r,n

t

fl1

Page 4: NP-COMPLETE, PROBTEMS · 180 Design and Analysis of Algorithms F Chapter 8 ta Some examples in P: Finding the shortest-path in a graph between two vertices such that the surn of the

-

182 Design and AnalYsis of Algorithms

(:: '

.iobjects that fits in the knapsack. Decision-Problem: Given k, is there a subset of the objects that

fits in the knapsack and has total profit atleastk?

SatisfiabilitY (SAT):A propositional variable (Boolean variable) is one that can be assigued the value "true" or

"false". A literal i. u propotitional variable or its negation (such asp )' A clause is a sequence of

literals separated by the logical O=[OfSr-$oI (;) A prdpb-Sitiondl formula is said to be in

conjunctive nor*ot 7or* iOffl if ii.oii.iiit of'a'sequence of clauses separated by the logical

AND operator (n). For examPle, .

(p, qvs)a(q v r)n(P v4 vrvi)

This is a Boolean formula in cNF. A truth assignment for 1 9e] of propositional variables is an

;;"*";r";t *" ".-4i." ""rue to tach

Sropo^sitional :"lt: ty:l^T:try::'"tt;Y1l::;i*"#;?;;;i; til;;t; ;h" urru. oi_tr," formula true. rn ",h"_'-y:.1:!i::i,: Boolean

saLIJl v o lvrururs r^ r!

formula in CNF, either irnd a satisffing truth assignment or else.report that none exists'

3SAT (Decision p."Lr"-i, ciu.i u CNF formula in which each clause is permiued

"o,,Eil ;i ri-;ri*"" rte.ut., is there a truth assignment to its variables that satisfies it?

8.2 CLASSBS P AND NP

An algorithm is said to be polynomially bounded if its worst-case complexity is bounded by a

polynomial function oi,fr" i"p", size. Aproblem is said to be polynomially bounded if there is a

polynomially bounded algorithm for it'. r ,-- ----:^!r-, L^.,..r^,{ .rL- imnlinqr:p is the class of all?ecision problems that are polynomially bounded' The. implication is

th"t; ;;i;i"" pr"ur"* X e P can be solved in polynomial time on a deterministic computation

model (such as a deterministic Turing machine^)'

Np represents tn" "tus,

of decistn problems which can be solved in polynomial time by a

non-deterministic model of computation. That is, a decision problem x e NP can be solved in

polynomial-time on a non-deterministic computation model (such as a non-deterministic Turing

machine). A non-deterministic model can make the right guesses on every move and race

towards the solution much faster than a deterministic model'

A determini*i" -u"t in" , al eachpoint in time, executes an instruction. Depending on the

outcome of executingihe instnrction, ii then executes some next instruction, which is unique' A

non-deterministic machine on the other hand has a choice of next steps' It is frge to choose any

that it wishes. Fo, "*ffi", it

"u, always choose a next step that leads to the best solution for

the problem. A ,ron-J"i"rministic ,nu"Lir" thus has the power of extremely good, optimal

guessing.X.t example, let us consider the decision version of rSP: Given a complete' weighted

-'- -1^L ^t ^^^+ lJ,

""fi ;,ff ;;6;;;;;;.,h*":"i'llHamiltonian:I:1"#*:"-t:1,::'lj"i"*.:',:ii

;;;'ffi;;;;inistic argorithm for the above TSp probrem starts with a vertex,

guesses the correct "ag"

i" gtt"osle, proceedl.to the-"!"i,Iiil'-,t:"t^Y,ih:.tlT::t"::::,1::il:::"J,ffi",;.'fi"rn polynomiul ti-" discovers a Hamiltonian cvcle of least cost and

^ Devices with infinite memory used to model any computer'

Chapter 8

provides an ar:

algorithm herquestion.

Another r

certificate), or:

YES instancemakes the rigt

It is easyquestion is per

8.3 NP-CC

We will look t

belong to P.considerable tmachine (or pr

that providespolynomial tirThat is, the ctproblems migl I

to be NP-corrcharacteristic.

The primareducibility.some known I'

r transformproblem,

r solve the Io transform

By "polyrtime: thus theexistence of a

definition) im1

The concr'example, to pt r

NP-complete 1

for the new prbe used to solproblems:

Travellingfind a tour

Page 5: NP-COMPLETE, PROBTEMS · 180 Design and Analysis of Algorithms F Chapter 8 ta Some examples in P: Finding the shortest-path in a graph between two vertices such that the surn of the

Chapter 8 NP-CompleteProblems 183

) "true" or.equence ofdtobeinthe logical

iables is ant is said toa Boolean

.s.

ermitted tot?

unded by aifthere is a

plication is

omputation

I time by ae solved instic Turinge and race

ling on the

l unique. Achoose any;olution forld, optimal

:, weightedk?1 a vertex,:ct edge tort cost and

provides an answer to the abovd problem. This is the power of non-determinism. A deterministic

atgoritnm here will have no choice but take super-polynomial time to answer the above

question.' Another way of viewing the above is that given a candidate Hamiltonian cycle (cal[ it

certificate), one can veriff iripolynomial time whether the answer to the above question is YES

or NO. Thus to check if a problem is in NP, it is enough to prove in polynomial time that any

YES instance is correct. We do not have to worry about NO instances since the program always

makes the right choice. q

It is easy to show that P q NP. However, it is unknowri whether P: NP. In fact, this

question is pirhaps the most celebraled of all open problems in computer science.

8.3 NP.COMPLETE PROBLEMS

We will look at a list of problems that are known to belong to NP but which might or might not

belong to P. That is, they are easy to solve on a non-deterministic machine, but, despite

considerable effort, no one has been able to find an efficient algorithm on a conventional

machine (or prove that none exists) for any of them. These problems have an additional property

that providei convincing evidence that P I NP: if any of the problems can be solved in

polynomial time on a deterministic machine, then so can all problems in NP (i.e., P : NP).

fnut ir, the collective failure of all the researchers to find efficient algorithms for all of these

problems might be viewed as a collective failure to prove that P : NP. Such problems are said

io be NP-complete. [t tums out that a large number of interesting practical problems have this

characteristic.The primary tool used to prove that problems are NP-complete uses the idea of p"glyaqmial

red.ucibiliJlrWe show that any algorithm to solve a new problem in NP can be used to solve

soineTnown NP-complete problem by the following process:

o transform any instance of the known NP-complete problem to an instance of the new

problem,o solve the problem using the given algorithm, then

o transform the solution back to a solution of the NP-complete problem.

By ..polynomially" reducible, we mean that the hansformations can be done in polynomial

time: ihus the existence of a polynomial-time algorithm for the new problem would imply the

existence of a polynomial-time algorithm for the NP-complete problem, and this would (by

definition) imply the existence of polynomial-time algorithms for all problems in NP.

fne concept of reduction piovides a useful mechanism for classiffing algorithms. For

example, to prove that a problem in NP is NP-complete, we need only show that some known

Np-complete problem is polynomially reducible to it that is, that a polynomial-time. algorithm

for the new pioblem could be used to solve the NP-complete problem, and then could, in tum,

be used to solve all problems in NP. For an example of reduction, consider the following two

problems:

Travelling Salesman Problem (TSP): Given a set of cities, and distances between all pairs,

find a tour of all the cities of distance less than k'

rla,

It'

lt+

flt-qtsr,

ra,

tt

\

{

rs

|l!fir

lr+'I

I -"t

'1.

1

l'h

Page 6: NP-COMPLETE, PROBTEMS · 180 Design and Analysis of Algorithms F Chapter 8 ta Some examples in P: Finding the shortest-path in a graph between two vertices such that the surn of the

Chapter 8

184 Design and AnalYsis of Algorithms

b'FlamiltonCycle:Givenaglaph,findasimplecyclethatincludesallthevertices.

SupposethatweknowtheHamiltoncycleprobleT.!:NP-cornpleteandwewishtodetermine *t "tt ",

t-, i-"iit "iSp i' uf'o

^f'W-"o"ipt"t9 Any algorithm for solving the TSP can

be used to sorve ,hJid;." ;;;";r"br.*, through the forlowing reduction:

GivenaninstanceoftheHamiltoncycleproblem(agraph)constructaninstanceoftheTSP(a set of

"iti"s, *itt'?;il;;;":';lt;il; +;r#"1T" cities for the traveling salesman

use the set of vertices in the graph; ro, airi*.., between each-oair of cities use 1 if there is an

edge betweet' ttr" correspo"Ii"g t'"*itt' io ti"?uptL 0 if'fhere is no edge' Then have the

aigorithm for the rii: rirl " t"rior aistance"r"'tt tri'"'"t "qual 1o

r' the number of vertices in the

graph. That ,"r, *i,r, ."i.rp""a pr".i*.rv i"l ii"#1,*'cycle' An eff,rcient algorithm for the

TSp would also be an efficient ulgorith*'iorin. ri.'"iltn cycle problem' That is' the Hamilton

cycle proble"t '"a*"' to the f5p' to ii' NP-complete""" oi the Hamilton cycle problem

iirpri"t the NP-completeness of the TSP'

ThereductionoftheHamiltoncycleproblemtolheTs|isrelativelysimplebecausetheproblems are so ,i6irr.-e.",-uffy, poiynorii;ii*" reductions can be quite complicated indeed

and can connect problems which -";;;; "q"it"

Ait'i*tlar' For eiample' it is possible to

reduce the satisfiability problem to trre HaJrtoi "y"t. qloblel' without going into details' we

can took at a sketch oithe proof. w" *iil;";l;#it'uif *".had a polynomial-time solution to

the Ham,ton cycle problem, then we ;ilg;;; p-;ry""mial-time solutio. to the satishabilitv

probtem by p"li""L;'H;;;;. dffiil.;I'iJ,.,",r a detailed method of construction

showing h.*, gi;;;^.-uiinrro,."" or tn. ,iii*rr*ility problem (a Boolean formula) to construct

(in polynomiul ti;;; In i""u""" tf 'h";;;il;"v"L p'out"m (a graph) with the properff that

knowing whettrer the graph has u nu*rt#'".vJr" iJrir * *tr"thei tfie formura is satisfiable' The

" graph is built ft";';;ii;;mponenrs i."".rp"rai"g. to the variables) which can be traversed bv

a simpte path in only one of two *;l;;;;;ang to the truth or falsity of the variables)'

These smar, "J;J#,, "r""^n""ti'#t{;i"sp.ecified bv the clauses, using more

complicated subgraphs which "urr,U1-Juu.r',.jUy

tiryf]"^naths ctrresponding to the truth or

falsity of the clauses. Itis quite a l"tg. r,.pi;;tfuit uti"raescriptionio the full construction:

the point i. to itirrrtrute that polyno*iui..Jo.tion can be applied toquite dissimilar problems'

Thus,ifweweretohaveapollmomial-timealgorithm.fortheTSP,thenwewouldhaveapoll,nomia1-time*a-rioritrr; ;"; .irr; H"*rir", ;t"Te problem, which would also give us a

polynomial-,i-. ufEo.irt m for the ,"rir?*tifiry'probLm' Each problem that is- proven NP-

complete or"r,J"li"n:;i#'o;;; basis for p-ring v"t a"oth"' turure probtem NP-complete'

The proof *igh;"-;;;ild1" u" tr," ,Ji*ii"o',ie;;;"d*." from the Hamilton cvcle problem to

It the TSp, or as complicated.as tir" trrrriJ*riio-n Jetched uUou" f'o* the satisfiability problem

, , to the Hamilton cycle problem, ., .";;;;;;.1, u"**". Literally thousands of problems have

been proven to be Np-comprete:"::":Xlyli"l"*ij":l,m;.;f;;";;;:",another in this

and only if therrthat each cliqueeasy reduction f

1. We aredetermi

2. In polyinstancc.of size 3

3. Obvioui

Following sBased on the abc

o The Cli<We say'

(a) '1

f'.l3rt.:HX;/;Xl'1""H'#JHT:H;;,;;"'et orvertices suoh that there is no edge

between any pair oru".ti""r.-consider rrru .*ffi in ;ig*; g'2, *h"* *" show a graph.G and

its complement graph (in the complement g.;;ii;ia, tf,"." i, u,, "og"

between two vertices if

8.3.1 NP-Harr

NP-hard (Non-detcontains all problmany-one reductiproblems that arethat if we can fincwe can constructreduction from thi

Assuming lani

1. I is inNtr2. I' in NP, r

NP-Hard assur

The notion ofbetween the compNP-complete whicclass NP-hard can X

Page 7: NP-COMPLETE, PROBTEMS · 180 Design and Analysis of Algorithms F Chapter 8 ta Some examples in P: Finding the shortest-path in a graph between two vertices such that the surn of the

I

NP-ComPteteProblems 185Chapter 8

tl'a'

lr!tlt

FilrI

tri-,

: ttf

\

and only ifTthere is no edge between these two vertices in the original gaph G)' -It

is. easy to see

that each clique in C i"io.rr". an independent set in the complimeni graph' This leads to the

;;;;;*;# from clique problem to rndependent Set Problem:

l.WearegivenaninstanceofCliqueProblem:givenagraphGandanintegerk,determine whether it has a clique of size k'

2. In polynomial-;i;, *" "oort o.t G' which is the complement graph of G. Now the

instance of Indefendent Set Problem is to determine whether G' has an independent set

ofsize k. i '3.obviouslyGhasacliqueofsizekifandonlyifG,hasanindependentsetofsizek.

Following similar steps, we can also.reduce Independent Set Problem to clique Problem'

Based on the'above discussion, the following statement holds:

oTheCliqueProblemcanbereducedtothelndependentSetProblem,andviceversa.We say these two problems are polynomially equivalent'

lt

rfte of the TSP

ng salesmanif there is an

,en have the

:rtices in the

ithm for the

he Hamiltoncle problem

because the

cated indeedr possible to

r details, we

e solution tosatisfiabilitYconstructionto constructrroPertY thatisfiable. The

. traversed bY

e variables).using morethe truth or

:onstruction:rroblems.

rould have ar give us a

proven NP-lP-comPlete.: problem tolity problemoblems haveother in this,-t'.

rf size k (i'e.

;raph has an

:e is no edge

graph G and'o vertices if

(a) Graph G - greY nodes

form a clique of size 4

#

(b) Complement Graph of G - grey nodes

form an indePendent set of size 4

$:

\..

Figure 8.2: Clique and independent set

8.3.1 NP-Ilardness and NP-Completeness

Np-hard ($on-determ"!!-stic Polynoml*j**g hard) refers to the class of decision problems that

contains alt problems ffiilffiAt"aUU;i;i;n"problems f il Nf there is a polynomial-time

many-one reduction to fi-irrio*ally this class cun be described as containing the decision

problems that are "t

f""ri"tfr"J u, ury problem in NP' This intuition is supported by the fact

that if we can tind an algorithm A thatrolr", one of these problems 11 in polynomial time then

we can construct " p";?;;i;i-ti*" utgo.itt- for every pioblem in NP by first executing the

reduction from this probl"* to H andtGn executing the algorithm'4'

Assuming language L to be NP-complete'

1. I is inNP2. I'inNP, I'< IM-Hard assumes language r satisfies property 2, but not necessarily property 1'

ThenotionofNP-hardnessplaysanimportantrole.inthediscussionabouttherelationshipbetween the complexity classes P a1d ]\T',It is also often used to define the complexity class

Np-complete which is'the intersection orr'w and NP-hard (see Figure 8'3)' Consequently the

class NP-hard can be understood as the class of problems that are NP-complete or harder'

;3

we wish tothe TSP can

Page 8: NP-COMPLETE, PROBTEMS · 180 Design and Analysis of Algorithms F Chapter 8 ta Some examples in P: Finding the shortest-path in a graph between two vertices such that the surn of the

Chapter 6

Design and AnalYsis of Algorithms186

The que

widely consiA decisi

polynomial I

A problem irCook's

reduction trz

algorithm fohard. Since r

The proe

We had to sh

a hard one.problem, we

Since thtall we need sin polynomia

CHAPTEF

' ComplexThe prolintractabproblems

. The haltibe solved

' P is the.cof all dettime.

NP-hard

Figure 8'3: Relationship among P' NP' NP-complete' and NP-hard problems

Acommonmistakeistothinkthatthe,,NP,,in,,NP.hard''stanclsfor''non.polynomial''.Althoughitiswidelysuspectedthatthereu.",,opoty''omial.timealgorithmsfortheseproblems,this has:ililnfi"lroll'iil_nrru

problem is the decision problem Subset-Sum. Given a set of

integers, does any ,"r-"*p* ."ri.r, of them?J.rp to ,oor That is a yes-or-no question' and

il"nr*J to be NP-complete' rrro Lorrr tr,r nof )There are also deiision problems that are NP-hard but not NP-complete' for example the

haltlrg g1!l3g,T#;;,h" fut"*.,,glr"r*ui;rr"- and its input, will it run forever?" That is

a yes_or-no q.r"rrorr, * ,rri.'.. u decis[n prout"* It is easy to prove that the halting problem is

Np-hard but not Np-complete. For exampr" ,i" i""r""' 'uii'f'utility problem can be reduced to

the halting problem U,'ir'"*lrr-ing it to the Jescription of a'Y"; machine that tries all tmth

varue assignments # ffi;;;ffi:;; rnur;t*d"s the formula ii halts and otherwise it goes

into an infinite loop. It is also easy to r"" ,rr", the halting problem is not in NP since all

problems in NP are iecidable and the halting problem is not'

8.4 COOK'S THEOREM

Before presenting Cook,s theorem, let us state some of the related definitions, though we have

defined pr"rio.rrty,'li;;il;;"ur"* i, i, Np ir it can be solved by a non-deterministic

algorithm in potynomiui ,i-". an mstancJ "r ir'" Bool"uo satisfiability problem is a Boolean

expression ttrt "*tir"r-Boo1eu, urriuti", ,rring Boolean operiiori' An expression is

satisfiable if there is some assignment oi-*-'tt "ut'i"t to the vaiables that makes the entire

expression true.

l.Cook,sTheoremstatesthatanyprobleminclassNPcanbereducedtoaninstanceofi SAT in PolYnomial time'!

Alternativelr, n "ur".

that the Boolean satisfiability problem is NP-complete' That is' any

problem in NP "* "C"'.La"ced

in p"f,""*i"f time by L deterministic Turing machine to a

problem of determini;; ;h"'h"t "^q;1:"' formula is satisfi able'

An important "onJ"qrr"r""

ofthe ttreorem is this: if there were a deterministic polynomial

time algorithm for sotving Boolean tuii'i*tifl*v' then there would exist a deterministic

oolvnomial ri*. i;"1";#?", *r"i"gdii,J,;; in NP. Cruciallv, the same follows for anv

ffi'"ornpt"te problem as these are also in NP'

Page 9: NP-COMPLETE, PROBTEMS · 180 Design and Analysis of Algorithms F Chapter 8 ta Some examples in P: Finding the shortest-path in a graph between two vertices such that the surn of the

Chapter 8 NP-CompleteProblems 187

The question of whether such an algorithm exists is called the P : NP problem and it iswidely considered the most important unsolved problem in theoretical computer science.

A decision problem is NP-hard if the time complexity on a deterministig machine is within a

3Iia

i('qI

I

',

p"ry;;;;if;;,;;;il complexity of any problem int:tY.-on( g$sh.Jll,t,A nrohlem is NP-comnlete if it is NP-hard and in NP. ffi t \:- | /PUIJTNITUAT lovlvl vl Llrw vvlrrPrv^ "^ "-'/en

A problem is NP-complete if it is NP-hard and in NP. >f1Cook's theorem proved SATISFIABILITY was M-hard by using a polynomial time

reduction translating each problem in NP into an instance of SAT. Since a polynomial time

algorithm for SAT would imply a polynomial time algorithm for everything in NP, SAT is NP-

hard. Since we can guess a solution to SAT, it is in NP and thus NP-complete. **L[q^Figure 8.4

PolynomialR.eduction from

SAT to X

Yes

Polynornialalgorithm means

P=NP

.Y1a7"

&-polynomial".ese problems,

iiven a set ofquestion, and

'example the

lver?" That isng problem is

be reduced totries all truth

:rwise it goes

NP since all

rugh we have-deterministicis a Boolean

lxpression is<es the entire

m instance of

. That is, anymachine to a

ic polynomialdeterministicllows for any

Cook's Theorem

The proof of Cook's Theorem, while quite clever, was certainly difficult and complicated-

We had io show that all problems in NP could be reduced to SAT to make sure we did not miss

a hard one. But now that we have a known NP-complete problem in SAT. For any other

problem, we can prove it NP-hard by polynomially transforming sAT to it!Since the composition of two polynomial time reductions can be done in polynomial time,

all we need show is that SAT, that is, any instance of SAT can be translated to an instance of Xin polynomial time.

CHAPTER SUMMARY, Complexity theory seeks to classify problems according to their computational complexity"

The problems that can and cannot be solved in polynomial time are tractable and

intrqitable, respectively. Complexity theory concentrates on decision problems, which are

problems with yes-or-no answers.

. The halting probleru is an example of an undecidable decision problem - that is, it cannot

be solved by anY algorithm.. p is the.class of all decision problems that can be solved in polynomial time. NP is the class

of all decision problems whose randomly guessed solutions can be verified in polynomial

time.

Page 10: NP-COMPLETE, PROBTEMS · 180 Design and Analysis of Algorithms F Chapter 8 ta Some examples in P: Finding the shortest-path in a graph between two vertices such that the surn of the

188 Design and AnalYsis of Algorithms

lDt. Many important problems in NP' such as Hamiltonian cycle problem' are known to be NP-

complete.AllotherproblemsinNParereducibletosuohaprobleminpolynomialtime.. The first proof of a problem's NP-completeness was published by Stefan cook for the cNF-

s atisfiabilitY Problem'r It is not known whether p : Np or p is a subset of NP. This question is the most important

unresolved issue in theoretical computer science' A finding oi a polynomial time algorithm

for any of the thousands knownNP-complete problems would imply that P : NP.

q-

SELF.TEST QUIZ8.1 Uncomputable functions correspond to problems that are called

(a) undecidable (b) intractabie

("i P+itn" (d) oPtimization

S.2Problemsforwhichnopollnomial-timesolutionsareknownarecalled(a) undecidable (b) intractable

i"i NP (d) oPtimization

8.3 The Halting Problem is

(a) undecidable (b) intractable

ic) Nr-comPlete (d) oPtimization

g.4 The informatio.-theoretic lower bound for a problem is given by the

-

height of the

decision tree for the best algorithm that solves the problem

Chapter I

8.5 The problem of sorting by comparisons is

(a) o(n) @) 66ten) (c) o(n21

8.6 The Hamiltonian-cycle problem is considered

(a) maximum(c) average

(a) intractable(c) tractable

(b) minimum(d) absolute

(b) undecidable(d) decidable

(e) relative

(b)(c)(d)(e)

8.1 I Finc ,

(a)(c)

8.12 SAT

(a)(b) .

(c) ,

(d) ,

(e) i8.13 Deci

(a)lr(b) ;(c) z

(d) t8.14 The t I

langu

(a) p

8.15 P is tl

(a) a(b) p(c) p(d) iI(e) e-

8.16 NP is

(a) al(b) p,' (c) pr

(d) in(e) e>

8.17 NPC i(a) er(b) pr(c) pr(d) in

.8.18 Proble

(a) P

(d) (nrgn)

8.7 The problem of evaluating a formula in propositional logic

(a) intractable(c) tractable

(b) undecidable(d) exponential

8.8 Deciding whether a formula in propositional togic is satisfiable is

(a) intractable (b) undecidable

icj tractable ididecidable (e) polvmorphic

If checking a given candidate solution to a problem is easy enough, then the problem is

ln(a) P (b) NP (c) NPC (d) EXP (e) none of these

S.l0ProblemAisreducibletoproblemBifthereisanalgorithmthatcan(a) transform any instance ofB to an instance ofA

8.9

Page 11: NP-COMPLETE, PROBTEMS · 180 Design and Analysis of Algorithms F Chapter 8 ta Some examples in P: Finding the shortest-path in a graph between two vertices such that the surn of the

NP-ComPleteProblems 189Chapter 8

be NP-time.

the CNF-

importantalgorithm

:ight of the

problem is

(b)(c)(d)(e)

transform any instance of A to an instance of B

solve Asolve Bsolve A as fast as B

ir*$

,t$

Sr-'

[tnr,

n

he

8.11 Finding the maximum value in an array rs the sorting Problem

(a) reducible to @) harderthan

- i;i a subproblem of (d) equivalent to

g.12 SAT is the problem of deciding whether a formula in propositional logic

(a) holds ., ^z --^r,^ :+ kr6(b) has a set of variable assignments that make it true

(c) is not a contradiction(d) is sYntacticallY correct

(e) is ProbablY true

8.13 Decision problems are equivalent to

(a) formulas in propositional logic

(b) assertions(c) arraYmaniPulations(d) languages 1 ,-.-- ^r ^+;-

8.l4TheCook-KarpThesisstatesthattheproblem.ofdecidingmembershipofstringsinalangtrage t t#tuUt" only if the language is decidable in

(a) polynomialtime (b) o(n) @) o(2") @) o(Lgn)

8.15 P is the set of(a) algorithms that execute in O(n) time'

(b) problemt i""ia'Uf" '.\O.d):iT" for some constant t'

i"i proUt"*s not decidable in O(n') time'

(d) intractable Problems'- .

(e) exPonential-time Problems'

8.16 NP is the set of(a) algorithms that execut e

1y !l1k) time for some constant k'

8] r:ll;n: f;:'iflif;13$I:fr:iions may be checked in o(nk) time

io-; intractable $roblems. .

(e) exPonential-time Problems

8.1? NPC is a set of(a) exPonential-time Problems-.(b) probleris al"iJ"ui" in o(nk) time for some constant k'

(c) proUt"*' i"' *f i"f' pot'ibl" t"f"i""t may be checked in O(nr) time'

(d) intractable Problems'

g.1g problems to which SAT or similar problems are reducible are called

(a) P 0) NP (c) NP-complete (d) NP-hard

ra

aa&.

*;iir

n k,,

l

;'$!

Page 12: NP-COMPLETE, PROBTEMS · 180 Design and Analysis of Algorithms F Chapter 8 ta Some examples in P: Finding the shortest-path in a graph between two vertices such that the surn of the

Design and Analysis'of Algorithms190

8.19 NP-complete problems are believed to have

(a) PolYnomial-time solutions

iUl "o iolYnomial-time solutions

(c) no exponential-time solutions

iil i" soiutions checkable in polynornial time

APPEND

KEY

CHAPTEN

1.1 (a)

1.8 Cons

EXERCISES8.1

8.2

8.3

8.4

8.5

8.6

8.7

8.8

8.9

Explain the classes of P and NP'

Erplain NP-completeness reduction with an example'

Erplain the satisfiability problem and write the algorithm for the same"

Explain the strategy to prove that a problem is NP-hard'

Sate and exPlain Cook's theorem'

Write a nondeterministic knapsack algorithm'

What is meantby Halting problem? Explain with an example'

Describe clique decision/optimization problem'

Differentiate between NP-complete and NP -hard'

r.e o(1)direcsize I

1.10 o(n)the te

1.11 Minirthe or

1.lZ x* x*'*^*o*x,t*,'*rtZ

*

Henc

1.13 (d) c

l.l4 10 x r

logzn

log2n