On Time Versus Space 1977

download On Time Versus Space 1977

of 6

Transcript of On Time Versus Space 1977

  • 7/25/2019 On Time Versus Space 1977

    1/6

    On Tim e Ve r s u s S p ac e

    J O H N

    H O P C R O F T

    Cornell Umversity, Ithaca, New York

    W O L F G A N G P A U L

    Cornell Umverslty, Ithaca, New York

    A N D

    L E S L I E V A L I A N T

    Umversity o f Lee ds, Leeds, G reat Braam

    ARSTRAcr. I t is shown tha t ev ery deterministic multltape Turlng machine o f time complexity

    t (n )

    can be

    simulated by a deterministic Turlng m achine of tape com plexity t(n)/log t(n). Consequently, for tape construct-

    able t(n), the class of languages recognizable by multltape Turmg machines of time complexity t(n) IS strictly

    contained in the class of languages recognized by Turing machines of tape complexity

    t (n )

    In particular the

    context-sensitive languages cann ot be recognized in hne ar tim e by deterministic m ultltape Turmg machines

    K EY W OR DS A N D P HR AS ES : T u r m g m a c h i n e s , t i m e c o m p l e x i t y , t a p e c o m p l e x i t y

    CR CA r~oam s. 5 25

    1 . I n t r o d u c t i o n

    T h e m a i n r e s u l t o f t h is p a p e r i s t o se t t l e m t h e a f f i r m a t i v e t h e f u n d a m e n t a l q u e s t i o n a s t o

    w h e t h e r s p a c e is s t ri c tl y m o r e p o w e r f u l t h a n t i m e a s a re s o u r c e f o r d e t e r m i n i s t i c

    m u l t i t a p e T u r i n g m a c h i n e s . W e e s t a b h s h f o r a l l f u n c t io n s

    t ( n )

    t h a t t h e c l a ss o f s e ts

    a c c e p t e d i n t i m e t ( n ) i s c o n t a i n e d w i t h t h e c l a ss o f s e ts a c c e p t e d m s p a c e t ( n ) / l o g t ( n ) . T h i s

    i m p l i e s b y th e s t a n d a r d d l a g o n a l i z a t i o n a r g u m e n t s [ 11 ] t h a t f o r f u n c t i o n s t ( n ) a n d 6 ( n )

    w h i c h a r e b o t h c o n s t r u c t a b l e o n t a p e

    t ( n )

    t h e c l a ss o f s e ts a c c e p t e d i n h m e

    t ( n )

    i s p r o p e r l y

    c o n t a i n e d i n t h e c l a ss o f s e ts a c c e p t e d i n sp a c e

    8 ( n ) t ( n ) / l o g t ( n )

    p r o v i d e d i n f 8 (n ) ~ ~ .

    O n e c o n s e q u e n c e o f t h e a b o v e r e s u l t i s t h a t t h e c o n t e x t - s e n s i t w e l a n g u a g e s c a n n o t b e

    r e c o g n i z e d i n l i n e a r t i m e o n a d e t e r m i n i s t i c m u l t i t a p e T u r i n g m a c h i n e . I n f a c t t h e r e

    e x is t s a d e t e r m i n i s t i c c o n t e x t - s e n s i t i v e l a n g u a g e w h i c h c a n n o t b e r e c o g n i z e d i n t i m e

    ( n l o g n ) / A - l ( n ) o n a d e t e r m i n i s t i c m u l t i t a p e T u r i n g m a c h i n e , w h e r e A - l ( n ) Is t h e in -

    v e r s e o f A c k e r m a n n ' s f u n c t i o n .

    2 . E f f i c w n t S pa c e S i m u l a ti o n o f T i m e B o u n d e d T u r in g M a c h i n es

    L e t D T I M E ( t ( n ) ) ( N T I M E ( t (n ) ) ) b e t h e c l as s o f s e t s a c c e p t e d b y d e t e r m i m s t i c ( n o n d e t e r -

    m i n i s t i c ) m u l t i ta p e T u r m g m a c h i n e s o f t i m e c o m p l e x i t y

    t ( n ) .

    L e t

    D S P A C E ( s ( n ) )

    ( N S P A C E ( s ( t i ) ) ) b e t h e c l as s o f s e ts a c c e p t e d b y d e t e r m i n i s t i c ( n o n d e t e r m i n i s t i c ) m u l t i -

    t a p e T u r i n g m a c h i n e s o f sp a c e c o m p l e x i t y

    s ( n ) .

    Copyright 1977, Association for Computing Machinery, Inc. Gene ral permission to repubhsh, but not for

    profit, all or part of this material is granted provided th at A CM 's copyright notice is given and that re feren ce is

    m ade to the publication, to its date o f issue, and to the fact that rep nntin g prtvdeges were granted by

    permission of the Association for Computing Machinery

    This research was supported m par t by D A A D (G erman A cadem ic Exchange Service) Grant NO 430/402/

    563/5 and the Off ice of Naval Research under Gra nt

    N-OOO14-67-A-O077-O021

    Auth ors ' present addresses J Hop crof t , Dep ar tmen t of Com puter Science. Cornel l Universi ty , I thaca. NY

    14853; W. Paul, 'Fakultat Mathem atik, Um versltat Blelefeld D-4 8, Bwlefeld, Germ any , L Valiant, University

    of Leeds, Leeds, Great Britain.

    Journal of the Association for Computing Machinery, Vol 24, No 2, Aprd 1977 , pp 332-337

  • 7/25/2019 On Time Versus Space 1977

    2/6

    O n T t m e V e r s u s S p a c e

    333

    We present an algorithm for simulating a deterministic multitape Turing machine of

    time complexity t by a deterministic Turing machin e of space complexity t/lo g t. For ease

    in unders tand ing the co nstructio n involved we first present a nond eterm inist ic simula-

    tion.

    Partition each tape into blocks of size t z/a. Next modify the time bou nde d T urmg

    machine so that it is

    b l o c k r e s p e c t i n g ;

    that is, tape heads will cross boun dar ies between

    blocks only at times which are integer multiples of t z/a. The modified T urin g machine

    must be so constructed so that it runs slower by at most a constant factor c. To do this

    block boundaries are marked on the tapes. An additional tape ~s added with one block

    marke d on it. The hea d on this new tape simply moves back and forth over the block and

    serves as a clock to ind icate multi ples of t 2/3 units of time. If either head on one of the

    origina l tapes atte mpts to cross a block boundar y at a time ot her tha n a m ultip le of t z~z,

    the simu lation temporarily halts until the clock tape indicates the next mu ltiple.

    A difficulty arises in that a tape he ad m ay simply move bac k and forth b etw een two

    adjac ent tape cells which are in different blocks. In this case the simulation would be

    slower by a factor o f t 2ts. This difficulty is ove rcome as follows. L et

    be an inscription of the jth tape of the original Turin g machine after

    m t 213

    steps where

    I w, I = tz/a- Then the c orre sponding inscri ption for the bloc k respec ting Turi ng machi ne

    after

    c m t 2 Is

    steps is

    w1

    w~

    wl

    w2

    w~

    w~

    W

    w~

    Wr

    where w r stands for w reversed. The extra tracks are used to g uar ant ee t ha tt 2/s moves can

    be s imul ated without crossing a block b oun da ry. Afte r t zja such moves o f actual simula-

    tion, the next c - 1)t2/a moves are used to update the tapes of the block respecting

    machine . The details of the simulation and of ma rking the block bound arie s are left to

    the reader. For help, consult the proof of The ore m 10.3 in [7].)

    Withou t loss of generality, let M be a block respecting deterministic k-tape Turin g

    machine of time complexity t and let w be an inpu t for M. Divide the com puta tion of M

    on input w into time segments. Each segment A corresponds to a time period of length

    t 2~3. Note that a tape head can cross a b oundar y only at the end of a segment. Since the

    original Turin g machine makes at most t moves and there are always t 2t3 moves be twe en

    crossings of block bou nda rie s, there are at most t 1/a time segme nts A.

    Let

    h ( i ,

    A) be the pos ition of the tape head on the tth ta pe of M after time se gme nt A.

    Let h A) = [h 1, A) . . . . .

    h ( k ,

    A)] and let h = [h 1) . . . .. h p/a)]. Fro m the sequenc e of

    head positions h, we construct a directed graph G with a vertex corresp onding to each

    time segment of the compu tatio n. Let v A) be the vertex corresp onding to time segment

    A. For each tape i, let A~ be the last time segm ent prio r to A such that t he ith head was

    scanning the same block dur ing the segment A, as during the segm ent A. The edges of G

    are v A - 1) --~ v A) and , for 1 _< i -< k, v A,) ~ v A). Bec ause the re are only t t/s time

    segment s A, the a bove graph has at most t 1/a vertices. To write dow n a descr iption of the

    graph require s space on the o rde r of k + 1) t ~/a log t since approxima tel y log t bits are

    needed to specify each edge.

    Let

    c ( i ,

    A) be the content after time segment A of that block on the ith tape of M

    scan ned by the tape head dur mg the time segment A. Let c A) = [c 1, A), . .. , c ( k , A)].

    Let f A) be the i nitial con ten ts of those blocks which are visited by M for the first time

    during the time segme nt A. With each vertex v A) in G we can associate the info rmat ion

    c A) an d f A).

  • 7/25/2019 On Time Versus Space 1977

    3/6

    3 3 4 J. HOPCROFT, W. PAUL, AND L. VALIANT

    L e t q (& ) b e t h e s ta t e o f M a f t e r t im e s e g m e n t A a n d l e t q = [ q ( 1 ) , . . . , q(t113 )]. I n o r d e r

    t o d e t e r m i n e t h e o u t c o m e o f t h e o r ig i n a l c o m p u t a t i o n o f M , w e n e e d o n l y d e t e r m i n e t h e

    s t a t e q ( A ) a f t e r t h e f i n a l t i m e s e g m e n t A .

    S u p p o s e w e h a v e g u e s s e d t h e s e q u e n c e o f h e a d p o s i t io n s h a n d t h e s e q u e n c e o f st a te s

    q . W e w a n t t h e m t o s im u l a t e M w i t h o u t u s i n g to o m u c h s p a c e a n d t o v e r if y t h a t w e

    g u e s s e d h a n d q c o r r e c t l y . B e c a u s e M i s d e t e r m i n i s t i c a n d b l o c k r e s p e c t i n g , th e f o l l o w i n g

    h o l d s f o r a n y A :

    ( 2 . 1 ) q ( A ) , h ( A ) , a n d c ( A ) c a n b e u n i q u e l y d e t e r m i n e d f r o m q ( A - 1 ), h ( A - I ) , c (A 1 ),

    . . , c ( A k) , a n d f ( A ) b y d i r e c t s i m u l a t i o n o f t im e s e g m e n t A . T h e s i m u l a t i o n r e q m r e s

    s p a c e t o s t o r e t h e c o n t e n t s o f k b l o c k s o r O(kt2/3) .

    ( 2 . 2 ) T o s t o r e c ( A ) r e q u i r e s s p a c e

    0(kt213) .

    f ( A ) , q ( A - 1 ), a n d h ( A - 1 ) c a n b e d e t e r m i n e d f r o m t h e g u e s s e d s e q u e n c e s q a n d h , a n d

    t h e e d g e s i n t o v e r t e x v( A ) i n t h e g r a p h G g i v e u s th e v e r t i c e s a s s o c i a t e d w i t h c ( A 1 ) , . . . ,

    c ( A k) . T h i s s u g g e s t s s e v e r a l s tr a t e g i e s t o s i m u l a t e M . O u r s t r a t e g y w i ll b e f i r s t t o

    d e t e r m i n e c ( 1 ) , t h e n c ( 2 ) , c (3 ) , a n d s o o n .

    N o w o b s e r v e t h a t in o r d e r t o c a r ry o u t t h e w h o l e s i m u l a ti o n w e n e e d n o t k e e p i n

    m e m o r y t h e c o n t e n t s o f t h e b l o c k s c o r r e s p o n d i n g t o a ll v e r t i c e s s i n c e w e c a n g o b a c k a n d

    r e c o n s t r u c t c e r t ai n b l o c k s w h e n e v e r w e n e e d t h e m . T h e q u e s t io n i s w h a t i s t h e m i n i m u m

    n u m b e r o f b l o c k s o n e m u s t s t o r e a t a n y o n e t i m e i n o r d e r t o c a r r y o u t t h e s i m u l a t i o n . T o

    a n s w e r t h i s q u e s t i o n w e s t u d y a g a m e o n g r a p h s .

    L e t G k b e t h e s e t o f a l l f i n it e d i r e c t e d a c y d i c g r a p h s w i t h i n d e g r e e a t m o s t k . V e r t i c e s

    w i t h i n d e g r e e 0 a r e c a l l e d i n p u t v e r t i c e s . T h e g a m e c o n s i s ts in p l a c i n g p e b b l e s o n t h e

    v e r t ic e s o f s u c h a g r a p h G a c c o r d i n g t o t h e f o l lo w i n g r u le s :

    ( 1 ) A p e b b l e c a n a l w a y s b e p l a c e d o n a n i n p u t v e r t e x .

    ( 2 ) I f a l l f a t h e r s o f a v e r t e x v h a v e p e b b l e s , t h e n a p e b b l e c a n b e p l a c e d o n v e r t e x v .

    ( 3 ) A p e b b l e c a n b e r e m o v e d a t a n y t i m e .

    T h e g o a l o f t h e g a m e is t o e v e n t u a l l y p l a c e a p e b b l e o n a p a r t i c u l a r v e r t e x v ,

    d e s i g n a t e d in a d v a n c e , b y a s c h e m e w h i c h m i n im i z e s t h e m a x i m u m n u m b e r o f p e b b l e s

    s i m u l t a n e o u s l y o n t h e g r a p h a t a n y in s t a n c e o f t im e . L e t P k ( n ) b e t h e m a x i m u m o v e r a ll

    g r a p h s i n G k w i t h n v e r t i c e s o f t h e n u m b e r o f p e b b l e s r e q u i r e d t o p l a c e a p e b b l e o n a n

    a r b i t r a r y v e r t e x o f s u c h a g r a p h . W e w i ll s h o w t h a t f o r e a c h k , P k ( n ) is O ( n / l o g n ) .

    LEMMA I.

    F o r e ac h k , P k ( n ) is O ( n / l o g n ) .

    P RO O F. F o r c o n v e n i e n c e l e t

    R k ( n )

    b e t h e m i n i m u m n u m b e r o f e d g e s o f a n y g r a p h i n

    G k

    w h i c h r e q u i r e s n p e b b l e s . S h o w i n g th a t

    Rk (n ) --> cn

    l o g n f o r s o m e c i s e q u i v a l e n t t o

    p r o v i n g t h a t P k ( n ) JS O ( n / l o g n ) .

    L e t

    G = ( V , E ) b e a g r a p h m G k w i t h R k ( n ) e d g e s w h i c h r e q u i r e s n p e b b l e s ,

    V~ = t h e s e t o f v e r t ic e s o f G t o w h i c h a p e b b l e c a n b e m o v e d u s i n g n / 2 o r f e w e r p e b b l e s ,

    V 2 = V - V ,

    E 1 = { ( u ~

    v ) / u

    --> v) ~ E , u , v ~ V1} ,

    E2 = {(u -->

    v ) / ( u --> v ) ~ E , u , v ~

    Vz},

    G~ = (V~, E~) an d

    G z = ( V z , E z ) .

    A = E - ( E l t.I E 2 ) , t h a t i s , A i s t h e s e t o f e d g e s f r o m v e r t i c e s i n V a t o v e r t i c e s i n V 2 .

    W e c l a i m t h a t t h e r e e x i s t s a v e r t e x i n G 2 w h i c h r e q u i r e s n / 2 - k p e b b l e s i f t h e g a m e is

    p l a y e d o n G 2 o n l y . O t h e r w i s e m o v e a p e b b l e t o a n y v e r t e x v o f G w i t h le s s t h a n n p e b b l e s

    b y t h e f o l l o w i n g s t r a t e g y . I f v i s i n V i , t h e n o n l y

    n / 2

    p e b b l e s a re n e e d e d . T h u s a s s u m e v

    i s i n V2. M o v e a p e b b l e t o v i n G b y u s in g t h e s t r a t e g y f o r G 2. W h e n e v e r w e n e e d t o p l a c e

    a p e b b l e o n a v e r t e x w o f G 2 w h i c h i n G h a s a f a t h e r i n V 1, m o v e p e b b l e s o n e a t a t i m e t o

    e a c h f a t h e r o f w i n V 1. S in c e w h a s a t m o s t k f a t h e r s i n V ~, a t m o s t n / 2 + k p e b b l e s a re

    e v e r p l a c e d o n v e r t i c e s in V ~. A s s o o n a s a p e b b l e is p l a c e d o n w , r e m o v e a l l p e b b l e s

    f r o m v e r t i c e s i n V~. H e n c e a t m o s t n - 1 p e b b l e s a r e e v e r u s e d , a c o n t r a d i c t i o n . T h u s G 2

    m u s t h a v e a t l e a s t R k ( n / 2 - k ) e d g e s .

    N e x t o b s e r v e t h a t G ~ h a s a v e r t e x w h i c h r e q u i r e s a t le a s t

    n / 2 - k

    p e b b l e s . T h i s f o ll o w s

  • 7/25/2019 On Time Versus Space 1977

    4/6

    O n T i m e V e rs u s S p a c e

    3 3 5

    f r o m t h e f a c t t h a t a v e r t e x r e q u i r i n g n p e b b l e s m u s t h a v e a n a n c e s t o r w h i c h r e q u i r e s a t

    l e a s t n - k p e b b l e s . T h u s G ~ m u s t h a v e a t l e a s t R e ( n ~ 2 - k ) e d g e s .

    N o w e i t h e r I A I -> n / 4 , i n w h i c h c a s e R k ( n ) --> 2 R e ( n / 2 - k ) + n / 4 , or e l s e I A } < n / 4 .

    I n t h e l a t t e r c a s e p e b b l e s c a n b e p l a c e d s i m u l t a n e o u s l y o n a ll v e r t i c e s o f V ~ w h i c h a r e

    t a i ls o f e d g e s i n A u s i n g a t m o s t

    3 n / 4

    p e b b l e s i n t h e p r o c e s s . L e a v m g

    n / 4

    p e b b l e s o n

    t h e s e v e r t ic e s , w e h a v e 3 n / 4 p e b b l e s f r e e a f t e r t h is h a s b e e n a c c o m p h s h e d . T h u s G ~ m u s t

    r e q u i r e

    3 n / 4

    p e b b l e s , fo r o t h e r w i s e G w o u l d n o t r e q u i r e n p e b b l e s . N o w a g r a p h w h i c h

    r e q u i r e s

    3 n / 4

    p e b b l e s m u s t h a v e a s u b g r a p h w i t h a t l e a s t

    ( 1 / k ) n / 4

    f e w e r e d g e s w h i c h

    r e q u i r e s a t l e a s t

    n / 2

    p e b b l e s . ( T o s e e th i s , n o t e t h a t t h e g r a p h m u s t h a v e a v e r t e x v o f

    o u t d e g r e e 0 w h i c h r e q u i r e s

    3 n / 4

    p e b b l e s . V e r t e x v m u s t h a v e a n a n c e s t o r w h i c h r e q u i r e s

    a t l e a s t

    3 n / 4 - k

    p e b b l e s . T h u s w e c a n d e l e t e v a n d t h e e d g e s i n t o v . T h e r e s u l t in g g r a p h

    s t il l r e q u i r e s a t l e a s t

    3 n / 4 - k

    p e b b l e s . R e p e a t i n g t h e p r o c e s s

    ( 1 / k ) n / 4

    t i m e s , w e o b t a i n

    a s u b g r a p h w i t h a t l e a s t ( 1 / k ) n / 4 f e w e r e d g e s w h i c h r e q u i r e s a t l e a s t n / 2 p e b b l e s . )

    T h u s i n b o t h c a s e s

    R k ( n ) --> 2 R k ( n / 2 - - k ) + ( I l k ) n ~ 4 .

    S o l v i n g th i s r e c u r r e n c e g i v e s

    R k ( n ) --> c n

    l o g n f o r s o m e c o n s t a n t c T h i s p r o o f w a s i n s p i r e d b y [ 9 ]. [ ]

    R e c e n t l y i t h a s b e e n s h o w n b y P a u l , T a r j a n , a n d C e l o n i ( p e r s o n a l c o m m u n i c a t i o n )

    t h a t

    P ~ ( n) -> c n / l o g n

    f o r s o m e c o n s t a n t c , a n d h e n c e L e m m a 1 is o p t i m a l . T h is i m p r o v e s

    o n a n e a r l i e r b o u n d o f

    c x / n

    g i v e n b y C o o k [ 2 ].

    LEMMA 2.

    D T I M E ( t ) C_ N S P A C E ( t / l o g t ) .

    P RO OF . L e t M b e a t l o g t t i m e b o u n d e d d e t e r m i n i s t i c k - t a p e T u r i n g m a c h i n e . W e

    c o n s t r u c t a n o n d e t e r m i n i s t i c m a c h i n e M ' w h i c h s i m u l a t e s M i n s p a c e t.

    M a k e M b l o c k r e s p e c t i n g a n d g u e s s a s e q u e n c e o f s t a te s

    q '

    a n d a s e q u e n c e o f h e a d

    p o s i t i o n s h ' , a s o p p o s e d t o th e c o r r e c t s e q u e n c e s q a n d h . E a c h s u c h s e q u e n c e h a s l e n g t h

    a t m o s t t ~ /3. I t r e q u i r e s s p a c e t ~/a t o w r i t e d o w n q ' a n d s p a c e t l / a lo g t t o w r i t e d o w n h ' .

    F r o m h ' c o n s t r u c t a g r a p h G a s d e s c r i b e d e a r l i e r . G h a s t ~ja v e r t i c e s a n d r e q u i r e s s p a c e

    t~ t31og t t o w r i t e do w n .

    B y L e m m a 1 t h e r e i s a st r a te g y to m o v e a p e b b l e t o th e o u t p u t n o d e o f G b y n e v e r

    u s i n g m o r e t h a n t ~ /3 /lo g t p e b b l e s . W e c a n a s s u m e t h a t t h i s s t r a t e g y h a s a t m o s t ~ = 2 t'~3

    m o v e s b e c a u s e t h e r e a r e o n l y z p a t t e r n s o f p e b b l e s o n G a n d t h e r e i s n o s e n s e i n

    r e p e a t i n g a p a t t e r n in a s t r a t e g y . H a v i n g g u e s s e d t h e s e q u e n c e s q ' a n d h ' , w e c a n h a v e

    M ' s i m u l a t e M a s f o l lo w s :

    b e g i n

    f o r x = s t e p 1 u n t i l r d o

    b e g i n

    nonde termm ts ttcal ly g uess x- th m ove o f above s tra tegy ,

    i f x - th m ove p laces pebble on

    v(A)

    t h e n

    b e g i n

    com pute and s tore q( ,~) , h(A) , an d c (~ ) ,

    i f q ( A ) -~ q ' ( A ) o r h ( A ) ~ h ' ( A ) t h e n reject ,

    i f space used t s greater tha n or equa l to t t h e n relect ,

    e n d e l s e i f x - th m ove removes pebble f rom v ( ,~) t h e n erase q(A) , h(~) , and c ( ,~) f ro m the w ork ing tape;

    e n d

    i f a f te r s tage z s tmulatzon t s no t com ple te t h e n relect

    e n d

    T h e e s s e n t i a l f e a t u r e o f th i s s i m u l a t i o n is t h a t a f t e r s t a g e x , M ' h a s c o m p u t e d a n d

    s t o r e d { c (A ) { v e r t e x v ( A ) h a s a p e b b l e a f t e r t h e x t h m o v e } . B y ( 2 . 2 ) s t o r i n g c ( A ) f o r o n e

    t a k e s s p a c e

    O ( f / 3 ) .

    T h u s i f M ' h a p p e n s t o g u e ss a s t r a t e g y w h i c h u s e s a t m o s t O

    ( t ~ / a / l o g t )

    p e b b l e s a t a t~ m e ( b y L e m m a 1 su c h a s t r a te g y a l w a y s e x is t s ) , t h e s i m u l a t i o n c a n i n d e e d

    b e c a r r i e d o u t i n s p a c e O ( t / l o g t ) , i n w h i c h c a s e M ' a c c e p t s i f f t h e l a s t c o m p o n e n t o f q '

    i s t h e a c c e p t i n g s t a t e o f M .

    T h e g l o b a l c o r r e c t n e s s o f t h e a b o v e s i m u l a t i o n is p r o v e d b y i n d u c t i o n o n x a n d f o l l o w s

    f r o m ( 2 . 1 ) , ( 2 . 2 ) , t h e c o n s t r u c t i o n o f

    G ,

    a n d t h e r u l e s o f t h e p e b b l e g a m e . A s m a l l b u t

    i m p o r t a n t p o i n t i s t h a t t h e r e a r e t h e e d g e s v (A - 1 ) --~ v ( A ) . T h i s g u a r a n t e e s t h a t t h e t i m e

    s e g m e n t A o f t h e c o m p u t a t i o n o f M c a n n o t b e s i m u l a t e d u n t i l i t h a s b e e n v e r i f i e d t h a t

  • 7/25/2019 On Time Versus Space 1977

    5/6

    3 3 6 J . H O PC RO F T, W . P A U L , A N D L . V A L I A N T

    q ( 1 ) . . . . . q ( ~ - 1) a n d h ( 1 ) . . . . , h ( A - 1 ) h a d b e e n g u e s s e d c o r r e c t l y . T h e d e t a i l s o f

    t h e c o r r e c t n e s s p r o o f a r e l e ft t o t h e r e a d e r .

    A t t h i s p o i n t t h e r e a d e r s h o u l d b e f a m i l ia r w i t h al l t h e i m p o r t a n t i d e a s . W e n o w

    e x p l a in h o w t o m a k e t h e s i m u l a t io n d e t e r m i n i s ti c . T h e r e a r e t w o n o n d e t e r m i n i s t i c s te p s

    i n t h e s i m u l a t i o n a lg o r i t h m . G u e s s i n g t h e s e q u e n c e s q ' a n d h ' c a n b e r e p l a c e d b y c y c li n g

    t h r o u g h a l l p o s s i b l e s u c h s e q u e n c e s .

    I n o r d e r t o d e t e r m i n e t h e n e x t m o v e i n t h e s t r a t e g y w h i c h m o v e s t h e p e b b l e s , f ir s t

    c o n s t r u c t a n o n d e t e r m i n i s t i c m a c h i n e w h i c h , g iv e n a d e s c r i p t i o n o f G , a p a t t e r n D o f

    p e b b l e s on G , a n d a n u m b e r x b e t w e e n 1 a n d 2 dl3 ( e a c h o f w h ic h c a n b e w r i t te n d o w n i n

    s p a c e t i / 3 1 0 g t o r l e s s ) , p r i n t s o u t t h e f i r s t m o v e i n a s t r a te g y w h i c h , s t a r t i n g f r o m D ,

    m o v e s a p e b b l e o n t h e o u t p u t v e r t e x o f G n e v e r u s i n g m o r e t h a n O ( t l /a l o g t ) p e b b l e s a n d

    m a k i n g a t m o s t 2 t 3 10 g t - x m o v e s , p r o v i d e d s u c h a s t r a t e g y e x i s t s .

    T h i s m a c h i n e c a n b e c o n s t r u c t e d i n a s t r a i g h t f o r w a r d w a y u s i n g s p a c e O (t l/ 31 o g t ) .

    U s i n g t e c h n i q u e s f r o m [ 1 0 ], o n e c a n m a k e i t d e t e r m i n i s t i c i n s p a c e O(t~J310g2t). U s i n g

    t h is m a c h i n e d u r i n g t h e s i m u l a t i o n a s a s u b m a c h i n e , o n e c a n a l w a y s f r o m t h e a c h i e v e d

    p a t t e r n o f p e b b l e s a n d f r o m x d e t e r m i n i s t ic a l l y f i n d t h e n e x t m o v e i n t h e r i g h t s t r a t e g y .

    T h u s w e h a v e s h o w n

    THEOREM 1. I f t tS t a p e c o n st r u c ta b l e , t h e n D T I M E ( t ) C_ D S P A C E ( t / l o g t ).

    S o m e e a s y c o r o l l a r i e s o f th i s h a v e b e e n s t a t e d i n th e I n t r o d u c t i o n . I n a d d i t m n o n e c a n

    s h o w

    COROLLARY 1. F o r a ll t: D T I M E ( t ) C D S P A C E ( t / I o g t) .

    PR OO V. I n s t e a d o f p r e c o m p u t i n g t , s u c c e s si v e l y t r y s i m u l a t i o n o f t h e p r o o f o f T h e o -

    r e m 1 f o r t ( n ) = 1 , 2 , 3 , . . u n t d y o u c a n c a r r y o u t th e s im u l a t i o n .

    COROLLARY 2. I f t ( n ) a n d 8 ( n ) a r e c o n s t r u c t a b l e o n ta p e t ( n ) a n d l ir a 8 ( n ) = t h e n

    D T I M E ( t ( n ) ) t s p r o p e r l y c o n t a i n e d m t h e cl a ss o f s e ts r e c o g n i z a b le i n t i m e 8 ( n ) t ( n ) lo g t( n )

    o n s p a c e t ( n ) .

    P RO O V. I n s t e a d o f b l o c k s i z e t 213, c h o o s e b l o c k s i z e t / ( l o g 8 ) ~12 s o t h a t t h e n u m b e r o f

    b l o c k s , a n d h e n c e t h e s i z e o f t h e g r a p h , i s ( l o g 6 )1 /% T h e n t h e t o t a l n u m b e r o f g r a p h s i s

    b o u n d e d b y 8 ~ n, a l l o w i n g u s to c y c l e t h r o u g h a l l g r a p h s c o n t r i b u t i n g a t m o s t a m u l t ip l i c a -

    t iv e t i m e f a c t o r o f 81 /2 . F o r a f i x e d g r a p h w e c a n c o n s t r u c t a p e b b l i n g s t r a t e g y i n t i m e 8 .

    ( T h e r e a r e a t m o s t 2 C~~ 8 )~ c o n f i g u r a t i o n s o f p e b b l e s , a n d h e n c e n o n d e t e r m i m s t i c s p a c e

    ( l o g 8 ) i/z i s s u f f i c i e n t . B y S a v i t c h ' s c o n s t r u c t i o n [ 1 0 ] d e t e r m i m s t i c s p a c e l o g 8 a n d h e n c e

    d e t e r m i n i s t i c t i m e 8 i s s u f f i c ie n t .) G i v e n a g r a p h a n d a p e b b h n g s t r a t e g y , s i m u l a t i o n

    r e q u i re s t im e e q u a l t o t h e p r o d u c t o f th e n u m b e r o f p e b b l e m o v e s a n d t / lo g 8 o r

    ( 8 ) u 2 t/ lo g 8 . T h e r e f o r e t h e t o t a l t i m e i s b o u n d e d b y 6 ~j2 [8 + 8 J /a t /l o g 6 ] o r 6 ( n ) t ( n ) . T h u s

    e a c h k - t a p e m a c h i n e o f t~ m e c o m p l e x i t y t c a n b e s i m u l a t e d b y a ( k + 1 ) - t a p e m a c h i n e o f

    t i m e c o m p l e x i t y le s s th a n ~ ( n ) t ( n ) a n d t a p e c o m p l e x i t y O ( t / l o g l o g 8 ) . N o w a n a p p e a l t o

    [ 5 ] y i e l d s t h e d e s i r e d r e s u l t .

    I t i s a n i n t e re s t in g o p e n p r o b l e m w h e t h e r N T I M E ( t ) C N S P A C E ( t / I o g t) . T h e d i ff i-

    c u l ty h e r e i s t h a t i n g o i n g b a c k a n d r e p e a t i n g a p o r t i o n o f a c o m p u t a t i o n w e c a n n o t b e

    s u r e t h a t t h e s a m e s e q u e n c e o f c h o i c e s i s m a d e t h e s e c o n d t i m e .

    3 . A n A p p l ic a t io n o f L e m m a 1

    A s t ra t g h t- l in e p r o g r a m o f le n g t h n i s a s e q u e n c e o f n a s s i g n m e n t s t a t e m e n t s o f th e f o r m

    X1 ~ - f l ( Y l l . . . . .

    Y l k ) ,

    x , + - -A ( Y m , . . , Y n k ) ,

    w h e r e t h e x , a n d y ~ a r e ( n o t n e c e s s a r d y d i s t i n c t ) v a r i a b l e s a n d t h e f , a r e ( n o t n e c e s s a r i l y

    d i s ti n c t) k - a r y o p e r a t i o n s . T h o s e v a r i a b le s w h ic h n e v e r a p p e a r o n t h e l e f t - b a n d s id e o f a n

    a s s i g n m e n t a r e c a l l e d i n p u t v a r t a b l e s .

    L e t u s a s s u m e t h a t e a c h v a l u e f o r a v a r i a b l e o c c u r r i n g d u r i n g t h e e x e c u t i o n o f t h e

    s t r a ig h t - l in e p r o g r a m c a n b e s t o r e d i n o n e r e g i s t e r a n d t h a t , g i v e n y,~ th r o u g h Y ,k,

  • 7/25/2019 On Time Versus Space 1977

    6/6

    O n T i m e V e r s u s S p a c e

    3 3 7

    f (Y , l . . . . .

    y,~)

    c a n b e c o m p u t e d u s in g a f i x ed n u m b e r o f r e g i s t er s . H o l d i n g k f i x e d , w e

    c a n a s k h o w m a n y a u x i l i a r y c e l l s , i . e . c e l l s o t h e r t h a n t h o s e w h i c h c o n t a i n t h e v a l u e s o f

    t h e in p u t v a r i a b l e s , a re n e e d e d t o e x e c u t e a s tr a ig h t - l i ne p r o g r a m o f l e n g t h n . W e c l a i m

    that O n / log n ) a u x d ia r y c e l l s a re s u f fi c ie n t . T h i s c a n b e s e e n a s f o l l o w s : M o d i f y t h e p r o -

    g r a m s o t h a t n o v a r i a b l e a p p e a r s t w i c e o n t h e l e f t - h a n d s i d e o f a n a s s i g n m e n t , t h e r e b y

    p o s s i b l y i n c r e a si n g t h e n u m b e r o f d i s ti n ct v a r i ab l e s u s e d . C o n s t r u c t a g r a ph G a s f o l l o w s :

    T h e v e r t i c e s o f G a r e t h e d i s t i n c t v a r i a b l e s o f t h e m o d i f i e d p r o g r a m . T h e r e i s a n e d g e

    v~ ~ v2 i f f i n o n e l i n e v~ o ccu rs o n th e l e f t -h an d s i d e an d v~ ap p ears o n th e r i g h t -h an d

    s i d e . G i s d i rec ted , i s acyc l i c , h as fan i n k , an d h as a t m o s t

    kn

    v e r t i c e s a n d e d g e s .

    B y L e m m a 1 t h e r e e x i s t s a p e b b l e s t r a t e g y f o r G u s i n g a t m o s t O n/ log n ) p e b b l e s ,

    w h i c h i n d u c e s a n e v a l u a t i o n s t r a t e g y f o r t h e s t r a i g h t - l i n e p r o g r a m i n a n o b v i o u s w a y .

    ( U n f o r t u n a t e l y t h i s s t r a t e g y m a y b e r a t h e r t i m e c o n s u m i n g )

    T h i s re su l t s tan d s i n p er fec t an a l o g y to th e fac t th a t each fo rm u l a o f l en g th n can b e

    e v a l u a t e d w i t h O ( l o g n ) a u x il ia r y c e ll s b e c a u s e e a c h k - a r y t r e e w i t h n l e a v e s c a n b e

    p e b b l e d w i th O ( l o g n ) p e b b l e s .

    R E F E R E N C E S

    ( N o t e . R e f e r e n c e s

    ll, 3, 4, 6, 8]

    are not c i ted m the text )

    1 A t t o , A . V , H O PC R O Vr , J . E . , A ND U L LM A N , J D .

    Th e D esign an d A n a l y s i s o f C o m p u t e r A l g o r it h m s

    A d d i s o n - W e s l e y , R e a d i n g , M a s s , 1 9 7 4

    2 C o o K . S A A n o b s e r v a t i o n o f

    nine -s torage trade -o f f Proc . F i fth A nnual

    A C M S y r up . o n T h e o r y o f

    C o m p u t , 1 9 73 , p p . 2 9 - 3 3

    3 HARTMANIS, J , AND STEARNS, R E O n the computat iona l complex i ty o f a lgor i thms. T r a n s . A m e r

    M a t h S o c 1 1 7 ( 1 9 6 5 ) , 2 8 5 - 3 0 6

    4 H E N NI E, F . C O n - h n e

    Tur lng machine computat ions

    1 E E E T r a n s. E l e c tr o n i c C o m p u t e r s E C - 1 5

    ( 1 9 6 6 ) , 3 5 - 4 4

    5 HENNIE , F C , AND S TEARNS , R E Tw o - t ap e s im u la t i o n o f mult i tape Turmg machines .

    J A C M 1 3 , 4

    ( O c t 1 9 6 6 ) , 5 3 3 - 5 4 6

    6 HOP CROF T, J E , AND ULLM AN, J D S o m e r es u l t s o n tape -bounded Tur lng machines . J A C M 1 6 , 1

    ( J a n 1 9 6 9 ) , 1 6 8 - 1 7 7

    7 HOPCR O~, J E , AND ULLM AN, J D

    F o r m a l Languages and T h e i r R e l a t t o n t o A u t o m a t a .

    A d d i s o n -

    W e s l e y , Reading , Mass , 1 9 6 9

    8 P AT ERSON, M S Ta p e bounds for t ime -bounded Turmg machines . J C o m p u t e r S y s t e m S ct . 6 ( 1 9 7 2 ) ,

    1 1 6 - 1 2 4

    9 PATERSON,M S , ANO VALIANT, L G Ct r cu i t s i ze i s nonhnear in depth Theory o f C o m p u t . R e p . 8 , U

    o f

    W a r w i c k . C o v e n t r y , E n g l a n d ,

    1 9 7 5 , t o a p p e a r m T h e o r e ti c a l C o m p u t e r S c l

    1 0 S Av r rc r t , W J Relat ionsh ips be tween nonde termlmst i c and de termini s t i c tape complex l t l eg . J . C o m -

    p u t e r S y s t e m S c t 4 , 2 ( 1 9 7 0 ) , 1 1 7 - 1 9 2

    ] 1 . S T EA R N S, R E , H AR TM A NIS , J , A ND L E W IS , P M H i e r a r c h i e s o f m e m o r y h m i t e d c o m p u t a t i o n s P r o c

    Sixth

    I E E E S y ru p . o n

    S w i t c h i n g a n d A u t o m a t a T h e o r y ,

    1 9 6 5 , p p . 1 9 1 - 2 0 2 .

    RECEIVED NOVEMnER 19 75 , REVISED ~AV 19 76

    Journal of th e A ssoclatlonfor ComputingMac hinery, Vol 24, No 2. April 1977