NP theory Pasi Fränti 25.10.2016 Turing machine vs. RAM © GEOFF DRAPER Palindrome example … … SOS ABBA SAIPPUAKAUPPIAS INNOSTUNUT SONNI SAIPPUAKIVIKAUPPIAS Turing machine solving palindrome q0 b b 0 b 1 b q1 0 b 1 b b b q2 b 0 b 1 b b q3 0 0 1 1 B b q4 q1 q1 q1 q1 q2 q2 q2 q3 q3 q3 q4 (b,S) (0,S) (1,S) (0,R) (1,R) (b,S) (b,S) (b,S) (b,L) (0,L) (1,L) (b,S) (b,S) Empty (b,S) (b,S) (0,R) Copy (1,R) (b,L) (0,L) Move (1,L) (b,R) (0,R) Compare (1,R) (b,S) Initial b,b q0 0,b 1,b b,b Rewind q2 Copy q1 0,b 1,b b,b b,0 b,1 Compare b,b q3 0,0 1,1 q4 Final Accept! Three programs to calculate NN PASCAL Assembler product := n; FOR i:=1 TO (n-1) DO product := product * n; ALGOL Input READ r1; IF r1≤0 THEN WRITE 0 Loop ELSE variable r2 r1; r3 r1-1; WHILE r3>0 DO r2 r2*r1; r3 r3-1; Output OD; WRITE r2; READ LOAD JGTZ WRITE JUMP pos: LOAD STORE LOAD SUB STORE while: LOAD JGTZ JUMP cont: LOAD MULT STORE LOAD SUB STORE JUMP endw: WRITE endif: HALT 1 1 pos =0 endif 1 2 1 =1 3 3 cont endw 2 1 2 3 =1 3 while 2 READ r1 IF r1≤0 r2 r1 r3 r1-1 WHILE r3>0 r2 r2*r1 r3 r3-1 WRITE r2 RAM and Turing compared RAM Sequence: Turing … r2 r2*r1; r3 r3-1; … Condition: IF r1≤0 THEN Loop: WHILE r3>0 DO q1 q2 q3 a q4 q5 a b b Simulating RAM by Turing One step: T(N) steps RAM Turing O(1) T(N) S(N) T(N)∙S(N) ≤ T(N)2 S(N) … Ь Ь x x x R/W head x x Rewind x Ь Ь … Next needed 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 SEARCH SORT MM MST SP SELECTION Known problems in NP NP COLORING TSP P SEARCH SORT MM EXACT COVER MST KP SP SAT SELECTION Anything outside of NP ? NP EXACT COVER COLORING TSP KP P SEARCH SORT MM GO MST SP SELECTION SAT CHESS HANOI Non-deterministic algorithm Coloring problem Coloring(E,V,k) FOR i1 TO n DO Color[i] Choose(1,k); Select combination FOR All e(i,j)V DO IF Color[i]=Color[j] FAIL; Check validity SUCCESS; Non-deterministic algorithm Traveling salesman problem TSP(E,V,k) Sum 0; Select combination FOR i1 TO n-1 DO Node[i] Choose(1,n); Sum Sum + w(Node[i-1],Node[i]); IF Sum<k THEN SUCCESS; ELSE FAIL; Check validity Reduction of problems L1 ≤p L2 Search ≤p Sort p I1 O1 p Isearch Osearch I2 O2 min A2 Osort Sort Transitivity: L1 ≤p L2 and L2 ≤p L3 L1 ≤p L3 I1 O1 p p I2 O2 p p I3 O3 A3 Empty space for notes NP-hard Problem L is NP-hard iff all problems in NP reduces to L in polynomial time: Lx ≤p L LxNP L3 NP ≤p L2 P L1 ≤p NP-hard ≤p L4 L ≤p NP complete Problem L is NP-complete iff L is NP-hard LNP NP-complete NP P NP-hard NP-complete Another view Problem L is NP-complete iff L is NP-hard LNP NP complete Difficulty increases P Intersection of P and NP-hard Case 1: PNP-hard = NP NP-hard P Case 2: L: LP L NP-hard NP P NP-hard Open question: P=NP ? NP P P=NP NP-hard Empty space for notes Turing is still going on strong… http://www.youtube.com/watch?v=cYw2ewoO6c4
© Copyright 2026 Paperzz