NP theory Pasi Fränti 22.10.2013. Turing machine vs. RAM © GEOFF DRAPER.
-
Upload
kaylynn-brinkworth -
Category
Documents
-
view
214 -
download
0
Transcript of NP theory Pasi Fränti 22.10.2013. Turing machine vs. RAM © GEOFF DRAPER.
![Page 1: NP theory Pasi Fränti 22.10.2013. Turing machine vs. RAM © GEOFF DRAPER.](https://reader035.fdocuments.in/reader035/viewer/2022062712/56649c785503460f9492d37a/html5/thumbnails/1.jpg)
NP theory
Pasi Fränti22.10.2013
![Page 2: NP theory Pasi Fränti 22.10.2013. Turing machine vs. RAM © GEOFF DRAPER.](https://reader035.fdocuments.in/reader035/viewer/2022062712/56649c785503460f9492d37a/html5/thumbnails/2.jpg)
Turing machine vs. RAM
© GEOFF DRAPER
![Page 3: NP theory Pasi Fränti 22.10.2013. Turing machine vs. RAM © GEOFF DRAPER.](https://reader035.fdocuments.in/reader035/viewer/2022062712/56649c785503460f9492d37a/html5/thumbnails/3.jpg)
Palindrome example
……
SOS
ABBA
SAIPPUAKAUPPIAS
INNOSTUNUT SONNI
SAIPPUAKIVIKAUPPIAS
![Page 4: NP theory Pasi Fränti 22.10.2013. Turing machine vs. RAM © GEOFF DRAPER.](https://reader035.fdocuments.in/reader035/viewer/2022062712/56649c785503460f9492d37a/html5/thumbnails/4.jpg)
Turing machine solving palindrome
Accept!
q1
q2
q4
q0
q3
Final
Initial
0,b1,b
b,b
1,b0,b
Copy
Rewind
Compare
b,b
b,b
b,0b,1
1,10,0
b,b
q0 b b q4 (b,S) (b,S) Empty
0 b q1 (0,S) (b,S)
1 b q1 (1,S) (b,S)
q1 0 b q1 (0,R)(0,R
)Copy
1 b q1 (1,R)(1,R
)
b b q2 (b,S) (b,L)
q2 b 0 q2 (b,S) (0,L) Move
b 1 q2 (b,S) (1,L)
b b q3 (b,L)(b,R
)
q3 0 0 q3 (0,L)(0,R
)Compar
e
1 1 q3 (1,L)(1,R
)
B b q4 (b,S) (b,S)
![Page 5: NP theory Pasi Fränti 22.10.2013. Turing machine vs. RAM © GEOFF DRAPER.](https://reader035.fdocuments.in/reader035/viewer/2022062712/56649c785503460f9492d37a/html5/thumbnails/5.jpg)
product := n;FOR i:=1 TO (n-1) DO
product := product * n;
Assembler
READ r1;IF r1≤0 THEN WRITE 0ELSE
r2 r1;r3 r1-1;WHILE r3>0 DOr2 r2*r1;r3 r3-1;OD;
WRITE r2;
PASCAL
ALGOL
READ 1LOAD 1JGTZ posWRITE =0JUMP endif
pos: LOAD 1STORE 2LOAD 1SUB =1STORE 3
while: LOAD 3JGTZ contJUMP endw
cont: LOAD 2MULT 1STORE 2LOAD 3SUB =1STORE 3JUMP while
endw: WRITE 2endif: HALT
Three programs to calculate NN
Loopvariable
Output
READ r1
IF r1≤0
r2 r1
r3 r3-1
r2 r2*r1
r3 r3-1
WHILE r3>0
WRITE r2
Input
![Page 6: NP theory Pasi Fränti 22.10.2013. Turing machine vs. RAM © GEOFF DRAPER.](https://reader035.fdocuments.in/reader035/viewer/2022062712/56649c785503460f9492d37a/html5/thumbnails/6.jpg)
RAM and Turing compared
RAM Turing
Sequence:
Loop:
Condition:
WHILE r3>0 DO
IF r1≤0 THEN
…r2 r2*r1;r3 r3-1;…
q1
q2
q3
q4a b
q5
a
b
![Page 7: NP theory Pasi Fränti 22.10.2013. Turing machine vs. RAM © GEOFF DRAPER.](https://reader035.fdocuments.in/reader035/viewer/2022062712/56649c785503460f9492d37a/html5/thumbnails/7.jpg)
RAM TuringOne step: O(1) S(N)T(N) steps T(N) T(N)∙S(N) ≤ T(N)2
Simulating RAM by Turing
x x x x x Ь ЬxЬЬ ……
R/W head Next needed
S(N)
Rewind
![Page 8: NP theory Pasi Fränti 22.10.2013. Turing machine vs. RAM © GEOFF DRAPER.](https://reader035.fdocuments.in/reader035/viewer/2022062712/56649c785503460f9492d37a/html5/thumbnails/8.jpg)
Empty space for notes
![Page 9: NP theory Pasi Fränti 22.10.2013. Turing machine vs. RAM © GEOFF DRAPER.](https://reader035.fdocuments.in/reader035/viewer/2022062712/56649c785503460f9492d37a/html5/thumbnails/9.jpg)
P and NP classes
P Problems that can be solvedin polynomial timeby deterministic Turing machine
P
![Page 10: NP theory Pasi Fränti 22.10.2013. Turing machine vs. RAM © GEOFF DRAPER.](https://reader035.fdocuments.in/reader035/viewer/2022062712/56649c785503460f9492d37a/html5/thumbnails/10.jpg)
P and NP classes
P Problems that can be solvedin polynomial timeby deterministic Turing machine
NP Problems that can be solvedin polynomial timeby non-deterministic Turing machine
NP
P
![Page 11: NP theory Pasi Fränti 22.10.2013. Turing machine vs. RAM © GEOFF DRAPER.](https://reader035.fdocuments.in/reader035/viewer/2022062712/56649c785503460f9492d37a/html5/thumbnails/11.jpg)
Known problems in P
NP
P
SORT
MM
SEARCH
SP
SELECTION
MST
![Page 12: NP theory Pasi Fränti 22.10.2013. Turing machine vs. RAM © GEOFF DRAPER.](https://reader035.fdocuments.in/reader035/viewer/2022062712/56649c785503460f9492d37a/html5/thumbnails/12.jpg)
Known problems in NP
NP
P
COLORING
TSP
EXACTCOVER
KP
SATSORT
MM
SEARCH
SP
SELECTION
MST
![Page 13: NP theory Pasi Fränti 22.10.2013. Turing machine vs. RAM © GEOFF DRAPER.](https://reader035.fdocuments.in/reader035/viewer/2022062712/56649c785503460f9492d37a/html5/thumbnails/13.jpg)
Anything outside of NP ?
NP
P CHESS
GO
COLORING
TSP
EXACTCOVER
KP
SAT
HANOISORT
MM
SEARCH
SP
SELECTION
MST
![Page 14: NP theory Pasi Fränti 22.10.2013. Turing machine vs. RAM © GEOFF DRAPER.](https://reader035.fdocuments.in/reader035/viewer/2022062712/56649c785503460f9492d37a/html5/thumbnails/14.jpg)
Coloring(E,V,k)
FOR i1 TO n DOColor[i] Choose(1,k);
FOR All e(i,j)V DOIF Color[i]=Color[j] FAIL;
SUCCESS;
Select combination
Check validity
Non-deterministic algorithmColoring problem
![Page 15: NP theory Pasi Fränti 22.10.2013. Turing machine vs. RAM © GEOFF DRAPER.](https://reader035.fdocuments.in/reader035/viewer/2022062712/56649c785503460f9492d37a/html5/thumbnails/15.jpg)
TSP(E,V,k)
Sum 0;
FOR i1 TO n-1 DONode[i] Choose(1,n);Sum Sum + w(Node[i-1],Node[i]);
IF Sum<k THEN SUCCESS;ELSE FAIL;
Select combination
Check validity
Non-deterministic algorithmTraveling salesman problem
![Page 16: NP theory Pasi Fränti 22.10.2013. Turing machine vs. RAM © GEOFF DRAPER.](https://reader035.fdocuments.in/reader035/viewer/2022062712/56649c785503460f9492d37a/html5/thumbnails/16.jpg)
Reduction of problems
L1 ≤p L2
Search ≤p Sort
Transitivity:
L1 ≤p L2 and L2 ≤p L3
L1 ≤p L3
A2
I1 I2p
pO1 O2
SortIsearch
Osearch Osortmin
A3
I1 I2p
pO1 O2
I3p
p O3
![Page 17: NP theory Pasi Fränti 22.10.2013. Turing machine vs. RAM © GEOFF DRAPER.](https://reader035.fdocuments.in/reader035/viewer/2022062712/56649c785503460f9492d37a/html5/thumbnails/17.jpg)
Empty space for notes
![Page 18: NP theory Pasi Fränti 22.10.2013. Turing machine vs. RAM © GEOFF DRAPER.](https://reader035.fdocuments.in/reader035/viewer/2022062712/56649c785503460f9492d37a/html5/thumbnails/18.jpg)
NP-hard
NP
P
NP-hard
L1
LL2
L4
L3 ≤p
≤p
≤p≤p
Problem L is NP-hard iff all problems in NP reduces to L in polynomial time:
Lx ≤p L LxNP
![Page 19: NP theory Pasi Fränti 22.10.2013. Turing machine vs. RAM © GEOFF DRAPER.](https://reader035.fdocuments.in/reader035/viewer/2022062712/56649c785503460f9492d37a/html5/thumbnails/19.jpg)
NP complete
NP
P
Problem L is NP-complete iff L is NP-hard LNP
NP-hard
NP-complete
![Page 20: NP theory Pasi Fränti 22.10.2013. Turing machine vs. RAM © GEOFF DRAPER.](https://reader035.fdocuments.in/reader035/viewer/2022062712/56649c785503460f9492d37a/html5/thumbnails/20.jpg)
NP-completeAnother view
P
NPcomplete
Difficultyincreases
Problem L is NP-complete iff L is NP-hard LNP
![Page 21: NP theory Pasi Fränti 22.10.2013. Turing machine vs. RAM © GEOFF DRAPER.](https://reader035.fdocuments.in/reader035/viewer/2022062712/56649c785503460f9492d37a/html5/thumbnails/21.jpg)
NP
P
Intersection of P and NP-hard
Case 1: PNP-hard =
NP-hard
NP
P
Case 2: L: LP L NP-hard
NP-hard
![Page 22: NP theory Pasi Fränti 22.10.2013. Turing machine vs. RAM © GEOFF DRAPER.](https://reader035.fdocuments.in/reader035/viewer/2022062712/56649c785503460f9492d37a/html5/thumbnails/22.jpg)
P=NP
Open question: P=NP ?
NP
PNP-hard
![Page 23: NP theory Pasi Fränti 22.10.2013. Turing machine vs. RAM © GEOFF DRAPER.](https://reader035.fdocuments.in/reader035/viewer/2022062712/56649c785503460f9492d37a/html5/thumbnails/23.jpg)
Empty space for notes
![Page 24: NP theory Pasi Fränti 22.10.2013. Turing machine vs. RAM © GEOFF DRAPER.](https://reader035.fdocuments.in/reader035/viewer/2022062712/56649c785503460f9492d37a/html5/thumbnails/24.jpg)
Turing is still going on strong…
http://www.youtube.com/watch?v=cYw2ewoO6c4