Theory of Computation Concepts Explained
Theory of Computation Concepts Explained
Automata Theory
• Operations in NFA
• Chomsky Normal Form (CNF)
• Minimization of FA Subject Code
• Union, Concatenation & Kleene’s 3151605
of CFG
• Pumping Lemma
is the set of states, is the alphabet, is the initial state and is the
set of accepting states.
• is defined as
𝑞1
1 1
𝑞0 0
𝑞4
1 0
𝑞2 1
𝑞3
Theory of Computation (2160704) 4 Darshan Institute of Engineering & Technology
Nonrecursive Definition of for NFA
• For an NFA , and any . For any and any is the set of all states for
which there is a sequence of states satisfying
• is defined as
0, 1
𝑞0 1
𝑞1 0, 1
𝑞2 0, 1
𝑞3
¿ ¿ 𝑟 ∈ {𝒒 𝟎 }𝛿(𝑟 , 0)
¿ 𝛿 ( 𝑞0 , 0 )
¿ {𝑞 0 }
• is defined as
0, 1 0, 1
𝑞0 1
𝑞1 1
𝑞2 0, 1
𝑞3
Check acceptability of
2
a b
1 {2,3} {4}
1
b
4
2 {} {4}
3 {4} {3}
a a 4 {} }
3
Transition Table
b
NFA
a a
b b
a
4 3
b
Theory of Computation (2160704) 18 Darshan Institute of Engineering & Technology
Exercise 2: Conversion from NFA to FA
δ Input
State
0, 1
𝑞0 1
𝑞1 0, 1
𝑞2 0, 1
𝑞3
0 𝑞0 𝑞3
0
𝑞0 𝑞2 1
0
𝑞0 1
𝑞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 }
0
𝑞0 𝑞3
1
0
𝑞0 𝑞2 1
0 𝑞0 𝑞1 𝑞3
𝑞0 1
𝑞0 𝑞1
1
0 𝑞0 𝑞2 𝑞3
𝑞0 𝑞1 𝑞2 1
𝑞0 𝑞1 𝑞2 𝑞3
Theory of Computation (2160704) 21 Darshan Institute of Engineering & Technology
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
𝑞0 𝑞2 1
0 0 𝑞0 𝑞1 𝑞3 0
𝑞0 1
𝑞0 𝑞1 1
1
1
0 𝑞0 𝑞2 𝑞3
𝑞0 𝑞1 𝑞2 1
𝑞0 𝑞1 𝑞2 𝑞3
Theory of Computation (2160704) 22 Darshan Institute of Engineering & Technology
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
obtained, the process 0
𝑞0 𝑞3
1
stops and we need to 0
𝑞0 𝑞2 1
define
states.
the accepting 0 0 𝑞0 𝑞1 𝑞3 0
Type 3
(Regular)
0
𝐶 →0 𝐴
𝐶 →1 𝐵
𝐵→0
At last, all the incoming transitions to
the accepting states are designated by
the production
Source State → input symbol
a B a
b
b
A C
b b
a a
a
E D
S S
S-S
S - S
S*S-S
Parse tree represents the
a*S-S S * S a
structure of derivation
a*a-S
a*a-a a a
Parse tree
Leftmost Derivation
Theory of Computation (2160704) 32 Darshan Institute of Engineering & Technology
Rightmost derivation
• A derivation of a string in a grammar is a right most derivation if
at every step the right most nonterminal is replaced.
• It is all called canonical derivation.
• Grammar: SS+S | S-S | S*S | S/S | a Output string: a*a-a
S S
S*S
S * S
S*S-S
S*S-a a S S
-
S*a-a
a*a-a a a
Parse Tree
Rightmost Derivation
Theory of Computation (2160704) 33 Darshan Institute of Engineering & Technology
Example: Derivation
SA1B
A0A | 𝜖
B0B | 1B | 𝜖 Perform leftmost & Rightmost derivation.
(String: 00101)
Leftmost Derivation Rightmost Derivation
S S
A1B
A1B
A10B
0A1B A101B
00A1B A101
001B 0A101
0010B
00A101
00101
00101B
00101
Theory of Computation (2160704) 34 Darshan Institute of Engineering & Technology
Exercise: Derivation
1. Perform leftmost derivation and draw parse tree.
SA1B
A0A | 𝜖
B0B | 1B | 𝜖
Output string: 1001.
2. Perform rightmost derivation and draw parse tree.
EE+E | E*E | id | (E) | -E
Output string : id + id * id.
S S
S S
S*S S S+S S S
* S +
S+S*S a+S
a+S*S S + S a a+S*S a S * S
a+a*S a+a*S
a a a a
a+a*a a+a*a
Here, Two leftmost derivation for string a+a*a is possible hence, above
grammar is ambiguous.
Theory of Computation (2160704) 37 Darshan Institute of Engineering & Technology
Unambiguous grammar
Grammar: S S+S | S*S | (S) | a Output string: a+a*a
Equivalent unambiguous grammar is S
S+T
S S + T | T Equivalent
unambiguous T+T
T T * F | F grammar
F (S) | a F+T
Try for second
Not possible???? a+T
leftmost derivation
a+T*F
a+F*F
Here, two left most derivation is not possible for a+a*F
string a+a*a hence, grammar is unambiguous.
a+a*a
Theory of Computation (2160704) 38 Darshan Institute of Engineering & Technology
Exercise: Ambiguous grammar
Check whether following grammars are ambiguous or not:
1. S aS | Sa | 𝜖 (string: aaaa)
2. S aSbS | bSaS | 𝜖 (string: abab)
3. SSS+ | SS* | a (string: aa+a*)
SA SA
SB AB
S-derivable={A,B} S-derivable={A,B}
δ(2,a)=4 δ(2,b)=5 b a 6
Consider pair (1,3) 3 a
b
δ(1,a)=2 δ(1,b)=3 2 b
7
δ(3,a)=6 δ(3,b)=7 3 X X
b
4 X
pair (2,6) is distinguished, so (1,3) is distinguished pair. 5 X X X
Consider pair (1,4) 6 X X X X X X
7 X X X X
δ(1,a)=2 δ(1,b)=3 1 2 3 4 5 6
δ(4,a)=4 δ(4,b)=5
2 b
Consider pair (3,4) 7
3 X X
δ(3,a)=6 δ(3,b)=7 b
4 X
δ(4,a)=4 δ(4,b)=5 5 X X X
pair (6,4) is distinguished, so (3,4) is distinguish pair. 6 X X X X X X
7 X X X X
Consider pair (3,5) 1 2 3 4 5 6
δ(3,a)=6 δ(3,b)=7
δ(5,a)=6 δ(5,b)=7
Theory of Computation (2160704) 59 Darshan Institute of Engineering & Technology
Example: Minimize FA
Consider pair (3,7) a
δ(3,a)=6 δ(3,b)=7 a
4
δ(7,a)=6 δ(7,b)=7 2 b a
a b
Consider pair (4,5)
5
δ(4,a)=4 δ(4,b)=5 1 b a
δ(5,a)=6 δ(5,b)=7
pair (6,4) is distinguished, so (4,5) is distinguished.
b a 6
Consider pair (4,7) 3 a
b
δ(4,a)=4 δ(4,b)=5 2 b
7
3 X X
δ(7,a)=6 δ(7,b)=7 b
4 X
pair (4,6) is distinguished, so (4,7) is distinguished. 5 X X X
Consider pair (5,7) 6 X X X X X X
δ(5,a)=6 δ(5,b)=7 7 X X X X
1 2 3 4 5 6
δ(7,a)=6 δ(7,b)=7
a
b a 6
3 a
b
𝑴𝒊𝒏𝒊𝒎𝒊𝒛𝒆𝒅 𝑭𝑨❑ 2
3 X X
b
7
b
4 X
5 X X X
1=2 1=4 2=4 1=2=4 6 X X X X X X
3=5 7 X X X X
3=7 5=7 3=5=7 1 2 3 4 5 6
a sequence of transition ^ ^
corresponding to if there
exist an integer , a
𝑞0 ^
𝑤
sequence satisfying , and a
^
sequence of states so that
for each with , .
^
𝑡 𝑢 𝑣 0 0
1 0
𝑝 𝑟 𝑠 1 0
^ ^
𝑞0 ^
𝑤
^
^
𝑡 𝑢 𝑣 0 0
1 0
^ ^
𝑞0 ^
𝑤
^
^
𝑡 𝑢 𝑣 0 0
1 0
𝑝 𝑟 𝑠 1 0
^ ^
𝑞0 ^
𝑤
^
^
𝑡 𝑢 𝑣 0 0
1 0
𝑝 𝑟 𝑠 1 0
∗
𝛿 ( 𝑞 0 ,0 )
^ ^
𝑞0 ^
𝑤 ¿ Λ ( ¿𝑟 ∈𝛿 ( 𝑞 0 , Λ ) ∗
𝛿 ( 𝑟
^
𝑡 𝑢 𝑣 0 0 ^
¿ Λ ( ¿𝑟 ∈{𝑞0 ,𝑝,𝑡}𝛿 ( 𝑟
1 0
𝛿 ( 𝑞0 ,01 )= Λ ( ¿𝑟 ∈𝛿 ( 𝑞0 ,0 ) 𝛿 (𝑟 ,1 ) )
∗ ∗
NFA - NFA FA
A {B} {A}
B {D} {C}
C {B}
D {D}
C
0 0
0 1
^ ^
A B D
¿¿ Λ { 𝐴 }={ 𝐴, 𝐵 , 𝐷 }
∗
𝛿 0
0
∗
𝛿 ( 𝐴, 0 )
¿ Λ¿ A
0
B D
¿ Λ ( ¿𝑟∈{𝐴,𝐵,𝐷}𝛿 ( 𝑟,0 ) ) 0
¿ Λ (𝛿 ( 𝐴 , 0 ) ∪𝛿 ( 𝐵 , 0 ) ∪𝛿 ( 𝐷 , 0 ) )
¿ Λ ( { 𝐴 , 𝐶 , 𝐷 })
¿{ 𝐴, 𝐵 , 𝐶 , 𝐷 }
¿ Λ ( ¿𝑟∈{𝐴,𝐵,𝐷}𝛿 ( 𝑟,1) )
0
0
A B D
¿ Λ ( 𝛿 ( 𝐴, 1 ) ) ∪ 𝛿 ( 𝐵 , 1 ) ∪ 𝛿 ( 𝐷 , 1 )
¿ Λ ( 𝜙) 0
¿ 𝜙
¿ Λ ( ¿𝑟 ∈{𝐵,𝐷}𝛿 ( 𝑟 ,0 ) ) A
0
B
0
D
¿ Λ ( 𝛿 ( 𝐵 , 0 ) ∪ 𝛿 ( 𝐷 , 0 )) 0
¿ Λ ({ 𝐶 , 𝐷 } )
¿ {𝐶 , 𝐷 }
¿ Λ ( ¿𝑟 ∈{𝐵,𝐷}𝛿 ( 𝑟 ,1 ) )
0
0
0 0
A B D
¿ Λ ( 𝛿 ( 𝐵 , 1 ) ∪ 𝛿 ( 𝐷 ,1 ) )
¿ Λ ( 𝜙) 0
¿ 𝜙
¿ Λ ( ¿𝑟 ∈{𝐶 }𝛿 ( 𝑟 ,0 ) ) A
0
B
0
D
¿ Λ ( 𝛿 ( 𝐶 , 0) ) 0
¿ 𝛬( 𝜙)
¿ 𝜙
¿ Λ ( ¿𝑟 ∈{𝐶 }𝛿 ( 𝑟 ,1 ) )
0 1
0 1
0 0
A B D
¿ Λ ( 𝛿 ( 𝐶 , 1 ))
¿ Λ ({ 𝐵 }) 0
¿ { 𝐵 , 𝐷 }
¿ Λ ( ¿𝑟 ∈{𝐷}𝛿 (𝑟 ,0 ) ) A
0
B
0
D
¿ Λ ( 𝛿 ( 𝐷 , 0 )) 0
¿ 𝛬 ({ 𝐷 })
¿ { 𝐷 }
¿ Λ ( ¿𝑟 ∈{𝐷}𝛿 (𝑟 ,1 ) ) 0 1 1
0 0
A B D
¿ Λ ( 𝛿 ( 𝐷 , 1) )
0
¿ 𝛬( 𝜙)
¿ 𝜙
Accepting =
State { if in
otherwise
Resulting NFA
Theory of Computation (2160704) 81 Darshan Institute of Engineering & Technology
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
0
FA
D
0
Theory of Computation (2160704) 83 Darshan Institute of Engineering & Technology
Exercise 1: Conversion from NFA- to FA
0 1
𝑝 𝑟 𝑠 1 0
^ ^
𝑞0 ^
𝑤
^
^
𝑡 𝑢 𝑣 0 0
1 0
0 {1, 7}
1 {2, 4}
2
3
4
5
6 {1, 7}
7
8
9
10