Volume 13, numbers 4,s
End 1981
INFORMATIONPROCESSINGLETTERS
TIMECOMPLEXITY OF LANGUAGESRECOGNIZED BY ONE-WAYMULTtHEAD PUStIDOwN AUTOMATA Wojciech RYTTER Institute of Informatics, Warsaw University, PKiN VIII p, 00-901 Warszaw~,Polimd Received 23 July 1981; revised version received 16 November 1981 Pushdown automata, context-free languages, time complexity
Let NPDA(k) be the class of languages recognized by pushdown automata having k one-way input heads (in short npda(k)‘s) and let CFL denote the class of context-free languages (hence CFL = NPDA(1)).We show that if T(n) is the time to recognize context-free languages then the time to recognjze languages from NPDA(k) is O(T(nk)). By [3,6] T(n) < n3 and therefore languages fron NPDA(k) are recognized in less than O(n3k) time. On the other hand, the time complexity of recognizing languages accepted by pushdown automata with k two-way input heads is 0(n3’) [II1. The proof consists of showing how any given npda(k) A can be transformed to a npda(1) A’ such that A accepts w iff A’ accepts g(w), where Ig(w)l = O(lwlk). (Iv1denotes the length of the word v.) We use ideas similar to Lemma 2.1 from [S] , Lemma 1 from [4] and Lemma 4.3 from [2] and [S]. Let hi be the homomorphism hi(a) = (a, i) for a E V, 1 G i G k, where V is any given alphabet. Intuitively hi(a) denotes the i-th copy of a. hi is naturally extended to the set of all words over V. Let Vi = hi(V). The elements of Vi are called i-symbols. Let V’ = Vr U V1 U 9..U Vk U ($}. The symbol ‘$, plays an auxiliary role, it is not an element Of any Vi. The operation @is defined for every two nonempty words w1 = ala2 .* a,, (each ai is a single symbol) and w2 is as follows:
Wetake g(w) to be Sk(w)if w is nonempty and w otherwise. For cxarnple if w = aa and if we write i insteadof (a, i) then Qaa)= 11, sa(aa)=2$$112$$11, ss(aa) = 3$$2$$112$$113$$2$$112~11.
3$$2$$112$$113$$2$$112$911~ t
~“8, ~0”(2,1,1);
w1Q w2 = ar$*w2a2$Yw2a3$Pw2 ... a,$Pw2.
3$$2$$112$$113$$2$$112$$11, t
p’= 21, $5 (2,192).
l
Define s1(w) = hl (w), si+1(iv; = hi+r (w) 8 si(w) 142
for 1 G i G k - 1.
Lemma 1. If [WI=n then lg(w)l = G(nk).
If p is a position in g(w) then range(i, p) denotes the maximalsubintervalof [ 1 .-*g(w)] containingp such that the subwordof g(w) determinedby this subintervaldoes not contain any (i + l)-symbol. We say that a position p in g(w) is properfi it contains a l-symbol. Let P be the set of properpositions p in g(w) and let Fbe the set of vectorsp of positions of k input hesds in w. Weestablisha correspondence betweenthese sets. I& pos(i, p) be the numberof i-symbolswhich are to the left of position p (including this position) in the word g(w) within ran@, p) for 1
Observethat p’ resultsfrom p when the third input head is moved.Weshall constructa npdatl) A’ which on input g(w) simulatesthe behaviourof a npda(k)A OOZO-0190~81/0000-0000~$02.75 @ 1981 North-Holland
tadurn%13, numbers4, s
on input W. The sttucture of&w)
INFORMATIONPROCESSINGLETTERS
helps A’ to simulate
End 1981
right to the i&h r-symbol, in this process the group of 4 r-counters is popped from the stack =&
{thereare no r-counters on the stack for any r, the position of the head of A’ is equal to p’).
Proof.Considerany
the input alphabet on in g(w). Intuitively, the input head of A> in of positions(of the represent8the vector input headsof A) in w. Wedescribehow the npda(1) A’ movesits head simulatinga move of an input head of A*Suppose that fi = (ia, i2, .... ik) correspondsto position p and the j-th head of A is moved. The next vector of p0dtiG.u is jj’ = (ia, .. . . ij + 1, . .. . ik) correspondingto the position p’ of the head of A’. The headofA’isscann@thepthsymbolofg(w),r,is the properposition and the scannedsymbol is I’l-symo bol. If j = 1 then A’ movesits head one step _I,% .. If j > 1 then A’ performsthe following act;ans: (1) (recordthe numbersn - iI, n - i2, .... t - ij_I using icounters and the stack} fm r := 1 to j - 1 do A’ movesits head rightto the first(r + l)-symbol and in everystep ifit scansr-symbolthen it pushes one r4ounter; (2) {now on the top of the stack aregroups(topdown) of n - in+ (j - l)=counters,n - iI-2 (j - 2)4zounters,...Sn - it l-counters,and the head of A’ is scan@ngthe next j*ymbol} ; A’ recordain its finite memorythe scannedj-symbol correspondingto the symbol scannedby the j& head of A after its move; (3) {reconstructing the positions of the fust j - 1 hea& of A) {A’ scansnow (r + Qsymbol and on the top of the stackis the groupof n - & counters); A’uam the followingafhr its head posltion n symbols $ repIacesthe group of n - &-Men; using r-countersto count r-symbolsA’ movesits head
After the application of the steps (l-3) the head of A’ is on the position p’ corresponding td the vector @’of the positions of the heads of A after the move of the j-th head. Weomit the details of the behaviour of A’ if one of the heads of A goes out of the St&g. The vector of initial positions of the heads of A is (1, 1s l*v 1) (in reality g(w) could begin in the position corresponding to this vector) which corresponds to the first proper position in g(w). A’ remembers in its finite memory for each i the last scanned i-symbol. These symbols correspond to the symbols scanned by the heads of A. In this manner A’ simulates A on g(w) and A’ accepts g(w) iff A accepts w. This completes the proof. Theorem I. If T(n) is the time to recognize context-
free languagesthen every language L E MDA(k) can be recognized in O(T(nk)) time. Proof.The thesis follows from Lemmas 1 and 2, the fact that CFL = NPDA(k) and that g(w) can be generated by a deterministic Turing machine in O(iwlk) time. Remark. Aithough in this paper we are primarily
interested in time complexity we show now how Lemma 2 can be applied to derive a theorem about the tape complexity of NPDA(k). Every npda(k) accepts a given input iff it accepts the input in time which is linear in the number of the moves of its input heads. There are at most n k moves of k oneway input heads. Hence applying Theorem 2 from [7] we obtain the following result: npda(k) languages l
have tape complexity (log2 nJ2. The same result can be obtained directly fi om Lemmas 1 and 2 because
the tape complexity of CFL is (log2rQ2and the Turing machine can treat the input w as the virtual input g(w) using some auxiliary counters (requiring log n space). Thus npda(k) language recognition is
reduced to context-free language recognition in the sense of space complexity.
143
Volume 13, numbers 4,s
INFORMATION PROCESSING LETTERS
References [l] A. Aho, J. Hopcroft and J. Ulhan, Time and tape complexity of pushdown automaten languages, Inform. and Control 13 (1968) 186-206. [2] 2. Galil, Some open problems in the theory of computation as questions about two-way deterministic pushdown automaton languages, Math. systems Theory 10 (1937) 211-228. {3] M. Harrison, Introduction to Formal YLanguageTheory (Addison-Wesley, Reading, M,4,1978). [4] 0. lbarra, On two-way multihead automata, J. Comput. System Sci 7 (1973) 28-36.
144
&d 1981
[S] 0. Ibarm, chara~terizationaof mm6tapeand timecanplexity classes of Turing machines in term@of n&had and auxiliary stack automata,J. Comput.SystemSci. 7
(1973) 88- 117. (6 ] L. Valiant, Generalcontext-freerecognition’in 171 181 (1975) 499.soo.