Presentation is loading. Please wait.

NP theory Pasi Fränti 22.10.2013. Turing machine vs. RAM © GEOFF DRAPER.

Presentation on theme: "NP theory Pasi Fränti 22.10.2013. Turing machine vs. RAM © GEOFF DRAPER."— Presentation transcript:

NP theory Pasi Fränti 22.10.2013

Turing machine vs. RAM © GEOFF DRAPER

Palindrome example …… SOS ABBA SAIPPUAKAUPPIAS INNOSTUNUT SONNI SAIPPUAKIVIKAUPPIAS

Turing machine solving palindrome Accept! q1q1 q2q2 q4q4 q0q0 q3q3 Final Initial 0,b 1,b b,b 1,b 0,b Copy Rewind Compare b,b b,0 b,1 1,1 0,0 b,b q0q0 bbq4q4 (b,S)(b,S)(b,S)(b,S) Empty 0bq1q1 (0,S)(b,S)(b,S) 1bq1q1 (1,S)(b,S)(b,S) q1q1 0bq1q1 (0,R) Copy 1bq1q1 (1,R) bbq2q2 (b,S)(b,S)(b,L)(b,L) q2q2 b0q2q2 (b,S)(b,S)(0,L) Move b1q2q2 (b,S)(b,S)(1,L) bbq3q3 (b,L)(b,L)(b,R)(b,R) q3q3 00q3q3 (0,L)(0,R) Compare 11q3q3 (1,L)(1,R) Bbq4q4 (b,S)(b,S)(b,S)(b,S)

product := n; FOR i:=1 TO (n-1) DO product := product * n; Assembler READ r1; IF r1≤0 THEN WRITE 0 ELSE r2  r1; r3  r1-1; WHILE r3>0 DO r2  r2*r1; r3  r3-1; OD; WRITE r2; PASCAL ALGOL READ1 LOAD1 JGTZpos WRITE=0 JUMPendif pos:LOAD1 STORE2 LOAD1 SUB=1 STORE3 while:LOAD3 JGTZcont JUMPendw cont:LOAD2 MULT1 STORE2 LOAD3 SUB=1 STORE3 JUMPwhile endw:WRITE2 endif:HALT Three programs to calculate N N Loop variable Output READ r1 IF r1≤0 r2  r1 r3  r3-1 r2  r2*r1 r3  r3-1 WHILE r3>0 WRITE r2 Input

RAM and Turing compared RAMTuring Sequence: Loop: Condition: WHILE r3>0 DO IF r1≤0 THEN … r2  r2*r1; r3  r3-1; … q1q1 q2q2 q3q3 q4q4 a b q5q5 a b

RAMTuring One step:O(1)S(N) T(N) stepsT(N)T(N)∙S(N) ≤ T(N) 2 Simulating RAM by Turing xxxxxЬЬxЬЬ …… R/W head Next needed S(N) Rewind

Empty space for notes

P and NP classes P Problems that can be solved in polynomial time by deterministic Turing machine P

P and NP classes P Problems that can be solved in polynomial time by deterministic Turing machine NP Problems that can be solved in polynomial time by non-deterministic Turing machine NP P

Known problems in P NP P SORT MM SEARCH SP SELECTION MST

Known problems in NP NP P COLORING TSP EXACT COVER KP SAT SORT MM SEARCH SP SELECTION MST

Anything outside of NP ? NP P CHESS GO COLORING TSP EXACT COVER KP SAT HANOI SORT MM SEARCH SP SELECTION MST

Coloring(E,V,k) FOR i  1 TO n DO Color[i]  Choose(1,k); FOR All e(i,j)  V DO IF Color[i]=Color[j] FAIL; SUCCESS; Select combination Check validity Non-deterministic algorithm Coloring problem

TSP(E,V,k) Sum  0; FOR i  1 TO n-1 DO Node[i]  Choose(1,n); Sum  Sum + w(Node[i-1],Node[i]); IF Sum<kTHEN SUCCESS; ELSE FAIL; Select combination Check validity Non-deterministic algorithm Traveling salesman problem

Reduction of problems L 1 ≤ p L 2 Search ≤ p Sort Transitivity: L 1 ≤ p L 2 and L 2 ≤ p L 3  L 1 ≤ p L 3 A2A2 I1I1 I2I2 p p O1O1 O2O2 Sort I search O search O sort min A3A3 I1I1 I2I2 p p O1O1 O2O2 I3I3 p p O3O3

Empty space for notes

NP-hard NP P NP-hard L1L1 L L2L2 L4L4 L3L3 ≤p≤p ≤p≤p ≤p≤p ≤p≤p Problem L is NP-hard iff all problems in NP reduces to L in polynomial time: L x ≤ p L  L x  NP

NP complete NP P Problem L is NP-complete iff  L is NP-hard  L  NP NP-hard NP-complete

NP-complete Another view P NP complete Difficulty increases Problem L is NP-complete iff  L is NP-hard  L  NP

NP P Intersection of P and NP-hard Case 1: P  NP-hard =  NP-hard NP P Case 2:  L: L  P  L  NP-hard NP-hard

P=NP Open question: P=NP ?  NP P NP-hard

Empty space for notes

Turing is still going on strong… http://www.youtube.com/watch?v=cYw2ewoO6c4

Similar presentations

Ads by Google