Space Complexity. then the space required by M on input x is. w i u i. F ) on. September 27, i=1

Similar documents
Turing-Computable Functions

satisfiability (sat) Satisfiability unsatisfiability (unsat or sat complement) and validity Any Expression φ Can Be Converted into CNFs and DNFs

The Traveling Salesman Problem

De Morgan s a Laws. De Morgan s laws say that. (φ 1 φ 2 ) = φ 1 φ 2, (φ 1 φ 2 ) = φ 1 φ 2.

The knapsack Problem

Complexity Theory VU , SS The Polynomial Hierarchy. Reinhard Pichler

Outline. Complexity Theory EXACT TSP. The Class DP. Definition. Problem EXACT TSP. Complexity of EXACT TSP. Proposition VU 181.

Complexity Theory 112. Space Complexity

Randomized Complexity Classes; RP

fsat We next show that if sat P, then fsat has a polynomial-time algorithm. c 2010 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 425

Complexity. Complexity Theory Lecture 3. Decidability and Complexity. Complexity Classes

NP-Completeness. Until now we have been designing algorithms for specific problems

CS151 Complexity Theory. Lecture 4 April 12, 2017

Announcements. Problem Set 7 graded; will be returned at end of lecture. Unclaimed problem sets and midterms moved!

CSCI3390-Lecture 6: An Undecidable Problem

max bisection max cut becomes max bisection if we require that It has many applications, especially in VLSI layout.

Space Complexity. The space complexity of a program is how much memory it uses.

Advanced topic: Space complexity

The Different Sizes of Infinity

NP-Complete and Non-Computable Problems. COMP385 Dr. Ken Williams

Lecture 20: conp and Friends, Oracles in Complexity Theory

Notes for Lecture Notes 2

Data Structures and Algorithms

CSCI3390-Lecture 14: The class NP

Cardinality of Sets. P. Danziger

Turing Machines and Time Complexity

Automata Theory CS S-18 Complexity Theory II: Class NP

ECS 120 Lesson 24 The Class N P, N P-complete Problems

1 Computational Problems

Design and Analysis of Algorithms

Notes on Complexity Theory Last updated: December, Lecture 2

CSCE 551 Final Exam, April 28, 2016 Answer Key

Computability and Complexity CISC462, Fall 2018, Space complexity 1

Theory of Computation Lecture Notes. Problems and Algorithms. Class Information

CPSC 421: Tutorial #1

Computational Models Lecture 8 1

COSE215: Theory of Computation. Lecture 20 P, NP, and NP-Complete Problems

Further discussion of Turing machines

Finite Automata. Mahesh Viswanathan

Computational Models Lecture 8 1

Most General computer?

1 Computational problems

FORMAL LANGUAGES, AUTOMATA AND COMPUTATION

Theory of Computation (IX) Yijia Chen Fudan University

Computational Models Lecture 8 1

BBM402-Lecture 11: The Class NP

NP, polynomial-time mapping reductions, and NP-completeness

A An Overview of Complexity Theory for the Algorithm Designer

Computational Complexity

Introduction. Pvs.NPExample

1 Reals are Uncountable

6.045 Final Exam Solutions

Polynomial Time Computation. Topics in Logic and Complexity Handout 2. Nondeterministic Polynomial Time. Succinct Certificates.

The Class NP. NP is the problems that can be solved in polynomial time by a nondeterministic machine.

The P versus NP Problem. Dean Casalena University of Cape Town CSLDEA001

CSC 5170: Theory of Computational Complexity Lecture 4 The Chinese University of Hong Kong 1 February 2010

COMP/MATH 300 Topics for Spring 2017 June 5, Review and Regular Languages

Chapter 7: Time Complexity

Problems, and How Computer Scientists Solve Them Manas Thakur

Lecture 3. 1 Terminology. 2 Non-Deterministic Space Complexity. Notes on Complexity Theory: Fall 2005 Last updated: September, 2005.

CSE 105 THEORY OF COMPUTATION

CSE 105 THEORY OF COMPUTATION

CS 583: Algorithms. NP Completeness Ch 34. Intractability

1 PSPACE-Completeness

Computability Theory

Theory of Computation CS3102 Spring 2014 A tale of computers, math, problem solving, life, love and tragic death

The P-vs-NP problem. Andrés E. Caicedo. September 10, 2011

CS5371 Theory of Computation. Lecture 23: Complexity VIII (Space Complexity)

CS154, Lecture 17: conp, Oracles again, Space Complexity

Finish K-Complexity, Start Time Complexity

Could we potentially place A in a smaller complexity class if we consider other computational models?

CMSC 441: Algorithms. NP Completeness

Artificial Intelligence. 3 Problem Complexity. Prof. Dr. Jana Koehler Fall 2016 HSLU - JK

CS 5114: Theory of Algorithms. Tractable Problems. Tractable Problems (cont) Decision Problems. Clifford A. Shaffer. Spring 2014

Outline. Complexity Theory. Example. Sketch of a log-space TM for palindromes. Log-space computations. Example VU , SS 2018

Introduction to Complexity Theory

SAT, NP, NP-Completeness

Lecture 6: Oracle TMs, Diagonalization Limits, Space Complexity

Lecture Notes 4. Issued 8 March 2018

an efficient procedure for the decision problem. We illustrate this phenomenon for the Satisfiability problem.

Data Structures in Java

Algorithms and Theory of Computation. Lecture 19: Class P and NP, Reduction

COSE215: Theory of Computation. Lecture 21 P, NP, and NP-Complete Problems

Combinatorial Optimization

Undecidability COMS Ashley Montanaro 4 April Department of Computer Science, University of Bristol Bristol, UK

Lecture 16: Time Complexity and P vs NP

Decidability (What, stuff is unsolvable?)

Intractable Problems [HMU06,Chp.10a]

NP-Completeness and Boolean Satisfiability

Umans Complexity Theory Lectures

Turing Machines Part III

Announcements. Friday Four Square! Problem Set 8 due right now. Problem Set 9 out, due next Friday at 2:15PM. Did you lose a phone in my office?

Decidability: Church-Turing Thesis

6.840 Language Membership

CS154, Lecture 13: P vs NP

13.1 Nondeterministic Polynomial Time

Definition: conp = { L L NP } What does a conp computation look like?

DRAFT. Diagonalization. Chapter 4

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: NP-Completeness I Date: 11/13/18

Comparison of several polynomial and exponential time complexity functions. Size n

Transcription:

Space Complexity Consider a k-string TM M with input x. Assume non- is never written over by. a The purpose is not to artificially reduce the space needs (see below). If M halts in configuration (H, w 1, u 1, w 2, u 2,..., w k, u k ), then the space required by M on input x is k w i u i. i=1 a Corrected by Ms. Chuan-Ju Wang (R95922018, September 27, 2006. F95922018) on c 2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 100

Space Complexity (continued) Suppose we do not charge the space used only for input and output. Let k > 2 be an integer. A k-string Turing machine with input and output is a k-string TM that satisfies the following conditions. The input string is read-only. The last string, the output string, is write-only. So the cursor never moves to the left. The cursor of the input string does not wander off into the s. c 2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 101

Space Complexity (concluded) If M is a TM with input and output, then the space required by M on input x is k 1 i=2 w i u i. Machine M operates within space bound f(n) for f : N N if for any input x, the space required by M on x is at most f( x ). c 2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 102

Let L be a language. Space Complexity Classes Then L SPACE(f(n)) if there is a TM with input and output that decides L and operates within space bound f(n). SPACE(f(n)) is a set of languages. palindrome SPACE(log n). a As in the linear speedup theorem (p. 96), constant coefficients do not matter. a Keep 3 counters. c 2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 103

Nondeterminism a A nondeterministic Turing machine (NTM) is a quadruple N = (K, Σ,, s). K, Σ, s are as before. K Σ (K {h, yes, no }) Σ {,, } is a relation, not a function. b 2008. For each state-symbol combination (q, σ), there may be multiple valid next steps. Multiple lines of code may be applicable. a Rabin and Scott (1959). b Corrected by Mr. Jung-Ying Chen (D95723006) on September 23, c 2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 104

Nondeterminism (concluded) As before, a program contains lines of code: We cannot write (q 1, σ 1, p 1, ρ 1, D 1 ), (q 2, σ 2, p 2, ρ 2, D 2 ), (q n, σ n, p n, ρ n, D n ).. δ(q i, σ i ) = (p i, ρ i, D i ) as in the deterministic case (p. 22) anymore. A configuration yields another configuration in one step if there exists a rule in that makes this happen. c 2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 105

Michael O. Rabin a (1931 ) a Turing Award (1976). c 2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 106

Dana Stewart Scott a (1932 ) a Turing Award (1976). c 2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 107

Computation Tree and Computation Path V K Ø QR Ù K Ø \HVÙ Ø \HV Ù c 2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 108

Decidability under Nondeterminism Let L be a language and N be an NTM. N decides L if for any x Σ, x L if and only if there is a sequence of valid configurations that ends in yes. In other words, If x L, then N(x) = yes for some computation path. If x L, then N(x) yes for all computation paths. c 2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 109

Decidability under Nondeterminism (concluded) It is not required that the NTM halts in all computation paths. a If x L, no nondeterministic choices should lead to a yes state. The key is the algorithm s overall behavior not whether it gives a correct answer for each particular run. Determinism is a special case of nondeterminism. a So accepts is a more proper term, and other books use decides only when the NTM always halts. c 2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 110

Complementing a TM s Halting States Let M decide L, and M be M after yes no. If M is a deterministic TM, then M decides L. So M and M decide languages that are complements of each other. But if M is an NTM, then M may not decide L. It is possible that both M and M accept x (see next page). So M and M accept languages that are not complements of each other. c 2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 111

[ [ K Ø QR Ù K Ø \HVÙ Ø \HV Ù K Ø \HV Ù K Ø QRÙ Ø QR Ù c 2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 112

Time Complexity under Nondeterminism Nondeterministic machine N decides L in time f(n), where f : N N, if N decides L, and for any x Σ, N does not have a computation path longer than f( x ). We charge only the depth of the computation tree. c 2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 113

Time Complexity Classes under Nondeterminism NTIME(f(n)) is the set of languages decided by NTMs within time f(n). NTIME(f(n)) is a complexity class. c 2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 114

NP Define NP = k>0 NTIME(n k ). Clearly P NP. Think of NP as efficiently verifiable problems (see p. 326). Boolean satisfiability (p. 119 and p. 196). The most important open problem in computer science is whether P = NP. c 2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 115

Simulating Nondeterministic TMs Nondeterminism does not add power to TMs. Theorem 5 Suppose language L is decided by an NTM N in time f(n). Then it is decided by a 3-string deterministic TM M in time O(c f(n) ), where c > 1 is some constant depending on N. On input x, M goes down every computation path of N using depth-first search. M does not need to know f(n). As N is time-bounded, the depth-first search will not run indefinitely. c 2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 116

The Proof (concluded) If any path leads to yes, then M immediately enters the yes state. If none of the paths leads to yes, then M enters the no state. The simulation takes time O(c f(n) ) for some c > 1 because the computation tree has that many nodes. Corollary 6 NTIME(f(n))) c>1 TIME(cf(n) ). c 2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 117

NTIME vs. TIME Does converting an NTM into a TM require exploring all computation paths of the NTM as done in Theorem 5 (p. 116)? This is the most important question in theory with important practical implications. c 2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 118

A Nondeterministic Algorithm for Satisfiability ϕ is a boolean formula with n variables. 1: for i = 1, 2,..., n do 2: Guess x i {0, 1}; {Nondeterministic choice.} 3: end for 4: {Verification:} 5: if ϕ(x 1, x 2,..., x n ) = 1 then 6: yes ; 7: else 8: no ; 9: end if c 2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 119

Computation Tree for Satisfiability [ [ [ [ [ [ [ [ Ø ÙØ ÙØ ÙØ Ø Ù ÙØ ÙØ ÙØ ÙØ Ù QR \HV QR \HV \HV QR QR QR \HV c 2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 120

Analysis The computation tree is a complete binary tree of depth n. Every computation path corresponds to a particular truth assignment out of 2 n. ϕ is satisfiable iff there is a truth assignment that satisfies ϕ. c 2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 121

Analysis (concluded) The algorithm decides language {ϕ : ϕ is satisfiable}. Suppose ϕ is satisfiable. That means there is a truth assignment that satisfies ϕ. So there is a computation path that results in yes. Suppose ϕ is not satisfiable. That means every truth assignment makes ϕ false. So every computation path results in no. General paradigm: Guess a proof and then verify it. c 2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 122

The Traveling Salesman Problem We are given n cities 1, 2,..., n and integer distance d ij between any two cities i and j. Assume d ij = d ji for convenience. The traveling salesman problem (tsp) asks for the total distance of the shortest tour of the cities. The decision version tsp (d) asks if there is a tour with a total distance at most B, where B is an input. a a Both problems are extremely important and are equally hard (p. 389 and p. 490). c 2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 123

A Nondeterministic Algorithm for tsp (d) 1: for i = 1, 2,..., n do 2: Guess x i {1, 2,..., n}; {The ith city.} a 3: end for 4: x n+1 := x 1 ; 5: {Verification:} 6: if x 1, x 2,..., x n are distinct and n i=1 d x i,x i+1 B then 7: yes ; 8: else 9: no ; 10: end if a Can be made into a series of log 2 n binary choices for each x i so that the next-state count (2) is a constant, independent of input size. Contributed by Mr. Chih-Duo Hong (R95922079) on September 27, 2006. c 2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 124

Analysis Suppose the input graph contains at least one tour of the cities with a total distance at most B. Then there is a computation path that leads to yes. a Suppose the input graph contains no tour of the cities with a total distance at most B. Then every computation path leads to no. a It does not mean the algorithm will follow that path. It just means such a computation path exists. c 2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 125

Remarks on the P? = NP Open Problem a Many practical applications depend on answers to the P? = NP question. Verification of password is easy (so it is in NP). A computer should not take a long time to let a user log in. A password system should be hard to crack (loosely speaking, cracking it should not be in P). It took mathematicians and logicians 63 years to settle the Continuum Hypothesis. a Contributed by Mr. Kuan-Lin Huang (B96902079, R00922018) on September 27, 2011. c 2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 126

Nondeterministic Space Complexity Classes Let L be a language. Then L NSPACE(f(n)) if there is an NTM with input and output that decides L and operates within space bound f(n). NSPACE(f(n)) is a set of languages. As in the linear speedup theorem (Theorem 4 on p. 96), constant coefficients do not matter. c 2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 127

Graph Reachability Let G(V, E) be a directed graph (digraph). reachability asks if, given nodes a and b, does G contain a path from a to b? Can be easily solved in polynomial time by breadth-first search. How about its nondeterministic space complexity? c 2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 128

The First Try: NSPACE(n log n) 1: Determine the number of nodes m; {Note m n.} 2: x 1 := a; {Assume a b.} 3: for i = 2, 3,..., m do 4: Guess x i {v 1, v 2,..., v m }; {The ith node.} 5: end for 6: for i = 2, 3,..., m do 7: if (x i 1, x i ) E then 8: no ; 9: end if 10: if x i = b then 11: yes ; 12: end if 13: end for 14: no ; c 2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 129

In Fact, reachability NSPACE(log n) 1: Determine the number of nodes m; {Note m n.} 2: x := a; 3: for i = 2, 3,..., m do 4: Guess y {v 1, v 2,..., v m }; {The next node.} 5: if (x, y) E then 6: no ; 7: end if 8: if y = b then 9: yes ; 10: end if 11: x := y; 12: end for 13: no ; c 2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 130

Space Analysis Variables m, i, x, and y each require O(log n) bits. Testing (x, y) E is accomplished by consulting the input string with counters of O(log n) bits long. Hence reachability NSPACE(log n). reachability with more than one terminal node also has the same complexity. reachability P (p. 239). c 2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 131

Undecidability c 2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 132

God exists since mathematics is consistent, and the Devil exists since we cannot prove it. André Weil (1906 1998) Whatsoever we imagine is finite. Therefore there is no idea, or conception of any thing we call infinite. Thomas Hobbes (1588 1679), Leviathan c 2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 133

Infinite Sets A set is countable if it is finite or if it can be put in one-one correspondence with N = { 0, 1,... }, the set of natural numbers. Set of integers Z. 0 0. 1 1, 2 3, 3 5,.... 1 2, 2 4, 3 6,.... Set of positive integers Z + : i i 1. Set of positive odd integers: i (i 1)/2. Set of (positive) rational numbers: See next page. Set of squared integers: i i. c 2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 134

Rational Numbers Are Countable 1/1 1/2 1/3 1/4 1/5 1/6 2/1 2/2 2/3 2/4 2/5 3/1 3/2 3/3 3/4 4/1 4/2 4/3 5/1 5/2 6/1 c 2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 135

Cardinality For any set A, define A as A s cardinality (size). Two sets are said to have the same cardinality, or A = B or A B, if there exists a one-to-one correspondence between their elements. 2 A denotes set A s power set, that is {B : B A}. E.g., { 0, 1 } s power set is 2 { 0,1 } = {, { 0 }, { 1 }, { 0, 1 } }. If A = k, then 2 A = 2 k. c 2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 136

Cardinality (concluded) Define A B if there is a one-to-one correspondence between A and a subset of B s. Obviously, if A B, then A B. So N Z. So N R. Define A < B if A B but A = B. If A B, then A < B? c 2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 137

Cardinality and Infinite Sets If A and B are infinite sets, it is possible that A B yet A = B. The set of integers properly contains the set of odd integers. But the set of integers has the same cardinality as the set of odd integers (p. 134). a A lot of paradoxes. a Leibniz uses it to prove that there are no infinite numbers (Russell, 1914). c 2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 138

Galileo s a Paradox (1638) The squares of the positive integers can be placed in one-to-one correspondence with all the positive integers. This is contrary to the axiom of Euclid b that the whole is greater than any of its proper parts. c Resolution of paradoxes: Pick the notion that results in better mathematics. The difference between a mathematical paradox and a contradiction is often a matter of opinions. a Galileo (1564 1642). b Euclid (325 B.C. 265 B.C.). c Leibniz never challenges that axiom (Knobloch, 1999). c 2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 139

Hilbert s a Paradox of the Grand Hotel For a hotel with a finite number of rooms with all the rooms occupied, a new guest will be turned away. Now imagine a hotel with an infinite number of rooms, all of which are occupied. A new guest comes and asks for a room. But of course! exclaims the proprietor. He moves the person previously occupying Room 1 to Room 2, the person from Room 2 to Room 3, and so on. The new customer now occupies Room 1. a David Hilbert (1862 1943). c 2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 140

Hilbert s Paradox of the Grand Hotel (concluded) Now imagine a hotel with an infinite number of rooms, all taken up. An infinite number of new guests come in and ask for rooms. Certainly, says the proprietor. He moves the occupant of Room 1 to Room 2, the occupant of Room 2 to Room 4, and so on. Now all odd-numbered rooms become free and the infinity of new guests can be accommodated in them. There are many rooms in my Father s house, and I am going to prepare a place for you. (John 14:3) c 2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 141

David Hilbert (1862 1943) c 2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 142

The point of philosophy is to start with something so simple as not to seem worth stating, and to end with something so paradoxical that no one will believe it. Bertrand Russell (1872 1970) c 2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 143