18CSC301T –Formal
Language and Automata
Unit 1 – Automata Fundamentals
Introduction to TOC
Need to Know 3 W’s of Theory of
Computation (TOC)
• What
• Why
• Where
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 2
What is TOC?
Definition:
• Theory of Computation is a branch of
computer science and mathematics that
mainly deals with “how and how
efficiently problems can be solved on a
computational model, using an
algorithm.”
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 3
TOC
• TOC is divided into 3 major branches
namely,
– Automata Theory
– Computability Theory
– Computational Complexity Theory
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 4
• Automata Theory
– Study of machines(automata) that solve the
computational problems
• Computational Theory
– what can or can’t be solved by the automata
• Computational Complexity Theory
– how efficiently a problem can be solved by
the automata includes time and space
complexity
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 5
Why TOC?
• Eg 1: Can you design a machine that accepts binary
strings that ends with 0.
– Ans : Yes
• Eg 2: Syntax for ‘if ’ in C programming
if(condition)
{ …..}
• If your syntax is
iff(condition)
{….}
//Whether it will be accepted by the compiler
– Ans : No
• In order to know the logic behind the acceptance, need
to study TOC
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 6
Where TOC?
• Applications of TOC
– Compiler Design
– Text Editors
– Pattern Matching
– Spell Checkers
– Artificial Intelligence
– Neural Networks
– Robotics etc..
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 7
Basics of T O C
Basic terminologies used in TOC are
• Symbol
• Alphabet
• String
• Language
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 8
Symbol
• Symbol is a character
• It is the smallest building block
• Examples:
– Alphabets: a,b,c,….,z | A , B , C … … . Z
– Digits : 0,1,2…..9
– Special Characters : +, - , * , / , _ , etc.
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 9
Alphabet
• Alphabet is a finite non-empty set of
symbols
• It is denoted by Σ
• Examples:
– Σ = { 0, 1 } is a set of of binary digits
– Σ = { 0, 1, 2, … . 9 } is a set of decimal digits
– Σ = { a, b, c } is a set of 3 lowercase letters
– Σ = { +, -, *, & , … .} is a set of all special characters
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 10
String
• String is a finite sequence of symbols
chosen from some alphabet
• String is denoted as w
• Length of a string - number of symbols in
the string.
– It is denoted as | w |
• Eg: 01001 is a string from binary alphabet
Σ = { 0, 1 }
– w = 01001
– |w|= 5
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 11
Empty String
• Empty String is the string with zero
occurrence of symbol
• It is denoted by ε
• The length of empty string is | w | = 0
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 12
Concatenation of String
• Joining of 2 or more strings
• Dot (.) operator is used for concatenation
• Eg: w1=ab and w2=ba
• Concatenation of w1 & w2 is
– w1 . w2 = ab.ba = abba
– w2 . w1= ba.ab = baab
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 13
Power of an Alphabet (Σ)
• Power of an Σ is the set of all strings of
certain length formed from the Σ by using
exponential notation
• It is denoted by Σ k is the set of all strings
of length k
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 14
Power of an Alphabet (Σ)
• There are two types of power
– Kleen Closure (*)
• Σ* = Σ0 U Σ1 U Σ 2 ……….
– Positive Closure(+)
• Σ+ = Σ1 U Σ 2 ……….
or
• Σ + = Σ* - ε
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 15
Formation of String from Σ
• Example: Consider Σ = { 0, 1 } is an alphabet of
binary digits
• String of length 0 | Σ | 0 = ε
• Strings of length 1 | Σ | 1 = 0, 1 21 = 2 strings
• Strings of length 2 | Σ | 2 = 00, 01, 10, 11 22 = 4 strings
• Strings of length 3 | Σ | 3 = 000, 001, 010, 011, 100, 101, 110, 111
23 = 8 strings
• Number of Strings of length n = | Σ | n
• Number of Strings of length 4 =(2) 4 = 16
• Since Σ={0,1} | Σ|=2 n =4
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 16
Power of Σ
• Example: Consider Σ = { 0, 1 } is an alphabet of binary
digits
• |Σ|0 = ε
• | Σ | 1 = 0, 1
• | Σ | 2 = 00, 01, 10, 11
• | Σ | 3 = 000, 001, 010, 011, 100, 101, 110, 111
• Σ* = Σ0 U Σ1 U Σ 2 … … … .
• Σ* = ε U {0,1} U {00,01,10,11} U … … . .
= {ε,0,1,00,01,10,11,….……..}
• Σ+ = Σ1 U Σ 2 … … … .
• Σ+ = {0,1} U {00,01,10,11} U … … . .
= {0,1,00,01,10,11,….……..}
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 17
Language
• A language is a finite set of non-empty
strings, chosen from some Σ*
Or
• A language(L) is a subset of Σ* .
• A language which can be formed over ‘ Σ ‘
can be Finite or Infinite.
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 18
Language - Examples
• Consider Σ = { 0, 1 } is an alphabet of binary digits
Therefore, Σ* = {ε, 0, 1, 00, 01, 10, 11……….}
• Language L = set of binary strings of length 2
• L = {00, 01, 10, 11} which is a subset of Σ*.
• Language L = set of binary strings ends with 0
• L = {0, 00, 10,……} which is a subset of Σ*.
• Language L = set of binary strings ends with
equal number of 0’s and 1’s
• L = {01, 10, 0011, 0101, 0110, 1100, 1010, … … }
which is a subset of Σ*.
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 19
Operations on Languages
• Complementation 𝐿 = Σ* -L
• Union
– L 1 U L 2 = {w|w is in L1 or L2}
• Intersection
– L 1 ∩ L 2 = {w| w is in L 1 and L 2}
• Concatenation
– L 1 . L 2 ={w1 .w2 |w 1 is in L1 and w2 is in L2}
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 20
Operations on Languages
• Reverse
– L r = {w r |w is in L}
• Kleen Closure
– L* = ∪ 𝒊=𝟎
∞ 𝑳𝒊
– Eg: L={a} L* ={ε, a, aa, aaa,……}
• Positive Closure
– L+ = ∪ ∞
𝒊=𝟏 𝑳 𝒊
– Eg: L={a} L* ={a, aa, aaa,……}
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 21
Introduction to
Mathematical
Inductive Proof
Deductive Proof
Kiruthika S.S., 2
AP/CSE/SRMIST, 2
Inductive Proof
It is a special form of proof that deals about the objects in
recursion.
Induction Principle:
If we prove S(i) and we prove that for all n>=I,
S(n)=>S(n+1), then we may conclude that s(n) for all n>=1.
It has two parts.
1.Basis part.
2.Inductive part.
Basis step: We have to show S(i) for a particular integer value
“i”, here “i “ may be zero or one.
Inductive step: We assume n>=i, where “i “ is the basis integer
and we have to show that if S(n) then S(n+1) i.e., S(n) =>S(n+1).
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 23
Prove by an induction method on “n”
i=0 ∑ n i2 =((n(n+1)(2n+1))/6).
Solution:
i=0 ∑ n i2 =((n(n+1)(2n+1))/6). ----> Equ 1
Induction Principle:
If we prove S(i) and we prove that for all n>=I, S(n)=>S(n+1),
then we may conclude that s(n) for all n>=1.
Basis:
Put n=0 in the equ 1
RHS= (0 (0+1) (2*0+1))/6 => 0
LHS = i=0 ∑ n (02) => 0
i.e., LHS = RHS.
Inductive step:
Put n =1 in the equ 1
S(n) = (n(n+1)(2n+1))/6.
= (2n3+2n2+n2+n)/6. ---> Equ 2
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 24
Put n=n+1 in the equ 1
S(n+1) => ((n+1)(n+2)(2n+3))/6.
=> ((n2+3n+2) (2n+3))/6.
=> (2n3+6n2+4n+3n2+9n+6)/6.->equ 3
From the induction principle:
= S(n+1) =S(n) + (n+1)2.
= ((2n3+3n2+n)/6) + (n+1)2
= ((2n3+3n2+n)/6) + (n2+2n+1)
Cross multiplying the ‘6’ on the numerator.
= ((2n3+3n2+n + 6n2+12n+6))/6.
= ((2n3+9n2+13n+6))/6. -- equ 4
Equ 4 satisfies equ 3
Hence proved.
Kiruthika S.S., 2
AP/CSE/SRMIST, 5
Finite Automata
Finite Automata is an abstract
computing device. It is a mathematical
model of a system with discrete input,
output, state and a set of transitions from
one state to another state that occurs on
input symbols from alphabet Σ.
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 26
Components of Finite Automata
left-end
input: x
x1 x2 x3 x4 x5 …… .... xn …. no right-end
Movable tape head (Read Only)
. Finite control (program)
initial state .
. .
Accept / Final state
current
state
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 27
Components of Finite Automata
• Input tape is divided into number of cells.
Each cell can hold one i/p symbol.
• Read head reads onΣe symbol at a time and
moves ahead.
• Finite control acts like a CPU. Depending
on the current state and input symbol read
from the input tape it changes state.
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 28
How Finite Automata operate?
depending on current state
and
current tape symbol Change state
Move tape head to the right by
one Cell
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 29
Finite Automata – Formal Definition
• A finite automaton is represented formally by
a 5 tuple
(Q, Σ, δ, q0, F)
where
– Q : a finite set of states
– Σ : alphabet (finite set of input symbols)
– δ : Transition function
– q0 : Initial State
– F : Final State
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 30
Representation of Finite Automata
• Graphical
– Transition Diagram
• Tabular
– Transition Table
• Mathematical
– Transition Function
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 31
Transition Diagram
• It is a directed graph associated with
Vertices refer to States and Edges refer to
input symbol
• Initial state begins with arrow ( ) symbol
• Final state is represented by double circle
Input Symbol
a b
q0 q1 q2
Current State Next State
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 32
Transition Table
• It is a tabular representation which takes two
arguments (a state and an i/p symbol) and returns
a value (the next state)
• Initial state is marked with arrow ( ) symbol
• Final state is marked with asterik (*) symbol
• Column – Input Symbols
• Row - States
Input Symbols
States
a b
Input Symbol
a q0 q1 -
b
q0 q1 q2 q1 - q2
Current State Next State *q2 - -
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 33
Transition Function
• Transition function is represented by δ
• It takes two inputs (a state and an i/ p symbol) and
returns a value (next state)
δ ( current state , current i/p symbol) = next state
• δ (q0, a) = q1 Input Symbol
a b
• δ (q1,b) = q2 q0 q1 q2
Current State Next State
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 34
Types of Finite Automata
• Finite Automata is categorized into two
types.
– Deterministic Finite Automata (DFA)
– Non Deterministic Finite Automata (NFA /
NDFA)
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 35
Deterministic Finite Automata
• In DFA , the machine reads only one input
symbol at a time
• For every input, there is only one transition
• Null transition is not accepted (ie) DFA
cannot change its state without reading an
input symbol
• It may contain multiple final states
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 36
DFA
• DFA is formally defined as (Q, Σ, δ, q0, F)
– Q : a finite set of states
– Σ : alphabet (finite set of input symbols)
– δ : Transition function Q xΣ Q
– q0 : Initial State
– F : Final State
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 37
DFA - Example
Transition Diagram:
Transition Function: Transition Table:
δ(q0,0)=q1 Input Symbols
δ(q0,1)=q0 States 0 1
δ(q1,0)=q1 ->q0 q1 q0
δ(q1,1)=q2 q1 q1 q2
δ(q2,0)=q2
*q2 q2 q2
δ(q2,1)=q2
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 38
Non Deterministic Finite Automata
• In NFA, for every input there is zero or one or
more than one transitions
• N ull/epsilon (ε) transition is allowed (ie) NFA
changes its state without reading an input
symbol
• It may contain multiple final states
• Construction of N F A is easier than the
construction of DFA
• Every N FA is not DFA, but can each N F A can
be translated to DFA
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 39
NFA
• N FA is formally defined as (Q, Σ, δ, q0, F)
– Q : a finite set of states
– Σ : alphabet (finite set of input symbols)
– δ : Transition function Q xΣ 2Q
– q0 : Initial State
– F : Final State
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 40
NFA - Example
Transition Diagram:
Transition Function: Transition Table:
Input Symbols
δ(q0,0)={q0,q1} States 0 1
δ(q0,1)=q0
->q0 {q0,q1} q0
δ(q1,1)=q2
q1 ∅ q2
*q2 ∅ ∅
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 41
Chomsky Hierarchy of Languages
Recursively Enumerable
Language
Recursive Language
Context Sensitive Language
Context Free Language
Regular Language
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 42
Language Acceptance
• Finite Automata accepts Regular Language.
• Let L be a language
• If and only if all the strings in L is accepted
by FA, then L is said to be a regular
language.
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 43
Language of DFA
• A DFA ‘M’ accepts w if there exists a path
from the initial state to an accepting state
(final state) that is labeled by w
• L(A) = { w | δ’(q0,w) F }
• (ie) L(A) = all strings that lead to a final state
from q0
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 44
Language of NFA
• A n NFA ‘M’ accepts w if there exists at
least one path from the start state to an
accepting (or final) state that is labeled by
w
• L(N) = { w | δ’(q0,w) ∩ F ≠ Φ }
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 45
Extended Transition Function
• To process single input symbol δ is used
• Eg: δ(q0,0) – the string length is 1
• δ‘ – Extended Transition Function
• If | w | > 1, then δ‘ should be used
• Eg: δ‘(q0, 01001) = δ‘ (δ(q0,0) , 1001)
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 46
Construction of DFA
Steps to Construct DFA:
Step 1:
• Determine the minimum number of states required
in the DFA. Draw those states.
Step 2:
• Decide the strings for which DFA will be
constructed.
Step 3:
• Construct a DFA for the strings decided in Step-02.
Step 4:
• Send all the left possible combinations to the
starting state.
• Do not send the left possible combinations over the
dead state. Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 47
1. Draw a DFA for the language accepting strings ending with
’01’ over input alphabets ∑ = {0, 1}
Solution:
• Regular expression for the given language = (0 + 1)*01
Step 1:
• All strings of the language ends with substring “01”.
• So, length of substring = 2.
Thus, Minimum number of states required in the DFA = 2 + 1 = 3.
Step 2:
It suggests that minimized DFA will have 3 states.
We will construct DFA for the following strings-
01, 001, 0101…
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 48
Step 3:
2. Draw a DFA for the language accepting strings starting with
‘ab’ over input alphabets ∑ = {a, b}
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 49
3. Design a FA with ∑ = {0, 1} accepts those string which starts
with 1 and ends with 0.
4. Design FA with ∑ = {0, 1} accepts even number of 0's and
even number of 1's.
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 50
Construction of NFA
1. Design an NFA with ∑ = {0, 1} accepts all string ending with
01.
2. Design an NFA with ∑ = {0, 1} accepts all string starting with
01.
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 51
3. Design an NFA in which all the string contain a substring
1110.
4. Design an NFA with ∑ = {0, 1} in which double '1' is followed
by double '0'.
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 52
5. Draw a NFAwhich accept the string “ab”.
Construction of NFA- ε
6. Draw a NFA with epsilon which accept the string “ab”.
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 53
Conversion from NFA to DFA
Steps in conversion from NFA to DFA:
1. The initial state of NFA(M) will be the initial state of DFA(M’).
Hence add q0 in Q’ of DFA and find the set of transitions.
2. For each state {q1, q2, … qi} in Q’, the transition for the each
input symbol Σ can be obtained as follows:
i. δ ([q1, q2, … qi],a) = δ (q1,a)U δ (q2,a) U…….U δ (qi,a)
= [q1, q2, … qk]
ii. Add the state [q1, q2, … qk] if it is not in Q’.
iii. Then, find the transition for every input symbol from Σ
for states [q1, q2, … qk] if we get some states which is not
in Q’ of DFA then add it to Q’.
iv. If there are new states generating from the transitions,
then stop the process after finding all the transition of
the states.
v. For the sates [q1, q2, … qk]€Q’ of DFA, if any state qj is
final state in NFA, then make all the states in DFA which
contains qj as final states. 54
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM
NFA to DFA
1. Convert0,1the following NFA to DFA.
1
0,1
q0 0 q1 q2
Solution:
In NFA M=(Q, Σ, δ, q 0, F),
Q=(q0,q1,q2) , Σ={0,1}, Initial state = q0, Final state = {q2}
Let the initial state of DFA be q0 ----- (A)
Transition Function for A: Transition Function for B:
δ (A,0)=δ(q0,0)=[q0] -------(A) δ (B,0)=δ({q0,q1},0)
δ(A,1)=δ (q0,1)=[q0,q1] -----(B) =δ(q0,0) U δ(q1,0)
=[q0,q2] -------------(C)
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 55
δ (B,1) = δ ({q0,q1}, 1) Transition Function for D:
= δ (q0, 1) U δ (q1, 1) δ (D,0)=δ({q0, q1,q2},0)
= [q0, q1, q2] ---------(D) =δ(q0,0) U δ(q1,0)U δ(q2,0)
Transition Function for C: =[q0,q2] -----------(C)
δ (C,0)=δ({q0,q2},0) δ (D,1)=δ({q0,q1,q2},1)
=δ(q0,0) U δ(q2,0) =δ(q0,1)U δ(q1,0)U δ(q2,1)
=[q0] -----------(A) =[q0,q1,q2] ----------(D)
δ (C,1)=δ({q0,q2},1)
=δ(q0,1) U δ(q2,1)
=[q0,q1] -----------(B)
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 56
In DFA M’ Q={[q0],[q0,q1], [q0,q2], [q0,q1,q2])},
Σ={0,1}, Initial state = [q0], Final state = { [q0, q2], [q0,q1,q2] }
Transition Table:
0 1
->A [q0] [q0] [q0, q1]
B[ q0, q1] [q0, q2] [q0, q1,q2]
*C [q0, q2] [q0] [q0, q1]
*D [q0, q1, q2] [q0,0q2] [q0, q1,q2]
1 0
Transition Diagram: [q0] [q0,q1] [q0,q2]
1 1
0
1
[q0,q1,q2]
0
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 57
ε- closure
It is the set of all states which are reachable from state p on
epsilon transition such that
• ε-closure (p) –{p} where p ∈ Q
• If there exists ε-closure(p) ={q} and δ(q, ε)={r} then ε-closure
(p)={p,q,r}
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 58
1. Find ε- closure for the given NFA.
Solution:
ε-closure {q0} = {q0, q1, q2}
ε-closure {q1} = {q1}
ε-closure {q2} = {q2}
ε-closure {q3} = {q3}
ε-closure {q4} = {q4}
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 59
Conversion from NFA-ε to NFA
1. Find all the ε transition for each state from Q that
will be called as and closure{qi} where qi is the
element of Q.
2. δ‘ can be obtained from δ(ie) an ε-closure of δ.
3. Step 2 is repeated for each input symboland for each
state of given NFA.
4. Using the resultant state, the transition table for
equivalent NFA without ε can be built.
δ(q,a)= ε-closure(δ(δ’(q, ε),a))
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 60
1. Convert the given NFA- ε to NFA without ε.
a ε b
q0 q1 q2
Step 1: Finding ε-closure of all states
ε- closure(q0)={q0}
ε- closure(q1)={q1,q2}
ε- closure(q2)={q2}
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 61
Processing state q0:
δ(q0,a) = ε-closure(δ(δ’(q0, ε),a))
= ε-closure(δ(ε-closure( q0),a))
= ε-closure(δ(q0,a))
= ε-closure(q1)
= {q1,q2}
δ(q0,b) = ε-closure(δ(δ’(q0, ε),b))
= ε-closure(δ(ε-closure( q0),b))
= ε-closure(δ(q0,b))
= ε-closure(Ø)
= {Ø}
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 62
Processing state q1:
δ(q1,a) = ε-closure(δ(δ’(q1, ε),a))
= ε-closure(δ(ε-closure( q1),a))
= ε-closure(δ({q1,q2},a))
= ε-closure(δ(q1,a) U δ(q2,a)))
= ε-closure(Ø U Ø )
= ε-closure(Ø)
= {Ø}
δ(q1,b) = ε-closure(δ(δ’(q1, ε),b))
= ε-closure(δ(ε-closure( q1),b))
= ε-closure(δ({q1,q2},b))
= ε-closure(δ(q1,b) U δ(q2,b)))
= ε-closure(Ø U q2 )
= ε-closure(q2)
= {q2}
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 63
Processing state q2:
δ(q2,a) = ε-closure(δ(δ’(q2, ε),a))
= ε-closure(δ(ε-closure( q2),a))
= ε-closure(δ(q2,a))
= ε-closure(Ø)
= {Ø}
δ(q2,b) = ε-closure(δ(δ’(q2, ε),b))
= ε-closure(δ(ε-closure( q2),b))
= ε-closure(δ(q2,b))
= ε-closure(q2)
= {q2}
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 64
Transition Table:
State a b
->q0 {q0,q1} Ø
q1 Ø {q2}
*q2 Ø {q2}
Transition Diagram :
a
a b b
q0 q1 q2
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 65
Conversion from NFA-ε to NFA
1. Find all the ε transition for each state from Q that
will be called as and closure{qi} where qi is the
element of Q.
2. δ‘ can be obtained from δ(ie) an ε-closure of δ.
3. Step 2 is repeated for each input symboland for each
state of given NFA.
4. Using the resultant state, the transition table for
equivalent NFA without ε can be built.
δ(q,a)= ε-closure(δ(δ’(q, ε),a))
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 66
DFA Minimization
Algorithm
Input − DFA
Output − Minimized DFA
Step 1 − Draw a table for all pairs of states (Qi, Qj) not necessarily
connected directly [All are unmarked initially]
Step 2 − Consider every state pair (Qi, Qj) in the DFA where Qi ∈ F
and Qj ∉ F or vice versa and mark them. [Here F is the set of final
states]
Step 3 − Repeat this step until we cannot mark anymore states −
If there is an unmarked pair (Qi, Qj), mark it if the pair {δ (Qi, A), δ
(Qi, A)} is marked for some input alphabet.
Step 4 − Combine all the unmarked pair (Qi, Qj) and make them a
single state in the reduced DFA.
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 67
Minimize the DFA.
Step 1 −Draw a table for all pair of states.
bb
cc
dd
ee
ff
aa bb cc dd ee
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 68
Step 2: Final states ={c,d,e} Non-final states = {a,b,f}.
The pairs of final and non-final are not equal.
So (a,c),(a,d),(a,e),(b,c),(b,d),(b,e), (f,c),(f,d),(f,e) are not
equivalent. In the table mark x in all the pairs.
Now, Check the remaining pairs are equivalent or not.
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 69
Check(a,b)
δ(a,0) = b δ(a,1)= c
δ(b,0) = a δ(b,1)= d
Since for input 0 both the states are reaching different non-final
states, take a string and heck whether from both the states it reach final
or not. IF it reaches final states then both are equivalent else not
equivalent.
Stirng = 01
δ(a,01) = d
δ(b,01) = c. Since both the states are reaching final states a ≡ b
Check (a,f)
δ(a,0) =b δ(a,1)= c
δ(f,0) = f δ(f,1)= f
For input 1 state a reaches final state and state f reaches non-final state.
Hence a ≠ f
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 70
Check(b,f)
δ(b,0) = a δ(b,1)= d
δ(f,0) = f δ(f,1) = f
For input 1 state b reaches final state and state f reaches non-final state.
Hence b ≠ f
Check(c,d)
δ(c,0) = e δ(c,1)= f
δ(d,0) = e δ(d,1)= f
Since all the states are same for all inputs,c ≡ d
Check(c,e)
δ(c,0) = e δ(c,1)= f
δ(e,0) = e δ(e,1)= f
Since all the states are same for all inputs,c ≡ e
Check(d,e)
δ(d,0) = e δ(d,1)= f
δ(e,0) = e δ(e,1)= f
Since all the states are same for all inputs,d ≡ e
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 71
Therefore the equivalent states are a ≡ b, c ≡ d ≡ e.
The distinguishabale states are f.
Now mark ✓ symbol in the table for equivalent state pairs and X
for remaining pairs.
Now, draw the minimized DFA
diagram.
0 0
[a,b] 1 [c,d,e]
f
0,1
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 72
Regular Expression
• The language accepted by finite automata can be easily
described by simple expressions called Regular Expressions. It is
the most effective way to represent any language.
• The languages accepted by some regular expression are
referred to as Regular languages.
• A regular expression can also be described as a sequence of
pattern that defines a string.
• Regular expressions are used to match character combinations
in strings. String searching algorithm used this pattern to find
the operations on a string.
• Eg: (0+1)*
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 73
Operations on RE
The various operations on regular language are:
• Union: If L and M are two regular languages then their union L
U M is also a union.
L U M = {s | s is in L or s is in M}
• Intersection: If L and M are two regular languages then their
intersection is also an intersection.
L ⋂ M = {st | s is in L and t is in M}
• Kleen closure: If L is a regular language then its Kleen closure
L1* will also be a regular language.
L* = Zero or more occurrence of language L.
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 74
Examples for RE
1. Write the regular expression for the language accepting all
combinations of a's, over the set ∑ = {a}
Solution:
All combinations of a's means a may be zero, single, double and
so on. If a is appearing zero times, that means a null string. That
is we expect the set of {ε, a, aa, aaa, ....}. So we give a regular
expression for this as:
R = a*
2. Write the regular expression for the language accepting all the
string containing any number of a's and b's.
RE = (a + b)*
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 75
Examples for RE
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 76
RE toFA
Thompson's Construction is used to find out a Finite Automaton
from a Regular Expression. We will reduce the regular expression
into smallest regular expressions and converting these to NFA
and finally to DFA.
N(S)=a, N(T) = b
a
a.b
a+b a*
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 77
Examples for RE to FA
1.(0+1)
2. (0+1)*
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 78
Examples for RE to FA
(0+1)*1(0+1)
Draw step by step
1. First draaw (0+1)
2. Second (0+1)*
3. Third 1
4. Fourth (0+1)
5. Merge 1, 2,3 and 4
6. Make the last state
as final state.
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 79
Conversion from FA to RE
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 80
Conversion from FA to RE
This method involves the following steps in finding the regular
expression for any given DFA:
Step 1: The initial state of the DFA must not have any incoming
edge.
Step 2: There must exist only one final state in the DFA. If there
exists multiple final states in the DFA, then convert all the final
states into non-final states and create a new single final state.
Step 3: The final state of the DFA must not have any outgoing
edge. If there exists any outgoing edge from the final state, then
create a new final state having no outgoing edge from it.
Step 4: Eliminate all the intermediate states one by one. These
states may be eliminated in any order.
In the end,
Only an initial state going to the final state will be left.
The cost of this transition is the required regular expression.
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 81
Find regular expression for the following DFA-
Step-01:
There exist multiple final states.
So, we convert them into a single final state.
The resulting DFA is-
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 82
Step-02:
Now, we start eliminating the intermediate states.
First, let us eliminate state q 4.
There is a path going from state q 2 to state qf via state q4.
So, after eliminating state q4 , we put a direct path from state
q2 to state qf having cost b.∈ = b.
Step-03:
Now, let us eliminate state q3.
There is a path going from state q 2 to state qf via state q3.
So, after eliminating state q3 , we put a direct path from state
q2 to state qf having cost c.∈ = c.
83
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM
Step-04:
Now, let us eliminate state q5.
There is a path going from state q 2 to state qf via state q5.
So, after eliminating state q5 , we put a direct path from state
q2 to state qf having cost d.∈ = d.
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 84
Step-05:
Now, let us eliminate state q2.
There is a path going from state q 1 to state qf via state q2.
So, after eliminating state q2 , we put a direct path from state
q1 to state qf having cost a.(b+c+d).
Final RE = a.(b+c+d)
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 85
Closure properties of Regular languages
Closure properties on regular languages are defined as certain
operations on regular language which are guaranteed to produce
regular language. Closure refers to some operation on a language,
resulting in a new language that is of same “type” as originally
operated on i.e., regular.
Regular languages are closed under following operations.
1. Kleen Closure
2. Positive Closure
3. Union
4. Intersection
5. Difference
6. Reverse
7. Complement
8. Homomorphism
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 86
Pumping Lemma
If L is a regular language, there is a pumping length p such that
any string w ∈ L of length ≥ p can be written as w = xyz, where y
≠ ε, |xy| ≤ p, and for all i ≥ 0, xykz ∈ L
Pumping lemma is used to check whether a grammar is regular
langugae or not.
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 87
Steps involved in Pumping lemma
1. Assume the language is in RL.
2. Take a string z from RL.
3. Find |z|≥n
4. Split z into uvwxy
i) |xy|≤n
ii)|y|≥ 1
iii) For all k>0, xykz is in L.
Kiruthika S.S., 8
AP/CSE/SRMIST, 8
1. Prove that the language L={0n1n} is not regular.
Solution:
1. Assume the language is in RL.
2. Take z= 0n1n
3. |z|≥n, n+n ≥ n, 2n ≥ n
4. z= 0n1n
xzy= 0n1n
xy = 0n , z=1n
i) |xy|≤n,
|0n| ≤n
n≤n
ii. |y|≥ 1, [xy= 0n so x= 0m y= 0n-m, n>m]
| 0n-m | ≥ 1
n-m ≥ 1
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 89
5. xykz = xyyk-1z
Put k=0
xy0z = 0n (0n-m)0-1 1n
= 0m 1n is not in L.
Put k=1
xy1z = 0n (0n-m)1-1 1n
= 0n 1n is in L.
Put k=2
xy2z = 0n (0n-m)2-1 1n
= 02n-m 1n is not in L.
Fork=0 and 2, the derived strinngs are not in L.
So, the given language is not a regular language.
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 90
Kiruthika S.S., AP/CSE/SRMIST, RAMAPURAM 91