Professional Documents
Culture Documents
Automata Theory
Automata theory
The word “Automata“ is the plural of “automaton"
which simply means any machine.
∑+ = ∑* -{є}
Languages-A set of strings which are chosen from some ∑*, where ∑ is a
particular alphabet, is called a language.
X Y X Y X y --------
Reading Head
Finite control System
p0 p1 p2 p3 p4
states
Main parts of pictorial representation of
Finite machine
Transition Table
Transition Diagram Notations
A transition diagram for DFA, M=(Q,∑, ,q0,F) is a
graph defined as follows:
For each state q in Q and each input symbol a in ∑,
there is a node represented by the circle
For each state q in Q and each input symbol a in ∑, let
(q,a)=P. This is represented by an arc from q to P
labelled a.
Transition Diagram Notations
If any state q in Q is the starting state
then it is represented by the circle with
arrow as
q
L(M)= { w|δ(q0,w) is in F}
Let Σ = {0, 1}. Give DFAs for {}, {ε}, Σ*, and Σ+.
0/1 0/1
0/1
q0 q0 q1
For Σ*: For Σ+:
0/1 0/1
0/1
q0 q0 q1
Example: Design a FA that accepts set of strings such that every string
ends in 00, over the alphabet
{0,1} i,e ∑={0, 1}
Inorder to design any FA, first try to fulfill the minimum condition.
0
Start q0 0 q1 0 q2
Being DFA, we must check every input symbol for output state from every
state. So we have to decide output state at symbol 1 from q0,q1 and q2.
Then it will be complete FA
1 1 0
start 0 0
q0 q1 q2
q2
1
Example: Design a FA that accepts set of strings such that every string
contains two alphabets, over the alphabet
{a,b} i,e ∑={a, b}
Sol: Inorder to design any FA, first try to fulfill the minimum
condition. The Language set for the statement={aa, ab, ba,
bb}
a a
q0 q1 q2
Start
Being DFA, we must check every input symbol for output state from every
state. So we have to decide output state at symbol 1 from q0,q1 and q2.
Then it will be complete FA
a/b
a/b
q3 Dead State
Construct a FA that accepts set of strings where the number of 0s
in every string is multiple of 3 over alphabet ∑={0,1}
1 1 1
start q0
0 q1 0 q2
0
As 0 existence of 0 is also multiple of 3, we have to consider
starting state as the final state.
Design FA which accepts set of strings containing exactly
four 1s in every string over alphabet ∑={0,1}
0 0 0 0 0
start
1 1 1 1
q0 q1 q2 q3 q2
q4
1
q5 is called the trap state or dead state. Dead 0/1
states are those states which transit to q5
themselves for all input symbols.
Design a FA that accepts strings containing exactly one 1 over
alphabet {0,1}. Also draw the transition table for the FA
generated
0 0
start 1
q1 q2
q2
1/0
1 0
0/1
q5
Design DFA for the language
L={w ϵ (a,b)*/nb(w) mod 3 > 1}
As given in the language, this can be interpreted that
number of b mod 3 has to be greater than 1 and there
is no restriction on number of a’s. Thus it will accept
string with 2 bs,5 bs, 8bs and so on.
a a a
start b b
q0 q1 q2
b
Q={q0,q1,q2}
F={q2}
Design DFA for the language
L={w ϵ (a,b)*/nb(w) mod 3 > 1}
As given in the language, this can be interpreted that
number of b mod 3 has to be greater than 1 and there
is no restriction on number of a’s. Thus it will accept
string with 2 bs,5 bs, 8bs and so on.
a a a
start b b
q0 q1 q2
b
Q={q0,q1,q2}
F={q2}
Design FA over alphabet ∑= {0,1} which accepts the set of
strings either start with 01 or end with 01
1/0
start 0 1
q0 q1 q2
1
q3 1
0 0
1
q4 0
0
1
q5
Example:
0/1
0/1 0/1
q0 q1 q2
Example :
b a/b
a
a
q0 q1 q2
b
Example :
b b
start qo
a q1
b q2
a a
a/b q3
Example :
b/c a a/b/c
a a
b
q0 q1 q2 q3
b/c
c
Example:
q0 a b q7
b
b a
b a
q4 q5 q6
b
Design FA over alphabet ∑={a,b} such that
string starts and ends with same symbol
start a b
A B b
C
b a
D b
a
b
E a
Design FA over alphabet ∑={a,b} such that
string starts and ends with different symbol
start a b
A B b
E
b a
C b
b a
D a
a)Design FA over the alphabet {a,b} such that string contains ‘a’
b) Design FA over the alphabet {a,b} such that string starts with ‘a’
c) Design FA over the alphabet {a,b} such that string ends with ‘a’
a) b
a/b b
a
start a
A B start a
A B
b) a/b b
start a
A B
C a/b
Automata for complement language
start a/b B
A
a/b
L2={a,aaa,b,bbb,aba,baa,baabb....}[L2 is complement of L1] [Odd number of alphabets]
start a/b
A B
a/b
Design FA over alphabet ∑={a,b} such that string starts
with character ‘a’
start a
A B a/b
a/b
C
Design FA over alphabet ∑={a,b} such that string does
not start with character ‘a’
start a
A C a/b
B a/b
Complementation
NFAs are a bit harder to think about than DFAs, because they do not
appear to define simple computational processes. They may seem at first
to be unnatural, like puzzles invented by professors for the torment of
students. NFAs and other kinds of nondeterministic automata arise
naturally in many ways, and they too have a variety of practical
applications.
Not A DFA
a
q0 q1
a,b
Does not have exactly one transition from every state
on every symbol:
Two transitions from q on a
0
No transition from q (on either a or b)
0
Though not a DFA, this can be taken as defining a
language, in a slightly different way
Formal Definition of NFA
0/1
q1 0 q2
0/1 0
start
q0
0/1
1 1 q4
q3
Design a NFA for the language L=(ab Ս aba)*
a
b
start a b a
q0 q1 q2 q3
a
b b
q4 a/b
DFA for the given statement
NFA’s for previous DFA
ab
b a
start
start start
q1 q0 q1 q0
q0
a
є b
a b
q2
q2 a aba
Spontaneous Transitions
An NFA can make a state transition
spontaneously, without consuming an input
symbol
Shown as an arrow labeled with
For example, {a}* {b}*:
q1 a
q0
q2 b
-Transitions To Accepting States
q1 a
q0
q2 b
q0
q2 b
a
a AB?
b
No: this NFA accepts
b
aab
Correct Union
a
A = {an | n is odd}
a
b B = {bn | n is odd}
b
a
AB
a
b
a b
{xy | x A and y B} ?
No: this NFA accepts abbaab
Correct Concatenation
a
A = {an | n is odd}
a
b
B = {bn | n is odd}
b
a b
a b
{xy | x A and y B}
Draw the state diagram for NFA accepting language
L=(ab)*(ba)* U aa*
start ba a
q1 q2
a
NFA for start q3 q4
(ab)*(ba)*
NFA for aa*
For Combining the two, we take a new state q0 and join the two NFAs with
null transition
ab ba
ba q2
ϵ q1
start
q0
a
ϵ
a
q3 q4
Find NFA with four state for the language
L={(an:n>=0) U (bna:n>=1)}
L=L1 U L2
L1= an:n>=0
L2= bna:n>=1
a b
start start a
q1 q2 b q4
q3
NFA for an
NFA for bna
Combined NFA
a
q1
ϵ b
b a
q2 q3 q4
Transformation of NFA to DFA
a,b b
start a a
q0 q1 q2
a,b
b
q3
Solution: Step1: Seek all the transition from starting state q0 for
every symbol in ∑ i.e (a,b).If we get a set of states for same
input, consider the set as a new single state
δ(q0,a)={q0,q1}-------------new state
δ(q0,b)={q0}
Step2: In step1 we are getting a new state {q0,q1}. Repeat step
1 for this new state only i.e check all transitions of a and b
from {q0,q1} as:
δ({q0,q1},a)= δ(q0,a) U δ(q1,a)
= {q0,q1} U {q2}
= {q0,q1,q2}-------------new state
δ({q0,q1},b)= δ(q0,b) U δ(q1,b)
= {q0} U {q1}
={q0,q1}---------------old state
Step 3: Repeat step 2 till you are getting any new state. All those
states that consist of any of the accepting state of given NFA
as member state will be considered as final states
δ({q0,q1,q2},a)= δ(q0,a) U δ(q1,a) U δ(q2,a)
={q0,q1} U {q2} U {q3}
={q0,q1,q2,q3}-------new state
δ({q0,q1,q2},b)= δ(q0,b) U δ(q1,b) U δ(q2,b)
= {q0} U {q1} U {q3}
={q0,q1,q3}--------new state
δ/∑ a b
q0 {q0,q1} {q0}
{q0,q1} {q0,q1,q2} {q0,q1}
*{q0,q1,q2} {q0,q1,q2,q3} {q0,q1,q3}
*{q0,q1,q2,q3} {q0,q1,q2,q3} {q0,q1,q2,q3}
*{q0,q1,q3} {q0,q1,q2,q3} {q0,q1,q2}
Let us say:
q0----A
{q0,q1}-----B
{q0,q1,q2}-----------C
{q0,q1,q2,q3}---------D
{q0,q1,q3}-----------E
A is the initial state and C,D and E are final states since they contain q2 and q3 as member
which are final states of NFA
δ/∑ a b
A B A
B C B
*C D E
*D D D
*E D C
b
b
start a B a
A
C
b
b a
E a,b
a D
Given NFA is
δ/∑ a b
q0 {q0,q1} {q2}
q1 {q0} {q1}
*q2 {q0,q1}
ᶲ
Convert it to DFA
A:{q0}
*B:{q2}
C:{q0,q1}
*D:{q1,q2}
start a C a
A b
a b
b
b D
B
a,b
a ᶲ
ϵ-NFA to NFA without ϵ
M={Q,∑,δ, q0,F)
Q={q0,q1,q2}
∑={a,b,c} and ϵ moves
initial state={q0}
F={q2}
δ/∑ a b c ϵ
q0 {q0} {ᶲ} {ᶲ} {q1}
q1 {ᶲ} {q2} {ᶲ} {q2}
*q2 {ᶲ} {ᶲ} {q2} {ᶲ}
Solution:
Step1: Find the states of NFA with ϵ transition
including initial state and final states as follows:
ϵ-closure(q0)={q0,q1,q2}
ϵ-closure(q1)={q1,q2}
ϵ-closure(q2)={q2}
Final states of NFA without ϵ-transition are all
those new states which contain final state of
NFA with ϵ-transition as member
So {q0,q1,q2},{q1,q2},{q2} are all final states.
Step 2: We have to decide δ’ to find out transitions as follows:
δ’({q0},a)=ϵ-closure(δ(ϵ-closure(q0),a)
=ϵ-closure(δ(q0,q1,q2),a)
= ϵ-closure(δ(q0,a) U δ(q1,a) U δ(q2,a) )
= ϵ-closure(q0 U ᶲ U ᶲ)
= ϵ-closure(q0)={q0,q1,q2}
Similarly, δ’({q0},b)=ϵ-closure(δ(ϵ-closure(q0),b)
=ϵ-closure(δ(q0,q1,q2),b)
= ϵ-closure(δ(q0,b) U δ(q1,b) U δ(q2,b) )
= ϵ-closure(ᶲ U q2 U ᶲ)
= ϵ-closure(q2)={q2}
δ’({q0},c)=ϵ-closure(δ(ϵ-closure(q0),c)
=ϵ-closure(δ(q0,q1,q2),c)
= ϵ-closure(δ(q0,c) U δ(q1,c) U δ(q2,c) )
= ϵ-closure(ᶲ U ᶲ U q2)
= ϵ-closure(q2)={q2}
In same fashion we can write δ’({q1},a)= ᶲ
δ’({q1},b)= {q2}
δ’({q1},c)= {q2}
δ’({q2},a)= ᶲ
δ’({q2},b)= ᶲ
δ’({q2},c)= {q2}
So transition table for NFA without ϵ transition
will be as follows:
δ’/∑ a b c
*{q0} {q0,q1,q2} {q2} {q2}
*{q1} {q2} {q2}
ᶲ
*{q2} {q2}
ᶲ ᶲ
NFA without epsilon
a q1
q0
a/b/c
b/c
c q2
Consider the NFA given by the following diagram
1 0
0
start є є
q0 q1 q2
ϵ-closure(q0)={q0,q1,q2}
ϵ-closure(q1)={q1,q2}
ϵ-closure(q2)={q2}
Final states of NFA without ϵ-transition are all
those new states which contain final state of
NFA with ϵ-transition as member
So {q0,q1,q2},{q1,q2},{q2} are all final states.
Step 2: We have to decide δ’ to find out transitions as follows:
δ’({q0},0)=ϵ-closure(δ(ϵ-closure(q0),a)
=ϵ-closure(δ(q0,q1,q2),0)
= ϵ-closure(δ(q0,0) U δ(q1,0) U δ(q2,0) )
= ϵ-closure(q0 U ᶲ U q2)
= ϵ-closure(q0) U ϵ-closure(q2) ={q0,q1,q2}U {q2}= {q0,q1,q2}
Similarly, δ’({q0},1)=ϵ-closure(δ(ϵ-closure(q0),1)
=ϵ-closure(δ(q0,q1,q2),1)
= ϵ-closure(δ(q0,1) U δ(q1,1) U δ(q2,1) )
= ϵ-closure(ᶲ U q1 U ᶲ)
= ϵ-closure(q1)={q1,q2}
δ’({q1},0)=ϵ-closure(δ(ϵ-closure(q1),0)
=ϵ-closure(δ(q1,q2),0)
= ϵ-closure(δ(q1,0) U δ(q2,0))
= ϵ-closure(ᶲ U q2)
= ϵ-closure(q2)={q2}
δ’({q1},1)=ϵ-closure(δ(ϵ-closure(q1),1)
=ϵ-closure(δ(q1,q2),1)
= ϵ-closure(δ(q1,1) U δ(q2,1))
= ϵ-closure(q1 U ᶲ)
= ϵ-closure(q1)={q1,q2}
δ’({q2},0)=ϵ-closure(δ(ϵ-closure(q2),0)
=ϵ-closure(δ(q2),0)
= ϵ-closure(q2)
={q2}
δ’({q2},1)=ϵ-closure(δ(ϵ-closure(q2),1)
=ϵ-closure(δ(q2),1)
= ϵ-closure( ᶲ)= ᶲ
𝛿/∑ 0 1
*q0 {q0,q1,q2} {q1,q2}
*q1 {q2} {q1,q2}
*q2 {q2} ᶲ
0/1
0 1 0
start 0/1
1/0 q2
q0 q1
0. 1
A ∊ B
0 0 0
∊
F 1 G
NFA without Epsilon
𝛿/∑ 0 1
*A {A,B,F,G} {B}
*B {G} {B}
F {B} {F G}
G {B} {F G}
convert the given epsilon NFA to NFA
without epsilons
∊
B C
∊
∊
A 0 0
1
1
G E
NFA without Epsilon
𝛿/∑ 0 1
A {G,E} {G}
B {G,E} {ᶲ}
C {E} {ᶲ}
G {B} {E}
*E {ᶲ} {ᶲ}
Minimization of DFA
Any DFA defines a unique langugae , but the converse
is not true. For a given language, there may be many
DFA’s that accepts it.
Minimization is a technique through which we can
minimize a given DFA to an optimum number of
states.
State categorization based on
productivity
Productive state- State is said to be productive
if it adds any accepting power to the machine
that its presence and absence affect the
language accepting capability.
A
a a b
b
D E
b
b
Procedure for Minimization:
partitioning method
b a b
B
{A D} a a C
E b
b
Minimize the DFA given below
a
b
Start b q3
q0 q2
b a
a
q1 b
a a
b
q5 a
q6
a a b
b
b
q4 q7
MINIMIZED DFA
b q1
q0 b
b
a a
a q6
a b
q5 q2
b a
Minimize the given DFA
q4
0 1
start 0
q0 q1 q2 0,1
q3
0 1 0,1
1 q5
0,1
Step 1: Eliminate unreachable states
q2 and q4 are unreachable. So eliminate them
After elimination of unreachable states
0
start
q0 q1
q3
0 1 0,1
1 q5
0,1
Equivalence sets:
0-equivalence:
𝛿(q0,0)=q1 𝛿(q0,1)=q3
𝛿(q1,0)=q0 𝛿(q1,1)=q3
Thus, q0 and q1 belong to same set after 1 equivalence
Equivalence sets:
1-equivalence for [q3 q5]
𝛿(q3,0)=q5 𝛿(q3,1)=q5
𝛿(q5,0)=q5 𝛿(q5,1)=q5
Thus, q3 and q5 belong to same set after 1
equivalence
2-equivalence for [q0 q1] [q3 q5]
0,1
0
start 1
q0
q3
Minimize the DFA
a a
start
A B
b b b
a C
minimization Procedure
Unreachable states: There are no unreachable states
a
start
A
b b
a C
Minimize DFA
a
start b
A B
b b a a
C D b
a
minimization Procedure
Unreachable states: There are no unreachable states
[B C] [D] [A]
Transition Table Of Minimized DFA
𝛿/∑ a b
*A A C B
B D A
C D A
D B D
FA with outputs
DFA and NFA are the automata which do not produce
any outputs. There are two automata which produce
output. These are:
Moore machine
Mealy machine
Moore machine
It is the FA in which one output is
associated with each state. In moore
machine every state of this finite
machine has a fixed output
Mathematically moore machine is a six-tuple machine and defined as
M0={Q,∑,∆,δ,λ’,q0}
0
1
1 0
0 q3 0
q2
0 1
Output for every state is written just above the state. If the input string is
n then output will be (n+1). This is because without consuming any
input, q0 is going to give output.
Mealy machine
It is finite automata in which output is associated with
each transition . In mealy machine every transition for
a particular input symbol has a fixed output.
Mathematically mealy machine is a six-tuple machine and defined as
M0={Q,∑,∆,δ,λ’,q0}
b a
a
q0 q1
b
Moore machine Design
Design a Moore machine that accepts all the
strings on ∑={a,b} with substring “ab”
a b C,1
A,0 B,0
a
b
States a b Output
A B A 0
B B C 0
C B A 1
Design a Moore machine that accepts all the
strings on ∑={a,b} with substring “baa”
States a B Output
A A B 0
B C B 0
C D B 0
D A B 1
Design a Moore machine that accepts all the
strings on ∑={0,1} which end with 10 with an
output of A and those ending with 11 with an
output of B and rest with an output of C.
Solution:
As outputs are given as A,B,C and ∑={0,1} ,
We can take Q={X,Y,Z}
For strings ending in 10, output is A
For strings ending in 11, output is B
Else, output C
1
0 W/B
1
1
X/C Y/C
0
1
Z/A
0
States 0 1 Output
X X Y C
Y Z W C
Z X Y A
W Z W B
Design a Moore machine that accepts all binary
numbers and give output the remainder
obtained by dividing the number by 3
(remainder modulo 3).
Solution:
As given , the outputs are: {0,1,2} as these are
the remainders we get when we divide any
binary number with 3 and ∑={0,1}
We can take Q={X,Y,Z}
0 1
1 0 Z,2
X,0 Y,1
0
1
States 0 1 Output
X X Y 0
Y Z X 1
Z Y Z 2
Shortcut for previous problem
1/0 0/0
1/0
q2 1/0
Design a mealy machine which checks
whether the number of b’s in the given
string are even or odd
Solution: we can assume that even
number of b’s will give output 0 and odd
number of b’s will give output 1.
b/1
q0 q1
b/0
Design a mealy machine to calculate one’s
complement of binary number assume that
string is read from LSB to MSB
Solution: As we know, one’s complement of
a binary number is generated by changing 1
to 0 and 0 to 1 bit in the string.
0/1
1/0
q0
Design a mealy machine to calculate 2’s
complement of binary number assume that
string is read from LSB to MSB and discard
end carry if any
Solution: If we take 2’s complement of a
binary number and LSB of the number is 0,
we obtain 2’s complement by keeping all 0’s
as such till first 1 is reached which is again
retained and rest of the string is
complemented
If LSB of the number is 1, we obtain 2’s
complement by keeping first 1 intact and
rest of the string is complemented
0/0
0/1
1/1
q0 q1 1/0
Equivalence of Mealy and Moore
Machines
Convert the following moore machine into
equivalent mealy machine
1
0 a q1 1
a a,b
q0 q3
b
0
b b
q2
a
Steps:
q0 q1 q2 0
q1 q3 q2 1
q2 q2 q3 0
q3 q3 q3 1
For every input symbol, we form the pair
consisting of the next state and corresponding
output and reconstruct the table for mealy
machine
Present a b
State state output state output
q0 q1 1 q2 0
q1 q3 1 q2 0
q2 q2 0 q3 1
q3 q3 1 q3 1
a/1 q1
a/1 a/1,b/1
start
q0 q3
b/0
b/0 b/1
q2
a/0
Convert the given moore machine to
equivalent mealy
a,b
q1/1
a a
b
q0/0 q2/0
b
Solution:
a/1,b/1
a/1 q1
q0
a/1
b/0 b/0
q2
Moore equivalent of given mealy
machine
Exercise: Convert the given mealy machine into
moore machine
b/1
a/0 a/1
q1
b/0
q0 a/1 q2
b/0 a/0
b/1 q3
Construct the transition table for the
given mealy machine
q0 q2 1 q3 0
q1 q0 0 q1 1
q2 q1 1 q2 0
q3 q2 0 q0 1
For every state qi, we look into the next
state column and determine the number
of outputs associated with qi in that
column.
We split qi into several different states
number of such states being equal to
number of outputs associated with qi.
In the given example, we will split q0,and
q2 as they have different outputs
Present input a input b
State state output state output
q00 q21 1 q3 0
q01 q21 1 q3 0
q1 q00 0 q1 1
q20 q1 1 q20 0
q21 q1 1 q20 0
q3 q20 0 q01 1
Present Next state output
State
i=a i=b
q00 q21 q3 0
q01 q21 q3 1
q1 q00 q1 1
q20 q1 q20 0
q21 q1 q20 1
q3 q20 q01 0
Solution:
b
1
a
0 a q1 0
a b
q00 a q20
b a
a b
1 0 1
b a
q 0
1
q3 q21
b
Convert the given mealy machine
into equivalent moore machine
Current Input Symbol
State a b
Next state Output Next State Output
q0 q1 1 q2 1
q1 q2 0 q0 1
q2 q0 1 q3 0
q3 q3 0 q1 1
Solution:
Current Input Symbol output
State
a b
q0 q1 q21 1
q1 q20 q0 1
q20 q0 q3 0
q21 q0 q3 1
q3 q3 q1 0
Regular expression
The simplest mechanism to define a language is to
express its grammatical rules through a regular
expression.
A regular expression generates a set of strings, known
as a regular set, and all the strings belonging to a
regular set are valid in the language, while others are
not
Definition of regular expression
By analyzing the problem, it is clear that 10th symbol from right has to
be 1 , Thus all symbols till 10th symbol from right can be either 1 or 0.
also symbols 11 onwards can also be either 0 or 1
So regular expression is:
r=(1+0)*1(1+0)9
Write a regular expression for the set of strings of 0’s
and 1’s not containing 101 as substring
r= (0*1*00)*0*1*
Write a regular expression over alphabet {a,b}for the set of strings
with even number of a’s followed by odd number of b’s that is for
language
L={a2nb2m+1: n>=0,m>=0}
r=(aa)*(bb)* b
Write regular expression for the language
L={w є {0,1}*: w has no pair of consecutive zeros}
r1=(1*011*)*(0+ є)+1*(0+ є)
OR
r1=(1+01)*(0+ є)
Write regular expression for the language
L={anbm/n>=4,m<=3}
1. ab(a+b)* 8. (a+b)(a+b)(a+b)
2. baa(a+b)* 9. (a+b)(a+b)(a+b)
3. (a+b)*abb (a+b)*
4. (a+b)*aab(a+b)* 10. ∊+(a+b)+(a+b)2+
5. a+a(a+b)*a (a+b)3
6. a+a(a+b)*a +b+
b(a+b)*b
7. a(a+b)*b+b(a+b)*a
Regular Expressions
1. |w|a=2 6. |w| mod 3=0
2. |w|a>=2 7. |w| mod 3=2
3. |w|a<=2 8. |w|b mod 3=0
4. 3rd symbol from left end 9. |w|a mod 3=1
is b 10. |w|b mod 3=2
5. 28th Symbol from right
end is a
Solutions
NFA with ϵ for r+s where R and S are automata for regular expressions r
and s respectively. First we reach the starting state of R and S and reach
the final state of either R or S.
R
ϵ ϵ
ϵ
S ϵ
NFA with ϵ for r*
ϵ ϵ
R
ϵ
NFA with ϵ for r.s
ϵ ϵ
R ϵ S
Find the automation for regular expression
a.(a+b)*.b.b
ϵ b ϵ
Find the automation for regular expression
a.(a+b)*.b.b
ϵ
b ϵ
ϵ
Find the automation for regular expression
a.(a+b)*.b.b
ϵ ϵ
b
ϵ
Find the automation for regular expression
a.(a+b)*.b.b
ϵ b
b ϵ
ϵ
Find the automation for regular expression
a.(a+b)*.b.b
ϵ b
b ϵ
b
ϵ
Construct ϵ-NFA for the regular expression
(0+1)*1(0+1)
a
C D
∊ ∊
A ∊ B ∊ c
G H I
∊ b ∊ ∊
E F d
∊
∊ L K J
M d
N e
∊
Arden’s Theorem
Let P and Q be two regular expressions over alphabet ∑. If P
does not contain null string ϵ, then
R=Q+RP
has a unique solution that is R=QP*
Arden’s theorem for finding regular
expressions for given automata
any ϵ moves
There should be exactly one initial state
regular expression.
Find the regular expression for transition
diagram given
a
start
q2
q1
b
a
a b a,b
q4
q3
b
Solution: The transitions required to reach a particular state in
given finite automaton are:
q1=q2b+q3a+ϵ
q2=q1a
q3=q1b
q4=q2a+q3b+q4a+q4b
Put q2 and q3 in q1
q1=q1ab+q1ba+ϵ
q1=ϵ+q1(ab+ba)
q1=ϵ(ab+ba)* (using arden’s theorem)
Since q1 is the only final state , the set of strings accepted by
given finite automaton corresponds to the regular expression is
(ab+ba)*
So required regular expression is (ab+ba)*
Construct a regular expression corresponding to the
state diagram given
0
start 1
q1 1
q2
0 1
q3
0
Solution:
q1=q10+q30+ϵ
q2=q11+q21+q31
q3=q20
q2=q11+q21+(q20)1=q11+q2(1+01)
q2=q11(1+01)* (using Arden’s theorem)
So q1=q10+q30+ ϵ=q10+q200+ ϵ
=q10+(q11(1+01)*)00+ ϵ
q1=q1(0+1(1+01)*00) +ϵ
q1= ϵ(0+1(1+01)*00)*
q1=(0+1(1+01)*00)*
As q1 is the only final state,
Find regular expression for the for the given DFA
0
1
1
q1 q2
0 0
0
1
q4 q3
1
Solution: q1=q10+q30+q40+ϵ
q2=q11+q21+q41
q3=q20
q4=q31
Now q4=q31=q201
Using q2 equation, we get q2=q11+q21+q2011
=q11+q2(1+011)
q2=q11(1+011)*
=q1(1(1+011)*)
Put q3 and q4 in q1 equation q1=q10+q200+q2010+ϵ
=q10+q2(00+010)+ ϵ
=q10+q11(1+011)*(00+010)+ ϵ
q1= ϵ(0+1(1+011)*(00+010))*
Put q2 in q4 equation q4=q11(1+011)*01=q1(1(1+01)*01)
Find the regular expression corresponding to
the given finite automaton
c c
a a
S A F
b
Solution: The transitions required to reach various states in
the finite automaton
S= ϵ +Sc
A= Sa + Ac + Fa
F=Ab
Using Arden’s theorem, S=ϵ + Sc=ϵc*=c*
Substituting value of S in A=c*a +Ac + Aba=c*a+A(c +ab)
Using Arden’s Theorem, A=c*a(c + ba)*
Substituting value of A in F= c*a(c + ba)*b
Since there are two final states, F and A, regular expression for
the finite automaton are c*a(c +ba)* and c*a(c +ba)*b
Find regular expression corresponding to the
finite automaton given
A b
a c
a,b
S B a F
b
Solution:
(a+b)*(ba+ab)c*
Construct Regular expression for DFA
given below
a,b q3
Start a,b a
q1 q2
b
a,b q4
Solution
q1=ε
q2=q1(a+b)+q3(a+b)+q4(a+b)
q3=q2a
q4=q2b
(Computing q2 as computation of q3 will complicate the problem)
q2=q1(a+b)+q3(a+b)+q4(a+b)
=ε(a+b)+q2a(a+b)+q2b(a+b)
=ε(a+b)+q2(a(a+b)+b(a+b))
=ε(a+b).(a(a+b)+b(a+b))*
= (a+b).(a(a+b))*. (b(a+b))*
q3= (a+b).(a(a+b))*. (b(a+b))* b --------- ans
Algebraic laws for regular expressions
P+Q=Q+P------ commutative law
(P+Q)+R=P+(Q+R)-----associative law
for union
(PQ)R=P(QR)----- associative law for
concatenation
Identities: ᶲ + L=L + ᶲ=L
ϵL=Lϵ=L
ᶲL=Lᶲ= ᶲ
P(Q+R)=PQ+PR Left Distributive law
(Q+R)P=QP+RP Right Distributive law
Idempotent law L+L= L
Laws of Closure
(L*)*=L*
L+=LL*=L*L
L*=L+ + ϵ
Identities of regular expression
I1 ᶲ+r=r
I2 ᶲr=rᶲ= ᶲ
I3 ϵr=r ϵ=r
I4 ϵ*=ϵ and ᶲ*=ϵ
I5 r + r=r
I6 r*r*=r*
I7 rr*= r*r=r+
I8 ϵ +rr*=r*=ϵ+r*r
I9 (pq)*p=p(qp)*
I10 (p+q)*=(p*q*)*=(p*+q*)*
I11 (p+q)r=pr+qr
Prove that t+RR*=R* where t is a null string and
R is a regular expression
Two regular expressions P and Q are equivalent if
P and Q represent the same set of strings
From Arden’s theorem, R’=Q+R’P is R’=QP*
t+RR*=R* comparing it with Arden’s theorem
Q=t
R’=R
P=R*
Solution of this equation will be R’=QP*
R1=QP*
= tR* = R* hence proved
Equivalence of two FAs
Two finite automata over ∑ are equivalent if
they accept the same set of strings over ∑.
When the two finite automata are not
equivalent, there is some string w over ∑
satisfying the following: One automaton
reaches a final state on application of w
whereas the other automaton reaches a
nonfinal state.
Equivalence of Two Finite Automata
• Two FA’s are equivalent if they accept the same set of strings
over any input.
Steps for comparison:
1. Construct a comparison table with entries (q,q’) where qЄM and q’ ЄM’
{M and M’ are two different machines}
2. Look for corresponding entries in a-column and b-column
reachable by(q,q’).
3. The pairs (q,q’) either belongs to both final states or both non final
states.
4. We repeat the construction by considering the pairs in second and
subsequent columns which are not in first column. There can be
two cases:
5. If there is a combination of non final and final state or vice versa,
we terminate the construction and conclude that two automatas
are not equivalent
6. Go on entering in first column till no new entry is left in second
and subsequent columns which are not in first column
Equivalence of Two Finite Automata
M and M’ are equivalent
(q,q’) (qc,q’c) (qd,q’d)
S aSa| bSb | c
S aSb | aXb
X cX | c
Thus the grammar for the language is
G={V={S,X}, ∑={a,b,c}, P, S}
Design a grammar for the language
L={anbm | m,n ≥1}
S XY
X aX|a
Y bY|b
Thus the grammar for the language is
G={V={S,X,Y}, ∑={a,b}, P, S}
Define Grammer for language
L={an | n>=0}
Sol:
S aS | ∊
Define grammer for language containing alphabets a
and b with atleast 2 symbols
(∑ U V)* (∑ U V)*
(∑ U V)* (∑ U V)*
A (∑ U V)*
A a
A aB
Regular languages
Sentential forms
Starting symbol plays an important role in deriving the final sentence or a string . The
final string is obtained by transitive application of productions in the given grammar
beginning with the starting symbol S.
lm rm
If rightmost variable is replaced by one of its
production bodies, such a derivation is called a
“rightmost derivation”
Parse Tree
There is a tree representation for derivation that has proved
extremely useful. It is the second way of showing derivations,
independent of the order in which productions are used is also
called derivation tree. A parse tree is an ordered tree in which
nodes are labeled with the left sides of productions and in
which the children of a node represent its corresponding right
sides.
Definition: let G=(Vn,Vt,P,S) be a context free grammar. An
ordered tree for this CFG is a derivation tree if and only if it has
the following properties:
The root is labeled by starting non terminal of the CFG that is S
Every leaf of the ordered tree has a label from Vt U {є}
Every Interior node of ordered tree has a label from Vn
A vertex with a child labeled є can have no other children.
Derivations
If α β is a production of P in CFG and
a and b are strings in (Vn U Vt)*, then
aαb G aβb
We say that production α β is applied
to the string a α b to obtain a β b
α1 G α2, α2 α3, α3 α4,………..
G G
αm-1 G
αm
α1 G* αm
Let G be CFG
S bB/aA
A b/bS/aAA
B a/aS/bBB
For the string bbaababa find
1) left most derivation
2) rightmost derivation
3) parse tree
S aAS S
aAa a A S
aSbAa S b A a
aSbbaa a b a
aabbaa
Example: Let there be a grammar G and is represented by the following
production
S ASA| BSB | a| b
A a
B b
A S A
a A S A a
a A S A a
a B S B a
b b b
Show that string aaabbbaaa is element of L using a) derivation approach b) recursive
inference approach
a a a b b b a a a
A A A B S B A A A
S
S
S
S
Recursive approach