0% found this document useful (0 votes)
17 views95 pages

Theory of Computation Concepts Explained

Uploaded by

xyz abc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views95 pages

Theory of Computation Concepts Explained

Uploaded by

xyz abc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

Formal Language and

Automata Theory
• Operations in NFA
• Chomsky Normal Form (CNF)
• Minimization of FA Subject Code
• Union, Concatenation & Kleene’s 3151605
of CFG
• Pumping Lemma

Theory of Computation (2160704) 1 Darshan Institute of Engineering & Technology


Outline
• 𝛿∗ in NFA
• NFA to FA
• FA to Regular Grammars
• Chomsky Normal Form (CNF)
• CFG to CNF
• Minimization of FA
• NFA with ⋀-Transitions
• 𝛿∗ in NFA- ⋀
• NFA- ⋀ to FA
• Union, Concatenation & Kleene’s of CFG
• Pumping Lemma

Theory of Computation (2160704) 2 Darshan Institute of Engineering & Technology


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.

Theory of Computation (2160704) 3 Darshan Institute of Engineering & Technology


Example of NFA for
δ Input
State

• 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

Theory of Computation (2160704) 5 Darshan Institute of Engineering & Technology


Recursive Definition of for NFA
• Let be an NFA. The function is defined as follows.
1. For any , .
2. For any , , and ,

Theory of Computation (2160704) 6 Darshan Institute of Engineering & Technology


Acceptance by NFA
• Let be an NFA. The string is accepted by if . The language
recognized, or accepted, by is the set of all string accepted by .
For any language is recognized by

Theory of Computation (2160704) 7 Darshan Institute of Engineering & Technology


Example: Recursive Definition of in NFA
δ Input
State

• is defined as

0, 1

𝑞0 1
𝑞1 0, 1
𝑞2 0, 1
𝑞3

Theory of Computation (2160704) 8 Darshan Institute of Engineering & Technology


Example: Recursive Definition of in NFA

𝛿 ∗ ( 𝑞 0 ,0 )
¿ ¿ 𝑟 ∈ 𝜹 (𝒒 , ⋀ ) 𝛿(𝑟 , 0)
𝟎

¿ ¿ 𝑟 ∈ {𝒒 𝟎 }𝛿(𝑟 , 0)
¿ 𝛿 ( 𝑞0 , 0 )
¿ {𝑞 0 }

Theory of Computation (2160704) 9 Darshan Institute of Engineering & Technology


Example: Recursive Definition of in NFA

𝛿 ∗ ( 𝑞 0 ,1 )
¿ ¿ 𝑟 ∈ 𝜹 (𝒒𝟎 , ⋀ ) 𝛿(𝑟 , 1)
¿ ¿ 𝑟 ∈ {𝒒 𝟎 }𝛿(𝑟 , 1)
¿ 𝛿 ( 𝑞0 , 1 )
¿ {𝑞 0 , 𝑞1 }

Theory of Computation (2160704) 10 Darshan Institute of Engineering & Technology


Example: Recursive Definition of in NFA

𝛿 ∗ ( 𝑞 0 ,11 )
¿ ¿ 𝑟 ∈ 𝜹 (𝒒𝟎 ,𝟏) 𝛿(𝑟 ,1)
¿ ¿ 𝑟 ∈ {𝒒 𝟎 , 𝒒𝟏 }𝛿(𝑟 , 1)
¿ 𝛿 ( 𝑞0 , 1 ) ∪ 𝛿 ( 𝑞 1 , 1 )
¿ {𝑞 0 , 𝑞1 } ∪ {𝑞 2 }
¿ {𝑞 0 , 𝑞1 , 𝑞 2 }

Theory of Computation (2160704) 11 Darshan Institute of Engineering & Technology


Example: Recursive Definition of in NFA

𝛿 ∗ ( 𝑞 0 ,01 )
¿ ¿ 𝑟 ∈ 𝜹 (𝒒𝟎 , 𝟎)𝛿(𝑟 , 1)
¿ ¿ 𝑟 ∈ {𝒒 𝟎 }𝛿(𝑟 , 1)
¿ 𝛿 ( 𝑞0 , 1 )
¿ {𝑞 0 , 𝑞1 }

Theory of Computation (2160704) 12 Darshan Institute of Engineering & Technology


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 }
Theory of Computation (2160704) 13 Darshan Institute of Engineering & Technology
Exercise: Recursive Definition of in NFA
δ Input
State

• is defined as

0, 1 0, 1

𝑞0 1
𝑞1 1
𝑞2 0, 1
𝑞3
Check acceptability of

Theory of Computation (2160704) 14 Darshan Institute of Engineering & Technology


NFA to FA using subset
construction method

Theory of Computation (2160704) 15 Darshan Institute of Engineering & Technology


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

Theory of Computation (2160704) 16 Darshan Institute of Engineering & Technology


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

Theory of Computation (2160704) 17 Darshan Institute of Engineering & Technology


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
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

Theory of Computation (2160704) 19 Darshan Institute of Engineering & Technology


Example 2: Conversion from NFA to FA

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 }

Theory of Computation (2160704) 20 Darshan Institute of Engineering & Technology


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
𝑞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

• To define accepting states, 𝑞0 1


𝑞0 𝑞1 1
1

the states which contain 1


0 𝑞0 𝑞2 𝑞3
the accepting states of 𝑞0 𝑞1 𝑞2 1 0 1
NFA will be accepting
states of final FA. 𝑞0 𝑞1 𝑞2 𝑞3
Theory of Computation (2160704) 23 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

• To define accepting states, 𝑞0 1


𝑞0 𝑞1 1
1

the states which contain 1


0 𝑞0 𝑞2 𝑞3
the accepting states of 𝑞0 𝑞1 𝑞2 1 0 1
NFA will be accepting
states of final FA. 𝑞0 𝑞1 𝑞2 𝑞3
Theory of Computation (2160704) 24 Darshan Institute of Engineering & Technology
FA to Regular Grammar

Theory of Computation (2160704) 25 Darshan Institute of Engineering & Technology


Type 3 grammar (Linear or Regular grammar)
• Their productions are of the form:
or
• Where are non terminals and is terminal.
• Example: X → a | aY
Y→b

Theory of Computation (2160704) 26 Darshan Institute of Engineering & Technology


Hierarchy of grammar

Type 3
(Regular)

Theory of Computation (2160704) 27 Darshan Institute of Engineering & Technology


FA to Regular Grammar
0 1
𝐴→ 0 𝐴
0 𝐴→ 1 𝐵
𝐵→0𝐶
𝐴 1
𝐵 𝐶 𝐵 →1 𝐵
1

0
𝐶 →0 𝐴
𝐶 →1 𝐵
𝐵→0
At last, all the incoming transitions to
the accepting states are designated by
the production
Source State → input symbol

Theory of Computation (2160704) 28 Darshan Institute of Engineering & Technology


Exercise: FA to Regular Grammar
b

a B a
b
b
A C

b b
a a

a
E D

Theory of Computation (2160704) 29 Darshan Institute of Engineering & Technology


-Context Free Grammar-
Derivation

Theory of Computation (2160704) 30 Darshan Institute of Engineering & Technology


Derivation
• Derivation is used to find whether the string belongs to a given
grammar or not.
• There are two types of derivation:
1. Leftmost derivation
2. Rightmost derivation

Theory of Computation (2160704) 31 Darshan Institute of Engineering & Technology


Leftmost derivation
• A derivation of a string in a grammar is a left most derivation if at
every step the left most nonterminal is replaced.
• Grammar: SS+S | S-S | S*S | S/S | a Output string: a*a-a

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: SS+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
SA1B
A0A | 𝜖
B0B | 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.
SA1B
A0A | 𝜖
B0B | 1B | 𝜖
Output string: 1001.
2. Perform rightmost derivation and draw parse tree.
EE+E | E*E | id | (E) | -E
Output string : id + id * id.

Theory of Computation (2160704) 35 Darshan Institute of Engineering & Technology


Ambiguous grammar

Theory of Computation (2160704) 36 Darshan Institute of Engineering & Technology


Ambiguous grammar
• Ambiguous grammar is one that produces more than one leftmost
or more then one rightmost derivation for the same sentence.
• Grammar: SS+S | S*S | (S) | a Output string: a+a*a

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. SSS+ | SS* | a (string: aa+a*)

Theory of Computation (2160704) 39 Darshan Institute of Engineering & Technology


Simplified forms & Normal forms

Theory of Computation (2160704) 40 Darshan Institute of Engineering & Technology


Nullable Variable
• A Nullable variable in a CFG, is defined as follows:
1. Any variable A for which P contains is nullable.
2. If P contains the production are nullable variable, then A is
nullable.
3. No other variables in V are nullable.

Theory of Computation (2160704) 41 Darshan Institute of Engineering & Technology


Eliminate ˄ production

SaX |Yb SaX | Yb | a^ SaX|Yb|a


X ˄ | S X^ | S XS
YbY|b YbY|b YbY|b

Nullable variable={X} Replacing X by ^ in all Removing ^ productions


productions containing
X on RHS and rewriting
the production again

Theory of Computation (2160704) 42 Darshan Institute of Engineering & Technology


Exercise: Eliminate ^ production
SAC SXaX|bX|Y
AaAb|˄ XXaX|XbX|˄
CaC|a Yab
After elimination of ^ production: After elimination of ^ production:
SAC | C S XaX | bX | Y | aX | Xa | a | b
AaAb| ab X XaX |XbX | aX | Xa | a | Xb | bX | b
CaC|a Yab

Theory of Computation (2160704) 43 Darshan Institute of Engineering & Technology


A-derivable
• A variable is called A-derivable ,
1. If is a production, B is A-derivable.
2. If C is A-derivable, is a production, and , then B is A-
derivable.
3. No other variables are A-derivable.

SA SA
SB AB
S-derivable={A,B} S-derivable={A,B}

Theory of Computation (2160704) 44 Darshan Institute of Engineering & Technology


Unit Production & Elimination of Unit productions
• A production of the form AB is termed as unit production.
Where A & B are nonterminals.
Algorithm
• Given a CFG with no ^ productions, construct a CFG having no
unit production as follows.
1. Initialize P1 to be P.
2. For each A ∈ V ,finding the set of A derivable variable.
3. For every pair (A, B) such that B is A- derivable and every non
unit production Bα, add the production Aα to P1 if it is
not already present in P1.
4. Delete all unit productions from P1.

Theory of Computation (2160704) 45 Darshan Institute of Engineering & Technology


Elimination of unit production
SABA|BA|AA|AB|A|B
Unit Productions
A aA|a
B bB|b are SA and SB

SABA|BA|AA|AB |aA|a|bB|b Removing unit


AaA|a
BbB|b productions

Theory of Computation (2160704) 46 Darshan Institute of Engineering & Technology


CFG to CNF

Theory of Computation (2160704) 47 Darshan Institute of Engineering & Technology


Chomsky Normal Form (CNF)
• A context free grammar is in Chomsky normal form (CNF) if every
production is one of these two forms:

Where and are nonterminal and is terminal.

Theory of Computation (2160704) 48 Darshan Institute of Engineering & Technology


Converting CFG to CNF
• Steps to convert CFG to CNF
1. Eliminate ˄-Productions.
2. Eliminate Unit Productions.
3. Restricting the right side of productions to single terminal or
string of two or more nonterminal.
4. Final step of CNF. (shorten the string of NT to length 2)

Theory of Computation (2160704) 49 Darshan Institute of Engineering & Technology


Example: CFG to CNF
Step 3: Replace all mixed string with solid NT
SAAC
SAAC|AC|aC|aPC
AaAb|˄ APAQ|PQ
aAb|ab
CaC|a C PC|a
aC|a
Pa
Step 1: Elimination of ^ production
Qb
Eliminate A^ Step-4: Shorten the string of NT to length 2
SAAC| AC | C
SAX XAC
AaAb| ab
SAC|PC|a
CaC|a
APY YAQ
Step-2: Eliminate Unit Production APQ
Unit Production is SC CPC|a
SAAC|AC| CaC|a Pa
AaAb|ab
CaC|a Qb Chomsky Normal Form

Theory of Computation (2160704) 50 Darshan Institute of Engineering & Technology


Example: CFG to CNF
SaAbB
AAb|b
BBa|a
Step 1 and 2 are not required as there is no ^ and unit productions
Step-3: Replace all mixed string with solid NT Step-4 : final step of CNF
SPAQB SPX
AAQ|b XAY
BBP|a YQB
AAQ|b
Pa
BBP|a
Qb
Pa
Qb

Theory of Computation (2160704) 51 Darshan Institute of Engineering & Technology


Exercise: CFG to CNF

Theory of Computation (2160704) 52 Darshan Institute of Engineering & Technology


Exercise: CFG to CNF
SAA
AB|BB
BabB|b|bb
Step 1 is not required as there is no ^ productions
Step-2: Eliminate Unit Production: Step-4 : Shorten the string of NT to length 2
SAA SAA
A PX|b|QQ|BB XQB
A abB|b|bb|BB
B PX|b|QQ
BabB|b|bb Pa
Step-3:Replace all mixed string with solid NT: Qb
SAA
A PQB|b|QQ|BB
B PQB|b|QQ
Pa
Qb

Theory of Computation (2160704) 53 Darshan Institute of Engineering & Technology


Exercise: CFG to CNF
SASB|^ Step-3:Replace all mixed string with solid NT:
AaAS|a SASB|AB
APAS|a|PA
BSbS|A|bb BSQS|PAS|a|PA|QQ|QS|SQ|b
Pa
Qb
Step-1: Eliminate ˄-Production:
SASB|AB Step-4 : Shorten the string of NT to length 2
AaAS|a|aA SAB|AX
XSB
BSbS|A|bb|bS|Sb|b Aa|PA|PY
YAS
Step-2: Eliminate Unit Production: B SL|PY|a|PA|QQ|QS|SQ|b
LQS
SASB|AB Pa
AaAS|a|aA Qb
BSbS|aAS|a|aA|bb|bS|Sb|b

Theory of Computation (2160704) 54 Darshan Institute of Engineering & Technology


Backus-Naur Form (BNF)
• BNF is one of the notation • Example:
techniques for context free <exp>=<exp> + <term> | <term>
grammar. <term>=<term> * <factor> | <factor>
• It is often used to describe syntax <factor>=<factor> ^ <primary> | <primary>
of the language used in computing.
<primary>=<id> | <const>
• Variables written between <..> are
<id>=<letter>
non terminals.
<const>=[+/-]<digit>
• Vertical bar ‘|’ indicating a
<letter>=a | b | c |……| z
alternate choice.
<digit>=0 | 1 |………….| 9
• […], which is used to enclosed an
optional specification.

Theory of Computation (2160704) 55 Darshan Institute of Engineering & Technology


Minimization of FA

Theory of Computation (2160704) 56 Darshan Institute of Engineering & Technology


Example: Minimize FA
Final state is {6} a
a
4
Non-Final state is {1,2,3,4,5,7}
(6, 1), (6,2), (6, 3), (6, 4), (6, 5), (6, 7) are distinguished pairs. 2 b a
a b
Consider pair (1,2) 5
δ(1,a)=2 δ(1,b)=3 1 b a

δ(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

Theory of Computation (2160704) 57 Darshan Institute of Engineering & Technology


Example: Minimize FA
Consider pair (1,5) a
δ(1,a)=2 δ(1,b)=3 a
4
δ(5,a)=6 δ(5,b)=7 2 b a
a b
pair (2,6) is distinguished, so (1,5) is distinguished pair.
5
Consider pair (1,7) 1 b a
δ(1,a)=2 δ(1,b)=3
δ(7,a)=6 δ(7,b)=7
b a 6
pair (2,6) is distinguished, so (1, 7) is distinguished pair. 3 a
b

Consider pair (2,3) 2 b


7
3 X X
δ(2,a)=4 δ(2,b)=5 b
4 X
δ(3,a)=6 δ(3,b)=7 5 X X X
pair (4,6) is distinguished, so (2, 3) distinguished pair. 6 X X X X X X
Consider pair (2,4) 7 X X X X
1 2 3 4 5 6
δ(2,a)=4 δ(2,b)=5
δ(4,a)=4 δ(4,b)=5
Theory of Computation (2160704) 58 Darshan Institute of Engineering & Technology
Example: Minimize FA
Consider pair (2,5) a
a
4
δ(2,a)=4 δ(2,b)=5
δ(5,a)=6 δ(5,b)=7 2 b a
a b
pair (4,6) is distinguished, so (2,5) is distinguished pair. 5
Consider pair (2,7) 1 b a
δ(2,a)=4 δ(2,b)=5
b a 6
δ(7,a)=6 δ(7,b)=7
pair (4,6) is distinguished, so (2,7) is distinguished pair.
3 a
b

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

Theory of Computation (2160704) 60 Darshan Institute of Engineering & Technology


Example: Minimize FA
a
a b a
4
a 2 b a
a b
5
124 b
357 b
6 1 b a

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

Theory of Computation (2160704) 61 Darshan Institute of Engineering & Technology


Nondeterministic Finite Automata with -Transitions
• A nondeterministic finite automaton with -transitions (NFA- ) is a
5-tuple where and are finite sets, , and

Theory of Computation (2160704) 62 Darshan Institute of Engineering & Technology


Nonrecursive Definition of for NFA-
0 1
For an NFA -
, states , and a string we
will say moves from to by 𝑝 𝑟 𝑠 1 0

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

Theory of Computation (2160704) 63 Darshan Institute of Engineering & Technology


-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 .

Theory of Computation (2160704) 64 Darshan Institute of Engineering & Technology


Applying Definitions of
0 1
Λ ( { 𝑞 0 } ) =¿𝑞 0 , 𝑝 ,𝑡

𝑝 𝑟 𝑠 1 0

^ ^

𝑞0 ^
𝑤
^
^
𝑡 𝑢 𝑣 0 0

1 0

Theory of Computation (2160704) 65 Darshan Institute of Engineering & Technology


Applying Definitions of
0 1
Λ ( { 𝑠 } ) =¿ 𝑠 ,𝑤 ,𝑞 0 , 𝑝 ,𝑡
𝑝 𝑟 𝑠 1 0

^ ^

𝑞0 ^
𝑤
^
^
𝑡 𝑢 𝑣 0 0

1 0

Theory of Computation (2160704) 66 Darshan Institute of Engineering & Technology


Recursive Definition of for NFA-
• Let be an NFA- . The extended transition function is defined as
follows.
1. For any
2. For any and ,

A string is accepted by if . The language recognized by is the set


of all strings accepted by .

Theory of Computation (2160704) 67 Darshan Institute of Engineering & Technology


Applying Definition of
0 1

𝛿 (𝑞0 , Λ )

𝑝 𝑟 𝑠 1 0

^ ^

𝑞0 ^
𝑤
^
^
𝑡 𝑢 𝑣 0 0

1 0

Theory of Computation (2160704) 68 Darshan Institute of Engineering & Technology


Applying Definition of
0 1

𝛿 (𝑞0 , Λ )

𝑝 𝑟 𝑠 1 0

𝛿 ( 𝑞 0 ,0 )
^ ^

𝑞0 ^
𝑤 ¿ Λ ( ¿𝑟 ∈𝛿 ( 𝑞 0 , Λ ) ∗
𝛿 ( 𝑟
^
𝑡 𝑢 𝑣 0 0 ^
¿ Λ ( ¿𝑟 ∈{𝑞0 ,𝑝,𝑡}𝛿 ( 𝑟
1 0

Theory of Computation (2160704) 69 Darshan Institute of Engineering & Technology


Applying Definition of

𝛿 ( 𝑞0 ,01 )= Λ ( ¿𝑟 ∈𝛿 ( 𝑞0 ,0 ) 𝛿 (𝑟 ,1 ) )
∗ ∗

𝛿 ( 𝑞0 ,010 ) =Λ ( ¿𝑟∈ 𝛿 ( 𝑞0 ,01 ) 𝛿 (𝑟 ,0 ) )


∗ ∗

Theory of Computation (2160704) 70 Darshan Institute of Engineering & Technology


NFA-^ to FA

Theory of Computation (2160704) 71 Darshan Institute of Engineering & Technology


NFA - to FA

NFA - NFA FA

Theory of Computation (2160704) 72 Darshan Institute of Engineering & Technology


Conversion from NFA- to FA

A {B} {A}
B {D} {C}

C {B}
D {D}

C
0 0
0 1

^ ^
A B D

Theory of Computation (2160704) 73 Darshan Institute of Engineering & Technology


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 ) )
¿ Λ ( { 𝐴 , 𝐶 , 𝐷 })
¿{ 𝐴, 𝐵 , 𝐶 , 𝐷 }

Theory of Computation (2160704) 74 Darshan Institute of Engineering & Technology


Conversion from NFA- to FA

𝛿 ( 𝐴, 1 )
¿ Λ¿ 0
C

¿ Λ ( ¿𝑟∈{𝐴,𝐵,𝐷}𝛿 ( 𝑟,1) )
0

0
A B D
¿ Λ ( 𝛿 ( 𝐴, 1 ) ) ∪ 𝛿 ( 𝐵 , 1 ) ∪ 𝛿 ( 𝐷 , 1 )
¿ Λ ( 𝜙) 0

¿ 𝜙

Theory of Computation (2160704) 75 Darshan Institute of Engineering & Technology


Conversion from NFA- ^ to FA
¿¿ Λ { 𝐵 }={ 𝐵 , 𝐷 }

𝛿 C

𝛿 ( 𝐵 , 0)
¿ Λ¿ 0 0
0

¿ Λ ( ¿𝑟 ∈{𝐵,𝐷}𝛿 ( 𝑟 ,0 ) ) A
0
B
0
D

¿ Λ ( 𝛿 ( 𝐵 , 0 ) ∪ 𝛿 ( 𝐷 , 0 )) 0

¿ Λ ({ 𝐶 , 𝐷 } )
¿ {𝐶 , 𝐷 }

Theory of Computation (2160704) 76 Darshan Institute of Engineering & Technology


Conversion from NFA- ^ to FA

𝛿 ( 𝐵 ,1 )
¿ Λ¿ 0
C

¿ Λ ( ¿𝑟 ∈{𝐵,𝐷}𝛿 ( 𝑟 ,1 ) )
0
0

0 0
A B D
¿ Λ ( 𝛿 ( 𝐵 , 1 ) ∪ 𝛿 ( 𝐷 ,1 ) )
¿ Λ ( 𝜙) 0

¿ 𝜙

Theory of Computation (2160704) 77 Darshan Institute of Engineering & Technology


Conversion from NFA- ^ to FA
¿¿ Λ { 𝐶 }= {𝐶 }

𝛿 C

𝛿 ( 𝐶 , 0)
¿ Λ¿ 0 0
0

¿ Λ ( ¿𝑟 ∈{𝐶 }𝛿 ( 𝑟 ,0 ) ) A
0
B
0
D

¿ Λ ( 𝛿 ( 𝐶 , 0) ) 0

¿ 𝛬( 𝜙)
¿ 𝜙

Theory of Computation (2160704) 78 Darshan Institute of Engineering & Technology


Conversion from NFA- to FA

𝛿 ( 𝐶 ,1 )
¿ Λ¿ 0
C

¿ Λ ( ¿𝑟 ∈{𝐶 }𝛿 ( 𝑟 ,1 ) )
0 1
0 1

0 0
A B D
¿ Λ ( 𝛿 ( 𝐶 , 1 ))
¿ Λ ({ 𝐵 }) 0

¿ { 𝐵 , 𝐷 }

Theory of Computation (2160704) 79 Darshan Institute of Engineering & Technology


Conversion from NFA- ^ to FA
¿¿ Λ { 𝐷 }= {𝐷 }

𝛿 C

𝛿 ( 𝐷 , 0)
¿ Λ¿ 0 0
0 1 1
0

¿ Λ ( ¿𝑟 ∈{𝐷}𝛿 (𝑟 ,0 ) ) A
0
B
0
D

¿ Λ ( 𝛿 ( 𝐷 , 0 )) 0

¿ 𝛬 ({ 𝐷 })
¿ { 𝐷 }

Theory of Computation (2160704) 80 Darshan Institute of Engineering & Technology


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
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

Theory of Computation (2160704) 82 Darshan Institute of Engineering & Technology


Conversion from NFA- ^ to FA
𝛿 ( {𝐶 , 𝐷 }, 0 ) = ¿
¿ { 𝐷 }
0
𝛿 ( {𝐶 , 𝐷 }, 1 ) =¿
¿{𝐵,𝐷}
1
𝛿 ( {𝐷 }, 0 ) ={𝐷 } ABCD BD
0
𝛿 ( {𝐷 },1 )=𝜙 0
1
A CD

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

Theory of Computation (2160704) 84 Darshan Institute of Engineering & Technology


Exercise 2: Conversion from NFA- to FA

0 {1, 7}
1 {2, 4}
2
3
4
5
6 {1, 7}
7
8
9
10

Theory of Computation (2160704) 85 Darshan Institute of Engineering & Technology


Union, Concatenation &
Kleene’s of CFG

Theory of Computation (2160704) 86 Darshan Institute of Engineering & Technology


Union, Concatenation & Kleene’s of CFG
Theorem:- If L1 and L2 are context - free languages, then the
languages L1 U L2, L1L2 , and L1* are also CFLs.
• The proof is constructive: Starting with CFGs
G1 = (V1, Ʃ, S1,P1) and G2 = (V2, Ʃ, S2,P2) ,
• Generating L1 and L2, respectively, we show how to construct a
new CFG for each of the three cases. G1:
1. Gu = (Vu, Ʃ, Su, Pu) generating L1 U L2 A → 00A | 01
2. Gc= (Vc, Ʃ, Sc, Pc) generating L1L2
G2:
3. G* = (V, Ʃ, S, P) generating L1 * E → 11F
F → 00F | ^

Theory of Computation (2160704) 87 Darshan Institute of Engineering & Technology


G1:
Gu:
Union Gu = (Vu, Ʃ, Su, Pu) SA →
→ A00A
AG2:
| E| 01
→ 00A | 01
EE →
→ 11F
11F
• A grammar Gu = (Vu, Ʃ, Su, Pu) generating L1 U L2. FF →
→ 00F || ^^
00F

• First, we rename the element of V2 if necessary, so that V1 ∩ V2= Ø


Vu= V1 U V2 U {Su}
Where Su is a new symbol not in V1 or V2. Then we let
Pu= P1 U P2 U { Su S1 | S2 }
• On the other hand, if x is derivable from Su in Gu, the first step in any
derivation must be
SuS1 or SuS2
• In the first case, all subsequent productions used must be productions in
G1, because no variables in V2 are involved, and thus x∈ L1; in the second
case, x ∈ L2. Therefore,
L(Gu) ⊆ L1 U L2
Theory of Computation (2160704) 88 Darshan Institute of Engineering & Technology
Concatenation Gc= (Vc, Ʃ, Sc, Pc)
• A grammar Gc= (Vc, Ʃ, Sc, Pc) generating L1L2 . Again, we relabeled
variables if necessary, so that V1 ∩ V2 = Ø and define
G1:
Gu:
Vc = V1 U V2 U {Sc} SA →
→ AE
00A | 01
A → 00A | 01
G2:
• This time we let EE →
→ 11F
11F
FF →
→ 00F || ^^
00F
Pc= P1 U P2 U { ScS1S2 }
• If x ∈L1L2 then x = x1x2 , where xi ∈Li for each i. we may then derive x
in Gc as follows:
Sc S1 S2  *x1 S2  * x1x2 = x
• First step in the derivation must be ScS1 S2 Where the second step
is the derivation of x1 in G1 and the third step is the derivation of x2 in
G2. So, x ∈ L1L2
Theory of Computation (2160704) 89 Darshan Institute of Engineering & Technology
Kleene (*)
• A grammar G* = (V, Ʃ, S, P) generating L1 * Let V = V1 U {S}
• Where S ∉ [Link] language L1*contains strings of the form x = x 1x2 …xk, where
each xi ∈ L1.
• Since each xi can be derived from S1, then to derive x from S it is enough to be
able to derive a string of k S1‘S. We can accomplish this by including the
productions G*:
G1:
SS1S | ^ S → AS | ^
A → 00A | 01
• In P. Therefore, let A → 00A | 01
P = P1U { SS1S | ^ }
• The proof that L1 * ⊆ L(G*) is straightforward. If x ∈ L(G*) , on the other hand,
then either x = or x can be derived from some string of the form S 1k in G* . In the
second case, since the only production in G* beginning with S 1 are those in G1, we
may conclude that
• x∈ L(G1)k ⊆ L(G1)* .
Theory of Computation (2160704) 90 Darshan Institute of Engineering & Technology
Pumping lemma

Theory of Computation (2160704) 91 Darshan Institute of Engineering & Technology


Define pumping lemma and its application.
• Suppose L is a regular language. Then there is an integer n so that for
any x∈ L with |x|>=n, there are strings u, v, and w so that
1. x=uvw
2. |uv|<=n
3. |v|>0
4. For any m>=0, ∈ L
Application
• The pumping lemma is extremely useful in proving that certain sets
are non-regular. The general methodology followed during its
applications is
• Select a string z in the language L.
• Break the string z into x, y and z in accordance with the above conditions
imposed by the pumping lemma.
• Now check if there is any contradiction to the pumping lemma for any value of i.
Theory of Computation (2160704) 92 Darshan Institute of Engineering & Technology
Use the pumping lemma to show that following language is
not regular: L = {ww|w ϵ {a,b}*}
Step 1:
Let us assume that L is regular and L is accepted by an FA with n
states.
Step 2:
Let us chose the string

Let us write w as xyz with


|y| > 0
And |xy|<=n
Since |xy|<=n, x must be of the form .
Since |xy|<=n, y must be of the form | r>0
Now =
Theory of Computation (2160704) 93 Darshan Institute of Engineering & Technology
Use the pumping lemma to show that following language is
not regular: L = {ww|w ϵ {0,1}*}
Step 3:
• Let us check whether x z for i=2 belongs to L.
= =
• Since, r>0, is not of the form as the number of a’s in the first half
is n+r and second half is n.
• Therefore, Ɇ L. Hence by contradiction we can say language is not
regular.

Theory of Computation (2160704) 94 Darshan Institute of Engineering & Technology


End of Unit

Theory of Computation (2160704) 95 Darshan Institute of Engineering & Technology

You might also like