time and space complexity
play

Time and Space Complexity For practical solutions to computational - PDF document

Time and Space Complexity For practical solutions to computational problems available time, and Computability and Complexity available memory are two main considerations. Lecture 14 We have already studied time complexity, now we will focus


  1. Time and Space Complexity For practical solutions to computational problems available time, and Computability and Complexity available memory are two main considerations. Lecture 14 We have already studied time complexity, now we will focus on space (memory) complexity. Space Complexity Savitch’s Theorem Question: Space Complexity Class PSPACE How do we measure space complexity of a Turing machine? given by Jiri Srba Answer: The largest number of tape cells a Turing machine visits on all inputs of a given length n . Lecture 14 Computability and Complexity 1/15 Lecture 14 Computability and Complexity 2/15 Definition of Space Complexity The Complexity Classes SPACE and NSPACE Definition (Complexity Class SPACE( t ( n ))) Definition (Space Complexity of a TM) Let t : N → R > 0 be a function. Let M be a deterministic decider. The space complexity of M is a function SPACE( t ( n )) def = { L ( M ) | M is a decider running in space O ( t ( n )) } f : N → N where f ( n ) is the maximum number of tape cells that M scans on Definition (Complexity Class NSPACE( t ( n ))) any input of length n . Then we say that M runs in space f ( n ). Let t : N → R > 0 be a function. NSPACE( t ( n )) def = Definition (Space Complexity of a Nondeterministic TM) { L ( M ) | M is a nondetermin. decider running in space O ( t ( n )) } Let M be a nondeterministic decider. The space complexity of M is a function In other words: f : N → N SPACE( t ( n )) is the class (collection) of languages that are where f ( n ) is the maximum number of tape cells that M scans on decidable by TMs running in space O ( t ( n )), and any branch of its computation on any input of length n . Then we NSPACE( t ( n )) is the class (collection) of languages that are say that M runs in space f ( n ). decidable by nondeterministic TMs running in space O ( t ( n )). Lecture 14 Computability and Complexity 3/15 Lecture 14 Computability and Complexity 4/15 Example: SAT is Decidable in Linear Deterministic Space Example: ALL NFA is Decidable in Linear Nondeterm. Space def Theorem = {� A � | A is an NFA such that L ( A ) = Σ ∗ } ALL NFA SAT ∈ SPACE( n ) Theorem Proof: Here is a deterministic decider M for SAT : ALL NFA ∈ NSPACE( n ) M = ”On input � φ � where φ is a Boolean formula: 1. For every truth assignment to the variables in φ , Proof: We want to find a nondeterministic decider M running in evaluate φ on that assignment. linear space such that 2. If φ gets ever evaluated to 1 then accept, else reject.” M accepts � A � where A is NFA if and only if L ( A ) � = Σ ∗ . Observe that M can reuse the space for the different truth Idea: Use the power-set construction to determinize A into DFA assignments. A det and accept iff A det has some rejecting computation. M runs in O ( n ) space (number of variables is bounded by n ). Problem: A det might be exponentially larger than A . Btw. the time complexity of the machine M is exponential! Solution: Find nondeterministically a rejecting path in A det while reusing the space (on-the-fly construction of a rejecting path). Lecture 14 Computability and Complexity 5/15 Lecture 14 Computability and Complexity 6/15

  2. A Nondeterministic Decider for ALL NFA Using O ( n ) Space Discussion We want to construct M such that So now we know that M accepts � A � if and only if L ( A ) � = Σ ∗ ALL NFA ∈ NSPACE( n ). M = ”On input � A � where A is an NFA with control states Q : What can we say about ALL NFA ? 1. Let s ⊆ Q be the initial state in A det . In order to complement the nondeterministic machine M from 2. Repeat 2 m times where m = | Q | : the proof above, we first need to determinize it. a) If s consists only of rejecting states of A then accept. Determinization of TM means exponential slow-down in the → s ′ in A det . a b) Nondeterministically select a transition s − running time. c) s := s ′ Does determinization imply that we will need also 3. Reject.” exponentially more memory? Space requirements: To store s , s ′ ⊆ Q we need O ( n ) space. Answer (Savitch’s Theorem): For every nondeterministic TM there is an equivalent deterministic To store a counter value in the loop we need O ( n ) space. TM that uses only quadratically more space! Total: O ( n ) of nondeterministic space. Lecture 14 Computability and Complexity 7/15 Lecture 14 Computability and Complexity 8/15 Savitch’s Theorem Computing CANYIELD( c 1 , c 2 , t ) Deterministically Savitch’s Theorem CANYIELD = Let t : N → R > 0 be a function such that t ( n ) ≥ n . Then ”On input � c 1 , c 2 , t � : 1. Case t = 1: NSPACE( t ( n )) ⊆ SPACE( t 2 ( n )) . If c 1 = c 2 or c 1 → c 2 (in N ) then accept, else reject. 2. Case t > 1: Proof: For all configurations c m (in N ) of length at most t ( n ): Let N be a nondeterministic TM using space O ( t ( n )). Call CANYIELD( � c 1 , c m , t / 2 � ). We want to find an equivalent deterministic TM M with Call CANYIELD( � c m , c 2 , t / 2 � ). space complexity O ( t 2 ( n )). If both calls accepted then accept. 3. Reject.” Algorithm CANYIELD( c 1 , c 2 , t ) accepts iff configuration c 2 is reachable (in N ) from c 1 in at most t steps. CANYIELD is implementable on a deter. TM using a stack. N is using O ( t ( n )) space which means that it has at most 2 dt ( n ) The initial call CANYIELD( c start , c accept , 2 dt ( n ) ) uses a stack of height O ( t ( n )). different configurations for some constant d . Every stack entry stores a configuration of size O ( t ( n )). Now N accepts w iff CANYIELD( c start , c accept , 2 dt ( n ) ) accepts. Total space used: O ( t ( n )) ∗ O ( t ( n )) = O ( t 2 ( n )). Lecture 14 Computability and Complexity 9/15 Lecture 14 Computability and Complexity 10/15 Complexity Class PSPACE Properties of the Class PSPACE Definition Theorem The class PSPACE is the class of languages decidable in NP ⊆ PSPACE polynomial space on deterministic Turing machine, i.e., Proof: Let L ∈ NP. PSPACE def � SPACE( n k ) . = Then there is nondeterministic decider M running in time k ≥ 0 O ( n k ) such that L ( M ) = L . Note that M can scan at most O ( n k ) tape cells and so Discussion: L ∈ NSPACE( n k ). The class PSPACE is robust with respect to nondeterminism Savitch’s Theorem gives that L ∈ SPACE( n 2 k ). (the class remains the same even if we use nondeterministic Hence L ∈ PSPACE. TM in its definition). Hence PSPACE=NPSPACE. Because every language L ∈ PSPACE has a deterministic Theorem poly-space TM M , we can swap the accept and reject states co-NP ⊆ PSPACE in M and get a poly-space decider for L , hence L ∈ PSPACE. Proof: Next tutorial. Example: SAT , SAT , ALL NFA , ALL NFA ∈ PSPACE Lecture 14 Computability and Complexity 11/15 Lecture 14 Computability and Complexity 12/15

  3. Properties of the Class PSPACE Overview of Time and Space Complexity Classes Theorem PSPACE ⊆ EXPTIME Proof: Let L ∈ PSPACE. Then there is a deterministic decider M running in space O ( n k ) such that L ( M ) = L . Note that M has at most 2 O ( n k ) different configurations. In any computation of the decider M none of the configurations can ever repeat (otherwise the machine loops). Hence the running time of M is bounded by 2 O ( n k ) and so L ∈ EXPTIME. Remarks: We know that P � = EXPTIME, but the strictness of all the other inclusions is still open! Lecture 14 Computability and Complexity 13/15 Lecture 14 Computability and Complexity 14/15 Exam Questions Definition of space complexity of deterministic and nondeterministic TMs. Definitions of SPACE, NSPACE and PSPACE. Savitch’s Theorem. Basic properties of the class PSPACE (hierarchy of complexity classes). Next time TEST! Lecture 14 Computability and Complexity 15/15

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend