Exercise Questions On Regular Language and Regular Expression
Exercise Questions On Regular Language and Regular Expression
Expression
Ex. 1: Find the shortest string that is not in the language represented by the regular
expression a*(ab)*b*.
Solution: It can easily be seen that , a, b, which are strings in the language with
length 1 or less. Of the strings wiht length 2 aa, bb and ab are in the language.
However, ba is not in it. Thus the answer is ba.
Solution: (a) Any string consisting of only a's or only b's and the empty string are
in r1. So we need to find strings of r2 which contain at least one a and at least one
b. For example ab and ba are such strings.
(b) A string corresponding to r1 consists of only a's or only b's or the empty string.
The only strings corresponding to r2 which consist of only a's or b's are a, b and the
strings consiting of only b's (from (a*b)*).
Ex. 3: Let r1 and r2 be arbitrary regular expressions over some alphabet. Find a
simple (the shortest and with the smallest nesting of * and +) regular expression
which is equal to each of the following regular expressions.
Solution: One general strategy to approach this type of question is to try to see
whether or not they are equal to simple regular expressions that are familiar to us
such as a, a*, a+, (a + b)*, (a + b)+ etc.
(a) Since (r1 + r2)* represents all strings consisting of strings of r1 and/or r2 , r1r2 +
r2r1 in the given regular expression is redundant, that is, they do not produce any
strings that are not represented by (r1 + r2)*. Thus (r1 + r2 + r1r2 + r2r1)*is reduced
to (r1 + r2)*.
(b) (r1(r1 + r2)*)+ means that all the strings represented by it must consist of one or
more strings of (r1(r1 + r2)*). However, the strings of (r1(r1 + r2)*) start with a
string of r1 followed by any number of strings taken arbitrarily from r1 and/orr2.
Thus anything that comes after the first r1 in (r1(r1 + r2)*)+ is represented by (r1 +
r2)*. Hence (r1(r1 + r2)*) also represents the strings of (r1(r1 + r2)*)+, and
conversely (r1(r1 + r2)*)+ represents the strings represented by (r1(r1 + r2)*).
Hence (r1(r1 + r2)*)+ is reduced to (r1(r1 + r2)*).
Ex. 4: Find a regular expression corresponding to the language L over the alphabet
{ a , b } defined recursively as follows:
Basis Clause: L
Solution: Let us see what kind of strings are in L. First of all L . Then
starting with , strings of L are generated one by one by prepending aab or
appending bb to any of the already generated strings. Hence a string of L consists
of zero or more aab's in front and zero or more bb's following them.
Thus (aab)*(bb)* is a regular expression for L.
Solution: Let us see what kind of strings are in L. First of all and a are in L .
Then starting with or a, strings of L are generated one by one by prepending aab
or bb to any of the already generated strings. Hence a string of L has zero or more
of aab's and bb's in front possibly followed by a at the end. Thus (aab + bb)*(a
+ ) is a regular expression for L.
Ex. 6: Find a regular expression corresponding to the language of all strings over
the alphabet { a, b } that contain exactly two a's.
Solution: A string in this language must have at least two a's. Since any string of
b's can be placed in front of the first a, behind the second a and between the two
a's, and since an arbitrasry string of b's can be represented by the regular
expression b*, b*a b*a b* is a regular expression for this language.
Ex. 7: Find a regular expression corresponding to the language of all strings over
the alphabet { a, b } that do not end with ab.
Ex. 8: Find a regular expression corresponding to the language of all strings over
the alphabet { a, b } that contain no more than one occurence of the string aa.
Solution: If there is one substring aa in a string of the language, then that aa can be
followed by any number of b. If an a comes after that aa, then that a must be
preceded by b because otherwise there are two occurences of aa. Hence any string
that follows aa is represented by ( b + ba )*. On the other hand if an a precedes the
aa, then it must be followed by b. Hence a string preceding the aa can be
represented by ( b + ab )*. Hence if a string of the language contains aa then it
corresponds to the regular expression ( b + ab )*aa( b + ba )* .
If there is no aa but at least one a exists in a string of the language, then applying
the same argument as for aa to a, ( b + ab )*a( b + ba )* is obtained as a regular
expression corresponding to such strings.
If there may not be any a in a string of the language, then applying the same
argument as for aa to , ( b + ab )*( b + ba )* is obtained as a regular expression
corresponding to such strings.
Altogether ( b + ab )*( + a + aa )( b + ba )* is a regular expression for the
language.
Solution: Since any string of even length can be expressed as the concatenation of
strings of length 2 and since the strings of length 2 are aa, ab, ba, bb, a regular
expression corresponding to the language is ( aa + ab + ba + bb )*. Note that 0 is
an even number. Hence the string is in this language.
Solution: A string in the language can start and end with a or b, it has at least one
b, and after the first b all the b's in the string appear in pairs. Any numbe of a's can
appear any place in the string. Thus simply put, it is the set of strings over the
alphabet { a, b } that contain an odd number of b's
Indicate which of the following statements are correct and which are not.
Click Yes or No , then Submit.
There are two sets of questions.
\Lambda for
a^* for a* , etc.
Properties of Regular Language
Subjects to be Learned
Contents
Here we are going to learn two of the properties of regular languages. We will see
more properties later.
To review definition of regular language click here
We say a set of languages is closed under an operation if the result of applying the
operation to any arbitrary language(s) of the set is a language in the set.
For example a set of languages is closed under union if the union of any two
languages of the set also belongs to the set.
The following theorem is immediate from the Inductive Clause of the definition of
the set of regular languages.
Note 1: Later we shall see that the complement of a regular language and the
intersection of regular laguages are also regular.
Note 2: The union of infinitely many regular languages is not necessarily regular.
For example while { akbk } is regular for any natural number k , { anbn | n is a
natural number } which is the union of all the languages { akbk } , is not
regular as we shall see later.
The following theorem shows that any finite language is regular. We say a
language is finite if it consists of a finite number of strings, that is, a finite
language is a set of n strings for some natural number n.
Proof: Let us first assume that a language consisting of a single string is regular
and prove the theorem by induction. We then prove that a language consisting of a
single string is regular.
Claim 1: A language consisting of n strings is regular for any natural number n
(that is, a finite language is regular) if { w } is regular for any string w.
Thus if we can show that { w } is a regular language for any string w, then we have
proven the theorem.
Basis Step: By the Basis Clause of the definition of regular language, { } and { a
} are regular languages for any arbitrary symbol a of .
Note that Claim 2 can also be proven by induction on the length of string.
<= for
In this chapter we are going to study a class of machines called finite automata.
Finite automata are computing devices that accept/recognize regular languages
and are used to model operations of many systems we find in practice. Their
operations can be simulated by a very simple computer program. A kind of
systems finite automnata can model and a computer program to simulate their
operations are discussed later.
Let us consider the operation of a soft drink vending machine which charges 15
cents for a can. Pretend that you are the machine. Initially you are waiting for a
customer to come and put some coins, that is, you are in the waiting-for-
customer state. Let us assume that only nickels and dimes are used for simplicity.
When a customer comes and puts in the first coin, say a dime, you are no longer
in the waiting-for-customer state. You have received 10 cents and are waiting for
more coins to come. So we might say you are in the 10-cents state. If the
customer puts in a nickel, then you have now received 15 cents and you wait for
the customer to select a soft drink. So you are in another state, say 15-cents state.
When the customer selects a soft drink, you must give the customer a can of soft
drink. After that you stay in that state until another coin is put in to start the
process anew or you may terminate the operation and start all over from the
initial state. The states and the transitions between them of this vending machine
can be represented with the diagram below. In the figure, circles represent states
and arrows state transitions. Ds on arrows represent a dime and Ns a nickel. It is
assumed that the machine terminates its operation when it receives 15 cents or
more. Click "NICKEL" or "DIME" in the figure and see how it operates (see how
arrows turn red).
In this example you as a vending machine have gone through
(transitions between) a number of states responding to the inputs from the
customer (coins in this case). A vending machine looked at this way is an example
of finite automaton.
Subjects to be Learned
Finite automata
State transition diagram
State transition table
Contents
Let Q be a finite set and let be a finite set of symbols. Also let be a function
1. The set Q in the above definition is simply a set with a finite number of
elements. Its elements can, however, be interpreted as a state that the system
(automaton) is in. Thus in the example of vending machine, for example, the
states of the machine such as "waiting for a customer to put a coin in", "have
received 5 cents" etc. are the elements of Q. "Waiting for a customer to put a
coin in" can be considered the initial state of this automaton and the state in
which the machine gives out a soda can can be considered the accepting
state.
2. The transition function is also called a next state function meaning that the
automaton moves into the state (q, a) if it receives the input symbol a
while in state q.
Thus in the example of vending machine, if q is the initial state and a nickel
is put in, then (q, a) is equal to "have received 5 cents".
3. Note that is a function. Thus for each state q of Q and for each symbol a
of , (q, a) must be specified.
4. The accepting states are used to distinguish sequences of inputs given to the
finite automaton. If the finite automaton is in an accepting state when the
input ceases to come, the sequence of input symbols given to the finite
automaton is "accepted". Otherwise it is not accepted. For example, in the
Example 1 below, the string a is accepted by the finite automaton. But any
other strings such as aa, aaa, etc. are not accepted.
5. A deterministic finite automaton is also called simply a "finite automaton".
Abbreviations such as FA and DFA are used to denote deterministic finite
automaton.
DFAs are often represented by digraphs called (state) transition diagram. The
vertices (denoted by single circles) of a transition diagram represent the states of
the DFA and the arcs labeled with an input symbol correspond to the transitions.
An arc ( p , q ) from vertex p to vertex q with label represents the transition
(p, ) = q . The accepting states are indicated by double circles.
Transition functions can also be represented by tables as seen below. They are
called transition table.
Note that for each state there are two rows in the table for corresponding to the
symbols a and b, while in the Example 1 there is only one row for each state.
A DFA that accepts all strings consisting of only symbol a over the alphabet { a, b
} is the next example.
A finite automaton can also be thought of as the device shown below consisting of
a tape and a control circuit which satisfy the following conditions:
1. The tape has the left end and extends to the right without an end.
2. The tape is divide into squares in each of which a symbol can be written
prior to the start of the operation of the automaton.
3. The tape has a read only head.
4. The head is always at the leftmost square at the beginning of the operation.
5. The head moves to the right one square every time it reads a symbol.
It never moves to the left. When it sees no symbol, it stops and the
automaton terminates its operation.
6. There is a finite control which determines the state of the automaton and
also controls the movement of the head.
Operation of finite automata
Let us see how an automaton operates when it is given some inputs. As an example
let us consider the DFA of Example 3 above.
Initially it is in state 0. When zero or more a's are given as an input to it, it stays in
state 0 while it reads all the a's (without breaks) on the tape. Since the state 0 is
also the accepting state, when all the a's on the tape are read, the DFA is in the
accepting state. Thus this automaton accepts any string of a's. If b is read while it is
in state 0 (initially or after reading some a's), it moves to state 1. Once it gets to
state 1, then no matter what symbol is read, this DFA never leaves state 1. Hence
when b appears anywhere in the input, it goes into state 1 and the input string is not
accepted by the DFA. For example strings aaa, aaaaaa etc. are accepted but strings
such as aaba, b etc. are not accepted by this automaton.
*
of DFA and its Properties
Subjects to be Learned
*
Language accepted by DFA
Contents
For a state q and string w, *( q , w ) is the state the DFA goes into when it reads
the string w starting at the state q. In general a DFA goes through a number of
states from the state q responding to the symbols in the string w. Thus for a DFA <
Q , , q0 , , A > , the function
* *
:Q -> Q
is defined recursively as follows:
*
Definition of :
*
Basis Clause: For any state q of Q , (q, ) = q , where denotes the empty
string.
*
Inducitve Clause: For any state q of Q, any string y and any symbol
a ,
* *
( q , ya ) = ( (q,y),a).
In the definition, the Basis Clause says that a DFA stays in state q when it reads an
empty string at state q and the Inductive Clause says that the state DFA reaches
after reading string ya starting at state q is the state it reaches by reading symbol a
after reading string y from state q.
Example
For example suppose that a DFA contains the transitions shown below.
*
Then ( q , DNR ) can be calculated as follows:
*
( q , DNR ) = ( *( q , DN ) , R ) by the Inductive Clause.
= ( ( *( q , D ) , N ) , R ) by applying the Inductive Clause to *
( q , DN
).
= ( ( *( q , D ) , N ) , R ) since D = D .
= ( ( ( *( q , ) , D ) , N ) , R ) by applying the Inductive Clause to
*
( q , D ).
= ( ( ( q , D ) , N ) , R ) , since ( q , ) = q .
= ( ( q1 , N ) , R ) , since ( q , D ) = q1 as seen from the diagram.
= ( q2 , R ) , since ( q1 , N ) = q2 as seen from the diagram.
= q3 since ( q2 , R ) = q3 as seen from the diagram.
*
Properties of
*
We can see the following two properties of .
Theorem 1: For any state q of Q and any symbol a of for a DFA < Q , ,
q0 , , A > ,
*
(q,a)= (q,a)
Proof : Since a = a ,
*
( q , a ) = *( q , a ) .
By the definition of * ,
*
( q , a ) = ( *( q , ) , a )
But *( q , ) = q by the definition of *
.
Hence ( *( q , ) , a ) = ( q , a ) .
The next theorem states that the state reached from any state, say q , by reading a
string, say w , is the same as the state reached by first reading a prefix of w, call it
x, and then by reading the rest of the w, call it y.
Theorem 2: For any state q of Q and any strings x and y over for a DFA < Q
, , q0 , , A > ,
* * *
( q , xy ) = ( (q,x),y).
*
Basis Clause: .
* *
Inductive Clause: If x and a , then xa .
*
Extremal Clause: Nothing is in unless it is obtained from the above two
clauses.
*
( q , xya ) = ( *( q , xy ) , a ) by the definition of *
= ( * ( *( q , x ) , y ) , a ) by the induction hypothesis.
= *( *( q , x ) , ya ) by the definition of * .
*
Test Your Understanding of of DFA and its Properties
Indicate which of the following statements are correct and which are not.
Click Yes or No , then Submit.
: \delta
* : \delta^*
: \Lambda
Language Accepted by DFA
Subjects to be Learned
Contents
Here we are going to formally define what is meant by a DFA (deterministic finite
automaton) accepting a string or a language.
*
A string w is accepted by a DFA < Q , , q0 , , A > , if and only if (
Example 1 :
This DFA accepts { } because it can go from the initial state to the accepting
state (also the initial state) without reading any symbol of the alphabet i.e. by
reading an empty string . It accepts nothing else because any non-empty symbol
would take it to state 1, which is not an accepting state, and it stays there.
Example 2 :
This DFA does not accept any string because it has no accepting state. Thus the
This DFA has two independent cycles: 0 - 1 - 0 and 0 - 2 - 0 and it can move
through these cycles any number of times in any order to reach the accepting state
from the initial state such as 0 - 1 - 0 - 2 - 0 - 2 - 0. Thus a string that is accepted by
this DFA can be represented by ( ab + bb )*.
Example 6 :
This DFA has two accepting states: 0 and 1. Thus the language that is accepted by
this DFA is the union of the language accepted at state 0 and the one accepted at
state 1. The language accepted at state 0 is b* . To find the language accepted at
state 1, first at state 0 read any number of b's. Then go to state 1 by reading one a.
At this point (b*a) will have been read. At state 1 go through the cycle 1 - 2 - 1 any
number of times by reading substring ba repeatedly. Thus the language accepted at
state 1 is b*a(ba)* .
Subjects to be Learned
Contents
In the previous section we have seen DFAs that accept some simple languages
such as , { } , and { a }. As you might have noticed, those DFAs have states
and transitions which do not contribute to accepting strings and languages. For
example all we need about an FA that accepts { a } is the following regardless of
the alphabet (whether be it { a } , { a , b } or any other) .
This is so to say the essence of such an FA. But it is not DFA. A DFA that accepts
{ a } would need more states and transitions as you can see below for example.
Without those extra state and transitions it is not a DFA if the alphabet is { a , b } .
To avoid those redundant states and transitions and to make modeling easier we
use finite automata called nondeterministic finite automata (abbreviated as NFA) .
Below we are going to formally define nondeterministic finite automata
(abbreviated as NFS) and see some examples. As we are going to see later, for any
NFA there is a DFA which accepts the same language and vice versa.
NFAs are quite similar to DFAs. The only difference is in the transition function.
NFAs do not necessarily go to a unique next state. An NFA may not go to any state
from the current state on reading an input symbol or it may select one of several
states nondeterministically (e.g. by throwing a die) as its next state.
Let Q be a finite set and let be a finite set of symbols. Also let be a function
1. As in the case of DFA the set Q in the above definition is simply a set with a
finite number of elements. Its elements can be interpreted as a state that the
system (automaton) is in.
2. The transition function is also called a next state function . Unlike DFAs an
NFA moves into one of the states given by (q, a) if it receives the input
symbol a while in state q. Which one of the states in (q, a) to select is
determined nondeterministically.
3. Note that is a function. Thus for each state q of Q and for each symbol a
of (q, a) must be specified. But it can be the empty set, in which case
the NFA aborts its operation.
4. As in the case of DFA the accepting states are used to distinguish sequences
of inputs given to the finite automaton. If the finite automaton is in an
accepting state when the input ends i.e. ceases to come, the sequence of
input symbols given to the finite automaton is "accepted". Otherwise it is
not accepted.
5. Note that any DFA is also a NFA.
Examples of NFA
1 a
1 b {2}
2 a
2 b
Note that for each state there are two rows in the table for corresponding to the
symbols a and b, while in the Example 1 there is only one row for each state.
Let us see how an automaton operates when some inputs are applied to it. As an
example let us consider the automaton of Example 2 above.
Initially it is in state 0. When it reads the symbol a, it moves to either state 1 or
state 2. Since the state 2 is the accepting state, if it moves to state 2 and no more
inputs are given, then it stays in the accepting state. We say that this automaton
accepts the string a. If on the other hand it moves to state 1 after reading a, if the
next input is b and if no more inputs are given, then it goes to state 2 and remains
there. Thus the string ab is also accepted by this NFA. If any other strings are
given to this NFA, it does not accept any of them.
*
Let us now define the function and then formalize the concepts of acceptance of
strings and languages by NFA.
Indicate which of the following statements are correct and which are not.
Click Yes or No , then Submit.
There are two sets of questions.
: \delta
Language Accepted by NFA
Subjects to be Learned
*
for NFA
Language accepted by NFA
Properties of *
Contents
*
Definition of
For a state q and string w, *( q , w ) is the set of states that the NFA can reach
when it reads the string w starting at the state q. In general an NFA
nondeterministically goes through a number of states from the state q as it reads
the symbols in the string w. Thus for an NFA < Q , , q0 , , A > , the function
*
*
:Q -> 2Q
is defined recursively as follows:
Definition of *:
*
Basis Clause: For any state q of Q, (q, ) = { q }, where denotes the
empty string.
*
Inducitve Clause: For any state q of Q, any string y and any symbol
a ,
*
( q , ya ) =
In the definition, the Basis Clause says that an NFA stays in state q when it reads
an empty string at state q and the Inductive Clause says that the set of states
NFA can reach after reading string ya starting at state q is the set of states it can
reach by reading symbol a after reading string y starting at state q.
Example
For example consider the NFA with the following transition table:
State (q) Input (a) Next State ( (q, a) )
0 a {0,1,3}
0 b {2}
1 a
1 b {3}
2 a {3}
2 b
3 a
3 b {1}
*
Then ( 0 , ab ) can be calculated as follows:
* *
( 0 , ab ) is the union of ( p, b ) for all p ( 0 , a ) by the Inductive
Clause of the definition of * .
*
We say that a string x is accepted by an NFA < Q, , q0, , A > if and
*
only if ( q0 , x ) A is not empty, that is, if and only if it can reach an accepting
state by reading x starting at the initial state. The language accepted by an NFA <
Q, , q0, , A > is the set of strings that are accepted by the NFA.
Some of the strings accepted by the NFA given above are , a, ab, aaa, abbbb etc.
and the language it accepts is a*( ab + a + ba )(bb)* .
*
for NFA has properties similar to that for DFA.
Theorem 1: For any state q of Q and any symbol a of for an NFA < Q , ,
q0 , , A > ,
*
(q,a)= (q,a)
Theorem 2: For any state q of Q and any strings x and y over for an NFA < Q
, , q0 , , A > ,
*
( q , xy ) =
These theorems can be proven in a manner similar to those for Theorems 1 and 2
for DFA.
*
Test Your Understanding of of NFA and its Properties
Indicate which of the following statements are correct and which are not.
Click Yes or No , then Submit.
: \delta
* : \delta^*
: \Lambda
Definition of Nondeterministic Finite Automata with -
Transitions
Subjects to be Learned
Contents
Let Q be a finite set and let be a finite set of symbols. Also let be a function
Example of NFA-
Here the transitions to are omitted from the table. A state transition diagram for
this finite automaton is given below.
When a symbol a is read at the initial state 0, for example, it can move to any of
the states other than 0. For once you are in state 1, for example, you can go to state
2, 3, 4 and 5 without reading any symbol on the tape. If you read string ab, then
you come to state 4. For though you go to states 1, 2, 3, 4 and 5 by reading a, there
are no transitions on reading b except from state 3. Thus 4 is the only state you can
go to from the initial state by reading ab.
Indicate which of the following statements are correct and which are not.
Click Yes or No , then Submit.
There are two sets of questions.
: \Lambda
Language Accepted by NFA-
Subjects to be Learned
-closure
*
for NFA-
Language accepted by NFA-
Properties of *
Contents
To formally define * for NFA- , we start with the concept of -closure for a
state which is the set of states reachable from the state without reading any symbol.
Using that concept we define * and then strings and languqges accepted by NFA-
.
Definition of -closure
As we can see from the example, ( S ) is the set of states that can be reached
from the states of S by traversing any number of arcs. That is, it is the set of
states that can be reached from the states of S without reading any symbols in .
*
Now with this -closure, we can define recursively as follows:
As in the cases of DFA and NFA, * gives the result of applying the transition
function repeatedly as dictated by the given string.
*
Definition of
*
is going to be defined recursively.
Let < Q , , q0 , , A > be an NFA- .
*
(q, )= ({q}).
*
Inductive Clause: For any state q, a string y in and a symbol a in ,
*
( q , ya ) = ( ).
What the Inductive Clause means is that *( q , ya ) is obtained by first finding the
states that can be reached from q by reading y ( *( q , y ) ), then from each of
those states p by reading a (i.e. by finding ( p , a ) ), and then by reading 's (
i.e. by taking the closure of the ( p , a )'s ) .
*
Example : For the NFA- of the following figure, ( 0 , ab ) can be obtained as
below:
First let us compute *( 0 , a ) .
For that we need ( { 0 } ).
Since it is the set of states reached by traversing the arcs from state 0, ( { 0 }
)={0,3,4}.
Next from each of the states in ( { 0 } ) we read symbol a and move to another
state (i.e. apply ). They are ( 0 , a ) = { 1 } , ( 3 , a ) = ( 4 , a ) = { 5 }.
Hence = { 1 , 5 } for q = 0 .
We then traverse the arcs from { 1 , 5 } to get to the states in *( 0 , a ) .
*
Since ( { 1 } ) = { 1 , 2 , 3 } and ( { 5 } ) = { 5 } , (0,a)={1,2,3,5}
.
Then to find *( 0 , ab ) read b from each of the states in *( 0 , a ) and then take
the arcs from there.
Now ( 1 , b ) , ( 3 , b ) and ( 5 , b ) are empty sets, and ( 2 , b ) = { 4 } .
Thus Since ( { 4 } ) = { 3 , 4 } , *( 0 , ab ) = { 3 , 4 } .
For example the NFA- of the figure given above accepts the language { ,a,
ab } .
*
Test Your Understanding of of NFA- and its Properties
Indicate which of the following statements are correct and which are not.
Click Yes or No , then Submit.
: \delta
*
: \delta^*
: \Lambda
Subjects to be Learned
Contents
One major objective in our study of FAs and regular languages is to learn that any
language recognized by a DFA is regular and that any regular language is
recognized by a DFA. To prove the former, we are going to show that simple
regular languages are recognized by some simple DFAs and then show that using
union, concatenation and Kleene star operations, DFAs to recognize more complex
languages can be constructed from those simple DFAs. Since those operations on
FAs can be described conveniently using NFA- s, they are going to be used to
construct complex FAs from simple ones. These NFA- s are then converted to
equivalent NFAs (without s ) , then to DFAs so that nondeterminisms are
removed and computer programs can be written for simulating them. Finally we
are going to learn that the DFAs that recognize a regular language can be
transformed into a unique DFA by minimizing the number of their states.
In this and the next sections we are going to study the conversion of NFA- s to
equivalent NFAs then to DFAs. The construction of NFA- s for regular
languages is discussed in the next chapter. The minimization of states is going to
be discussed a little later in another chapter.
Q2 = Q1,
q2,0 = q1,0,
*
2 ( q, a ) = 1 (q,a)= ( )
A2 = A1 { q1,0 } if ( { q1,0 } ) A1
= A1 otherwise .
Thus to obtain an NFA M2 = < Q2, , q2,0 , 2 , A2 > which accepts the same
language as the given NFA- M1 = < Q1 , , q1,0 , 1 , A1 > does,
Find ( {q} ), that is all the states that can be reached from q by
traversing arcs. Then collect all the states that can be reached from each state
of ( {q} ) by traversing one arc labeled with the symbol a. The closure of the
set of those states is 2( q , a ) .
The set of accepting states A2 is the same as A1 if no accepting states can be
reached from the initial state q1,0 through arcs in M1 . Otherwise, that is if an
accepting state can be reached from the initial state q1,0 through arcs in M1 , then
all the accepting states of M1 plus state q1,0 are the accepting states of M2 .
The set of states Q2 of NFA is { 0, 1, 2, 3 ), the initial state is 0 and the accepting
states are 1 and 0, since 1 is in ( { 0 } ) . The transition function 2 is obtained
as follows:
2( 0 , a ):
First ( { 0 } ) = { 0 , 1 } . Then from the transition function of the NFA-
( 0 , a ) = , and 1( 1 , a ) = { 1 , 2 }.
1
Hence 2( 0 , a ) = ( { 1 , 2 } ) = { 1 , 2 } .
b)= .
Similarly 2 can be obtained for other states and symbols. They are given in the
The set of states Q2 of NFA is { 0, 1, 2, 3, 4 ), the initial state is 0 and the accepting
states are 1 and 0, since 1 is in ( { 0 } ) . The transition function 2 is obtained
as for Example 1. 2 is given in the table below together with ({q}), 1 (p
, ) and
Indicate which of the following statements are correct and which are not.
Click Yes or No , then Submit.
There are two sets of questions.
1 : \delta1 2 : \delta2
* : \delta^* : \Lambda Equivalence of DFAs, NFAs and
NFA- s
Subjects to be Learned
Contents
One major objective in our study of FAs and regular languages is to learn that any
language recognized by a DFA is regular and that any regular language is
recognized by a DFA. To prove the former, we are going to show that simple
regular languages are recognized by some simple DFAs and then show that using
union, concatenation and Kleene star operations, DFAs to recognize more complex
languages can be constructed from those simple DFAs. Since those operations on
FAs can be described conveniently using NFA- s, they are going to be used to
construct complex FAs from simple ones. These NFA- s are then converted to
equivalent NFAs (without s ) , then to DFAs so that nondeterminisms are
removed and computer programs can be written for simulating them. Finally we
are going to learn that the DFAs that recognize a regular language can be
transformed into a unique DFA by minimizing the number of their states.
In this and the next sections we are going to study the conversion of NFA- s to
equivalent NFAs then to DFAs. The construction of NFA- s for regular
languages is discussed in the next chapter. The minimization of states is going to
be discussed a little later in another chapter.
Q2 = Q1,
q2,0 = q1,0,
*
2 ( q, a ) = 1 (q,a)= ( )
A2 = A1 { q1,0 } if ( { q1,0 } ) A1
= A1 otherwise .
Thus to obtain an NFA M2 = < Q2, , q2,0 , 2 , A2 > which accepts the same
language as the given NFA- M1 = < Q1 , , q1,0 , 1 , A1 > does,
Find ( {q} ), that is all the states that can be reached from q by
traversing arcs. Then collect all the states that can be reached from each state
of ( {q} ) by traversing one arc labeled with the symbol a. The closure of the
set of those states is 2( q , a ) .
The set of accepting states A2 is the same as A1 if no accepting states can be
reached from the initial state q1,0 through arcs in M1 . Otherwise, that is if an
accepting state can be reached from the initial state q1,0 through arcs in M1 , then
all the accepting states of M1 plus state q1,0 are the accepting states of M2 .
The set of states Q2 of NFA is { 0, 1, 2, 3 ), the initial state is 0 and the accepting
states are 1 and 0, since 1 is in ( { 0 } ) . The transition function 2 is obtained
as follows:
2( 0 , a ):
First ( { 0 } ) = { 0 , 1 } . Then from the transition function of the NFA-
( 0 , a ) = , and 1( 1 , a ) = { 1 , 2 }.
1
Hence 2( 0 , a ) = ( { 1 , 2 } ) = { 1 , 2 } .
b)= .
Similarly 2 can be obtained for other states and symbols. They are given in the
The set of states Q2 of NFA is { 0, 1, 2, 3, 4 ), the initial state is 0 and the accepting
states are 1 and 0, since 1 is in ( { 0 } ) . The transition function 2 is obtained
as for Example 1. 2 is given in the table below together with ({q}), 1 (p
, ) and
Indicate which of the following statements are correct and which are not.
Click Yes or No , then Submit.
There are two sets of questions.
*
1 : \delta1 2 : \delta2 : \delta^* : \Lambda
A={q Q|q A2 }
To obtain a DFA M = < Q, , q0 , , A > which accepts the same language as the
given NFA M2 = < Q2 , , q2,0 , 2 , A2 > does, you may proceed as follows:
Initially Q = .
First put { q2,0 } into Q. { q2,0 } is the initial state of the DFA M.
Then for each state q in Q do the following:
add the set , where here is that of NFA M2, as a state to Q if it is not
already in Q for each symbol a in .
For this new state, add ( q, a ) = to , where the on the right hand
side is that of NFA M2.
When no more new states can be added to Q, the process terminates. All the states
of Q that contain accepting states of M2 are accepting states of M.
Note: The states that are not reached from the initial state are not included
in Q obtained by this procedure. Thus the set of states Q thus obtained is not
necessarily equal to 2Q2 .
Note that there are no states of Q2 in . Hence there are no states that M2 can go to
For the accepting states of M, since states 0 and 1 are the accepting states of the
NFA, all the states of Q that contain 0 and/or 1 are accepting states. Hence { 0 }, {
1 , 2 } and { 1 , 3 } are the accepting states of M.
Indicate which of the following statements are correct and which are not.
Click Yes or No , then Submit.
There are two sets of questions.
: \delta
We are going to prove that the NFA obtained from NFA- by the conversion
algorithm accepts the same language as the NFA- .
NFA- that recognizes a language L is denoted by M1 = < Q1 , , q1,0 , 1 , A1 >
and NFA obtained by the conversion is denoted by M2 = < Q2, , q2,0 , 2 , A2 >
* *
First we are going to prove that 1 (q,w)= 2( q , w ) for any non-empty string
w.
*
To review the definition of for NFA, and NFA- , and the conversion of NFA-
to NFA click here.
When it is proven, it implies that NFA- M1 and NFA M2 accept the same non-
empty strings. The case when w is an empty string is going to be proven
separately.
Proof: This is going to be proven by induction on w. Recall that the set of strings
is defined recursively (click here for a quick review). Thus we first prove that it is
true for any arbitrary symbol, then assuming it holds for any arbitrary string w we
prove it for any of the children of w, that is wa for any symbol a in the alphabet.
* *
Inductive Step: We need to show that if 1 (q,w)= 2 ( q , w ) for an arbitrary
string w (Induction Hypothesis),
* *
then 1 ( q , wa ) = 2 ( q , wa ) holds for any arbitrary symbol a in .
*
( q , wa ) =
2
Since 2 ( q , w ) = 1*( q , w ) by the induction hypothesis,
*
=
*
Since 2( q , a ) = 1 ( q , a ) by the way NFA is constructed from NFA- .
=
*
Hence 2 ( q , wa ) = , that is (1) has been proven.
*
Let us next prove (2), that is = 1 ( q , wa ) .
By the definition of 1* for NFA- ,
*
1 (p,a)=
Substituting this into the left hand side of (2) produces
= .
The right hand side of this equality is equal to
because = .
To see an explanation for this click here.
Hence = .
* *
On the other hand = 1 ( q , wa ) , by the definition of 1 .
Hence = 1*( q , wa ) .
Hence we have proven (2).
Thus from (1) and (2) 1*( q , wa ) = 2*( q , wa ) .
End of Induction
With this Claim 1 we can see that any non-empty string w is accepted by NFA
if and only if it is accepted by the corresponding NFA- .
As for the empty string , if it is accepted by an NFA- , then ( { q10 }
Thus NFA- and the corresponding NFA accept the same language.
(S T) (S) ( T ) and
, ) (S) (T).
Proof of ( S ) (S T):
By induction on (S).
in (S T ) , then ( q , ) (S T).
of -closure ( q , ) (S T).
Claim 3: ( Si ) = ( Si ) .
Proof : Proof by induction on n.
( Si ) = ( S1 ) .
*
: \delta : \Lambda : \Sigma : \Sigma^* : \cup