Time complexity of loop-free two-way pushdown automata

Time complexity of loop-free two-way pushdown automata

Information Processing Letters 16 (1983) 127-129 North-Holland Publishing Company TIME COMPLEXITY Wojciech Institute 15 April 1983 OF LOOP-FREE TW...

216KB Sizes 1 Downloads 33 Views

Information Processing Letters 16 (1983) 127-129 North-Holland Publishing Company

TIME COMPLEXITY Wojciech Institute

15 April 1983

OF LOOP-FREE

TWO-WAY PUSHDOWN

AUTOMATA

RYTTER

of Informatics,

Warsaw Unroerstty, 00-901

Warsrawa,

PKiN

VIII p, skr.pocz.

1210, Poland

Communicated by W.M. Turski Received I November 1982

Kqwords:

Two-way

pushdown

automata,

simulation,

time complexity

1. Introduction In this paper we consider time complexity of languages recognized by two-way nondeterministic pushdown automata with one input head (2npda’s, for short). The best known upper bound on time complexity of 2npda languages is still O(n) (see [l]), while there are algorithms recognizing lnpda (context-free) languages in less than cubic time (see [5,9]). None of these algorithms works for 2npda’s. In [7] the bound O(n3) was improved for some very small subclasses of 2npda’s. In this paper we improve this bound for a large subclass of 2npda’s. We say that a Znpda A is loop-free if there is no possible infinite computation of A on any input word. The class of languages recognized by loopfree 2npda’s properly includes the class of context-free languages and we conjecture that it is equal to the class of all Znpda languages. We prove that each loop-free 2npda can be simulated in O(n3/log n) time. Our simulation is designed using the tabulation method [3,4,6] together with ideas of the ‘four Russians’ algorithm [2] and the fast on-line recognition of context-free languages [5]. Our model of the computation is a random access machine with the uniform cost criterion. 2. Preliminaries We refer the reader to [ 1,2] for the detailed definition of a Znpda. By a surface configuration of a Znpda A for a given input word w (configura0020-0190/83/$03.00

0 1983 North-Holland

tion, for short) we mean a vector x = (top, s, h), where top is an element of the stack alphabet, s a state of A and h a position of the input head. For x = (top, s, h) we write TOP(X) = top. The configuration only contains the top element of the stack; however, it is enough to determine the set of possible (nondeterministic) moves of A on a given moment. We assume without loss of generality that if a 2npda A accepts, then its stack is one-element, accepting configurations are pop configurations and each move of A is a pop or a push move. Moreover, assume that if A makes a pop move, then the next state and the next position of the input head are uniquely determined by the current configuration (pop moves are deterministic) and at most two different configurations can result from a given configuration by a push move. Let us fix a loop-free 2npda A and an input word w of length n. Let K denote the set of all configurations and x0 be the initial configuration. Observe that ]I(] = O(n), where ]I(] is the cardinality of K. We introduce some useful notation (as in [S]). For every configuration x = (top, s, h) define: (1) POP(x) is true iff x is a pop configuration; (2) PUSH(X) is true iff x is a push configuration; (3) xl = PUSHFI(X) and x2 = PUSHFZ(X) iff xl, x2 are configurations which can result from x by a push move (assume that xl G x2, where G is any linear order on K which is easily computable); (4) z = POPF(X, y) iff z results from y by a pop move (which determines the next state and the next position of the input head) and TOP(z) = TOP(X); 127

(5) TERM(X)= {y I there is a computation of A starting with x and one-element stack and ending with y and one-element stack). The elements of TERM(X) are called terminators of x. The simulation of A can be reduced to the computation of TERM. We assume (to ease the presentation) that for each x E K exactly one of the conditions POP(X), PUSH(X) holds. Moreover, if PUSH(X) is true, then PUSHFI(X), PUSHF2(x) are both defined and if POP(X) is true, then POPF(y, x) is defined for each x E K. The following recursive definition of the function TERM gives an (exponential time) algorithm to compute TERM:

TERM(X) =

if

then {x}

U

else

If A is loop-free, then TERMI called with the actual parameter x = x0 terminates and TERMI = TERM. For each x E K we compute TAB(X) at most once. The cost of computing TAB(X) is dominated by the cost of (1). For a given x the cost of computing (1) is O(n2), disregarding the cost of executing recursive calls in (1) (these costs are counted in other instances of the function). Hence the total cost of computing TERMI is 0(n3). We improve now the total cost of (1) by applying another type of the tabulation. Let

TERM(POPF(X,

y ETERM(PUSHFl(x))”

y)) .

3. Outline of the algorithm Let TAB be the array such that, for each x E K, TAB(X) contains a subset of K or a special value ‘ undefined’. Initially, TAB(X) = ‘ undefined’ for each x E K. S is the local variable whose values are subsets of K.

SnK,,SnK,

begin if TAB(X)

=

,...,

SnK,

can be computed in O(n log n) time (it can be done using any easily computable linear order on K). Let us fix such a partition of K and denote Sci, = S n Ki. We introduce the table TAB~ such that, for each 1 < i ( r and Sci, C Ki, TABI(i, Sci,) contains a subset of K or the special value ‘undefined’. Initially each entry of TAB~ contains the value ‘undefined’. There are 0(n3j2/log n) entries of TABI because there are O(2q) = 0(n’12) subsets of a given set Ki (IKil < q). We replace the instruction (1) by the following instruction: for

TERMl(X);

r = [lKl/ql.

TERM(PUSHF2(x))

In the next section we shall apply twice the tabulation method to obtain an efficient algorithm.

function

and

q = 1; log(n)]

We can partition K into r disjoint subsets K,, K Z,. . . , K,, each of size q (the last one can have a smaller size) in such a way that for any set S G K the sequence of sets

= POP(X)

15 April 1983

INFORMATION PROCESSING LETTERS

Volume 16, Number 3

i :=

1 to r do

begin

‘undefined’

compute SCi,; if TABl(i, S,,,) = ‘undefined’ then

then

begin TAB(X)

if

:= 8;

TABl(i,

then TAB(X):= else begin S := TERMl(PUSHFl(X)) POP(X)

s := {Z I Z = POPF(X,

TAB(X)

128

zlJ,jTERMl(Z);

{x} TAB(X):= y),

:= us

TERMI

TERM1

:= TAB(X)

TAB(X)

U TABl(i,

S,,,)

end;

U TERMi(PUSHFP(X));

end end; end;

SC,,):=

(2)

y E s};

(1)

We claim that now (after the replacement) the cost of computing TERMI is 0(n3/log n). The instruction (2) is executed O(n) times, hence the instruction TAB(X) := TAB(X) uTABl(i,

S,,,)

Volume

16, Number

3

INFORMATION

LETTERS

15 April 1983

References

is executed O(n . r) = O(n*/log

PROCESSING

n)

[)I A.V. Aho, J.E. Hopcroft

times, giving in total the cost O(n3/log n). The mstructlon TABI(I, SCi,): = . . . is executed at most once for each 1
A can be simulated

and J.D. Ullman, Time and tape complexity of pushdown automaton languages, Inform. and Control 13(3) (1968) 186-206. PI A.V. Aho, J.E. Hopcroft and J.D. Ullman, The Design and Analysis of Computer Algorithms (Addison-Wesley, Reading, MA, 1976) Section 6.6. [31 R. Bird, Tabulation techniques for recursive programs, ACM Comput. Surveys 12(4) (1980). of recur141 R. Bird, Improving programs by the introduction sion, Comm. ACM 20( 11)(1977). M.A. Harrison and W.L. Ruzzo, On-line [51S.L. Graham, context-free recognition in less than cubic time, Proc. STOC 8 (1976) 112-120. 161W. Rytter, The dynamic simulation of recursive and stack manipulating programs, Inform. Process. Lett. 13(2) (1981) 58-63. pushdown [71W. Rytter, A note on two-way nondeterministic automata, Inform. Process. Lett. 15(l) (1982) 5-9. of deterministic pushPI W. Rytter, An effective simulation down automata with many two-way and one-way heads, Inform. Process. Lett. 12(5) (1981) 234-236. recognition in less than cubic time, [91 L. Valiant, Context-free J. Comput. Systems Sci. 10 (1975) 308-315.

129