مهدراهچلصف يتابساحميگديچيپربيرورم An Overview of Computational Complexity يدلبوفمظاك kazim@fouladi.ir رتويپماكوقربيسدنهميهدكشناد نارهتهاگشناد رتويپماكوقربيسدنهميهدكشناداهنيشامواهنابزيهيرظن
Computational Complexity 2
Time Complexity: The number of steps during a computation Space used Space Complexity: during a computation 3
Time Complexity • We use a multitape Turing machine • We count the number of steps until a string is accepted • We use the O(k) notation 4
Example: n n { : 0 } L a b n Algorithm to accept a string : w • Use a two-tape Turing machine • Copy the on the second tape a • Compare the and a b 5
n n { : 0 } L a b n Time needed: • Copy the on the second tape (| w |) O a • Compare the and a b (| w |) O Total time: (| w |) O 6
n n { : 0 } L a b n For string of length n time needed for acceptance: ( n ) O 7
Language class: ( n ) DTIME ( n ) DTIME L 1 L 3 L 2 A Deterministic Turing Machine accepts each string of length n in time ( n ) O 8
( n ) DTIME n n { : 0 } a b n { ww } 9
In a similar way we define the class ( ( )) DTIME T n for any time function: ( n ) T 2 3 Examples: ( ), ( ),... DTIME n DTIME n 10
Example: The membership problem for context free languages L { : is generated by grammar } w w G ( 3 L (CYK - algorithm) ) DTIME n Polynomial time 11
k k 1 Theorem: DTIME n ( ) DTIME n ( ) 1 k ( ) DTIME n ( k ) DTIME n 12
Polynomial time algorithms: ( k ) DTIME n Represent tractable algorithms: For small we can compute the k result fast 13
The class P ( k for all k ) P DTIME n • Polynomial time • All tractable problems 14
P CYK-algorithm n b n { } a { ww } 15
Exponential time algorithms: ( n 2 ) DTIME Represent intractable algorithms: Some problem instances may take centuries to solve 16
Example: the Traveling Salesperson Problem 5 3 1 2 4 2 6 10 8 3 Question: what is the shortest route that connects all cities? 17
5 3 1 2 4 2 6 10 8 3 Question: what is the shortest route that connects all cities? 18
Example: the Hamiltonian Problem s t Question: is there a Hamiltonian path from s to t? 19
s t YES! 20
A solution: search exhaustively all paths L = {<G,s,t>: there is a Hamiltonian path in G from s to t} n ( ! ) ( 2 ) L DTIME n DTIME Exponential time Intractable problem 21
Example: The Satisfiability Problem Boolean expressions in Conjunctive Normal Form: t t t t 1 2 3 k t x x x x 1 2 3 i p Variables Question: is expression satisfiable? 22
Example: ( ) ( ) x x x x 1 2 1 3 Satisfiable: 0 , 1 , 1 x x x 1 2 3 ( ) ( ) 1 x x x x 1 2 1 3 23
Example: ( ) x x x x 1 2 1 2 Not satisfiable 24
L { : expression is satisfiabl e} w w For variables: L ( n n 2 ) DTIME exponential Algorithm: search exhaustively all the possible binary values of the variables 25
Non-Determinism Language class: ( n ) NTIME ( n ) NTIME L 1 L 3 L 2 A Non-Deterministic Turing Machine accepts each string of length n in time ( n ) O 26
L Example: { ww } Non-Deterministic Algorithm to accept a string : ww • Use a two-tape Turing machine • Guess the middle of the string and copy on the second tape w • Compare the two tapes 27
L { ww } Time needed: • Use a two-tape Turing machine • Guess the middle of the string (| w |) O and copy on the second tape w • Compare the two tapes (| w |) O Total time: (| w |) O 28
( n ) NTIME L { ww } 29
In a similar way we define the class ( ( )) NTIME T n for any time function: ( n ) T 2 3 Examples: ( ), ( ),... NTIME n NTIME n 30
Non-Deterministic Polynomial time algorithms: L ( k ) NTIME n 31
The class NP ( k for all k ) NP P NTIME n Non-Deterministic Polynomial time 32
The satisfiability problem Example: L { : expression is satisfiabl e} w w Non-Deterministic algorithm: • Guess an assignment of the variables • Check if this is a satisfying assignment 33
L { : expression is satisfiabl e} w w Time for variables: n • Guess an assignment of the variables ( n ) O • Check if this is a satisfying assignment ( n ) O Total time: ( n ) O 34
L { : expression is satisfiabl e} w w L NP The satisfiability problem is an - Problem NP 35
Observation: P NP Deterministic Non-Deterministic Polynomial Polynomial 36
P Open Problem: ? NP WE DO NOT KNOW THE ANSWER 37
P Open Problem: ? NP Example: Does the Satisfiability problem have a polynomial time deterministic algorithm? WE DO NOT KNOW THE ANSWER 38
NP-Completeness A problem is NP-complete if: • It is in NP • Every NP problem is reduced to it (in polynomial time) 39
Polynomial Time Reductions Polynomial Computable function : f For any computes w ( w ) f in polynomial time 40
Language A is polynomial time reducible to language B if there is a polynomial computable function such that: f ( ) w A f w B 41
Theorem: Suppose that is polynomial reducible to . A B B A If then . P P Proof: Let be the machine to accept B M Machine to accept in polynomial time: A On input : w 1. Compute ( w ) f 2. Run on input ( w ) M f 42
3CNF formula: ( ) ( ) ( ) ( ) x x x x x x x x x x x x 1 2 3 3 5 6 3 6 4 4 5 6 Each clause has three literals Language: 3SAT ={ : is a satisfiable w w 3CNF formula} 43
Clique: A 5-clique CLIQUE = { : contains a -clique} k G , G k 44
Theorem: 3SAT is polynomial time reducible to CLIQUE Proof: give a polynomial time reduction of one problem to the other 45
( ) ( ) ( ) x x x x x x x x x 1 1 2 1 2 2 1 2 3 x x x 2 1 2 x x 1 1 x x 1 2 x x 2 3 46
( ) ( ) ( ) x x x x x x x x x 1 1 2 1 2 2 1 2 3 1 x 1 0 x 2 1 x 3 x x x 2 1 2 x x 1 1 x x 1 2 x x 2 3 47
Cook’s Theorem: The satisfiability problem is NP-complete Proof: Convert a Non-Deterministic Turing Machine to a Boolean expression in conjunctive normal form 48
Other NP-Complete Problems: • The Traveling Salesperson Problem • Vertex cover • Hamiltonian Path All the above are reduced to the satisfiability problem 49
Observation: If we can solve any NP-complete problem in Deterministic Polynomial Time (P time) then we know: P NP 50
Observation: If we prove that we cannot solve an NP-complete problem in Deterministic Polynomial Time (P time) then we know: P NP 51
Observations: It is unlikely that NP-complete problems are in P The NP-complete problems have exponential time algorithms Approximations of these problems are in P 52
Recommend
More recommend