Unit-2 Regular Languages & Finite Automata (Part1)
Unit-2 Regular Languages & Finite Automata (Part1)
Theory of Computation
Unit-2
Regular Languages &
Finite Automata
Topics to be covered
• Regular expressions & Regular languages
• Finite Automata
• Union, Intersection and Complement of Regular Languages
• Non-Deterministic Finite Automata
• Conversion from NFA to FA
• ^ - Non-Deterministic Finite Automata
• Conversion of NFA-^ to FA
• Kleene’s Theorem Part – I
• Finite Automata with Output (Moore machine, Mealy machine)
• Minimization of FA
• Moore machine & Mealy machine
• Pumping Lemma – Regular and Non Regular Languages
Regular Expression
Regular expression
• A regular expression is a sequence of characters that define
a pattern.
• Notational shorthand's
1. One or more occurrences:
2. Zero or more occurrences:
3. Alphabets:
Regular expression
L = Zero or More Occurrences of a = a*
*
𝜖
a
aa
aaa Infinite …..
aaaa
aaaaa…..
Regular expression
+
L = One or More Occurrences of a = a+
a
aa
aaa Infinite …..
aaaa
aaaaa…..
Precedence and associativity of operators
Operator Precedence Associative
Kleene * 1 left
Concatenation 2 left
Union | 3 left
Regular expression examples
1. 0 or 1
𝑺𝒕𝒓𝒊𝒏𝒈𝒔 :𝟎 ,𝟏𝑹 . 𝑬 .=𝟎∨𝟏
2. 0 or 11 or 111
𝑺𝒕𝒓𝒊𝒏𝒈𝒔:𝟎 ,𝟏𝟏,𝟏𝟏𝟏 𝑹. 𝑬 .=𝟎|𝟏𝟏| 𝟏𝟏𝟏
𝑹 . 𝑬 .=𝒂 ∗
String having zero or more a.
3. 𝑺𝒕𝒓𝒊𝒏𝒈𝒔:𝜖,𝒂,𝒂𝒂,𝒂𝒂𝒂,𝒂𝒂𝒂𝒂…..
4. 𝑺𝒕𝒓𝒊𝒏𝒈𝒔:𝒂,𝒂𝒂,𝒂𝒂𝒂,
String having one or 𝑹a.. 𝑬 .=𝒂 +¿
𝒂𝒂𝒂𝒂…..
more
12. 𝑺𝒕𝒓𝒊𝒏𝒈𝒔:𝟎𝟎,𝟏𝟎𝟏,𝒂𝒃𝒂,𝒃𝒂𝒂𝒃…
String starts and ends with same character
Regular expression examples
13. All string of a and b starting with a
… 𝑹. 𝑬 .=𝒂(𝒂∨𝒃)∗
14. String of 0 and 1 ends with 00
… 𝑹. 𝑬 .=(𝟎∨𝟏)∗𝟎𝟎
15. String ends with abb
… 𝑹. 𝑬 .=(𝒂∨𝒃)∗𝒂𝒃𝒃
16. String starts with 1 and ends with 0
… 𝑹. 𝑬 .=𝟏(𝟎∨𝟏)∗𝟎
17. All binary string with at least 3 characters and 3rd character should be
zero … 𝑹.𝑬.=( 𝟎|𝟏 )( 𝟎|𝟏) 𝟎(𝟎∨𝟏)∗
18. Language which consist of exactly two b’s over the set
… 𝑹. 𝑬 .=𝒂∗𝒃 𝒂∗𝒃𝒂∗
Regular expression examples
19. The language with such that 3rd character from right end of the string is
always
… 𝑹.𝑬.=(𝒂∨𝒃)∗𝒂(𝒂∨𝒃)(𝒂∨𝒃)
20. Any no. of followed by any no. of followed by any no. of
… 𝑹. 𝑬 .=𝒂∗𝒃∗𝒄 ∗
21. String should contain at least three
∗ ∗ ∗ ∗
…. 𝑹.𝑬.=(𝟎∨𝟏) 𝟏(𝟎∨𝟏) 𝟏(𝟎∨𝟏) 𝟏(𝟎∨𝟏)
22. String should contain exactly two
∗ ∗ ∗
….
𝑹
23. No. of zero should be multiple of 3
. 𝑬 .=𝟎 𝟏 𝟎 𝟏 𝟎
∗ ∗ ∗
…. 𝑹. 𝑬 .=(𝟏 𝟎𝟏 𝟎𝟏 𝟎
Regular expression examples
24. The language with where should be multiple of 3
𝑺𝒕𝒓𝒊𝒏𝒈𝒔:𝒂𝒂𝒂,𝒃𝒂𝒂𝒂,𝒃𝒂𝒄𝒂𝒃𝒂,𝒂𝒂𝒂𝒂𝒂𝒂.. ∗ ∗ ∗
𝑹.𝑬.=( ( 𝒃∨𝒄 ) 𝒂 ( 𝒃∨𝒄 ) 𝒂 ( 𝒃∨𝒄 ) 𝒂 ( 𝒃∨𝒄 ) )
∗∗
𝑺𝒕𝒓𝒊𝒏𝒈𝒔:𝟎𝟎𝟏𝟏,𝟏𝟏𝟎𝟎,𝟏𝟎𝟎𝟏𝟏𝟎,𝟎𝟏𝟎𝟎𝟏𝟏…
32. String ending with 1 and not contain 00
𝑹 . 𝑬 .=( 𝟏|𝟎𝟏 ) +¿
𝑺𝒕𝒓𝒊𝒏𝒈𝒔:𝟎𝟏𝟏,𝟏𝟏𝟎𝟏,𝟏𝟎𝟏𝟏….
Finite Automata
Finite Automata
• Finite automata are used to recognize patterns.
• It takes the string of symbol as input and
changes its state accordingly. When the desired
symbol is found, then the transition occurs.
• At the time of transition, the automata can either
move to the next state or stay in the same state.
• Finite automata have two states, Accept
state or Reject state. When the input string is
processed successfully, and the automata reached its
final state, then it will accept.
Finite Automata
• A finite automaton, or finite state machine is a 5-tuple where
• is finite set of states;
• (Summation) is finite alphabet of input symbols/alphabets;
• (initial state);
• (the set of accepting states);
• (Delta) is a function from (the transition function).
• For any element of and any symbol , we interpret as the state to
which the FA moves, if it is in state and receives the input .
Example: Finite Automata
δ Input
State
• is defined as
1 1 0
0 0
𝑞0 𝑞1 𝑞2
1
Applications of FA
• Lexical analysis phase of a compiler.
• The initial stage or phase of the compiler
• Scans the source code and transforms the input program into a series
of a token
• Design of digital circuit.
• String matching.
• Communication Protocol for information exchange.
FA Examples
• The string with next to last symbol as 0.
0
1
0 𝐶
𝐴 0
𝐵 1
1
0 𝐷
1
FA Examples
The strings which ends with ‘a’ and contains symbols
{a,b}
b a
a
𝐴 𝐵
b
FA Examples
• The strings ending with 10.
0 1
𝐴 1
𝐵 𝐶
1
0
FA Examples
• The string ending in 10 or 11 1
C
0
1
1
A B 0
0
1
D
0
Design FA for following languages.
1) Strings ending with 10
2) String start with bba
3) r= 11(1+0)*
4) (0+1)*0
5) String ends with (11+10)
23
FA Examples
• The string corresponding to Regular expression {00}*{11}*
0,1
1
B D
0 0 0
0 1
1
A C E
1
FA Examples
• (a+b)*baaa b
a B a
b
b
A C
b b
a a
a
E D
Extended Transition Function for FA
An extended transition function δ^ traces
the path of an automaton and determines the
final state when an initial state q and an input
string x are passed through it.
Simple Transition Function - Performs a
transition of a single character/instance
Extended Transition Function - Performs
the transitions on a complete string
Extended Transition Function for FA
It is a function
defined as,
(q, ε) = q
(q, xa) = , a)
where,
x∈
a ∈Σ
(q, xa) = , a)
Example
Consider FA
a
𝑞 𝑞1 b
𝑞2 c
𝑞3
Calculate
Exercise :
Consider following FA
X
𝑞 𝑞1 Y
𝑞2
1. calculate
=
Acceptance by FA
• Let be an FA. A string is accepted by if . If string is not accepted,
we can say it is rejected by . The language accepted by , or the
language recognized by , is the set
1 0,1 1 0
0 1
𝐴 1
𝐵 0
𝐶 𝑃 0
𝑄 0
𝑅
1
𝑴𝟏 𝑴𝟐
Computation for , and
• Here and 1
• So,
𝐴𝑃 𝐵𝑃 𝐶𝑃
• Computing Transition Function 0
𝛿 ( ( 𝐴, 𝑃 ) , 0 ) =(𝛿 ( 𝐴, 0 ) , 𝛿 ( 𝑃 , 0 ) ) 𝐴𝑄 𝐵𝑄 𝐶𝑄
¿ 𝐵𝑄
𝛿 ( ( 𝐴, 𝑃 ) ,1 ) =(𝛿 ( 𝐴 ,1 ) , 𝛿 ( 𝑃 ,1 ))
¿ 𝐴𝑃 𝐴𝑅 𝐵𝑅 𝐶𝑅
BQ
Computation for , and
𝛿 ( ( 𝐵 ,𝑄 ) , 0 ) =(𝛿 ( 𝐵, 0 ) , 𝛿 (𝑄 , 0 ) ) 1
¿ 𝐶𝑄
𝛿 ( ( 𝐵 ,𝑄 ) , 1 ) =(𝛿 ( 𝐵 ,1 ) , 𝛿 ( 𝑄 , 1 ) )
¿ 𝐴𝑅
𝛿 ( ( 𝐶 ,𝑄 ) ,0 ) =(𝛿 ( 𝐶 ,0 ) , 𝛿 (𝑄 , 0 ) )
𝐴𝑃 𝐵𝑃 𝐶𝑃
0
¿ 𝐶𝑄 0
𝛿 ( ( 𝐶 ,𝑄 ) ,1 ) =(𝛿 ( 𝐶 ,1 ) , 𝛿 ( 𝑄 , 1 ) )
¿ 𝐶𝑅 1 𝐴𝑄 𝐵𝑄 0
𝐶𝑄
𝛿 ( ( 𝐴, 𝑅 ) , 0 ) =(𝛿 ( 𝐴 , 0 ) , 𝛿 ( 𝑅 , 0 ) ) 0
1
¿ 𝐵𝑄 1
𝛿 ( ( 𝐴, 𝑅 ) , 1 ) =(𝛿 ( 𝐴, 1 ) , 𝛿 ( 𝑅 ,1 ) )
¿ 𝐴𝑃
𝐴𝑅 𝐵𝑅 𝐶𝑅
BQ CQ AR CR
Computation for , and
𝛿 ( ( 𝐶 , 𝑅 ) ,0 ) =(𝛿 ( 𝐶 ,0 ) , 𝛿 ( 𝑅 , 0 ) ) 1 1
¿ 𝐶𝑄
𝛿 ( ( 𝐶 , 𝑅 ) ,1 ) =(𝛿 ( 𝐶 ,1 ) , 𝛿 ( 𝑅 , 1 ) ) 𝐴𝑃 𝐵𝑃 𝐶𝑃
¿ 𝐶𝑃 0
0 0
𝛿 ( ( 𝐶 , 𝑃 ) , 0 ) =(𝛿 ( 𝐶 , 0 ) , 𝛿 ( 𝑃 , 0 ) )
¿ 𝐶𝑄 1 𝐴𝑄 𝐵𝑄 0
𝐶𝑄 1
0
𝛿 ( ( 𝐶 , 𝑃 ) , 1 )=(𝛿 ( 𝐶 , 1 ) , 𝛿 ( 𝑃 ,1 ) ) 1
0 1
¿ 𝐶𝑃 𝐴𝑅 𝐵𝑅 𝐶𝑅
BQ CQ AR CR CP
Removing Unconnected States
1 1
𝐴𝑃 𝐵𝑃 𝐶𝑃
0
0 0
1 𝐴𝑄 𝐵𝑄 0
𝐶𝑄 1
0
0 1
1
𝐴𝑅 𝐵𝑅 𝐶𝑅
𝐿1 ∪ 𝐿2
1 1
𝐴1={ 𝐴, 𝐵 }
𝐴2={ 𝑅 }
As per theorem stated
𝐴𝑃 𝐶𝑃
0
earlier, the states which 0 0
consists A or B or R will be
Accepting states in the 1 𝐵𝑄 0
𝐶𝑄 1
resultant FA. 0
0 1
1
𝐴𝑅 𝐶𝑅
Accepting States
𝐿1 ∩ 𝐿2
𝐴1={ 𝐴, 𝐵 } 1 1
𝐴2={ 𝑅 }
Therefore, as per theorem 𝐴𝑃 𝐶𝑃
0
stated earlier, the states 0 0
which consists (A and R)
and (B and R) will be 1 𝐵𝑄 0
𝐶𝑄 1
𝐴𝑅 𝐶𝑅
Accepting States
𝐿1 − 𝐿2
𝐴1={ 𝐴, 𝐵 } 1 1
𝐴2={ 𝑅 }
Therefore, as per theorem 𝐴𝑃 𝐶𝑃
0
stated earlier, the states 0 0
which consists A or B but
should not contain R with 1
𝐵𝑄 0
𝐶𝑄 1
𝐴𝑅 𝐶𝑅
Accepting States
Exercise
Draw Finite Automata for following languages:
1. L1={x/x 11 is not substring of x, x ∈ {0,1}*}
2. L2={x/x ends with 10, x ∈ {0,1}*}
Draw FA for , and .
0 0,1 0 1
1 0
𝐴 0
𝐵 1
𝐶 𝑃 1
𝑄 1
𝑅
0
𝑴𝟏 𝑴𝟐
Nondeterministic Finite Automata (NFA)
• A nondeterministic finite automaton is a 5-tuple where and are
nonempty finite sets, , and
is the set of states, is the alphabet, is the initial state and is the
set of accepting states.
DFA v/s NFA
DFA NFA
Dead configuration is not Dead configuration is
allowed allowed
Multiple choices are not Multiple choices are
available corresponding to available corresponding to
an input an input
ε move is not allowed ε move is allowed
Digital computers are Non deterministic feature in
deterministic not associated with real
computers
Design and understanding is Design and understanding is
difficult easy
42
Example of NFA for
δ Input
State
• is defined as
𝑞1
1 1
0
𝑞0 𝑞4
1 0
𝑞2 1
𝑞3
Convert following NFA into DFA (Practice Examples)
Example - 1
0,1
1 0, 1
q0 q1 q2
Example - 2
0, 1
0 0, 1
1 0
q0 q1 q2
1
44
Convert following NFA into DFA
Example - 3
1
0
0, 1
q0 q2
1
45
for NFA
Non-recursive Definition Recursive Definition
• is defined as
0, 1
1 0, 1 0, 1
𝑞0 𝑞1 𝑞2 𝑞3
Example: Recursive Definition of in NFA
∗
¿ ¿ 𝑟 ∈ 𝜹 (𝒒 , ⋀ ) 𝛿(𝑟 , 0)
𝛿 ∗ ( 𝑞 0 ,0 )
𝟎
¿ ¿ 𝑟 ∈ {𝒒 𝟎 }𝛿(𝑟 , 0)
¿ 𝛿 ( 𝑞0 , 0 )
¿ {𝑞 0 }
Example: Recursive Definition of in NFA
∗
¿ ¿ 𝑟 ∈ 𝜹 (𝒒𝟎 , ⋀ ) 𝛿(𝑟 ,1)
𝛿 ∗ ( 𝑞 0 ,1 )
¿ ¿ 𝑟 ∈ {𝒒 𝟎 }𝛿(𝑟 , 1)
¿ 𝛿 ( 𝑞0 , 1 )
¿ {𝑞 0 , 𝑞1 }
Example: Recursive Definition of in NFA
∗
¿ ¿ 𝑟 ∈ 𝜹 (𝒒𝟎 ,𝟏) 𝛿(𝑟 ,1)
𝛿 ∗ ( 𝑞 0 ,11 )
¿ ¿ 𝑟 ∈ {𝒒 𝟎 , 𝒒𝟏 }𝛿(𝑟 , 1)
¿ 𝛿 ( 𝑞0 , 1 ) ∪ 𝛿 ( 𝑞 1 , 1 )
¿ {𝑞 0 , 𝑞1 } ∪ {𝑞 2 }
¿ {𝑞 0 , 𝑞1 , 𝑞 2 }
Example: Recursive Definition of in NFA
∗
¿ ¿ 𝑟 ∈ 𝜹 (𝒒𝟎 , 𝟎)𝛿(𝑟 , 1)
𝛿 ∗ ( 𝑞 0 ,01 )
¿ ¿ 𝑟 ∈ {𝒒 𝟎 }𝛿(𝑟 , 1)
¿ 𝛿 ( 𝑞0 , 1 )
¿ {𝑞 0 , 𝑞1 }
Example: Recursive Definition of in NFA
∗
∗
𝛿 ( 𝑞 0 ,111 )
¿¿𝑟 ∈ 𝜹 (𝒒 ,𝟏𝟏)𝛿(𝑟 , 1)
𝟎
¿¿𝑟 ∈ {𝒒 𝟎 ,𝒒𝟏 ,𝒒𝟐 }𝛿(𝑟 ,1)
¿ 𝛿 ( 𝑞0 , 1 ) ∪ 𝛿 ( 𝑞 1 , 1 ) ∪ 𝛿 ( 𝑞 2 , 1 )
¿ {𝑞 0 , 𝑞1 , 𝑞 2 , 𝑞 3 }
∗
∗
𝛿 ( 𝑞 0 ,011 )
¿¿𝑟 ∈ 𝜹 (𝒒𝟎 , 𝟎𝟏)𝛿(𝑟 , 1)
¿ 𝛿 ( 𝑞0 , 1 ) ∪ 𝛿 ( 𝑞 1 , 1 )
¿ {𝑞 0 , 𝑞1 , 𝑞 2 }
NFA to FA using subset
construction method
Example 1: Conversion from NFA to FA
2
a b
1 {2,3} {4}
1
b
4
2 {} {4}
3 {4} {3}
a a 4 {} }
3
Transition Table
b
NFA
Example 1: Conversion from NFA to FA
𝛿 1 ( 1 , 𝑎 ) ={ 2 , 3 }
𝛿 1 ( 1 , 𝑏 )= { 4 }
𝛿 1 ( { 2 ,3 } , 𝑎 ) = 𝛿 ( 2, 𝑎 ) ∪ 𝛿 ( 3 , 𝑎)
¿ {4 }
𝛿 1 ( { 2 ,3 } , 𝑏 ) =𝛿 ( 2 , 𝑏 ) ∪ 𝛿 ( 3 , 𝑏)
¿ {3 , 4 }
𝛿 1( 4 , 𝑎)= {∅ } a b
1 2,3 3,4
𝛿 1( 4 , 𝑏)={ ∅ }
a
b
4
Example 1: Conversion from NFA to FA
𝛿 1 ( {3 , 4 }, 𝑎 ) = 𝛿 ( 3 , 𝑎 ) ∪ 𝛿 ( 4 , 𝑎 )
¿ {4 }
𝛿1 ( { 3 , 4 } , 𝑏 ) =𝛿 ( 3 , 𝑏 ) ∪ 𝛿(4 , 𝑏)
¿ {3 }
𝛿 1( 3 , 𝑎)={4 }
𝛿 1( 3 , 𝑏)={3 } a b
1 2,3 3,4
a a
b b
a
4 3
b
Example 2: Conversion from NFA to FA
δ Input
State
0, 1
1 0, 1 0, 1
𝑞0 𝑞1 𝑞2 𝑞3
Example 2: Conversion from NFA to FA
0 𝑞0 𝑞3
0
𝑞0 𝑞2 1
0
1
𝑞0 𝑞0 𝑞1 𝑞0 𝑞1 𝑞3
1
𝛿 1 ( {𝑞0 }, 0 ) ={𝑞0 } 𝑞0 𝑞1 𝑞2
𝛿1 ( {𝑞0 }, 1 )={𝑞 0 , 𝑞 1 }
𝛿 1 ( {𝑞0 , 𝑞1 }, 0 ) = 𝛿 ( { 𝑞0 } , 0 ) ∪ 𝛿 ( { 𝑞1 } , 0 ) ={ 𝑞 0 } ∪ { 𝑞 2 }={𝑞 0 , 𝑞 2 }
𝛿 1 ( {𝑞0 , 𝑞1 },1 ) = 𝛿 ( { 𝑞 0 } , 1 ) ∪ 𝛿 ( { 𝑞1 } , 1 ) ={ 𝑞 0 ,𝑞 1 } ∪ { 𝑞2 }={𝑞0 , 𝑞1 ,𝑞 2 }
𝛿 1 ( {𝑞0 , 𝑞 2 }, 0 ) = 𝛿 ( { 𝑞 0 } , 0 ) ∪ 𝛿 ( { 𝑞 2 } , 0 ) = {𝑞 0 } ∪ { 𝑞 3 } ={𝑞 0 ,𝑞 3 }
𝛿 1 ( {𝑞0 , 𝑞 2 },1 ) = 𝛿 ( { 𝑞 0 } , 1 ) ∪ 𝛿 ( { 𝑞2 } ,1 ) = { 𝑞0 , 𝑞1 } ∪ { 𝑞 3 } ={𝑞 0 ,𝑞 1 , 𝑞 3 }
Example 2: Conversion from NFA to FA
𝛿 1 ( {𝑞0 , 𝑞1 , 𝑞2 },0 ) =𝛿 ( { 𝑞0 } , 0 ) ∪ 𝛿 ( { 𝑞1 } , 0 ) ∪ 𝛿 ( { 𝑞2 } , 0 ) ={𝑞 0 ,𝑞 2 ,𝑞 3 }
𝛿1 ( {𝑞0 , 𝑞1 , 𝑞2 },1 ) =𝛿 ( { 𝑞 0 } ,1 ) ∪ 𝛿 ( { 𝑞1 } , 1 ) ∪ 𝛿 ( { 𝑞2 } , 1 ) ={𝑞0 , 𝑞1 ,𝑞 2 ,𝑞 3 }
𝛿 1 ( { 𝑞0 , 𝑞 3 } , 0 ) = 𝛿 ( { 𝑞 0 } , 0 ) ∪ 𝛿 ( {𝑞 3 } , 0 )= {𝑞 0 }
𝛿 1 ( {𝑞0 , 𝑞 3 }, 1 )= 𝛿 ( { 𝑞0 } , 1 ) ∪ 𝛿 ( { 𝑞 3 } , 1 )= {𝑞 0 , 𝑞 1 }
0
0
𝑞0 𝑞3
1
0 1
𝑞0 𝑞2
0 𝑞0 𝑞1 𝑞3
1
𝑞0 𝑞0 𝑞1
0 𝑞0 𝑞2 𝑞3
1
𝑞0 𝑞1 𝑞2 1
𝑞0 𝑞1 𝑞2 𝑞3
Example 2: Conversion from NFA to FA
𝛿 1 ( {𝑞0 , 𝑞1 , 𝑞3 }, 0 ) = 𝛿 ( { 𝑞0 } , 0 ) ∪ 𝛿 ( { 𝑞 1 } ,0 ) ∪ 𝛿 ( { 𝑞 3 } , 0 ) ={𝑞0 , 𝑞2 }
𝛿 1 ( {𝑞0 , 𝑞1 , 𝑞3 },1 ) = 𝛿 ( { 𝑞 0 } , 1 ) ∪ 𝛿 ( { 𝑞1 } , 1 ) ∪ 𝛿 ( { 𝑞 3 } ,1 )= {𝑞 0 ,𝑞 1 , 𝑞2 }
𝛿 1 ( {𝑞0 , 𝑞 2 , 𝑞3 }, 0 ) = 𝛿 ( { 𝑞 0 } , 0 ) ∪ 𝛿 ( { 𝑞 2 } , 0 ) ∪ 𝛿 ( { 𝑞 3 } , 0 ) = {𝑞 0 , 𝑞 3 }
𝛿 1 ( {𝑞0 , 𝑞 2 , 𝑞3 },1 )= 𝛿 ( {𝑞 0 } , 1 ) ∪ 𝛿 ( { 𝑞 2 } ,1 ) ∪ 𝛿 ( { 𝑞 3 } , 1 ) ={𝑞 0 ,𝑞 1 ,𝑞 3 }
0
0
𝑞0 𝑞3
1
0 1
𝑞0 𝑞2 0
0 0 𝑞0 𝑞1 𝑞3
1 1
𝑞0 𝑞0 𝑞1 1
0 𝑞0 𝑞2 𝑞3
1
𝑞0 𝑞1 𝑞2 1
𝑞0 𝑞1 𝑞2 𝑞3
Example 2: Conversion from NFA to FA
𝛿1 ( {𝑞0 ,𝑞1 ,𝑞2 ,𝑞3 },0 ) =𝛿 ( {𝑞0 } ,0 ) ∪𝛿 ( {𝑞1 } ,0 ) ∪𝛿 ( {𝑞2 } ,0 ) ∪𝛿 ( {𝑞3 } ,0 )={𝑞0 ,𝑞2 ,𝑞3 }
𝛿1 ( {𝑞0 ,𝑞1 ,𝑞2 ,𝑞3 },1 ) =𝛿 ( {𝑞0 } ,1 ) ∪𝛿 ( {𝑞1 } ,1 ) ∪𝛿 ( {𝑞2 },1 ) ∪𝛿 ( {𝑞3 } ,1 )={𝑞0 ,𝑞1 ,𝑞2 ,𝑞3 }
0
• As now no new states are
0
𝑞0 𝑞3
1
obtained, the process
stops and we need to 0 1
𝑞0 𝑞2 0
0 𝑞0 𝑞1 𝑞3
define the accepting
0
1 1
states.
• To define accepting states, 𝑞0 𝑞0 𝑞1 1
0 𝑞0 𝑞2 𝑞3
the states which contain 1
the accepting states of 𝑞0 𝑞1 𝑞2 1 0 1
NFA will be accepting
states of final FA. 𝑞0 𝑞1 𝑞2 𝑞3
Nondeterministic Finite Automata with -Transitions
• A nondeterministic finite automaton with -transitions (NFA- ) is a
5-tuple where and are finite sets, , and
Non-recursive Definition of for NFA-
• For an NFA - , states , and a string we will say moves from to by
a sequence of transition corresponding to if there exist an
integer , a sequence satisfying , and a sequence of states so that
for each with , .
-closure of a Set of States
• Let be an NFA-, and let be any subset of . The -closure of is the
set () defined as follows:
1. Every element of is an element of
2. For any , every element of ) is in
3. No other elements of are in .
Applying Definitions of
0 1
Λ ( { 𝑞 0 } ) =¿𝑞 0 , 𝑝 ,𝑡
𝑝 𝑟 𝑠
1 0
^ ^
𝑞0 ^
𝑤
^
^
𝑡 𝑢 𝑣
0 0
1 0
Applying Definitions of
0 1
Λ ( { 𝑠 } ) =¿ 𝑠 ,𝑤 ,𝑞 0 , 𝑝 ,𝑡
𝑝 𝑟 𝑠
1 0
^ ^
𝑞0 ^
𝑤
^
^
𝑡 𝑢 𝑣
0 0
1 0
Recursive Definition of for NFA-
• Let be an NFA- . The extended transition function is defined as
follows.
1. For any
2. For any and ,
𝑝 𝑟 𝑠
1 0
^ ^
𝑞0 ^
𝑤
^
^
𝑡 𝑢 𝑣
0 0
1 0
Applying Definition of
0 1
∗
𝛿 (𝑞0 , Λ )
𝑝 𝑟 𝑠 1 0
∗
𝛿 ( 𝑞 0 ,0 )
^ ^
𝑞0 ^
𝑤 ¿ Λ ( ¿𝑟 ∈𝛿 ( 𝑞 0 , Λ∗
) 𝛿 ( 𝑟
^
𝑡 𝑢 𝑣 0 0 ^
¿ Λ ( ¿𝑟 ∈{𝑞0 ,𝑝,𝑡}𝛿 ( 𝑟
1 0
Applying Definition of
𝛿 ( 𝑞0 ,01 )= Λ ( ¿𝑟 ∈𝛿 ( 𝑞0 ,0 ) 𝛿 (𝑟 ,1 ) )
∗ ∗
qo ^
q1
a
q2
75
Conversion from NFA- to FA
A {B} {A}
B {D} {C}
C {B}
D {D}
C
0 0
0 1
^ ^
A B D
Conversion from NFA- ^ to FA
Step 1: To convert NFA - ^ to NFA C
¿¿ Λ { 𝐴 }={ 𝐴, 𝐵 , 𝐷 }
∗
𝛿 0
0
∗
𝛿 ( 𝐴, 0 )
¿ Λ¿ A
0
B D
¿ Λ ( ¿𝑟∈{𝐴,𝐵,𝐷}𝛿 ( 𝑟,0 ) ) 0
¿ Λ (𝛿 ( 𝐴 , 0 ) ∪𝛿 ( 𝐵 , 0 ) ∪𝛿 ( 𝐷 , 0 ) )
¿ Λ ( { 𝐴 , 𝐶 , 𝐷 })
¿{ 𝐴, 𝐵 , 𝐶 , 𝐷 }
Conversion from NFA- to FA
∗
𝛿 ( 𝐴, 1 )
¿ Λ¿ 0
C
¿ Λ ( ¿𝑟∈{𝐴,𝐵,𝐷}𝛿 ( 𝑟,1) )
0
0
A B D
¿ Λ ( 𝛿 ( 𝐴, 1 ) ) ∪ 𝛿 ( 𝐵 , 1 ) ∪ 𝛿 ( 𝐷 , 1 )
¿ Λ ( 𝜙) 0
¿ 𝜙
Conversion from NFA- ^ to FA
¿¿ Λ { 𝐵 }={ 𝐵 , 𝐷 }
∗
𝛿 C
∗
𝛿 ( 𝐵 , 0)
¿ Λ¿ 0 0
0
¿ Λ ( ¿𝑟 ∈{𝐵,𝐷}𝛿 ( 𝑟 ,0 ) ) A
0
B
0
D
¿ Λ ( 𝛿 ( 𝐵 , 0 ) ∪ 𝛿 ( 𝐷 , 0 )) 0
¿ Λ ({ 𝐶 , 𝐷 } )
¿ {𝐶 , 𝐷 }
Conversion from NFA- ^ to FA
∗
𝛿 ( 𝐵 ,1 )
¿ Λ¿ 0
C
¿ Λ ( ¿𝑟 ∈{𝐵,𝐷}𝛿 ( 𝑟 ,1 ) )
0
0
0 0
A B D
¿ Λ ( 𝛿 ( 𝐵 , 1 ) ∪ 𝛿 ( 𝐷 ,1 ) )
¿ Λ ( 𝜙) 0
¿ 𝜙
Conversion from NFA- ^ to FA
¿¿ Λ { 𝐶 }= {𝐶 }
∗
𝛿 C
∗
𝛿 ( 𝐶 , 0)
¿ Λ¿ 0 0
0
¿ Λ ( ¿𝑟 ∈{𝐶 }𝛿 ( 𝑟 ,0 ) ) A
0
B
0
D
¿ Λ ( 𝛿 ( 𝐶 , 0) ) 0
¿ 𝛬( 𝜙)
¿ 𝜙
Conversion from NFA- to FA
∗
𝛿 ( 𝐶 ,1 )
¿ Λ¿ 0
C
¿ Λ ( ¿𝑟 ∈{𝐶 }𝛿 ( 𝑟 ,1 ) )
0 1
0 1
0 0
A B D
¿ Λ ( 𝛿 ( 𝐶 , 1 ))
¿ Λ ({ 𝐵 }) 0
¿ { 𝐵 , 𝐷 }
Conversion from NFA- ^ to FA
¿¿ Λ { 𝐷 }= {𝐷 }
∗
𝛿 C
∗
𝛿 ( 𝐷 , 0)
¿ Λ¿ 0 0
0 1 1
0
¿ Λ ( ¿𝑟 ∈{𝐷}𝛿 (𝑟 ,0 ) ) A
0
B
0
D
¿ Λ ( 𝛿 ( 𝐷 , 0 )) 0
¿ 𝛬 ({ 𝐷 })
¿ { 𝐷 }
Conversion from NFA- ^ to FA
∗
𝛿 ( 𝐷 , 1)
¿ Λ¿ 0 0
C
¿ Λ ( ¿𝑟 ∈{𝐷}𝛿 (𝑟 ,1 ) ) 0 1 1
0 0
A B D
¿ Λ ( 𝛿 ( 𝐷 , 1) )
0
¿ 𝛬( 𝜙)
¿ 𝜙
Accepting =
State { if in
otherwise
Resulting NFA
Conversion from NFA- ^ to FA
Step 2: To convert NFA to FA
𝛿 ( { 𝐴 }, 0 )={ 𝐴 , 𝐵 , 𝐶 , 𝐷 }
𝛿 ( { 𝐴 } , 1 )= 𝜙
𝛿 ( { 𝐴 , 𝐵 , 𝐶 , 𝐷 }, 0 )=¿
{C,D} {} {D} =
𝛿 ( { 𝐴 , 𝐵 , 𝐶 , 𝐷 }, 1 ) =¿
¿{𝐵,𝐷} 0
𝛿 ( { 𝐵 , 𝐷 }, 0 )= ¿
1
¿ {𝐶 , 𝐷 } ABCD BD 0
0
𝛿 ( { 𝐵 , 𝐷 }, 1 ) =¿
CD
¿ 𝜙A
Conversion from NFA- ^ to FA
𝛿 ( {𝐶 , 𝐷 }, 0 ) = ¿
¿ { 𝐷 }
0
𝛿 ( {𝐶 , 𝐷 }, 1 ) =¿
¿{𝐵,𝐷}
1
𝛿 ( {𝐷 }, 0 ) ={𝐷 } ABCD BD
0
𝛿 ( {𝐷 },1 )=𝜙 0
1
A CD
0
FA
D
0
Practice Example
a b c
q0 ^ ^
q1 q2
87