BCS503_MODULE1_MODULE5_NOTES
BCS503_MODULE1_MODULE5_NOTES
BCS503
Finite Automata
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.
as S1 U S2 = {x | x ϵ S1 or x ϵ
S2} S1 Ո S2 = {x | x ϵ S1 and x ϵ
S2} S1 - S2 = {x | x ϵ S1 and x
S2}
The complement of a set S, denoted by Ṡ consists of all elements not in S. To make this
meaningful, we need to know what the universal set U of all possible elements is. If U is
specified, then
Page 1.
2
Finite Automata
Ṡ={x | x ϵ U, x S}
The set with no elements, called the empty set or the null set, is denoted by ɛ. From the definition of
a set, it is obvious that
S U ɛ = S - ɛ =S
SՈɛ=ɛ
ἕ= U
De Morgan's laws: The following useful identities, known as De Morgan's laws.
Graphs:
A graph is a construct consisting of two finite sets, the set V = {υ1, υ2,…, υn} of vertices and the set E =
{e1, e2,…, em} of edges. Each edge is a pair of vertices from V, for instance,
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
Page 1.
3
Finite Automata
alphabet. For example, if the alphabet ∑ = {0}, then ∑* to denote the set of strings obtained by
concatenating zero or more symbols from ∑.
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
The combination of transitions and states is called a transition diagram.
Figure 1.4 shows a transition diagram to map cities and their roads.
Page 1.
4
Finite Automata
δ:
δ (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.
5
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.
For example: ∑ = {0, 1}
There is no outgoing transition from initial state, for a symbol ‘1 ‘and similarly there is no outgoing
transition from final state for ‘0’.
Transition Function for string:
Note: 1) δ is the transition function, used for symbols.
(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
Page 1.
6
Finite Automata
1, 2}
Figure 1.9: Transition diagram
Table 1.3: Transition table for the figure 1.9
{FS}) δ:
δ (A0, 0)=A1 δ (A0, 1)=A2 δ(A0,
2)=A0 δ (A1, 0)=A2 δ (A1, 1)=A0
Page 1.
7
Finite Automata
δ(A1, 2)=A1
δ (A2, 0)=A2 δ (A2, 1)=A1 δ(A2, 2)=A0
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.
Page 1.
8
Finite Automata
ɛ. (q0, ɛ)=q0;
Page 1.
9
Finite Automata
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
Page 1.
10
Finite Automata
‘0’, one
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. We can define above DFA as MDFA=(A, ∑, δ, IS, {FS})
A={ A0, A1, A2}; ∑={0, 1}
δ:
δ (A0, 0)=A1 δ (A0,
1)=A0 δ (A1, 0)=A1 δ
(A1, 1)=A2 δ (A2, 0)=A1 δ
(A2, 1)=A0 IS=A0; FS=A2
Example 1.9: Design a DFA which accept all the strings ends with substring 012 over the alphabet
∑={0, 1, 2}.
condition 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. We can define above DFA as MDFA=(A, ∑, δ, IS, {FS})
A={ A0, A1, A2, A3}; ∑={0, 1, 2}
δ:
δ (A0, 0)=A1 δ (A0, 1)=A0 δ(A0, 2)=A0
δ (A1, 0)=A1 δ (A1, 1)=A2 δ(A1, 2)=A0
δ (A2, 0)=A1 δ (A2, 1)=A0 δ(A2, 2)=A3
δ (A3, 0)=A1 δ (A3, 1)=A0 δ(A3, 2)=A0
IS=A0; FS=A3
Example 1.10: Design a DFA which accept all the strings begins with symbol ‘a’ over the alphabet
∑={a, b}.
Page 1.
12
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}.
L={01, 010, 011, 0100, 0101…}.
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.
13
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. We can define above DFA as MDFA=(A, ∑, δ, IS, {FS})
A={ A0, A1, A2 A3}; ∑={0, 1}
δ:
δ (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}.
L={01, 010, 011, 0100, 001, 101, 0001,1001, 0101, 01101…}
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.
14
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. L={ ɛ, 10, 100, 110, …}
To design DFA we need to make the following assumptions.
Page 1.
15
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. To design a DFA we need to make following assumptions,
1. If there is no ‘x’ in the string, such a string should not be accepted.
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.
We can define designed DFA as MDFA=(A, ∑, δ, IS,
{FS}) A= { A0, A1, A2, A4, A4, A5, A6} ∑={x, y}
δ:
δ (A0, x)= A4 δ (A0, y)= A1 ; δ (A1, δ (A1,
x)=A5 y)=A2
δ (A2, x)=A6 δ (A2, y)=A3; δ (A3, x)=A3 δ (A3, y)=A3
δ (A4, x)=A5 δ (A3, y)=A5; δ (A5, x)=A6 δ (A5, y)=A6 ;
Page 1.
16
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.
17
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}. We can define designed DFA as MDFA=(A, ∑, δ, IS, {FS})
A={ A0, A1, A2 A3, A4, A5, A6} ∑={0, 1}
δ:
δ (A0, 0)=A1 δ (A0, 1)=A4 ; δ (A1, 0)=A0 δ (A1, 1)=A2
δ (A2, 0)=A2 δ (A2, 1)=A3 ; δ (A4, 0)=A2 δ (A4, 1)=A5
δ (A5, 0)=A3 δ (A5, 1)=A6 ; δ (A6, 0)=A6 δ (A6, 1)=A6
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.
18
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.
19
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.
20
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
To search a text “shine” and “hire” the DFA shown in figure 1.52 is used
Page 1.
21
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.
22
Finite Automata
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.
23
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.
24
Finite Automata
DFA:
= ɛ-closure(δ({q0q1}, 0).
Page 1.
25
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.
26
Finite Automata
= φ
= ɛ-closure(δ(q1, 2)
= ɛ-closure(q2)
= [q1 q2]
= ɛ-closure(φ U q1)
= ɛ-closure(q1)
= q1
= ɛ-closure(q0 U φ)
= ɛ-closure(q0)
= [q0, q1]
Page 1.
27
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.
28
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
Page 1.
29
REGULAR EXPRESSION
Chapter 2
REGULAR EXPRESSIONS
Language represented in the form of expression (symbols separated by operator) is called
regular expression. δ 1U2
∑= {a, b, 0, 1}
Before studying regular expression in detail, we will discuss some fundamental rules of the
regular expression.
Page 2.
30
REGULAR EXPRESSION
xxvi. Sets of all strings which starts with either 00 or 11 or ends with 00 or 11
RE=(00+11) (0+1)* +(0+1)*(00+11).
xxvii. Find the regular expression of the language L={anbm :n≥0,
m≥0} L={Ɛ+a+aa..}{Ɛ+b+bb…}
RE=a*b*
xxviii. Find the regular expression of the language L={anb2m+2 : n≥0,
m≥0} RE=(aa)*(bb)*bb.
xxix. Find the regular expression of the language L={a2nbm : n≥4,
m≤3} RE=(aaaa)*(Ɛ+b+bb+bbb)
xxx. Find the regular expression of the language L={anbm/n+m is
even} RE=(aa)*(bb)*+a(aa)*b(bb)*
2.1.
But in regular expression each symbol is having its own finite automata.
Definition for the finite automat which accept the symbol ‘1’ is
Definition for the finite automat which accept the symbol ‘0’ or ‘1’
Q={Q0 U Q1 U E U F} ={ A, B, C, D, E. F);
∑= {0, 1}
δ(A, 0)= B; δ (C, 1)= D; δ(E, Ɛ)={A, C}; δ(D, Ɛ)=F: δ(D, Ɛ)=F
IS=E; FS=F
For the symbol ‘0’ the finite automata is shown in figure 2.2
Page 2.
31
REGULAR EXPRESSION
Definition for the finite automat which accept the symbol ‘1’ is
We are joining these two finite automata with disturbing the regular expression 0+1 as shown in
figure
2.4. To join these two finite automata we need more extra states, one for the initial state and second
is for the final state, states A and B no more initial states and B and D are no more final states. All
these states will now become intermediate states as shown in figure 2.4.
Definition for the finite automat which accept the symbol ‘0’ or ‘1’
Q={Q0 U Q1 U E U F} ={ A, B, C, D, E. F);
∑={0, 1}
δ(A, 0)= B; δ (C, 1)= D; δ(E, Ɛ)={A, C}; δ(D, Ɛ)=F: δ(D, Ɛ)=F
IS=E; FS=F
For the regular expression 01 the finite automata is shown in figure 2.6.
Page 2.
32
REGULAR EXPRESSION
We can join the two finite automata shown in figure2.5 and figure 2.6 without disturbing the
regular expression 01 is shown in figure 2.6.
∑={0, 1}
IS=A; FS=D
The designed finite automata accept all the strings of 0* ie., {Ɛ, 0, 00, 000…}
is
Page 2.
33
REGULAR EXPRESSION
Q={Q0 U E U F} ={ A, B, E, F);
∑=0
IS=E; FS=F
Example 2.1: Design a finite automat for the regular expression 0*1
Join finite automata of 0* and 1, which will be the solution for the regular expression 0*1
Example 2.2: Design a finite automat for the regular expression 0(0+1)*1
Page 2.
34
REGULAR EXPRESSION
i. Draw the finite automata for the symbol ‘0’ and ‘1’
Page 2.
35
REGULAR EXPRESSION
they are:
i. Recursive Method.
ii. State Elimination Method.
i. Recursive Method :
In this method it uses recursive method, to construct new regular
expression. For example the regular expression of DFA shown in figure
2.17 is
In order to obtain the value of regular expression , we use all the (transition) possible
regular expression of the DFA. The possible regular expression of the figure 2.17 is shown in the
table2.1.
Equations to obtain the regular expression of all the transitions are as follows:
If state 2 and 3 are final states then the regular expression is written as:
Example 2.3: Find the regular expression of DFA shown in figure 2.17 by using recursive method.
Page 2.
36
REGULAR EXPRESSION
Example 2.4: Find the regular expression of DFA shown in figure 2.18 by using recursive method.
Page 2.
37
REGULAR EXPRESSION
In state elimination method, we obtain regular expression, by eliminating all the intermediate
states. After eliminating the intermediate states, it is easy to find the regular expression for the
remaining states (initial and final).
RE=01
Page 2.
38
REGULAR EXPRESSION
The regular expression of the finite automata shown in figure 2.2 is:
Figure2.22: Finite
automata RE=0a*1
From the above examples we come to know that eliminating state has one predecessor state A 0 and
one successor state A2. In complex finite automata the eliminating state may have more number of
predecessors and successors. One Such example is shown in the figure 2.23.
Before eliminating any state from the finite automata, we need to find out the path passing through
the eliminating state. The paths passing through the eliminating state are P1ESn, P1ES1, PnES1 and
PnESn. After eliminating state E, the automata is shown in the figure 2.24.
After eliminating all predecessors and successors, leaving initial state and final state, the remaining
machine looks shown in the figure 2.25.
Page 2.
39
REGULAR EXPRESSION
Figure 2.25: Finite automata after eliminating all predecessors and successors.
The regular expression is, language accepted by the initial state of finite automata and Su*.
The language accepted by the initial state is {R*+Su*t+R*Su*t + su*tR*…}, this is like {x*+y*+xy + yx
…}
We can simplify it as (x+y)* similarly, we can simplify the language for the initial state as (R+Su*t)*.
Therefore, regular expression of finite automata is (R+Su*t)*Su*. Note that in some cases the same
state is initial as well as final state.
Page 2.
40
REGULAR EXPRESSION
Example 2.5: Construct regular expression for the finite automat shown in figure 2.30.
No intermediate in the given finite automata, hence we can’t eliminate any of the
Therefore RE =(R+Su*t)*Su*
= (b+aa*b)*aa*
=b(Ɛ+aa*)*aa*
=b(aa*)*aa*
Example 2.6: Construct regular expression for the finite automat shown in figure 2.31 by using state
elimination method.
We can eliminate one intermediate state A1, the paths passing through the eliminating state are
A0A1A0, A0A1A2, A2A1A0 and A2A1A2.
Page 2.
41
REGULAR EXPRESSION
Automata RE=(R+Su*t)*Su*
= ((2+02*1)+(1+02*0)(0+12*0)*(2+02*0))*((1+02*0)(0+12*0)*.
Pumping lemma:
If more 0s, there will be more number of pumping. In such a case it is very difficult to count the
number of pumping. To count the number of pump easily we draw circles around the intermediate
state so that we can easily count the number of pumping to prove the language as non-regular.
Page 2.
42
REGULAR EXPRESSION
To prove the language as non-regular, smallest string of language is divided into uvw by considering
two conditions.
i. V Ɛ.
ii. |UV|≤n where n is the smallest string of the language. To prove the language as a non-
regular, throughout the proof the value of n is constant.
Example 2.7: Prove that the language L={ :i≥1} is not regular.
0(00)i000000 ЄL
I=1
000000000
ЄL I=2
00000000000 L
When i=2 the string obtained is not belongs to language, hence proved language is not regular.
Example 2.8: Prove that the language L={anbn+1 :n≥2} is not regular.
i=1
aaabbbb Є L
I=2
Aaabaabbbb L
When i=2 the string obtained is not belongs to language, hence proved the language is non-regular.
Page 2.
43
REGULAR EXPRESSION
Till now we have seen many regular expressions and their applications. These regular expressions
are bounded/ related by operators called closure properties of regular expression. The different
operators used to relate regular expressions are:
i. Boolean.
ii. Reversal.
iii. String Homomorphism and Inverse Homomorphism.
i. Boolean Operator:
They are of different types
a. Union b. Intersection c. Difference d. Compliment.
a. Union Operation.
To perform union operation it uses following steps.
• This operation is applied on two machines
defined as M1=(Q1, ∑1, δ1, IS1, FS1)
M2=(Q2, ∑2, δ2, IS2, FS2)
• Find the language L1 and L2 of the two machines.
• Perform union operation on the two languages L1 and L2 to obtain language L3
• Combine two machines to perform union operation.
• Apply language L3 on combined machines to obtain machine for
union operation.
In order to obtain the finite automata for the union operation, we need to join two finite automata.
The transition table for union operation is shown in table…
Page 2.
44
REGULAR EXPRESSION
Figure 2.38: Finite Automata after combining figure 2.36 and 2.37.
Page 2.
45
REGULAR EXPRESSION
The final automata for the union operation is shown in figure 2.42
Figure 2.44: Difference of two finite automata of figure 2.36 and 2.37.
Compliment:
iii. Compliment DFA. Reverse all transitions and convert all final to non final and vice-versa.
State B and φ are not reachable from the initial State. Hence the two states are removed from the
finite automata.
2.48 is
RE=Ɛ
String Homomorphism:
Page 2.
47
REGULAR EXPRESSION
Inverse Homomorphism:
If the homomorphism from an alphabet {0, 1, 2} to {a, b} is defined by h(0)=ab; h(1)=b; &
h(2)=aa, then:
i. What is h(2201).
ii. If L is language 1*02* what is h(L).
iii. If L is language(ab+baa)*bab then what is h-1(L)
i. h(2201)=aaaaabb
ii. h(L)=h(1*02*)=b*ab(aa)*
iii. (ab+baa)*bab=(0+12)*10
In Equivalence, two different DFA’s are given, we need to find out the two DFA’s are similar or
not. By filling table and Preshapat tree we can decide the two DFAs are similar | not similar.
Preshapat Tree: To find pair of nodes similar | not similar Preshapat tree is used. It consists of
root node, intermediate nodes and leaves nodes. The root node of the tree is pair of initial states
of two DFAs. Next we construct branches of tree depending on number of input symbols. If
leaves node do not have a cross in the difference table and same pairs are repeating, we stop
constructing tree and decide the root pair is similar or else dissimilar, any of leaves node has a
cross in the difference table.
Page 2.
48
REGULAR EXPRESSION
Note that root of the tree is pair of initial states. Leaves nodes of the tree do not have cross in the
difference table and nodes are repeating, hence the two DFA’s are similar.
Example 2.11: Find out the two DFAs are similar or not.
Page 2.
49
REGULAR EXPRESSION
The leaves node AG has X in the table; hence two DFAs are dissimilar.
In case of minimization, the two states are minimized to one state if they are similar. For example
state X and Y are equal, they are replaced by one state as shown in figure 2.59
To decide the states are similar | not similar we use Shanprepat tree.
Shanprepat Tree: To find equivalence between pair of states Shanprepat tree is used. It consists of
root node, intermediate nodes and leaves nodes. The root node of the tree is pair of states used to
find the similar | not similar states. Next we construct branches of tree depending on number of
input symbols. If leaves node do not have a cross in the difference table and same pairs are
repeating, we stop constructing tree and decide the root pair is similar or else decide two states are
dissimilar, any of leaves node has a cross in the difference table.
Example 2.12: Using table filling method, minimize the DFA shown in figure 2.60 and draw the
transition diagram of the resulting DFA.
Page 2.
50
REGULAR EXPRESSION
Example 2.13: Using table filling method, minimize the DFA shown in figure 2.63 and draw the
transition diagram of the resulting DFA.
From the given DFA we draw the dissimilar table as shown in figure. As compared to final state C all
states are different (non-final states), hence X is marked.
The leaves node decides the root node. Any leaves node has X in the table, the root node is marked
as X or else pair node repeats. Stop when the pair nodes start repeating, and decide the root node
pair is similar.
Page 2.
51
REGULAR EXPRESSION
From the table, we come to know that A=E, B=H and D=F. the resulting DFA is shown in figure..
Page 2.
52
REGULAR EXPRESSION
Example 2.14: Using table filling method, minimize the DFA shown in table and draw the
transition diagram of the resulting DFA.
The table shows the dissimilarity in the states of the given problem.
Page 2.
53
REGULAR EXPRESSION
Page 2.
54
CONTEXT FREE GRAMMAR
Chapter 3
CONTEXT FREE GRAMMAR
To define a language, English grammar is used such a concept is called as Context Free Language
(CFL) or Context Free Grammar (CFG). For example:
// it is a
symbol. L={0}*={Ɛ, 0, 00, 000, …}
0S
P is Productions
ii. Production which separate the symbols (anbn where, n={0, 1, 2,,}) is
G = (V, T, P, S)
V=S, T= {a, b}
Page 3.
55
CONTEXT FREE GRAMMAR
P is production
S is starting symbol = S
G=(V, T, P, S)
V={S, B} T= {a, b}
P is
production
S=S
Example 3.3: Construct the grammar for palindrome over the ∑={a,
G=(V, T, P, S)
V=S, T={a, b}
P is
production
S=S
Example 3.4: Construct the grammar for the language L={x |na(x)=nb(x)}
G= (V, T, P, S)
V=S, T= {a, b}
P is
production
S=S
Page 3.
56
CONTEXT FREE GRAMMAR
Example 3.5: Construct the grammar for the language L={x |na(x)
nb(x)} L={a, aab. aba, baa, ….b, bba, bab, abb…}
G= (V, T, P, S)
V={A, B, S} T={a, b}
P is
production
S=S
Example 3.6: Construct the grammar for the language L= {0i1j2k |i=j or
To obtain the language L= {0i1j2k |i=j or j=k} club the above productions
G= (V, T, P, S)
V={S, B, A, C, D} T= {0, 1, 2}
P is
production
Page 3.
57
CONTEXT FREE GRAMMAR
S=S
Example 3.7: Construct the grammar for the language L= {xiyjzk |i+2j=k}
G= (V, T, P, S)
V= {B, A} T={x, y, z}
P is
production
S=A
Example 3.8: Construct the grammar for the language L= {w|wЄ(0+1)*} with at least one
occurance of 110
G=(V, T, P, S)
V= {B, A, S} T={0, 1}
P is
production
S=S
Page 3.
58
CONTEXT FREE GRAMMAR
It is a tree, consisting of root node, intermediate node and leaf node. They are of two types:
Left Most Derivation Tree (LMD): In LMD left most variable simplified followed by other variables.
Example 3.9: Construct LMD and RMD for the string xxxyyy using production
Identifier:
Identifier is letters followed by zero or more than zero letters or digits. We can write identifier in
the form of expression over ∑={a, b, 0, 1} as follows:
I= (a + b) (a+b+0+1)*
Expression can be
According to mathematical equation of identifier, we can write the following productions for the
identifier as
Example 3.10: Design grammar for valid expression over operator + and *. The argument of the
expressions is valid identifier over symbols a, b, 0, 1. Derive LMD and RMD for the string
w=(a11+b0)*(b00+001).
Page 3.
59
CONTEXT FREE GRAMMAR
Page 3.
60
CONTEXT FREE GRAMMAR
Ambiguity:
Two different trees for a LMD or RMD called ambiguity. For example, the production:
for the string a+a+a, two LMD and RMD are shown in figure 3.4 and 3.5 respectively.
Figure 3.4: Two different LMD for the production over the string a+a+a
Example 3.11: Show that the given grammar is ambiguous by using LMD and RMD for the
production over a string (()()()).
Page 3.
61
CONTEXT FREE GRAMMAR
Figure 3.6: Two different LMD for the production over a string (()()()).
Figure 3.7: Two different RMD for the production over a string (()()()).
For both RMD and LMD, the tree obtained for the same production has two different trees
called Ambiguity.
Resolve Ambiguity:
Page 3.
62
CONTEXT FREE GRAMMAR
Page 3.
63
PUSHDOWN AUTOMATA
Chapter 5
PUSHDOWN AUTOMATA (PDA)
To process input string PDA uses stack along with input, such an automata is called Push Down
Automata (PDA). PDA is defined with seven tuples, (Q, ∑, δ, Z0, ┌, IS, FS)
∑ is input alphabet
┌ is stack
symbols IS is
initial state FS is
final state
Figure 5.1: Different position of stack for the input string is 100001.
In Deterministic Push Down Automata (DPDA), we are designing PDA. The design of PDA begins
with Instantaneous Description (IDs), each IDs consist of state, input string to be processed and
initial symbol of the stack (z0).
The Instantaneous Descriptions (IDs) for the given problem are as follows:
Page 5.1
PUSHDOWN AUTOMATA
By making use of the above IDs we can obtain the transition functions, which are required for the
construction of PDA.
For first transition function, ID1 is used for input transition and ID2 is used as output.
Next ID2 is the input of transition and ID3 is used for output transition function.
δ(q0, 0, 0)=q0, 00
δ(q0, 1, 0)=q0, Ɛ
δ(q0, Ɛ, z0)=q1,
z0
The Instantaneous Descriptions (IDs) for the given problem are as follows
By making use of the above IDs we can obtain the transition functions, which are required
to construct the PDA.
For first transition function, ID1 is used for input transition and ID2 is used as output.
Page 5.2
PUSHDOWN AUTOMATA
Next ID2 is the input of transition and ID3 is used for output transition function.
δ(q0, b, a)=q0, Ɛ
δ(q0, Ɛ, z0)=q1,
z0
The Instantaneous Descriptions (IDs) for the given problem are as follows
By making use of the above IDs we can obtain the transition functions, which are required for the
construction of a PDA.
For first transition function, ID1 is used for input transition and ID2 is used as output.
δ(q0, a, z0)=q0,
az0 Possible
transition δ(q0, b,
z0)=q0, bz0
Next ID2 is the input of transition and ID3 is used for output transition function.
δ(q0, a, a)=q0, aa
Possible transition
Page 5.3
PUSHDOWN AUTOMATA
δ(q0, b, b)=q0, bb
δ(q0, b, a)=q0,
δ(q0, a, b)=q0, Ɛ
δ(q0, Ɛ, z0)=q1,
z0
The Instantaneous Descriptions (IDs) for the given problem are as follows
By making use of the above IDs we can obtain the transition functions, which are required
to construct the PDA.
For first transition function, ID1 is used for input transition and ID2 is used as output.
Next ID2 is the input of transition and ID3 is used for output transition function.
δ(q0, a, a)=q0, aa
δ(q0, b, a)=q0, Ɛ
δ(q0, c, c)=q0, cc
Page 5.4
PUSHDOWN AUTOMATA
δ(q0, Ɛ, c)=q0, Ɛ
i. Symbol of first half continues in the same state and push the symbol to top of the stack.
ii. Symbol of second half, it just changes the state and continues further.
The Instantaneous Descriptions (IDs) for the given problem are as follows
δ(q0, a, a)=q0, aa
δ(q0, a, a)=q1, a
δ(q1, a, a)=q1, Ɛ
δ(q1, Ɛ, z0)=q2, z0
Page 5.5
PUSHDOWN AUTOMATA
CFG begins with starting symbol. Therefore starting symbol in the form of transition function of PDA
is derived as:
In this case productions of CFG’s are given; we need to find out equivalent transition functions
of PDA.
Example 5.7: Convert following productions of CFG into transition function of PDA.
Before converting CFG to PDA, see that all productions are in the form of Greibach Normal form.
In Greibach Normal form there should not be undesired production and all the right hand side
production are only terminal or terminal followed by any number of variables.
Page 5.6
PUSHDOWN AUTOMATA
CFLs are closed under operator; there are different types of operators
i. Union
ii. Concatenation
iii. Star Closure
iv. Intersection of two CFLs
v. Intersection of CFL and regular language
vi. Compliment of CFLs
vii. Reversal.
viii. Substitution.
ix. Inverse Homomorphism,
i. Union:
CFL1=G1=(V1, T1, P1, S1) CFL2=( V2, T2, P2,
S2) CFL3=G3 =(V1UV2, T1UT2, P1UP2,
S1|S2)
ii. Concatenation:
CFL3=G3 =(V1V2, T1T2, P1P2, S1S2)
iii. Star Closure:
CFL1=G1=(V1, T1, P1,
S1) S1=TS1|Ɛ;
iv. Intersection of two CFLs:
CFL1=L1={anbnci :n≥0, i≥0}
CFL2=L2={aibncn :n≥0, i≥0} is not a
CFL
Proof:
abc, aabbcc…}
Page 5.7
PUSHDOWN AUTOMATA
={anbncn :n≥0}
The above language is neither belongs to L1 nor L2 therefore intersection of two CFLs are not CFL.
vii. Reversal:
In this case the right hand side of production is reversed.
viii. Substitution:
h(0)= aba; h(1)= ba
h(010)=ababaaba
S(0)= {anbn:n≥0}; S(1)={aa, bb}
S(01)={anbnaa, anbnbb}
ix. Inverse Homomorphism:
Page 5.8
TURING MACHINE
Chapter 6
TURING MACHINE
Turing machine was invented by Alan Turing in 1936. It is a mathematical model of computer.
Turing machines prove fundamental limitations on the power of mechanical computation. While
they can express arbitrary computations, their minimalistic design makes them unsuitable for
computation in practice: real- world computers are based on different designs that, unlike Turing
machines, use random-access memory.
Turing completeness is the ability for a system of instructions to simulate a Turing machine. A
programming language that is Turing complete is theoretically capable of expressing all tasks
accomplishable by computers; nearly all programming languages are Turing complete if the
limitations of finite memory are ignored.
The pictorial representation of Turing machine is shown in the figure 6.1. The machine consists of a
finite control, which can be in any of a finite set of states. It has an input tape divided into finite
cells; each can hold one symbol. Initially an input string over alphabet is stored in the tape. Default
value of tape is blank symbol called B, it is a tape symbol it is not an input symbol. There is a tape
head always pointing at the leftmost cell of the tape. A move of the Turing machine is a function of
the state of the finite control and the tape symbol scanned. In one move Turing machine will:
i. Change state. The next state optionally may be the same as the current state.
ii. Write a tape symbol in the cell scanned. This tape symbol replaces whatever symbol
was in that cell.
Turing machine can be defined with 5-tuples
MT= (Q, ∑, δ, B, ┌, IS, FS)
Q= Number of states used in the Turing machine.
∑= {a, b}
┌ = Tape symbol {a, b, B}
B = Blank symbol.
δ:
Q x ∑=Q, ┌, D where, D is direction
of TM.
For example if the input string is aabb, it is stored in the input tape shown in figure 6.1.
Turing machine uses IDs to process string; the IDs consist of state and input string. The IDs for
the string aabb is shown below.
Page 6.2
TURING MACHINE
δ(q0, a)=q1, X, R;
δ(q1, a)=q1, a, R;
δ(q1, b)=q2, Y, L;
δ(q2, a)=q2, a, L;
δ(q2, X)=q0, X, R;
δ(q2, Y)=q2, Y, L;
δ(q0, Y)=q0, Y, R;
δ(q0, B)=q3, B, R;
Example 6.1: Design a Turing machine for the language L={anbncn : n≥1}
The processing of string aabbcc is shown below.
δ(q0, a)=q1, X, R;
δ(q1, a)=q1, a, R;
Page 6.3
TURING MACHINE
δ(q1, b)=q2, Y, R;
δ(q2, b)=q2, b, R;
δ(q2, c)=q3, Z, L;
δ(q3, Z)=q3, Z, L;
δ(q3, b)=q3, b, L;
δ(q3, Y)=q3, Y, L;
δ(q3, a)=q3, a, L;
δ(q3, X)=q0, X, R;
δ(q1, Y)=q1, Y, R;
δ(q2, Z)=q2, Z, R;
δ(q0, Y)=q0, Y, R;
δ(q0, Z)=q0, Z, R;
δ(q0, B)=q4, B, R;
δ(q0, B)=q3, B, R;
Page 6.4
TURING MACHINE
δ(q1, 0)=q1, 0, R;
δ(q2, X)=q0, X, R;
δ(q2, 0)=q2, 0, L;
δ(q2, 1)=q2, 1, L;
δ(q0, Y)=q0, Y, R;
δ(q0, B)=q3, B, R;
Page 6.5
TURING MACHINE
δ : Q × Γ→ Q × Γ ×{L, R, U, D},
Where U and D specifies movement of the read-write head up and down.
Page 6.6
TURING MACHINE
Figure 6.9: Multi-dimensional Turing machine in the form of multi-tape Turing machines.
Page 6.7