GS019 - Lecture 1 on Complexity Theory Jarod Alper (jalper) Introduction to Complexity Theory Big O Notation Review Linear function: r(n)=O(n). Polynomial function: r(n)=2O(1) Exponential function: r(n)=2nO(1) Logarithmic function: r(n)=O(log n) Poly-log function: r(n)=logO(1) n Definition 1 (TIME) Let t : . Define the time complexity class, TIME(t(n)) to be ℵ−→ℵ TIME(t(n)) = L DTM M which decides L in time O(t(n)) . { |∃ }
Definition 2 (NTIME) Let t : . Define the time complexity class, NTIME(t(n)) to be ℵ−→ℵ NTIME(t(n)) = L NDTM M which decides L in time O(t(n)) . { |∃ }
Example 1 Consider the language A = 0k1k k 0 . { | ≥ } Is A TIME(n2)? Is A ∈ TIME(n log n)? Is A ∈ TIME(n)? Could∈ we potentially place A in a smaller complexity class if we consider other computational models?
Theorem 1 If t(n) n, then every t(n) time multitape Turing machine has an equivalent O(t2(n)) time single-tape turing≥ machine.
Proof: see Theorem 7.8 in Sipser (pg. 232)
Theorem 2 If t(n) n, then every t(n) time RAM machine has an equivalent O(t3(n)) time multi-tape turing machine.≥
Proof: optional exercise
Conclusion: Linear time is model specific; polynomical time is model indepedent.
Definition 3 (The Class P )
k P = [ TIME(n ) k Definition 4 (The Class NP) GS019 - Lecture 1 on Complexity Theory Jarod Alper (jalper)
k NP = [ NTIME(n ) k Equivalent Definition of NP NP = L L has a polynomial time verifier . A polynomial{ | time verifier for a language A} is an algorithm, V ,whereA = w V acepts
Example 2 Let RELPRIME =
M = “On Input
To show an algorithm runs in polynomial, one must show that each step is executed only a poly- nomial number of steps as well as each steps executes in polynomial time.
Example 4 SAT = <φ> φ is a satisfiable boolean formula .IsSAT NP? { | } ∈ Construct a nondeterministic polynomial time Turing machine, M, as follows:
M = “On Input <φ>: 1. Nondeterministically select an assignment of the variables, x. 2. Teset where x satisfies φ. 3. If thest test passes, accept ; otherwise, reject.”
Example 5 VALUE = <φ,x > φ(x) where φ is a boolean formula and x an assignment of variables .IsVALUE {P ? | } ∈
Example 6 RATIONALROOT =
q Q such that p(q)=0where p(x)=a0 + a1x + k { |∃ ∈ ...+ akx is a polynomial of degree k where i =1...k, ai . Is RATIONALROOT P ? ∀ ∈ℵ ∈ Construct a nondeterministic polynomial time Turing machine, M, for RATIONALROOT:
M = “On Input
where p(x)=a + a x + ...+ a xk, a . 0 1 k i ∈ℵ GS019 - Lecture 1 on Complexity Theory Jarod Alper (jalper)
1. Nondeterministically select q Q. 2. Evaluate p(q). ∈ 3. If p(q)=0,accept ; otherwise, reject.”
Does this run in polynomial time? Cearly, to evaulate p(q) is polynomial in the length of q since multipication can be computed in polynomial time. How big is q though? From the Rational Root Theorem in algebra, any rational root, x,ofp(x)=0isoftheformx = s where s a and t a . t | 0 | k Since a0 =log(a0) Example 7 Let SUBSETSUM = M = “On Input nk EXPTIME = [ TIME(2 ) k Definition 6 (The Class NEXPTIME) nk NEXPTIME = [ NTIME(2 ) k Relations: P NP EXPTIME NEXPTIME ⊆ ⊆ ⊆ Definition 7 (Space Complexity Classes) SPACE(t(n)) = L DTM M which decides L in space O(t(n)) . { |∃ } NSPACE(t(n)) = L NDTM M which decides L in space O(t(n)) . { |∃ } k PSPACE = [ SPACE(n ) k k NPSPACE = [ NSPACE(n ) k GS019 - Lecture 1 on Complexity Theory Jarod Alper (jalper) Definition 8 (Logarithmic Space Classes) L = SPACE(log n) NL = NSPACE(log n) How can our definition of a turing machine use only logarithmic space since the input tape uses linear space? We introduce a new turing machine with two tapes: a read-only input tape and a read/write tape. Example 8 PATH NL ∈ Relations between time and space: Theorem 4 TIME(f(n)) SPACE(f(n)) ⊆ Proof: A deterministic turing machine that decides membership in O(f(n)) steps can use at most O(f(n)) space since one TM step requires can only write to one memory cell. 2 Theorem 5 If f(n) log(n), SPACE(f(n)) TIME(kf(n)) ≥ ⊆ Proof: Define a configuration as a snap shot of a turing machine including the position of the heads, the state of the control unit, and the contents of all cells on tape. If our turing machine is restricted to O(f(n)) space, the work tape head can be in only O(f(n)) locations and the input tape head canbeinonlyO(n). The control unit can be in any of c positions were c is a constant representing the number of states in the fsm. If we have k characters that can be written to a cell, then there are O(kf(n)) possibilities for the content of the tape. Thus, there are O(cnf(n) kf(n))=O(kf(n)) configurations. If the turing machine is to halt, there will be no duplicate configuration and thus it must run in O(kf(n))2. Corollary 1 L P ⊆ Corollary 2 P PSPACE ⊆ Corollary 3 PSPACE EXPTIME ⊆ Complements of complexity classes Definition 9 (coC) The complement of a complexity class of decision problems C,denotedcoC, is the set of decision problems that are complemnt of decision problems of C. Example 9 coSAT = <φ> φ is NOT a satisfiable boolean formula .IscoSAT NP? Is coSAT EXPTIME?Is{ coSAT| PSPACE? } ∈ ∈ ∈ Theorem 6 If C is a deterministic time or space complexity class, then C=coC. GS019 - Lecture 1 on Complexity Theory Jarod Alper (jalper) Proof: Deterministic turing machines are closed under complementation. Is NP = coNP? Theorem 7 NP coNP = T 6 {} Proof: Let PRIMALITY = p 1 Lemma 1 An integer p>2 is prime iff there is an integer 1 y1,y2,... ,yn = Y S = s1,s2,... ,sn such that y = t { |∃{ } ⊆ { } Pi i } Construct a nondeterministic polynomial time Turing machine, M, as follows:: 1. Nondeterministically select a subset c of the numbers in S. 2. Test whether c is a collection of numbers that sum to t. 3. If thest test passes, accept ; otherwise, reject.” Theorem 3 P NP ⊆ Proof: A O(t(n)) DTM has an equivalent O(t(n)) NDTM. 2 Definition 5 (The Class EXPTIME)