NP-Compltnss 1. Polynomil tim lgorithm 2. Polynomil tim rution 3.P vs NP 4.NP-ompltnss (som slis y P.T. Um Univrsity o Txs t Dlls r us) Trvling Slsprson Prolm Fin minimum lngth tour tht visits h ity on n rturns to th strting ity. Polynomil tim lgorithm O(n k ) (n is th input siz; k is onstnt) Supr-polynomil tim lgorithm (som popl ll it non-polynomil) O(2 n ), O(n!) Wht s th Big Dl? 2.20 GHz (Jn 2002) (2.20 illion yls pr son) Supr-st mhin: omput 1 TSP tour in 1 yl. 2.20 illion TSP tours in 1 son. 120 * 10 21 sons 1 yr = 31536000 s 38 * 10 14 yrs! 3800 trillion yrs!!! Ag o Erth = 4.6 illion yrs! Wht s th Big Dl? 2.53 GHz (Aug 2002) (2.53 illion yls pr son) Supr-st mhin: omput 1 TSP tour in 1 yl. 2.53 illion TSP tours in 1 son. 104 * 10 21 sons 1 yr = 31536000 s 32 * 10 14 yrs! 3200 trillion yrs!!! Ag o Erth = 4.6 illion yrs! Wht s th Big Dl? 3.06 GHz (Jn 2003) (3.06 illion yls pr son) Supr-st mhin: omput 1 TSP tour in 1 yl. 3.06 illion TSP tours in 1 son. 86 * 10 21 sons 1 yr = 31536000 s 27 * 10 14 yrs! 2700 trillion yrs!!! Ag o Erth = 4.6 illion yrs! 1
Progrss in Thnology Supr-st mhin: omput 1 TSP tour in 1 yl. Ag o Erth (rth) = 4.6 illion yrs. Ag o th Milky Wy Glxy (mwg) = 13 illion yrs. Ag o th Univrs (univ) = 15 illion yrs. Jn 2002 3800 trillion yrs 826, 086 rth 292, 307 mwg 253, 333 univ Aug 2002 3200 trillion yrs 695, 652 rth 246, 153 mwg 213, 333 univ Jn 2003 2700 trillion yrs 586, 956 rth 207, 692 mwg 180, 000 univ Trtl or intrtl? Trtl giv polynomil tim lgorithm. Intrtl show th prolm is NPomplt n xplor othr mns o solving th prolm. Trtl or intrtl? Trtl giv polynomil tim lgorithm. Intrtl show th prolm is NPomplt n xplor othr mns o solving th prolm. Giv n iint polynomil tim lgorithm. 3 GHz ; 3 illion yls/s ; 0.33 ns/yl N = 1, 000, 000 O(n) = 330 µs O(n 2 ) = 330 s = 5.5 minuts O(n 3 ) = 330 million s = 10 yrs 1. NP-Compltnss Bor ining P n NP, lt's unrstn th irns twn prolm tht rquir to Mor Exmpl: olouring Givn grph G=<V,E>, w wnt to pint th vrtis so tht or ny (v,u) in E, th olour o v is irnt rom th olour o u. 1) giv YES or NO nswr (ision prolm) 2) in th ost o th optiml solution 3) in th optiml solution. or xmpl 1) Dos th grph ontin spnning tr with wight t most 40? 2) Wht is th wight o th minimum spnning tr. 3) Fin th minimum spnning tr 1) COLD: On input G n n intgr k, is G is k-olourl? ( spil s whn k=3, is know s th 3-olour prolm, 3COL). 2) COLO: On input G wht is th minimum numr o olours rquir to pint th grph? 3) COLC: On input G, in th wy to pint th grph with minimum olours. 2
Mor Exmpl: k-liqu Givn grph G=<V,E>, w wnt to in sugrph o G tht is omplt grph. A grph is omplt i ny two vrtis r onnt y n g. A omplt grph with k vrtis is lso known s k-liqu. 1. Polynomil tim lgorithm A lgorithm is polynomil tim i its worst-s running tim is in O(n k ) whr n is th siz o th input, n k is onstnt inpnnt o n. For xmpl, this grph ontins 4-liqu quiksort is polynomil tim O(n 2 ). mrgsort is polynomil tim O(n log n) whih is lso in O(n 2 ). Prim's lgorithm is polynomil tim O( V log V + E ). i w tk th (n= V + E ) s th siz o th input, thn Prim's lgorithm is in O(n log n). Th ollowing is not polynomil tim lgorihtm. 1) CLQD: On input G n n intgr k, trmin whthr G ontins k-liqu. 2) CLQO: On input G in th siz o th lrgst liqu. 3) CLQC: Fin th lrgst liqu in G. 1) input n n-it intgr M. 2) or i=1 to M; print i; n; Not tht th siz o th prolm is n. Th running tim is O(2 n ), whih is not polynomil. 2. Polynomil tim rution Suppos w hv n lgorithm, known s th orl, tht n trmin whthr grph hs k-liqu in O(1) worst s running tim, n w in th k-liqu sily? In othr wors, i w n solv th ision prolm, n w solv th othr 2 orms o prolm? CLQO: On input G in th siz o th lrgst liqu. To in th siz o th lrgst liqu, w n sk th orl in th ollowing wy, For i=n own to 1 I th grph ontins i-liqu, rturn (i). n Th worst s running tim is O(n), whih is polynomil. (th running tim n improv to O(log n)). Suppos w n solv CLQO in O(1) tim, n w solv CLQC iintly? 3) CLQC: Fin th lrgst liqu in G. 1. Lt T th st o ll vrtis. Lt G' th grph G. 2. Ask th orl th siz o th lrgst liqu in G. Lt k th siz. 2. Slt vrtx v rom T. Rmov v n ll gs inint to v rom G'. 3. Ask th orl out G'. Lt k' th siz o th lrgst liqu in G'. 4. I k not qul k', thn put v n ll gs rmov in stp 2 k to G'. 5. Rpt stp 2 to stp 4 until T is mpty. 6. Output G'. Th running tim o th ov is O(n 2 ) whr n is th numr o vrtis in G. Dinition: Lt A n B two prolms. W sy tht A is polynomilly Turing ruil to B i thr xists polynomil tim lgorithm or solving A i w oul solv B in O(1) tim. I A is polynomilly Turing ruil to B, w writ A B ( or B A) I A B n B A, w sy tht A n B r polynomilly Turing quivlnt, writtn s A = B. I A B, w n viw "B is mor iiult or qul to A, us i w n solv B, thn w n solv A". 3
Rmrk Proprtis o rution: 1) I A B n B C, thn A C. 2) A A. Rll tht CLQD CLQO n CLQO CLQC Furthrmor, it is lr tht CLQC CLQD. Thus w hv CLQD = CLQO = CLQC. This ltur not tking short-ut in ining polynomil Turing ruil. Th nottion us or polynomil Turing ruil is usully this : T, whih is to istinguish rom polynomil mny-to-on ruil, usully not s: m. For polynomil mny-to-on ruil, w n only ll th orl on. In polynomil Turing ruil, w n us it polynomil numr o tims. So, th 3 prolms r tully quivlnt. Tutoril: Show tht COLD = COLO = COLC. I you tll m tht this grph is 3-olourl, But i you tll m tht this grph is 3-olorl n giv m solution, it is vry sy or m to vriy whthr you r right. it is vry iiult or m to hk whthr you r right. Loosly spking, prolms tht r iiult to omput, ut sy to vriy r known s Non-trministi Polynomil. P vs NP Mor xmpls: Dinition: P P is th st o ision prolms tht n solv y polynomil tim lgorithm. Rll tht n lgorithm is polynomil tim i its worst-s running tim is in O(n k ) whr n is th siz o th input, n k is onstnt inpnnt o n. W n rprsnt ision prolm using st, sy K. An instn x is in K i on input x, th output is YES. For xmpl, lt K 1 th prolm whr givn n input, output YES i th input is lry sort in inrsing orr. Thn, K 1 is th st o squns whih r sort, K 1 = {, 1,2, 1,3, 2,3, 1,2,3, 1,4... } It is sy to writ linr tim lgorithm or K 1, thus, K 1 is in P (or w simply writ K 1 P ). 1. Lt K 2 th st o inry squn whos inry rprsnttion is ivil y 3. K 2 = { 11, 110, 1001, 1100, 1111,...} ={3,6,9,12,15,...} K 2 is in P. (th lngth o th input "15" is 4, us 15 = 1111 2 ) 2. Lt K 3 th st o inry squn whos inry rprsnttion is prim. K 3 = {10,11,101, 111, 1011, 1101,...} ={2,3,5,7,11,13,...} For mny hunrs o yrs, w on't hv n lgorithm tht n solv K 3 in polynomil tim, lthough popl liv tht thr shoul on. Rntly, rsrhrs rom Ini in polynomil tim lgorithm, i.. thy prov tht K 3 P. 3. Lt K 4 th st o wight grphs whos Minimum Spnning Tr hv wight lss thn 30. Thn K 4 P. 4
Dinition: NP (non-trministi polynomil) A ision prolm K is NP i, thr xists Q P s.t. x K i n only i thr xists y s.t. x,y Q. Th y in th inition is known s th witnss or rtiit or proo tht x K. For xmpl, lt Q th st o <x,y>, whr x is ivil y y, whr (y>1) n (x>y). Hr x n y r rprsnt s inry squns. Q={ <100,10>,<110,10>,... } ={ <4,2>,<6,2>,<6,3>,<8,2>,<8,4>,<9,3>,<10,2>,<10,5>,..} Not tht Q P. Lt K th st o inry squns, whih rprsnt non-prim numr tht is grtr thn 1. (For mny yrs, no on know whthr K P. Rntly, rsrhrs rom Ini prov tht K P). By th ov inition, lrly, K NP. This is us numr x is non-prim i thr xists y>1 n x>y s.t. x is iviisil y y. For g., 135 is not prim us <135,5> Q. 13 is prim us thr on't xists ny y s.t. <13,y> Q. Th prolm Q is known s th proo systm. So, non-trministi polynomil r prolms tht hv proo systm tht n solv in polynomil tim. In othr wors, non-trministi polynomil r prolms tht n sily vrii in polynomil tim. W sy tht ision prolm is ision-ruil i, givn n orl tht solvs th ision prolm in O(1) tim, w n in th witnss in polynomil tim. Mor xmpls o NP prolms. 1. 3COL (3-olorility) is in NP. 2. CLQD (k-liqu) is in NP. 5. Pking: Givn st o tmplt or th n prts in jn, n k pis o stnr siz loth. Cn w ut thm out rom k pis o stnr siz loth. In th optimiztion vrsion, w wnt to know how to ut thm rom minimum numr o stnr siz loth. 3. Givn squn o intgr, 1, 2, 3,..., n, n n intgr k, n w group thm into k groups s.t. th sum o h group is lss thn 50. 4. Prtition prolm. Givn squn o intgrs, 1, 2, 3,..., n, n w group thm into 2 groups s.t. th sum o h group is th sm. n w pk ths into 2 stnr siz loth? 6. Ship prking.. W hv n ships, whr h ship is rprsnt s irl with rtin rius. (th rius pn on th siz o th ship). Coul w prk ths ships in th port? Tht is, pk th irls with no ovrlp? ship 3 ship 4 ship 1 ship 2 1 km N 7. Shuling. mrin pr 1.4 km Suppos our hror hs 2 oking ilitis A n B. Thus w n srv 2 ship onurrntly. Givn list o n ships, n th xpt oking tim n rrivl tim o h ship. Cn w ssign th ship to ithr A or B so tht h ship will not wit or mor thn 3 hours, n th vrg witing tim is lss thn 1 hour? tim 0 1 2 3 8. Shuling. Givn th mouls tkn y n stunts, n w pln two-wk xm so tht thr is no rsh, n h stunt will tk t most two xms in ny 3 onsutiv ys. Hunrs o NP-hr prolms r list in M.R.Gry, D.S. Johnson, Computrs n Intrtility: gui to th thory o NP-Compltnss, 1979, Frmn. So, NP r importnt prolms. 5
Thorm P NP Now, th million ollrs opn prolm is, This thorm stts tht ny prolm tht n solv in polynomil tim, n lso vrii in polynomil tim. (this is so oviously tru...) In proo, lt K prolm in P. Lt us onsir this prolm Q whih is in s Q = { <x,0> x K }. Now, Q n proo systm or K, n thus K NP. Sin or ny K P, w hv K NP, thror P NP. is NP P? i this is tru (i., NP=P), thn ny prolm in NP n solv iintly. A lot o rsrhrs hv work on som NP prolms ut gt no progrss. So, thr might som prolms in NP tht nnot solv iintly. (i.. NP P ). Unortuntly, w still on't know th nswr. Most popl strongly liv tht NP P. 4. NP-omplt Thorm Dinition: NP-hr A ision prolm K is NP-hr i 1) K Y or vry Y NP. Dinition: NP-omplt A ision prolm K is NP-omplt i 1) K NP, n 2) K is NP-hr. Th irst inition n viw s: K is mor iiult or qul to ny prolm in NP. Not tht NP-omplt prolm K is th "tikt" to ll NP prolms. I w n solv K in polynomil tim, thn w n solv ALL NP prolms in polynomil tim, n thus NP=P. Convrsly, i in NP P, thn NP-omplt prolm n not solv in polynomil tim. Now th qustion is to in ths NP-omplt prolms. I K NP, n K Y whr Y is NP-omplt. Thn K is NP-omplt. Anothr NP prolm SAT-3-CNF inition: A litrl is Booln or its ngtion or 1 or 0. A 3-lus is isjuntion ("or") o 3 litrls. A 3-CNF o is onjuntion ("n") o 3-luss..g. A= (++)(++)(+0+0) B= (++)(++0)(+0+0) Th input is 3-CNF with n vrils. Is thr wy to ssign 0/1 (TRUE/FALSE) to th vrils so tht th ormul is 1 (TRUE). in th ov g. y ssigning =1, =0, =0, =0, thn A is 1. Eqution B is lwys 0. Wht n w o i prolm is NP-hr Exmpls (pproximtion lgo) 1. Fst lgorithm tht in th solution or smll input. 2. Algorithm tht in pproximt solution. 3. Algorithm tht in solution or spil typ o instns. Trvling Slsmn prolm. Input: A omplt unirt grph G=<V,E> tht hs nonngtiv ost (u,v) ssoit to h g (u,v). Output: A yl (tht is, pth tht strt n n t th som vrtx) tht visits h vrtx on, with minimum ost. Approximtion Solution/Algorithm Lt OPT th ost o th optiml solution. I w n in solution with ost APR, suh tht This is NP-hr prolm. Lt us now look t spil s whr th grph is n Eulin Grph, n giv 2-pproximtion lgorithm. APR < ε OPT, whr ε is onstnt grtr thn 1. thn w sy tht th solution is ε-pproximtion solution, n th lgorithm tht in th pproximtion solution is ll th ε-pproximtion lgorithm. 6
Trvling slsmn on Eulin Grph (tringlur inqulity) input optiml Algorithm Approx-TSP 1. Fin th minimum spnning tr. (Not tht th MST n onvrt into yl.) 2. Rnomly slt vrtx n signt it s th root. 3. Do prorr trvrsl o th tr. 4. Rturn th yl tht visits th vrtis in th orr omput in stp 3. MST MST givs yl.. Clim: Approx-TSP is 2-pproximtion lgorithm. Lt H* th optiml yl, n lt T th MST. By rmoving ny g rom H*, it om spnning tr. Thus ost (T) ost (H*). Th yl otin rom T in stp 1 trvrss vry gs in T twi. Lt W this yl. Clrly ost (W) = 2 ost (T). Not tht W is not solution, us vrtis r visit twi. Now, just rmov th rpting vrtis. I W visits th vrtis in this orr..... v 1, v 2, v 3,... By rmoving v 2, w will visit v 3 tr visiting v1,. Tht is, th g rom (v 1,v 2 ) n (v 2,v 3 ) will rpl y th g (v 1,v 3 ). By tringulr inqulity, th lngth o (v 1,v 3 ) lnght o (v 1,v 2 ) + lnght o (v 2,v 3 ). Lt H th yl otin y rmoving ll rpting vrtis. W hv ost (H) ost (W) = 2 ost (T) < 2 ost (H*). Thus ost (H) 2 ost (H*) Rmrk on Approximtion lgorithm Not, howvr, tht thr r prolm tht os not hv pproximtion lgorihtm (unlss P=NP). For xmpl, w n prov tht, unlss P=NP, TSP on gnrl grph os not hv n -pproximtion lgorithm, whr is onstnt. 7