Chapter1 FLAT Module 1
Chapter1 FLAT Module 1
Chapter1
FINITE AUTOMATA
Finite automata are basic modules of a computer system, which addresses simple real time problems.
Figure 1.1 shows conceptual view of finite automata. It has an input tape, read head and finite controller.
Input tape is divided into finite cells and each cell stores one input symbols. Read head is used to read the
input symbol from the input tape. The finite controller used to record the next state of finite automat.
Page 1.
1
Finite Automata
S U ɛ = S - ɛ =S
SՈɛ=ɛ
ἕ= U
De Morgan's laws: The following useful identities, known as De Morgan's laws.
ei=(v, vj).
Languages:
A finite, nonempty set of symbols are called the alphabet and is represented with symbol ∑. From the
individual symbols we construct strings, which are finite sequences of symbols from the alphabet. For
example, if the alphabet ∑ = {0}, then ∑* to denote the set of strings obtained by concatenating zero or
more symbols from ∑.
If ∑ = {0, 1}
0 and 1 are input alphabets or symbols, then:
(02=00, 03=000, 12=11, 13=111, where as in mathematics they are numbers 02=0, 12=1)
L=∑*={ ɛ, 0, 1, 00, 01, 10, 11, 000, 001, 010 ……….}
Kleen closure(*closure):
*closure = {∑0U∑1U∑2U∑3 ………}
∑0={ ɛ} ∑1={0, 1} ∑2={00, 01, 10, 11}
∑3={000, 001, 010, 011, 100, 101, 110, 111}
Therefore ∑*={ ɛ , 0, 1, 00, 01, 10, 11, 000, 001, 010, 011, 100, 101,……}
+
Closure on ∑ = {0, 1}
∑+= {∑1U∑2U∑3…}
∑*=∑+ + ɛ
Therefore ∑+=∑*- ɛ
Formal Languages and Automata Theory: IT is a mathematical model used to design computer
programs and sequential logic circuits. It is state machines which captures and makes transition to
accept or reject.
Finite automata has input tape, read head and finite controller Input tape: It is divided into finite cell and
each cell is used to store one input symbol. Read head: Read head is used to read input symbol from
input tape. Finite Controller: Finite controller records, the transition to next state. The default value of
finite controller is initial state q0. States are represented with circles; they are of three types,
Initiation Termination
Figure 1.4 shows a transition diagram to map cities and their roads.
Page 1.
3
Finite Automata
Q={q0,q1,q2} ∑ ={a, b, c}
δ:
δ (q0, a)=q1 δ (q0,b)=q0 δ (q0,c)=q2
δ (q1,a)=q1 δ (q1,b)=q2 δ (q1,c)=q0
δ (q2,a)=q2 δ (q2,b)=q1 δ (q2,c)=q2
Note: Initial State is q0 and final state is q2
Page 1.
4
Finite Automata
Q\∑ a b c
q0 q1 q0 q2
q1 q1 q2 q0
*q2 q2 q1 q2
If outgoing transitions are not dependent on number of input symbols, then such automata are called as
Nondeterministic Finite Automata.
There is no outgoing transition from initial state, for a symbol ‘1 ‘and similarly there is no outgoing
transition from final state for ‘0’.
{}=ɛ
{a}=a
(q0, ɛ)= q0 //q0 is reading empty string, string is empty therefore, transition to same state q0.
(q0, wa)
Where ‘w’ is the multi-symbol string and ‘a’ is a symbol, hence we separate the transition function for
strings and symbols as given below:
δ( (q0, w), a)
Page 1.
5
Finite Automata
Example 1.3: Write a transition table for a DFA shown in figure 1.8.
δ:
δ (A0, 0)=A1 δ (A0, 1)=A2 δ(A0, 2)=A0
δ (A1, 0)=A2 δ (A1, 1)=A0 δ(A1, 2)=A1
Page 1.
6
Finite Automata
Example 1.5: Find out whether the given string is accepted by the DFA. Assume the string as abab.
From the given string ∑ = {a,b} . Note that always string is traversed by left side to right side,
= δ (q2, b) =q3 2
(q0, aba)= δ( (q0, ab), a) from equation 2 (q0, ab)= q3
= δ(q3, a)=q1
(q0, abab)= δ( (q0, aba), b)
= δ( (q1, b)= q0
Given string is accepted by a DFA.
(q0, ɛ)=q0;
In general we can write L={w |w is a string consist of even number of a’s and even number of b’s}
Design of DFA :
Example 1.8: Design a DFA which accept all the strings ends with symbol a over the alphabet ∑={a, b}.
Page 1.
8
Finite Automata
Convert all states of NFA to DFA, that is from each state two outgoing transitions, one for symbol ‘a’
another for ‘b’. From initial state only one outgoing transition on symbol ‘a’, one more outgoing
transition is required that is on ‘b’. If the condition in the given problem ends with, the outgoing
transition on the other symbol b, definitely loop to a initial state.
Termination state for symbol ‘a’ is q1 and for ‘b’ it is q0. Outgoing transition from q1 on
symbol ‘a’ is loop, and for ‘b’ it is to q0 .
Figyre 1.16 :DFA which accept all the strings ends with a.
∑={0, 1}.
ii. Convert all states of NFA to DFA, that is from each state two outgoing transitions, one for
symbol ‘0’ another for ‘1’. From initial state only one outgoing transition on symbol ‘0’, one
Page 1.
9
Finite Automata
more outgoing transition is required that is on ‘1’. If the condition in the given problem is,
ends with, the outgoing transition on the other symbol 1, definitely loop to a initial state.
Termination state for symbol ‘0’ is A1 and for ‘1’ it is A0. Outgoing transition from A1 on
symbol ‘0’ is loop. From A2 on symbol ‘0’ to A1 and on symboll ‘1’ to A0.
Figyre 1.20 :DFA which accept all the strings ends with 01.
∑={0, 1, 2}.
i. Draw the NFA for the smallest string 012 of the language.
The NFA for the string 012 is
ii. Convert all states of NFA to DFA, that is from each state three outgoing transitions, one for
symbol ‘0’ second for ‘1’ third from ‘2’. From initial state only one outgoing transition on
symbol ‘0’, two more outgoing transitions are required that is on ‘1’ and ‘2’. If the condition
Page 1.
10
Finite Automata
in the given problem ends with, the outgoing transition on the other symbols ‘1’and ‘2’,
definitely loop to a initial state.
Termination state for symbol ‘0’ is A1 and for ‘1’ and ‘2’ is A0. Outgoing transition from A1 on
symbol ‘0’ is loop and for’2’ is A0. From A2 on symbol ‘0’ to A1 and on symbol ‘1’ to A0. From
A3 on symbol ‘0’ to A1 and on symbols ‘1’ and ‘2’ to A0.
Figure 1.24 :DFA which accept all the strings ends with 012.
∑={a, b}.
Page 1.
11
Finite Automata
Convert all states of NFA to DFA, that is from each state two outgoing transitions, one for
symbol ‘a’ another for ‘b’. From initial state only one outgoing transition on symbol ‘a’, one
more outgoing transition is required that is on ‘b’. If the condition in the given problem is,
begin with, the outgoing transition on the other symbol ‘b’, is to new state called dead state.
Dead state: In finite automata the string travers from initial state to final state, in some
situation we make finite automata to die called dead state. Dead state is a non-final state,
from which all outgoing transitions are loop to the same state.
Figure 1.26 : DFA which accept all the string begin with a.
ii. Condition is begin, outgoing transitions from final state is loop.
∑={0, 1}.
ii. Convert all states of NFA to DFA, that is from each state two outgoing transitions, one for
symbol ‘0’ another for ‘1’. From initial and intermediate states only one outgoing transition,
one more outgoing transition is required. If the condition in the given problem is, begin with,
the outgoing transition from both the states to new state called dead state.
Page 1.
12
Finite Automata
Figure 1.28 : DFA which accept all the string begin with 01.
iii. Condition is begin, outgoing transitions from final state A2 on symbol ‘0’ and ‘1’ is loop.
δ:
δ (A0, 0)=A1 δ (A0, 1)=A0
δ (A1, 0)=A1 δ (A1, 1)=A2
δ (A2, 0)=A1 δ (A2, 1)=A0
δ (A3, 0)=A3 δ (A3, 1)=A3
IS=A0; FS=A2
Example 1.12: Design a DFA which accept all the strings begins with 01 or ends with 01 or both over the
alphabet ∑={0, 1}.
We have already designed both the DFAs, joining of these DFAs, is the solution for the given problem.
Figure 1.29: DFA which accept all the string begin with 01.
Figure 1.30: DFA which accept all the string ends with 01.
Page 1.
13
Finite Automata
Figure 1.31: DFA which accept all the string begin with 01, end with 01 begin and end with 01.
Example 1.13: Design a DFA which accept all the binary strings divisible by 2.
Example 1.14: Design a DFA which accept all the binary strings divisible by 5.
Page 1.
14
Finite Automata
IS=q0; FS=q0
Example 1.15: Design a DFA which accept string over x, y every block of length 3 contains at least one x.
Figure 1.35: NFA which is accepting three symbol string in which one symbol is x.
3. The position of A1 and A5 is same as A0 and A4. In between A0 and A4 the symbol is ‘x’,
inbetwwen A1 and A5 is also x and so on.
Figure 1.36: DFA which accept string over x, y if every block of length 3 contains at least one x.
Page 1.
15
Finite Automata
Example 1.16: Design a DFA which accept even number of r and even number of s over the symbol ∑={r,
s}.
i. Draw separate DFA, one accept even number of r’s and another one accept even number of
s’s.
ii. Join two DFA, we get four new states AB, AC, BC, BD. Designed DFA accept even number of r
and even number of s, out of four states AB satisfied this condition, hence this state is a final
state.
i. Exchange I symbol of first string with the last symbol of the first string, the string obtained is
the second string of the language.
ii. Draw NFA for two smallest strings, for both NFA initial and final states are same.
Page 1.
16
Finite Automata
Figure 1.39: Two DFAs for the string 011 and 110 with same initial and final state.
Figure 1.40: DFA which accept all the strings described by the language L={N0(w)≥ 1 and N1(w)=2}.
IS=A0; FS={A3}
In DFA the outgoing transitions are defined in advance, where as in NFA the outgoing transitions are not
defined in advance. In DFA, the string is either accepted or not accepted, where as in NFA both are
possible. The finite automata shown in the figure 1.41 is a NFA. There is no outgoing transition for the
symbol ‘a’ from the state q1.
Page 1.
17
Finite Automata
The NFA shown in figure 1.42 is, accepting as well as not accepting the string hod.
Example 1.18: Design NFA which accept all strings, if second symbol from right side is 1 over the
alphabet ∑={0, 1}.
ii. Draw the intermediate state and transition for the symbols ‘0’ and ‘1’.
iii. Draw the initial state and transition for the symbol ‘1’.
Figure 1.45: Non-deterministic finite automata accepting two strings 10, 11.
iv. Designed NFA has to accept all the strings, if second symbol from right side is symbol ‘1’, to
do this, mark loop to initial state on symbols ‘0’ and ‘1’.
Figure 1.46: NFA which accepts all strings, if second symbol from right side is 1 over the alphabet ∑={0, 1}.
Figure 1.47: NFA which accept all strings, if second symbol from right side is 1 over the alphabet ∑={0, 1}.
Page 1.
18
Finite Automata
We have already seen both NFA and DFA, both are same in the definition but they differ in transition
function. If number of states in NFA has two states q0 and q1. Here, q0 is initial state and q1 is final state.
The equivalent states in DFA’s are [q0], [q1] and [q0, q1]. Where q0 is initial state and (q1), (q0, q1) are the
final states. The pair (q0, q1) is final state because; one of its states is final state. They are represented as
shown in figure 1.48
Example 1.19: Convert the NFA shown in figure 1.49 into its equivalent DFA.
The conversion begins with the initial state of the NFA which is also an initial state of DFA. Conversion
generates number of new states, for every new state we are finding the outgoing transitions for
different symbols.
Page 1.
19
Finite Automata
No further new states; mark the final state of DFA. Any pair of state which consists of final state of the
NFA, the particular pair is a final state in DFA.
Finite automat is used to search a text. There are two methods used to search text, they are:
To search a text “shine” and “hire” the NFA shown in figure 1.51 is used
To search a text “shine” and “hire” the DFA shown in figure 1.52 is used
Page 1.
20
Finite Automata
Figure 1.52: DFA used to search strings ending with shine and hire
Example 1.20: Design a finite automata, that reads string made up of letters HONDA, and recognize
those string that contain the word HOD as a substring.
i. Find out the alphabet from the string HONDA. The input symbols are ∑={H, O, N, D, A}
ii. Draw the NFA for the substring HOD.
Figure 1.54: DFA accept all the strings ends with HOD over the symbols {H, O, N, D, A}
Till now whatever automata we studied were characterized by a transition on the symbols. But there are
some finite automata having transition for empty string also, such NFAs are called NFA- ɛ transition.
ɛ-closure (q0): states which are closed / related to state q0 on empty transition(ɛ) is called ɛ-closure (q0).
Example 1.21: Find out ɛ-closure of all the states of ɛ-NFA shown in figure 1.55.
Page 1.
21
Finite Automata
Example 1.22: Convert the ɛ-NFA shown in figure 1.57 into NFA
Note: state ɛ-closure consist of final state of ɛ-NFA, the particular state is a final state in NFA.
= ɛ-closure(δ({q0q1}, 0).
=ɛ-closure(q0 U q2).
=ɛ-closure(q0) U ɛ-closure(q2).
={q0q1} U {q0q1q2}
={q0q1q2}
= ɛ-closure(δ({q0q1}, 1).
Page 1.
22
Finite Automata
=ɛ-closure(q0 U φ).
=ɛ-closure(q0) U ɛ-closure(φ).
={q0q1}
= ɛ-closure(δ(q1, 0)).
= ɛ-closure(q2).
={q0q1q2}
= ɛ-closure(δ(q1, 1)).
= ɛ-closure(φ).
=φ
= ɛ-closure(δ({q0q1q2}, 0).
=ɛ-closure(q0 U q2 U φ).
={q0q1q2}
= ɛ-closure(δ({q0q1q2}, 1).
=ɛ-closure(q0 U φ U φ).
= {q0q1}
Page 1.
23
Finite Automata
= ɛ-closure(δ({q0q1}, 0).
Page 1.
24
Finite Automata
=ɛ-closure(φ U q1).
=ɛ-closure(φ) U ɛ-closure(q1).
= φ U q1
=q1
= ɛ-closure(δ({q0q1}, 1).
=ɛ-closure(q0U φ).
=ɛ-closure(q0) U ɛ-closure(φ).
={q0q1}U φ
=[q0q1]
= ɛ-closure(δ({q0q1}, 2).
=ɛ-closure(φ U q2).
=ɛ-closure(q2).
=[q1q2 ]
= ɛ-closure(δ(q1, 0).
= ɛ-closure(q1).
= q1
= ɛ-closure(δ(q1, 1).
= ɛ-closure(φ).
Page 1.
25
Finite Automata
= φ
= ɛ-closure(δ(q1, 2)
= ɛ-closure(q2)
= [q1 q2]
= ɛ-closure(φ U q1)
= ɛ-closure(q1)
= q1
= ɛ-closure(q0 U φ)
= ɛ-closure(q0)
= [q0, q1]
Page 1.
26
Finite Automata
= ɛ-closure(φ U q2 )
= ɛ-closure(q2)
= [q1 q2]
= ɛ-closure(δ(q1, 0 ) U δ (q2, 0 ))
= ɛ-closure(q1 U φ).
= ɛ-closure(q1)
= q1
= ɛ-closure(δ(q1, 1 )U δ (q2, 1 ))
= ɛ-closure(φ U φ).
= ɛ-closure(φ)
=φ
= ɛ-closure(δ(q1, 2 )U δ (q2, 2 ))
= ɛ-closure(q2 U φ).
= ɛ-closure(q2)
Page 1.
27
Finite Automata
= [q1 q2]
( φ, (0,1,2))= φ
Mark the final states, any pair which has a final state of ɛ -NFA the particular pair is afinal state in DFA.
Page 1.
28