Essentials of Theoretical Computer Science-173-230
Essentials of Theoretical Computer Science-173-230
Thus far we have been concerned with two major topics: the discovery of an
appropriate model for computation and an examination of the intrinsic
properties of computation in general. We found that since Turing machines are
equivalent to prograns, they form an appropriate model for computation. But
we also discovered that in some sense they possessed far too much
computational power. Because of this we ran into great difficulty when we tried
to ask questions about them, and about computation in general. Whenever we
wished to know something nontrivial, unsolvability sprang forth. And even in
the solvable or recursive realm, we found intractability.
Finite Automata
Closure Properties
Nondeterministic Operation
Regular Sets and Expressions
Decision Problems for Finite Automata
Pushdown Automata
Unsolvable Problems for Pushdown Automata
Linear Bounded Automata
If we do not allow writing or two-way operation of the tape head, we have what
has been traditionally called a finite automaton. This machine is only allowed to
read its input tape and then, on the basis of what it has read and processed,
accept or reject the input. This restricted machine operates by:
a) Reading a symbol,
b) Transferring to a new instruction, and
c) Advancing the tape head one square to the right.
When it arrives at the end of its input it then accepts or rejects depending upon
what instruction is being executed.
Look closely at this machine. It stays on instruction one until it reads a one.
Then it goes to instruction two and accepts any input unless another one arrives
(the symbol 1 - not another input). If two or more ones appear in the input,
then it ends up executing instruction three and does not accept when the input
is over. And if no ones appear in the input the machine remains on instruction
one and does not accept. So, this machine accepts only inputs that contain
exactly one 1.
Finite Automata 2
(N.B. Endmarkers are not needed since the machine just moves to the right.
Accepting happens when the machine finishes the input while executing an
instruction that calls for acceptance. Try this machine out on the inputs 000,
0100, 1000100, etc.)
Traditionally these machines have not had instructions but states. (Recall A. M.
Turing's states of mind.) Another way to represent this same machine is to put
the next instruction or next state or goto portion under the input in a table like
that in figure 1.
1 1
1 2 3
0 0 0,1
Input
State Accept?
0 1
1 1 2 no
2 2 3 yes
3 3 3 no
(Note that the two circles that surround state two mean acceptance.)
Before continuing let's examine the computation of a finite automaton. Our first
example begins in state one and reads the input symbols in turn changing
states as necessary. Thus a computation can be characterized by a sequence of
states. (Recall that Turing machine configurations needed the state plus the
tape content. Since a finite automaton never writes, we always know what is on
the tape and need only look at a state as a configuration.) Here is the sequence
for the input 0001001.
Input Read: 0 0 0 1 0 0 1
States: 1 → 1 → 1 → 1 → 2 → 2 → 2 → 3
Finite Automata 3
Our next example is an elevator controller. Let's imagine an elevator that serves
two floors. Inputs are calls to a floor either from inside the elevator or from the
floor itself. This makes three distinct inputs possible, namely:
0 - no calls
1 - call to floor one
2 - call to floor two
The elevator itself can be going up, going down, or halted at a floor. If it is on a
floor it could be waiting for a call or about to go to the other floor. This
provides us with the six states shown in figure 2 along with the state graph for
the elevator controller.
0,2 2
W2 D2
W1 Waiting on first floor 0,2 0,1
U1 About to go up 1 1
UP Going up UP DN
DN Going down
0,2 0,1
W2 Waiting - second floor
D2 About to go down 2 2
W1 D1
0,1 1
Input
State
none call to 1 call to 2
W1 (wait on 1) W1 W1 UP
U1 (start up) UP U1 UP
UP W2 D2 W2
DN W1 W1 U1
W2 (wait on 2) W2 DN W2
D2 (start down) DN DN D2
Accepting and rejecting states are not included in the elevator design because
acceptance is not an issue. If we were to design a more sophisticated elevator,
it might have states that indicated:
Finite Automata 4
a) power failure,
b) overloading, or
c) breakdown
Let us make a few small notes about the design. If the elevator is about to move
(i.e. in state U1 or D2) and it is called to the floor it is presently on it will stay.
(This may be good - try it next time you are in an elevator.) And if it is moving
(up or down) and gets called back the other way, it remembers the call by going
to the U1 or D2 state upon arrival on the next floor. Of course the elevator does
not do things like open and close doors (these could be states too) since that
would have added complexity to the design. Speaking of complexity, imagine
having 100 floors.
That is our levity for this section. Now that we know what a finite automaton is,
we must (as usual) define it precisely.
We also need some additional notation. The next state function is called the
transition function and the accepting states are often called final states. The
entire machine is usually defined by presenting a state table or a state graph. In
this way, the states, alphabet, transition function, and final states are
constructively defined. The starting state is usually the lowest numbered state.
Our first example of a finite automaton is:
At this point we must make a slight detour and examine a very important yet
seemingly insignificant input string called the empty string. It is a string
without any symbols in it and is denoted as ε. It is not a string of blanks. An
example might make this clear. Look between the brackets in the picture below.
Finite Automata 5
[] []
Let's look again at a computation by our first finite automaton. For the input
010, our machine begins in s1, reads a 0 and goes to δ(s1,0) = s1, then reads a 1
and goes to δ(s1,1) = s2, and ends up in δ(s2,0) = s2 after reading the final 0. All
of that can be put together as:
δ(δ(δ(s1,0),1),0) = s2
Definition. Let M = (S,I,δ,s0,F). For any input string x, input symbol a, and
state si, the transition function on strings δ* takes the values:
δ*(si,(*e) = si
δ*(si,a) = δ(si,a)
δ*(si,xa) = δ(δ*(si,x),a).
That certainly was terse. But, δ* is really just what one expects it to be. It
merely applies the transition function to the symbols in the string. Let's look at
this for the example in figure 3.
b
s0 s1
a a b
s3 s2
a,b a,b
This machine has a set of states = {s0 , s1 , s2 , s3} and operates over the input
alphabet {a, b}. Its starting state is s0 and its set of final or accepting states, F =
{s2}. The transition function is fully described twice in figure 3; once in figure
3a as a state table and once in figure 3b as a state graph.
Finite Automata 6
Input
State Accept?
a b
0 3 1 no
1 3 2 no
2 2 2 yes
3 3 3 no
If the machine receives the input bbaa it goes through the sequence of states:
while when it gets an input such as abab it goes through the state transition:
Now we shall become a bit more abstract. When a finite automaton receives an
input string such as:
x = x1 x2 ... xn
where the xi are symbols from its input alphabet, it progresses through the
sequence:
s k 1 , sk 2 , ... , sk n+1
sk1 = s0
sk2 = δ(sk1 , x1) = δ(s0 , x1)
sk3 = δ(sk2 , x2 ) = δ ∗ (s0 , x1x 2 )
!
skn+1 = δ(skn , xn ) = δ ∗ (s0 , x1x2 ...xn )
i 1 2 3 4 5 6
xi b b a b a
sk i s0 s1 s2 s2 s2 s2
Finite Automata 7
We have mentioned acceptance and rejection but have not talked too much
about it. This can be made precise also.
This set of accepted strings (named T(M) to mean Tapes of M) is merely all of
the strings for which M ended up in a final or accepting state after processing
the string. For our first example (figure 1) this was all strings of 0's and 1's that
contain exactly one 1. Our last example (figure 3.1.3) accepted the set of strings
over the alphabet {a, b} which began with exactly two b's.
Closure Properties
Removing power from Turing machines provided us with a new machine. We
also found a new class of sets. Now it is time to examine this class. Our first
questions concern operations on sets within the class.
Set complement is our first operation to examine. Since we are dealing with
strings (rather than numbers), we must redefine this operation. Thus the
definition of complement will slightly different. This is to be expected because
even though 0100 and 100 are the same number, they are different strings.
Here is the definition. If a set contains strings over an alphabet, then its
complement contains all of the strings (over the alphabet) not in the set.
Proof. Let the finite automaton M = (S, I, δ, s0, F) accept the set T(M). We
must now show that there is a finite automaton which accepts the set of
strings over the alphabet I which M does not accept. Our strategy will be
to look at the operation of M, accepting when it rejects and rejecting
when M accepts. Since we know that strings which take M to a state of F
are accepted by M and those which take M into S-F are rejected, then our
course is fairly clear. Consider the machine:
It is exactly the same as M except for its final or accepting states. Thus it
should accept when M rejects. When we precisely examine this, we find
that for all strings x over the alphabet I:
The last proof contained an example of our first method of dealing with finite
automata: rearranging an existing machine. Now we shall employ another
strategy: combining two machines. This is actually going to be parallel
Closure Properties 2
processing. Suppose we take the two machines whose state graphs are in figure
1.
a
b
s0 s1 q0
a a b a
b
a
s3 s2 q q2
1 b
a,b a,b b
(a) (b)
Figure 1 - Finite Automaton Examples
We have seen the machine (M1) of figure 1a before, it accepts all strings (over {a,
b}) which begin with two b's. The other machine (M2) accepts strings which end
with two b's. Let's try to combine them into one machine which accepts strings
which either begin or end with two b's.
Why not run both machines at the same time on an input? We could keep track
of what state each machine is in by placing pebbles upon the appropriate states
and then advancing them according to the transition functions of each machine.
Both machines begin in their starting states, as pictured in the state graphs
below
b
s1
a a b a
b
a
s3 s2 q q2
1 b
a,b a,b b
with pebbles on s0 and q0. If both machines now read the symbol b on their
input tapes, they move the pebbles to new states and assume configurations
like these
Closure Properties 3
b
s0 q0
a a b a
b
a
s3 s2 q2
b
a,b a,b b
with pebbles on s1 and q1. The pebbles have advanced according to the
transition functions of the machines. Now let's have them both read an a. At
this point, they both advance their pebbles to the next state and enter the
configurations
b
s0 s1
a a b a
b
a
s2 q q2
1 b
a,b a,b b
With this picture in mind, let's trace the computations of both machines as they
process several input strings. Pay particular attention to the pairs of states the
machines go through. Our first string is bbabb, which will be accepted by both
machines.
Input: b b a b b
M1's states s0 s1 s2 s2 s2 s2
M2's states q0 q1 q2 q0 q1 q2
Input: b a b a b
M1's states s0 s1 s3 s3 s3 s3
M2's states q0 q1 q0 q1 q0 q1
And finally, the string baabb which will be accepted by M2 but not M1.
Closure Properties 4
Input: b a a b b
M1's states s0 s1 s3 s3 s3 s3
M2's states q0 q1 q0 q0 q1 q2
We shall try the multiprocessing pebble machine concept and work it into
the definition of finite automata. Thus the states of M3 are pairs of states
(one from M1 and one from M2). This works out nicely since the set of
pairs of states from S and Q is known as the cross product (written S×Q)
between S and Q. The starting state is obviously <s0 , q0>. Thus:
Our final states are all of the pairs which contain a state from F or a state
from G. In cross product notation this is:
H = (F×Q) ∪ (S×G).
By manipulating the notation we have shown that two finite automata can be
combined. Let's take a look at the result of applying this construction to the
machines of figure 1. (This is pictured in figure 2.)
a
b
a sq sq
sq 3 0 3 1
0 0
a
b a a b
sq sq sq
1 1 2 1 32
b
b b
a b
sq sq
2 2 2 0
a
b a
Note that not all pairs of states are included in the state graph. (For example,
<s0, q1> and <s1, q2> are missing.) This is because it is impossible to get to
these states from <s0 , q0>.
Closure Properties 6
a
b
a sq sq
sq 3 0 3 1
0 0
a
b a a b
sq sq sq
1 1 2i 32
b
a,b b
This is very likely what anyone would design if they had to build a machine
from scratch rather than use the construction detailed in the theorem. Lest
anyone think that finding smaller, equivalent machines is always this simple, we
must admit that this was an elementary example and we did some prior
planning to provide such clean results.
The final Boolean operation is set intersection. We state this here and leave the
proof as an exercise in Boolean algebra identities (De Morgan's Laws) or
machine construction - as you wish!
a
s0 S2 s1
b
b b a a
s3 s4
b
a,b a
If the input to this machine begins with the string ab, it will progress from s0 to
s1 to s2. Now, if the next input symbol is an a, it has a choice of whether to go
back to s1 or to move to s4. So, now what does it do? Well, it transfers to the
state which will eventually take it into a final state if possible. Simple as that!
But, how does it know when it has not seen the remainder of the input yet? Do
not worry about that - it always chooses the right state!
The above explanation of the operation of the machine of figure 1 is a slight bit
mystical. But we can (if we wish) define machines with choices in their
transition functions. And we can (if we wish) define acceptance to take place
whenever a correct sequence of states under the input will end up in a final
state. In other words, if the machine can get to a final state in some proper
manner, it will accept. Now for a formal definition.
b
s0 s1
a
b a
a
s2 s3
b
a,b a
Input Accept?
State
a b
0 1,3 2 yes
1 3 0 no
2 2 2 no
3 3 2 yes
(N.B. We must note that the transition indicator δ is not a function any more.
To be precise about this we must state that it has become a relation. In other
words, since δ(s, a) is a set, it indicates which states are members of δ(s, a). If
that is confusing then forget it and consider δ(s, a) to be a set.) Our next step is
to define acceptance for nondeterministic finite automata. We could extend the
transition indicator so that it will handle strings. Since it provides a set of next
states, we will just note the set of states the machine is in after processing a
string. Let's look at a picture. Think about the last machine (the one in figure
2). Now imagine what states it might go through if it processed all possible
strings of length three. Now, look at figure 3.
Nondeterministic Operation 3
s0
a a b
s1 s3 s2
a b a b a,b
s3 s0 s3 s2 s2
a b a a b a b a,b a,b
s3 s2 s1 s3 s2 s3 s2 s2 s2
In processing the string abb, the machine ends up in s2, but it can get there in
two different ways. These are:
s0 → s1 → s0 → s2
s0 → s3 → s2 → s2
Likewise, the machine can end up in 3 after processing the string aaa. But since
the automaton is nondeterministic, it can have the option of ending up in
several states after processing an input. For example, after aba, the set of states
{s1 , s2 , s3} is reached.
In fact, a set of states is reached by the machine after processing an input. This
set depends upon the choices the automaton was offered along the way. And, if
a final state was in the set reached by the machine, we accept. In the above
example only the strings aba and aaa can be accepted because they were the
only strings which took the automaton into s3.
This gives a definition of δ* as the set of states reached by the automaton and
the tapes accepted as:
T(M) = { x | δ*(s0,x) ∩ F ≠ ∅ }
state to a final state under the input string. (Note that we do not discuss how a
machine might find this sequence - that does not matter! We just say that the
input is accepted if there exists such a sequence of states.)
With this definition of acceptance in mind, we define the set of tapes accepted
by a nondeterministic finite automaton (denoted T(M) as before) as exactly
those inputs for which there is a sequence of states leading from a starting
state to an accepting state.
The rest of the transition relation ξ is just a combination of δ and γ, and the
state graph for the new union machine might resemble:
S'
M 1 's M 2's
state state
graph graph
Nondeterministic Operation 5
Thus the union machine is M = (S∪Q∪{s'}, I, ξ, s', F∪G). Acceptance takes place
whenever there is a sequence to an accepting state through either the state
graph of M1 or that of M2.
Let's try another closure property and build a nondeterministic machine which
realizes it. This will be a string property called concatenation or juxtaposition.
For strings this is easy, the concatenation of x and y is xy. If we have the sets A
and B then the concatenation of them is defined as:
AB = { xy | x ∈ A and y ∈ B }.
M3 = (S∪Q, I, ξ, {s0}, G)
and define ξ so that M3 accepts AB. Our strategy will be to start out processing
as M1 might and then when M1 wishes to accept a part of the input, switch to
M2 and continue on. With any luck we will end up in G, the final state set of
M2. Nondeterminism will be used to make the change from M1 to M2. The
transition relation ξ will operate just like δ on the state set S and like γ on the
state set Q except for the final states F ⊆ S. There it will include a transition to
the starting state q0 of M2. One might picture this as:
q0
S-F
Q
F
T(M3) = AB = T(M1)T(M2)
noting that the only way to get from s0 to a state in G via ξ is via a string in AB.
A final note on the machine M3 which was just constructed to accept AB. If A
contains the empty word then of course s0 is a final state and thus q0 also must
be a member of the starting state set. Also, note that if B contains the empty
word, then the final states of M3 must be F∪G rather than merely G.
A0 = {ε}
A1 = A
A2 = AA
A3 = AA2 = AAA
Nondeterministic Operation 7
A0 = {ε}
Ai+1 = AiA
Definition. The Kleene Closure (written A*) of the set A is the union of Ak
over all integer values of k.
γ(s',a) = {δ(s0,a)}
γ(si,a) = {δ(si,a)} for si ∈ S-F
γ(si,a) = { s0, δ(si,a)} for si ∈ F
The machine which accepts [T(M)]* is M' = (S∪{s'},I,γ,{s'},F∪{s'}). Now that we have
seen how useful nondeterministic operation can be in the design of finite
automata, it is time to ask whether they have more power than their
deterministic relatives.
Nondeterministic Operation 8
To show the other necessary relation we must demonstrate that every set
accepted by a nondeterministic machine can be accepted in a
deterministic manner. We shall bring forth again our pebble automaton
model.
Since we moved pebbles on all of the paths Mn could have taken from a
starting state to a final state (and we did not miss any!), we should accept
whenever Mn does. And, also, if we accept then there was indeed a path
from a starting state to a final state. Intuitively it all seems to work.
But, can we define a deterministic machine which does the job? Let's try.
First let us define some states which correspond to the pebbled states of
Mn. Consider:
q1 means a pebble upon s0
q2 means a pebble upon s1
q3 means pebbles upon s0 and s1
q4 means a pebble upon s2
q5 means pebbles upon s0 and s2
•
•
•
q means pebbles upon s0, s1, ... ,sn
2n+1 −1
Nondeterministic Operation 9
This is our state set Q. The starting state is the qk which means pebbles
on all of S0. Our set of final states (G) includes all qi which have a pebble
on a state of F. All that is left is to define the transition function γ and we
have defined a deterministic finite automaton Md = (Q, I, γ, qk, G) which
should accept the same set as that accepted by Mn.
This is not difficult. Suppose qi means pebbles upon all of the states in s'
⊆ S. Now we take the union of δ(sk,a) over all sk ∈ s' and find the qj
which means pebbles on all of these states. Then we define γ(qi, a) = qj.
With this theorem and our previous constructions firmly in mind, we now state
the following.
We shall build expressions from the symbols 0, 1, +, and & using the operations
of union, concatenation, and Kleene closure. Several intuitive examples of our
notation are:
OK, fine. Regular expressions are strings put together with zeros, ones,
epsilons, stars, plusses, and matched parentheses in certain ways. But why did
we do it? And what do they mean? We shall answer this with a list of what
various general regular expressions represent. First, let us define what some
specific regular expressions represent.
Regular Sets 2
Now for some general cases. If α and β are regular expressions representing the
sets A and B, then:
The sets which can be represented by regular expressions are called regular
sets. When writing down regular expressions to represent regular sets we shall
often drop parentheses around concatenations. Some examples are 11(0 + 1)*
(the set of strings beginning with two ones), 0*1* (all strings which contain a
possibly empty sequence of zeros followed by a possibly null string of ones),
and the examples mentioned earlier. We also should note that {0,1} is not the
only alphabet for regular sets. Any finite alphabet may be used.
From our precise definitions of the regular expressions and the sets they
represent we can derive the following nice characterization of the regular sets.
Then, very quickly we shall relate them to finite automata.
Theorem 1. The class of regular sets is the smallest class containing the
sets {0}, {1}, {ε}, and ∅ which is closed under union, concatenation, and
Kleene closure.
See why the above characterization theorem is true? And why we left out the
proof? Anyway, that is all rather neat but, what exactly does it have to do with
finite automata?
Proof. The singleton sets {0}, {1}, {ε}, and ∅ can all be accepted by finite
automata. The fact that the class of sets accepted by finite automata is
closed under union, concatenation, and Kleene closure completes the
proof.
Just from closure properties we know that we can build finite automata to
accept all of the regular sets. And this is indeed done using the constructions
Regular Sets 3
until the desired machine has been built. This is easily done automatically, and
is not too bad after the final machine is reduced. But it would be nice though to
have some algorithm for converting regular expressions directly to automata.
The following algorithm for this will be presented in intuitive terms in language
reminiscent of language parsing and translation.
Initially, we shall take a regular expression and break it into subexpressions. For
example, the regular expression (aa + b)*ab(bb)* can be broken into the three
subexpressions: (aa + b)*, ab, and (bb)*. (These can be broken down later on in
the same manner if necessary.) Then we number the symbols in the expression
so that we can distinguish between them later. Our three subexpressions now
are: (a1a2 + b1)*, a3b2, and (b3b4)*.
Symbols which lead an expression are important as are those which end the
expression. We group these in sets named FIRST and LAST. These sets for our
subexpressions are:
Note that since the FIRST subexpression contained a union there were two
symbols in its FIRST set. The FIRST set for the entire expression is: {a1 , a3 , b1}.
The reason that a3 was in this set is that since the first subexpression was
starred, it could be skipped and thus the first symbol of the next subexpression
could be the first symbol for the entire expression. For similar reasons, the
LAST set for the whole expression is {b2 , b4}.
Formal, precise rules do govern the construction of the FIRST and LAST sets.
We know that FIRST(a) = {a} and that we always build FIRST and LAST sets from
the bottom up. Here are the remaining rules for FIRST sets.
Regular Sets 4
Examining these rules with care reveals that the above chart was not quite what
the rules call for since empty strings were omitted. The correct, complete chart
is:
Rules for the LAST sets are much the same in spirit and their formulation will
be left as an exercise.
One more notion is needed, the set of symbols which might follow each symbol
in any strings generated from the expression. We shall first provide an example
and explain in a moment.
Symbol a1 a2 a3 b1 b2 b3 b4
FOLLOW a2 a1, a3, b b2 a1, a3, b1 b3 b4 b3
Now, how did we do this? It is almost obvious if given a little thought. The
FOLLOW set for a symbol is all of the symbols which could come next. The
algorithm goes as follows. To find FOLLOW(a), we keep breaking the expression
into subexpressions until the symbol a is in the LAST set of a subexpression.
Then FOLLOW(a) is the FIRST set of the next subexpression. Here is an example.
Suppose that we have αβ as our expression and know that a ∈ LAST(α). Then
FOLLOW(a) = FIRST(β). In most cases, this is the way it we compute FOLLOW
sets.
Regular Sets 5
Another example. Let's find the FOLLOW set for b1 in the regular expression (a1
+ b a *)*b *(a + b ). First we break it down into subexpressions until b is in a
1 2 2 3 3 1
LAST set. These are:
After computing all of these sets it is not hard to set up a finite automaton for
any regular expression. Begin with a state named s0. Connect it to states
Regular Sets 6
denoting the FIRST sets of the expression. (By sets we mean: split the FIRST set
into two parts, one for each type of symbol.) Our first example (a1a2 +
b )*a b (b b )* provides:
1 3 2 3 4
a
s0 a1,3
b1
Next, connect the states just generated to states denoting the FOLLOW sets of
all their symbols. Again, we have:
a b
s0 a1,3 b
2
b a a
b1 a2
a b b2
s0 a1,3
b a a a a b
b1 a2 b3
b
a
b
b b
sr b4
a
a,b
Regular Sets 7
a b b2,4
s0 a1,3
b a a a b b
a2b sr b3
1 a
b a,b
a a1,3
s0
b b
a a
b 123 123
b
b a
We now close this section with the equivalence theorem concerning finite
automata and regular sets. Half of it was proven earlier in the section, but the
translation of finite automata into regular expressions remains. This is not
included for two reasons. First, that it is very tedious, and secondly that nobody
ever actually does that translation for any practical reason! (It is an interesting
demonstration of a correctness proof which involves several levels of iteration
and should be looked up by the interested reader.)
Theorem 3. The regular sets are exactly those sets accepted by finite
automata.
Decision Problems for Finite Automata
Now we wish to examine decision problems for the sets accepted by finite
automata (or the regular sets). When we tried to decide things concerning the
r.e. sets we were disappointed because everything nontrivial seemed to be
unsolvable. Our hope in defining finite automata as a much weaker version of
Turing machines was to gain solvability at the expense of computational power.
Let us see if we have succeeded. Our first result indicates that we have.
Proof. This is very easy indeed. With a universal Turing machine we can
simulate any finite automaton. To decide whether it accepts an input we
need just watch it for a number of steps equal to the length of that input.
So far, so good. In order to decide things a bit more intricate than membership
though, we need a very useful technical lemma which seems very strange
indeed until we begin to use it. It is one of the most important results in finite
automata theory and it provides us with a handle on the finiteness of finite
automata. It tells us that only the information stored in the states of a finite
automaton is available during computation. (This seems obvious, but the proof
of the following lemma points this out in a very powerful manner.)
a) x = uvw,
b) v is not the empty string, and
c) for all k ≥ 0, uvkw ∈ T(M).
s j ,...,s j
1 n +1
Finite Automata Decision Problems 2
a) s j = s0,
1
b) for each i ≤ n, δ(s j ,xi) = s j , and
i i+1
c) s j ∈ F.
n+1
Since M has no more than n states (our initial assumption about the
length of x not being less than the number of M’s states), at least one of
the states in the sequence must be repeated because there are n+1 states
in the sequence. We shall assume that this repeat occurs at s ja and s j
b
where a < b.
Now let's consider the string xa ... xb-1, the portion of the input which is
processed by M as it goes through the sequence of states s ja , ... ,s j . We
b
shall say that v is this substring of x and note that since a < b, v ≠ ε. Now
we shall assign the remaining characters of x to u and w. The following
picture illustrates this.
← u → ← v → ← w →
In other words, M enters and leaves the substring v in the same state. Now
we shall examine exactly what this means. If we were to omit v and
process uw, M would leave u in s ja = s j and finish w in s j just as
b n+1
before. Thus uw is in T(M). If we were to make M process uvvw then M
would leave uv in s j = s ja , leave uvv in s j and finish w in the same
b b
state as before. Thus uvvw ∈ T(M). In fact, no matter how many times we
add another v between u and w, M always leaves and enters each v in s ja
and therfore finishes the entire input in the same final state. Thus for
any k ≥ 0, uvkw ∈ T(M).
Finite Automata Decision Problems 3
If we go back and examine our proof of the pumping lemma, we find that we
can prove something a little more powerful. In fact, something that will come
in handy in the future. Something which will make our lives much more
pleasing. Here it is.
Proof. Just note that in any substring of x which is no shorter than the
number of states, we can find a repeated state while processing. This
provides a v and the proof proceeds as before.
This technical lemma (referred to as the pumping lemma from now on) is one of
the most useful results in theoretical work involving finite automata and the
regular sets. It is the major tool used to
The usefulness of the pumping lemma comes from the fact that it dramatically
points out one of the major characteristics of finite automata, namely that they
have only a finite amount of memory. Another way to state this is to say that if
a finite automaton has n states, then it can only remember n different things! In
fact, if δ*(s0, x) = δ*(s0, y) then the machine with the transition function δ
cannot tell the difference between x and y. They look the same to the machine
since they induce the same last state in computations involving them. And, if a
finite automaton accepts a very long string, then chances are that this string
contained repetitive patterns.
Our first use of the pumping lemma will be to present a non-regular set. This is
the favorite example for computer science theorists and illustrates the method
almost always used to prove sets non-regular.
Theorem 2. The set of strings of the form {0n1n} for any n ≥ 0 is not a
regular set.
Proof. Assume that the set of strings of the form 0n1n is a regular set
and that the finite automaton M = (S, I, δ, s0, F) accepts it. Thus every
string of the form 0k1k for k larger than the size of the state set S will be
accepted by M.
If we take one of these strings for some k > |S| then the pumping lemma
assures us that there are strings u, v, and w such that:
Finite Automata Decision Problems 4
a) uvw = 0k1k,
b) v ≠ ε, and
c) for all n ≥ 0, uvnw ∈ T(M).
Next, we shall use the deflation aspect of the pumping lemma in order to show
that emptiness is solvable for regular sets.
Proof. Let M be a finite automaton which accepts the string x and that
the length of x is no less than the size of M's state set. Assume further
that M accepts no strings shorter than x. (This is the opposite of our
theorem.)
Immediately the pumping lemma asserts that there are strings u, v, and w
such that uvw = x, v ≠ ε, and uw ∈ T(M). Since v ≠ ε, uw is shorter than
uvw = x. Thus M accepts shorter strings than x and the theorem follows.
Here is a sequence of corollaries which follow from the last theorem. In each
case the proof merely involves checking membership for all strings of length
less than the size of the state set for some finite automaton or the machine
which accepts the complement of the set it accepts. (Recall that the class of
regular sets, namely those accepted by finite automata is closed under
complement.)
Thus, to solve the finiteness problem for M = (S, I, δ, s0, F), we need to
determine whether or not:
Proof. Let's take two finite automata (M1 and M2) and examine a picture
of the sets they accept.
T(M1 ) T(M2 )
If the intersection is the same as both sets then indeed they are identical.
Or, on the other hand, if the areas outside the intersection are empty then
both sets are identical. Let's examine these outside areas.
T(M1 ) T(M2 )
The picture on the left represents the set accepted by M1 and rejected by
M2 while that on the right is the set which M2 accepts and M1 rejects.
If these two areas (or sets) are empty then the sets accepted by M1 and
M2 are exactly the same. This means that the equivalence problem for
T(M1) and T(M2) is exactly the same as the emptiness problem for:
[ T(M1) ∩ T(M2 ) ] ∪ [ T(M2 ) ∩ T(M1) ]
So, if we can solve the emptiness problem for the above set, then we can
solve the equivalence problem for T(M1) and T(M2). Since the regular sets
are closed under union, complement, and intersection; the above set is a
regular set. And, we know that emptiness is solvable for the class of
regular sets.
Here is yet another cautionary note. The last proof was quite slick and elegant,
but one should not do the construction in an attempt to prove that two finite
Finite Automata Decision Problems 7
automata accept the same set. We know that the complexity of any algorithm
which attempts to do this is very large since it would take a while to do
emptiness for a machine formed from the unions and intersections of four
different machines.
Let's begin. In fact, let's provide a finite automaton with a data structure which
will allow it to recognize strings of the form anbn. To tell if a string is of the
form anbn we need to match the a's with the b's. We could use a counter for
this, but thinking ahead a bit, there is a computer science way to do this. We
shall allow the machine to build a pile of discs as it processes the a's in its
input. Then it will unpile these disks as it passes over the b's. Consider the
following algorithm for a machine of this kind.
n n
Figure 1 - a b Recognition Algorithm
It is clear exactly what happens when the algorithm of figure 1 is used on the
input aaabbb. The machine reads the a's and builds a pile of three discs. Then
it reads the b's and removes the discs from the pile one by one as each b is
read. At this point it has finished the input and its pile is empty so it accepts.
If it was given aabbb, it would place two discs on the pile and then remove them
Pushdown Automata 2
as it read the first two b's. Then it would leave the second while loop with one
b left to read (since the pile was empty) and thus not accept. For aaabb it would
end with one disk on the pile and not accept that input either. When given the
input string aabbab, the machine would finish the second loop with ab yet to be
read. Now, try the strings aaa and bbb as exercises. What happens?
We now have a new data structure (a pile) attached to our old friend, the finite
automaton. During the last algorithm several conventions implicitly arose.
They were:
Let us now attempt something a bit more difficult. Here's where we shall use a
structure more powerful than a counter. Why not try to recognize strings of the
form w#wR where w is a string over the alphabet {a, b} and wR is the reversal of
the string w? (Reversal is just turning the string around end for end. For
example, abaaR = aaba.) Now we need to do some comparing, not just counting.
Examine the algorithm of figure 2.
repeat
if (symbol scanned = a and red disk on pile)
or (symbol scanned = b and blue disk on pile)
then remove top disk; advance input head
until (pile is empty) or (no input remains)
or (no disk removed)
We will now look at what happens to the disc pile when this machine processes
the input string abaa#aaba. Here is a picture:
Input: a b a a # a a b a
red red
Pile: red red red red
blue blue blue blue blue blue
red red red red red red red red
At the right end of the picture, the machine reads the a and removes the red
disk from the stack. Since the stack is empty, it accepts.
Our first machine (figure 1) used its discs to count the a's and match them
against the b's. The second machine (figure 2) used the pile of discs to full
advantage in that it compared actual symbols, not just the number of them.
Note how this machine recorded the symbols before the marker (#) with discs
and then matched them against the symbols following the marker. Since the
input was completely read and the pile was empty, the machine accepted.
Input: a b a a # a a a
red red
Pile: red red red red
blue blue blue blue blue blue
red red red red red red red
In this case, the machine stopped with ab yet to read and discs on the pile since
it could not match an a with the blue disc. So, it rejected the input string. Try
some more examples as exercises.
The machines we designed algorithms for above in figures 1 and 2 are usually
called pushdown automata. All they are is finite automata with auxiliary
storage devices called stacks. (A stack is merely a pile. And symbols are
normally placed on stacks rather than various colored discs.) The rules
involving stacks and their contents are:
We call placing a symbol upon the stack a push operation and removing one
from the top of the stack a pop operation.
Pushdown Automata 4
i n p u t t a p e
f in it e
s
contro l
t
a
c
k
Pushdown automata can be presented as state tables in very much the same
way as finite automata. All we need to add is the ability to place (or push)
symbols on top of the stack and to remove (or pop) symbols from the top of the
stack. Here is a state table for our machine of figure 1 which accepts strings of
the form anbn.
Note that this machine operates exactly the same as that of the algorithm in
figure 1. During operation, it:
Thus, the states of the pushdown machine perform exactly the same as the
while loops in the algorithm presented in figure 1.
A trace of the computation for the above pushdown automaton on the input
aaabbb is provided in the following picture:
Pushdown Automata 5
A
Stack: A A A
A A A A A
A
Stack: A A A
A A A A A
In the first computation (for input aaabbb), the machine ended up in state s2
with an empty stack and accepted. The second example ended with an A on the
stack and thus the input aaabb was rejected. If the input was aaabba then the
following would take place:
A
Stack: A A A
A A A A A
In this case, the machine terminates computation since it does not know what
to do in s2 with an a to be read on the input tape. Thus aaabba also is rejected.
Our second machine example (figure 2) has the following state table.
Note that it merely records a's and b's on the stack until it reaches the marker
(#) and then checks them off against the remainder of the input.
Pushdown Automata 6
Note that the input string decreases in length by one each time a configuration
yields another. This is because the pushdown machine reads an input symbol
every time it goes through a step.
There are other conventions for defining pushdown automata which are
equivalent to that proposed above. Often machines are provided with an initial
stack symbol Z0 and are said to terminate their computation whenever the stack
is empty. The machine of figure 2 might have been defined as:
Pushdown Automata 7
where in state s1 the symbols which were popped are placed back upon the
stack.
Converting this example to this format merely involves detecting when the
stack has only one symbol upon it and changing to an accepting state if things
are satisfactory at this point. We do this by placing special sentinels (X and Y)
on the bottom of the stack at the beginning of the computation. Here is our
example with s3 as an accepting state. (Note that the machine accepts by empty
stack also!).
All of these conventions are equivalent (the proofs of this are left as exercises)
and we shall use any convention which seems to suit the current application.
Now to get on with our examination of the exciting new class of machines we
have defined. Our first results compare them to other classes of automata we
have studied.
Proof. This is very easy indeed. Since finite automata are just pushdown
machines which do not ever use their stacks, all of the regular sets can be
accepted by pushdown machines which accept by final state. Since
strings of the form an bn can be accepted by a pushdown machine (but
not by any finite automaton), the inclusion is proper.
Proof. For the same reason that the regular sets are recursive. Pushdown
machines are required to process an input symbol at each step of their
computation. Thus we can simulate them and see if they accept.
As you may have noticed (and probably were quite pleased about), the
pushdown machines designed thus far have been deterministic. These are
usually called dpda's and the nondeterministic variety are known as npda's. As
with nondeterministic finite automata, npda's may have several possible moves
for a configuration. The following npda accepts strings of the form wwR by
nondeterministicly deciding where the center of the input string lies.
Note that in s0 there are choices of either to remain in s0 and process the w
part of wwR or to go to s1 and process the wR portion of the input. Here is an
example computation of the machine on the string abbbba.
B
Stack: B B B
A A A A A
One should note that the machine does in fact change from s0 to s1 when bba
remains to be read and a B is on top of the stack. We shall not prove it here, but
nondeterminism does indeed add power to pushdown machines. In fact, the set
of strings of the form wwR cannot be accepted by a deterministic pushdown
automaton because it would have no way to detect where the center of the input
occurs.
The strategy for the machine design is based on the method in which these
simple expressions are generated. Since an expression can be:
a) a variable,
b) a variable, followed by a plus, followed by an expression, or
c) an expression enclosed in parentheses.
Here is a simple but elegant, one state, nondeterministic machine which decides
which of the above three cases is being used and then verifies it. The machine
begins computation with the symbol E upon its stack.
Lemma. The set of strings that are valid Turing machine configurations is
a regular set.
Since the regular sets are closed under concatenation and Kleene star these
kinds of strings form a regular set also.
Now let us examine just what makes a sequence of valid Turing machine
configurations not a valid halting computation for a particular machine. Either:
Parts (1) and (2) are easy to recognize. An initial configuration is merely a string
of the form (I1)[0+1+b]* and a halting configuration is a string of the form
[0+1+b]*. These are both regular sets. Part (3) is regular also because Turing
machine instructions are required to be members of a sequence beginning at I1
and there can be only a finite number of them for a particular Turing machine.
Thus this is regular also because a finite automata can recognize finite sets.
Let us now put this in the form of a lemma that we shall use later when we wish
to build a pushdown machine which check Turing machine computations.
Lemma. For each Turing machine there are finite automata that are able
to detect:
a) initial configurations,
b) halting configurations, and
c) configurations with improper instructions.
The final situation that leads to a string not being a valid Turing machine
computation is part (4) of our previous list. This when a configuration does not
yield the next in the sequence. We shall show now that a nondeterministic
pushdown machine can detect this.
a) No configuration can follow C1. There are three possible reasons for
this, namely:
1) C1 is a halting configuration.
2) The instruction in C1 is not defined for the symbol read.
3) C1 = (Ik)x and the Turing machine wishes to move left.
Since these three conditions are finite, a finite automaton could detect
them, and so can our pushdown machine.
C1 = x a ( I k ) c y
and instruction Ik calls for the Turing machine to write the symbol d
and transfer to instruction Im if it reads the symbol c. Then it should
be the case that
C2 = x ( I m ) a d y
C2 = x a d ( I m ) y
C2 = u ( I m ) v
Unsolvable Problems for PDA 4
The errors that could take place have been tabulated in the following
table.
To recap, our pushdown automaton first selects the error that makes C1
not yield C2 and then verifies that it did indeed take place.
Now we possess all of the tools necessary to show that pushdown machines can
analyze strings and detect whether or not they are Turing machine
computations. This is done by enumerating what could be making the string
not a proper computation, and then verifying that something of this sort took
place.
This theorem is very interesting in its on right. as well as being a nice example
of nondeterministic computation. In fact, the guess and verify strategy cannot
be carried out on a deterministic device unless the choices remain constant no
matter how long the input gets.
It also indicates that pushdown automata can in some sense analyze the
computations of Turing machines. (By the way, npda cannot detect valid halting
computations for Turing machines. This should become clear after observing
linear bounded automata that is a more powerful device that is able to
recognize valid computations.) The major use of this theorem, however, is to
Unsolvable Problems for PDA 5
Proof. We shall reduce the emptiness problem for Turing machines (is Wi
= ∅?) to this problem (known as the Σ* problem since Σ is the input
alphabet) for pushdown machines.
Let Mi be a Turing machine and let Pg(i) be the pushdown automaton that
accepts the set of strings that are not valid halting computations for
Turing machine Mi. Then note that:
That was the reduction from the emptiness problem for Turing machines
to the Σ* problem for pushdown machines. Recalling our results on
reducibilities indicates that both must be unsolvable. (Also they are not
r.e.)
Here is the motivation for the design of this class of machines. Computers are
finite devices. They do not have unending amounts of storage like Turing
machines. Thus any actual computation done on a computer is not as extensive
as that which could be completed on a Turing machine. So, to mimic (or maybe
model) computers, we must restrict the storage capacity of Turing machines.
This should not be as severely as we did for finite automata though. Here is the
definition.
That seems quite reasonable. We allow the computing device to use just the
storage it was given at the beginning of its computation. As a safety feature, we
shall employ endmarkers (* on the left and # on the right) on our lba tapes and
never allow the machine to go past them. This will ensure that the storage
bounds are maintained and help keep our machines from leaving their tapes.
At this point, the question of accepting sets arises. Let's have linear bounded
automata accept just like Turing machines. Thus for lba halting means
accepting.
Now that we know what these devices are, let's look at one. A set which cannot
be accepted by pushdown machines (this is shown in the material on formal
languages) is the set of strings whose length is a perfect square. In symbols this
is:
Here is the strategy. We shall use a four track machine with the input written
on the first track. The second and third tracks are used for scratch work while
the fourth track is holds strings of square length which will be matched against
the input string.
To do this we need to generate some strings of square length. The second and
third tracks are used for this. On the second track we will build strings of length
k = 1, 2, 3, and so forth. After each string is built, we construct (on the fourth
track) a string whose length is the square of the length of the string on the
second track by copying the second track to the fourth exactly that many times.
The third track is used to count down from k. Here is a little chart which
explains the use of the tracks.
track content
1 an (input)
2 ak
3 ak-m
4 amk
Then we check to see if this is the same length as the input. The third track is
used for bookkeeping. The algorithm is provided as figure 1.
repeat
clear the 3 rd and 4th tracks
add another a to the 2 nd track
copy the 2nd track to the 3rd track
while there are a’s written on the 3 rd track
delete an a from the 3rd track
add the 2 nd track's a's to those on 4th track
until overflow takes place or 4th track = input
if there was no overflow then accept
Now we've seen something of what can be done by linear bounded automata.
We need to investigate some of the decision problems concerning them. The
first problem is the halting problem.
Proof. Our argument here will be based upon the number of possible
configurations for an lba. Let's assume that we have an lba with one track
(this is allowed because can use additional tape symbols to simulate
tracks as we did with Turing machines), k instructions, an alphabet of s
Linear Bounded Automata 3
a) an instruction,
b) the tape head's position, and
c) the content of the tape.
That is all. We now ask: how many different configurations can there be?
It is not too difficult to figure out. With s symbols and a tape which is n
squares long, we can have only sn different tapes. The tape head can be
on any of the n squares and we can be executing any of the k instructions.
Thus there are only
k*n*sn
The theorem follows from this. We only need to simulate and observe the
lba for k*n*sn steps. If it has not halted by then it must be in a loop and
will never halt.
Let's pursue this notion about step counting a bit more. We know that an lba
will run for no more than k&n&sn steps because that is the upper bound on the
number of configurations possible for a machine with an input of length n. But,
let us ask: exactly how many configurations are actually reached by the
machine? If we knew (and we shall soon) we would have a sharper bound on
when looping takes place. Thus to detect looping, we could count steps with an
lba by using an extra track as a step counter.
Now let's make the problem a little more difficult. Suppose we had a
nondeterministic linear bounded automaton (nlba). We know what this is;
merely a machine which has more than one possible move at each step. And, if
it can achieve a halting configuration, it accepts. So we now ask: how many
configurations can an nlba reach for some input? We still have only k*n*sn
Linear Bounded Automata 4
If the nlba has k instructions, one track, s symbols, and the input is
length n, then we know that there are at most k&n&sn possible
configurations (Ci) reachable from the starting configuration (which we
shall call C0). We can enumerate them and check whether the nlba can
get to them. Consider:
x = 0
for i = 1 to k*n*sn
generate C i
guess a path from C0 to Ci
verify that it is a proper path
if Ci is reachable then x = x + 1
verify that x ≥ m (otherwise reject)
Note also that every step above can be carried out using n tape squares
and several tracks. Our major problem here is to count to k*n*sn. We
need to first note that for all except a few values of n, this is smaller than
(s+1)n and we can count to this in base s+1using exactly n tape squares.
n0 = 1
i = 0
repeat
i = i + 1
ni = 0
m := 0
for j = 1 to k*n*sn
generate Cj
guess whether C j can be reached in i steps or less
if path from C0 to C j is verifiable then
ni = ni + 1
if reached in less than i steps then m = m + 1
verify that m = n i-1 (otherwise reject)
until n i = n i-1
Proof. Most of our work has been done. To build a machine which
accepts the complement of the set accepted by some nlba involves
putting the previous two together. First find out exactly how many
configurations are reachable. Then examine all of them and if any halting
configurations are encountered, reject. Otherwise accept.
Linear Bounded Automata 6
Our final topic is decision problems. Unfortunately we have seen the only
important solvable decision problem concerning linear bounded automata. (At
least there was one!) The remaining decision problems we have examined for
other classes of machines are unsolvable. Most of the proofs of this depend
upon the next lemma.
The proof of this important lemma will remain an exercise. It should not be too
hard to see just how an lba could check a string to see if it is a computation
though. After all, we did a rather careful analysis of how pushdown machines
recognize invalid computations.
Proof. Note that if a Turing machine accepts no inputs then it does not
have any valid halting computations. Thus the linear bounded automaton
which accepts the Turing machine's valid halting computations accepts
nothing. This means that if we could solve the emptiness problem for
linear bounded automata then we could solve it for Turing machines.
In the treatment of formal languages we shall prove that the class of sets
accepted by linear bounded automata properly contains the class of sets
accepted by pushdown machines. This places this class in the hierarchy
fa ⊂ pda ⊂ lba ⊂ TM
(By the way, we could intuitively indicate why lba's are more powerful than
pushdown machines. Two observations are necessary. First, a tape which can
be read and written upon is as powerful a tool as a stack. Then, note that a
pushdown machine can only place a bounded number of symbols on its stack
during each step of its computation. Thus its stack cannot grow longer than a
constant times the length of its input.)