Toc Unit I
Toc Unit I
Toc Unit I
UNIT- I
INTRODUCTION
Symbol
A character, glyph, mark.
An abstract entity that has no meaning by itself, often called uninterrupted.
Letters from various alphabets, digits and special characters are the most commonly
used symbols.
Alphabet
A finite set of symbols.
An alphabet is often denoted by sigma, yet can be given any name.
B = {0, 1} Says B is an alphabet of two symbols, 0 and 1.
C = {a, b, c} Says C is an alphabet of three symbols, a, b and c.
FINITE AUTOMATA:
M = (Q, Sigma, delta, q0, F) is a definition of a Finite Automata.
To be fully defined the following must be provided:
Q a finite set of states often called q0, q1, ... , qn or s0, s1, ... , sn.
What is a DFA?
3. A transition function ,
4. An initial state ,
where
The table represents the function , i.e. to find the value of we have to look at the
row labelled and the column labelled . The initial state is marked by an and all
final states are marked by .
We write for the set of words (i.e. sequences) over the alphabet . This includes the
empty word which is written . I.e.
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.
Inductive 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.
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)
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 ) .
Recursive definition of *:
Basis Clause: *.
Q, a set of states
S, an single state which is an element of Q. This is the start state.
F, a set of states designated as the final states
Sigma, the input alphabet
delta, a transition function that maps a state and a letter from the input alphabet, to a
state
• Q, a set of states
• S, an single state which is an element of Q. This is the start state.
• Sigma, the input alphabet
• Pi, the output alphabet
• delta, a transition function that maps a state and a letter from the input alphabet, to
a state and a letter from the output alphabet.
The primary difference is that there is no set of final states, and that the transition
function not only puts you in a new state, but also generates an output symbol.
. Moore machines add outputs to each state. Thus, each state is associated with an output.
When you transition into the state, the output corresponding to the state is produced. The
information in the state is typically written as 01/1. 01 indicates the state, while 1
indicates the output. 01/1 is short hand for q1q0 = 01/z = 1
The number of bits in the output is arbitrary, and depends on whatever your application
needs. Thus, the number of bits may be less than, equal, or greater than the number of
bits used to represent the state.
A Mealy machine has outputs that are a function of state and input, that is That is, z = f(
qk-1,..., q0, xm-1,..., x0 ).
We usually indicate that the output is dependent on current state and input by drawing the
output on the edge. In the example below, look at the edge from state 00 to state 01. This
edge has the value 1/1. This means, that if you are in state 00, and you see an input of 1,
then you output a 1, and transition to state 01.
As an example we calculate :
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.
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 4 :
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)* .
There is a systematic way of finding the language accepted by a DFA and we are going to
learn it later. So we are not going to go any further on this problem here.
What is an NFA?
Nondeterministic finite automata (NFA) have transition functions which may assign
several or no states to a given state and an input symbol
belongs to its language ( ). Indeed we shall see that every NFA can be
translated into an DFA which accepts the same language.
Here is an example of an NFA which accepts all words over s.t. the symbol
before the last is .
3. A transition function ,
Hence, the only difference to DFAs is to have start states instead of a single one and the
type of the transition function. As an example we have that
where so given by
Note that we diverge he slightly from the definition in the book, which uses a single
initial state instead of a set of initial states. Doing so means that we can avoid introducing
-NFAs
Initially we have
After reading we have to use two markers because there are two arrows from which
are labeled :
Now after reading 0 the automaton has still got two markers, one of them in an accepting
state:
However, after reading the 2nd 0 the second marker disappears because there is no edge
leaving and we have:
To specify the extended transition function for NFAs we use an generalization of the
In the special cases of the empty sets of sets and a one element set of sets we define:
As an example
(3)
(4)
delta | a | b | c |epsilon
------+------+------+------+-------
q0 | {q0} | phi | phi | {q1}
------+------+------+------+-------
q1 | phi | {q2} | phi | {q2}
------+------+------+------+-------
q2 | phi | phi | {q2} | phi
------+------+------+------+-------
The language accepted by the above NFA with epsilon moves is the set of strings over
{a,b,c} including the null string and all strings with any number of a's followed by any
number of b's
followed by any number of c's. ("any number" includes zero)
Thus q0 in the NFA-epsilon becomes {q0,q1,q2} because the machine can move from
q0 to q1 by an epsilon move, then check q1 and find that it can move from q1 to q2 by
an epsilon move.
q1 in the NFA-epsilon becomes {q1,q2} because the machine can move from q1 to q2
by an epsilon move.
q2 in the NFA-epsilon becomes {q2} just to keep the notation the same. q2 can go
nowhere except q2, that is what phi means, on an epsilon move.
We do not show the epsilon transition of a state to itself here, but, beware, we will take
into account the state to itself epsilon transition when converting NFA's to regular
expressions.
The initial state of our new machine is {q0,q1,q2} the epsilon closure of q0
The final state(s) of our new machine is the new state(s) that contain a state symbol that
was a final state in the original machine.
The new machine accepts the same language as the old machine, thus same sigma.
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:
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 .
Initially Q is empty. Then since the initial state of the DFA is {0} , {0} is added to Q.
Since 2( 0 , a ) = { 1 , 2 } , { 1 , 2 } is added to Q and ( { 0 } , a ) = { 1 , 2 } .
Note that there are no states of Q2 in . Hence there are no states that M2 can go to from
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.
• State A is the accepting state. It represents strings with an even number of a's and
a number of b's divisible by 3 (#b's = 0 mod).
• State B represents strings with an even number of a's and a number of b's = 1 mod
3.
• State C represents strings with an even number of a's and a number of b's = 2 mod
3.
• State D represents strings with an odd number of a's and a number of b's divisible
by 3 (#b's = 0 mod).
• State F represents strings with an even number of a's and a number of b's = 1 mod
3.
• State G represents strings with an even number of a's and a number of b's = 1 mod
3.
The state names indicate the meaning of each state. State Q10 is the state we are in after
seeing one 0 and zero 1's. State Q12 is the state we are in after seeing one 0 and two 1's.
State Qn0 is the state we are in after seeing more than two 0's and zero 1's.
We would need 25 states to recognize a language consisting of strings with exactly 3 0's
or 3 1's.
2. Convert the following NFA into the equivalent DFA.
What language does this NFA accept? (Hint, The machine consisting of states
0,1,2 and 3 should look familiar).
Answer
The top half of the NFA is the x = 0 mod 3 machine from the homework. The bottom
half of the NFA is a x = 0 mod 4 machine. The NFA is the union of these two machines.
Therefore L(M)= binary strings x such that x = mod 3 or x = 0 mod 4.
3.(a) Convert the following NFA with /\ transitions into an NFA without /\
transitions.
Answer
(a)
(b)