P, NP, and NP-Complete Problems (due to: Anany Levitin) Definition 1 – We say an algorithm solves a problem in polynomial time if its worst case time efficiency belongs to O(p(n)) where p(n) is a polynomial of the problem’s input size n. Remember when we say O(x) we are giving an upper boun an clearly the function f(n) ! log"n is less than the function g(n) ! n#. $roblems that can be solve in polynomial time are sai to be tractable an those that cannot be solve in polynomial time are intractable.
% refresher from the beginning of the course in the following table n ' ' '* '*
log"n #.# . ' '#
n ' ' '* '*
1,
1!
1,
log n "n ## '* '#* 1,!,
n" ' '* '** '**
"n ' '.#x'#
n& #.x' +.#x'',
1,,,
Definition " / 0lass $ is a class of ecision problems that can be solve in polynomial time by (eterministic) algorithms. 1his class of problems is calle polynomial.
1his raises the 2uestion are all problems ecision problems3 4n fact the answer can be state as yes since we can convert the problem to a ecision problem that re2uires a yes5no answer. %s an example instea of as6ing what is the minimum number of colors neee to color a graph so that no two a7acent vertices have the same color can be restate as* oes there exist a graph with m colors for m ! '* "* #* 8(calle the m/ coloring problem). 9ow* we woner* can every ecision problem be solve in polynomial time3 1he answer unfortunately is no. 1here are even some problems that are 6nown to be undecidable. 1he most famous problem in this class is calle the #altin$ problem state by %lan 1uring in '+#. 1he halting problem as6s* given computer program $ an input set 4 oes the program halt. :ere is a simple an short proof of this fact. We will use contraiction an start by assuming that there exists algorithm % that solves the halting problem. 4n other wors for any program $ an input 4 we have; %($*4) !
'* if program $ halts in input 4< * if program $ oes not halt in input 4.
We can now consier program $ as an input to itself an use the output of algorithm % for pair ($*$) to construct the program = as follows; =($)! halts* if %($*$)!* i.e.* if program $ oes not halt in input $< oes not halt* if %($*$) ! '* i.e.* if program $ halts in input $.
1hen we substitute = for $ an get; =(=)! halts* if %(=*=)!* i.e.* if program = oes not halt on input =< oes not halt* if %(=*=)!'* i.e.* if program = halts on input =. 1his is a contraiction since neither of the two outcomes for program = is possible* an therefore completes the proof. 9ow* are there eciable but intractable problems3 1urns out the answer is yes* but luc6ily for us this is a very small set of 6nown problems. 1here are however many 6nown problems that o not have polynomial time algorithms (at least that we 6now of). 1he classic paper was publishe by >arey an ?ohnson in '+-+ an lists several hunre such problems. Definition % – % nondeterministic al$orit#mis a two/stage proceure that ta6es as input an instance 4 of a ecision problem an oes the following.
9oneterministic (guessing) stage; %n arbitrary string @ is generate that can be thought of as a caniate solution to the given instance 4. Aeterministic (verification) stage; % eterministic algorithm ta6es both 4 an @ as its input an outputs yes if @ represents a solution to instance 4. (4f @ is not a solution to instance 4* the algorithm either returns no or is allowe not to halt at all). We say that a noneterministic algorithm solves a ecision problem if an only if for every yes instance of the problem it returns yes in some execution. 4n other wors it guesses the answer an then verifies that the answer is correct. Binally we call the noneterministic algorithm nondeterministic polynomialif the time efficiency of the verification stage is polynomial. Definition & – 0lass 9$ is the class of ecision problems that can be solve by noneterministic polynomial algorithms. 1his class of problems is calle nondeterministic polynomial.
Cost ecision problems are in fact in 9$. Birst of all* this class inclues all the problems in $; P ⊆ NP.
1his is true since if a problem is in $* we can use a eterministic polynomial time algorithm that solves it in the verification stage of a noneterministic algorithm that simply ignores the string @ generate by the guessing stage. Of course the open 2uestion is oes;
$ ! 9$3 Definition ' – % ecision problem A ' is sai to be polynomially reducible to a ecision problem A" if there exists a function t that transforms instances of A ' to instances of A" such that
'. t maps all yes instances of A ' to yes instances of A " an all no instances in A' to no instances of A "< ". t is computable by a poly nomial time algorithm. 1his says that if A' is polynomially reucible to some problem A " that can be solve in polynomial time* the A' can also be solve in polynomial time. Definition – % ecision problem A is sai to be NP-complete if
'. it belongs to the class 9$* an ". every problem in 9$ is polynomially reucible to A.
9ow assuming that we alreay 6now that the D1raveling @alesperson $roblemE to be 9$/ complete we will show that the D:amiltonian 0ircuit $roblemE also 9$/0omplete. ravelin$ *alesperson– Bin the shortest tour through n cities with 6nown positive integer istances between them. +amiltonian Circuit – Aetermine whether a given graph has a :amiltonian circuit (a path that starts an ens at the same vertex an passes through all the other vertices exactly once)
1o o this we nee to show that :amiltonian 0ircuit problem is polynomially reucible to the ecision version of 1raveling @alesperson. 1he latter can be state as the problem to etermine whether there exists a :amiltonian circuit in a given complete graph with positive integer weights whose length is not greater than a given positive integer m. We can map a graph > of a given instance of the :amiltonian circuit problem to a complete weighte graph >’ representing an instance of the traveling salesperson problem by assigning ' as the weight to each ege in > an aing an ege with weight " between any pair of non/a7acent vertices in >. %s an upper boun m in the :amiltonian circuit length* we ma6e m ! n* where n is the number of vertices in > (an >’). Obviously this transformation can be one in polynomial time. Fet > be a yes instance of the :amiltonian 0ircuit problem. 1hen > has a :amiltonian circuit* an its image >’ will have length n* ma6ing the image a yes instance of the ecision traveling salesperson problem. 0onversely* if we have a :amiltonian circuit of length not larger than n in >’* then its length must be exactly n (why3) an hence a circuit must be mae up of eges present in >* ma6ing the inverse image a yes instance of the traveling salesperson be a yes instance of the :amiltonian circuit problem. 1his completes the proof.
Thank you for interesting in our services. We are a non-profit group that run this website to share documents. We need your help to maintenance this website.