You are on page 1of 140

Unit 2: Regular Languages and

Finite Automata
Topics to be covered
• Regular expressions & Regular languages
• Finite Automata
• RL Properties- 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: Σ
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
𝑺𝒕𝒓𝒊𝒏𝒈𝒔: 𝟎, 𝟏𝟏, 𝟏𝟏𝟏 𝑹. 𝑬. = 𝟎 𝟏𝟏 𝟏𝟏𝟏
3. String having zero or more a.

𝑺𝒕𝒓𝒊𝒏𝒈𝒔: 𝝐, 𝒂, 𝒂𝒂, 𝒂𝒂𝒂, 𝒂𝒂𝒂𝒂 … . . 𝑹. 𝑬. = 𝒂
4. String having one or more a.
+
𝑺𝒕𝒓𝒊𝒏𝒈𝒔: 𝒂, 𝒂𝒂, 𝒂𝒂𝒂, 𝒂𝒂𝒂𝒂 … . . 𝑹. 𝑬. = 𝒂
5. Regular expression over 𝛴 = {𝑎, 𝑏, 𝑐} that represent all string of length
3.
𝑺𝒕𝒓𝒊𝒏𝒈𝒔: 𝒂𝒃𝒄, 𝒃𝒄𝒂, 𝒃𝒃𝒃, 𝒄𝒂𝒃, 𝒂𝒃𝒂 … . 𝑹. 𝑬. = 𝒂 𝒃 𝒄 𝒂 𝒃 𝒄 (𝒂 𝒃 𝒄)
6. All binary string.
𝑺𝒕𝒓𝒊𝒏𝒈𝒔: 𝟎, 𝟏𝟏, 𝟏𝟎𝟏, 𝟏𝟎𝟏𝟎𝟏, 𝟏𝟏𝟏𝟏 … 𝑹. 𝑬. = (𝟎 | 𝟏) +
Regular expression examples
7. 0 or more occurrence of either a or b or both
𝑺𝒕𝒓𝒊𝒏𝒈𝒔: 𝝐, 𝒂, 𝒂𝒂, 𝒂𝒃𝒂𝒃, 𝒃𝒂𝒃 … 𝑹. 𝑬. = (𝒂 | 𝒃) ∗
8. 1 or more occurrence of either a or b or both
𝑺𝒕𝒓𝒊𝒏𝒈𝒔: 𝒂, 𝒂𝒂, 𝒂𝒃𝒂𝒃, 𝒃𝒂𝒃, 𝒃𝒃𝒃𝒂𝒂𝒂 … 𝑹. 𝑬. = (𝒂 | 𝒃) +
9. Binary no. ends with 0
𝑺𝒕𝒓𝒊𝒏𝒈𝒔: 𝟎, 𝟏𝟎, 𝟏𝟎𝟎, 𝟏𝟎𝟏𝟎, 𝟏𝟏𝟏𝟏𝟎 … 𝑹. 𝑬. = (𝟎 | 𝟏) ∗ 𝟎

10. Binary no. ends with 1


𝑺𝒕𝒓𝒊𝒏𝒈𝒔: 𝟏, 𝟏𝟎𝟏, 𝟏𝟎𝟎𝟏, 𝟏𝟎𝟏𝟎𝟏, … 𝑹. 𝑬. = (𝟎 | 𝟏) ∗ 𝟏
11. Binary no. starts and ends with 1
𝑺𝒕𝒓𝒊𝒏𝒈𝒔: 𝟏𝟏, 𝟏𝟎𝟏, 𝟏𝟎𝟎𝟏, 𝟏𝟎𝟏𝟎𝟏, … 𝑹. 𝑬. = 𝟏 (𝟎 | 𝟏) ∗ 𝟏
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 1


𝑺𝒕𝒓𝒊𝒏𝒈𝒔: 𝟏𝟏𝟏, 𝟎𝟏𝟏𝟎𝟏, 𝟎𝟏𝟎𝟏𝟏𝟏𝟎…. 𝑹. 𝑬. = (𝟎|𝟏)∗ 𝟏 (𝟎|𝟏)∗ 𝟏 (𝟎|𝟏)∗ 𝟏 (𝟎|𝟏)∗
22. String should contain exactly two 1
𝑺𝒕𝒓𝒊𝒏𝒈𝒔: 𝟏𝟏, 𝟎𝟏𝟎𝟏, 𝟏𝟏𝟎𝟎, 𝟎𝟏𝟎𝟎𝟏𝟎, 𝟏𝟎𝟎𝟏𝟎𝟎…. 𝑹. 𝑬. = 𝟎∗ 𝟏𝟎∗ 𝟏𝟎∗
23. Length of string should be at least 1 and at most 3
𝑺𝒕𝒓𝒊𝒏𝒈𝒔: 𝟎, 𝟏, 𝟏𝟏, 𝟎𝟏, 𝟏𝟏𝟏, 𝟎𝟏𝟎, 𝟏𝟎𝟎…. 𝑹. 𝑬. = 𝟎|𝟏 𝟎|𝟏 𝟎|𝟏 𝟎|𝟏 𝟎|𝟏 𝟎|𝟏
24. No. of zero should be multiple of 3
𝑺𝒕𝒓𝒊𝒏𝒈𝒔: 𝟎𝟎𝟎, 𝟎𝟏𝟎𝟏𝟎𝟏, 𝟏𝟏𝟎𝟏𝟎𝟎, 𝟎𝟎𝟎𝟎𝟎𝟎, 𝟏𝟎𝟎𝟎𝟏𝟎𝟎𝟏𝟎…. 𝑹. 𝑬. = (𝟏∗ 𝟎𝟏∗ 𝟎𝟏∗ 𝟎𝟏∗ )∗
Regular expression examples
25. The language with 𝛴 = {𝑎, 𝑏, 𝑐} where 𝑎 should be multiple of 3
𝑺𝒕𝒓𝒊𝒏𝒈𝒔: 𝒂𝒂𝒂, 𝒃𝒂𝒂𝒂, 𝒃𝒂𝒄𝒂𝒃𝒂, 𝒂𝒂𝒂𝒂𝒂𝒂. . 𝑹. 𝑬. = ( 𝒃|𝒄 ∗ 𝒂 𝒃|𝒄 ∗ 𝒂 𝒃|𝒄 ∗ 𝒂 𝒃|𝒄 ∗ )∗

26. Even no. of 0


𝑺𝒕𝒓𝒊𝒏𝒈𝒔: 𝟎𝟎, 𝟎𝟏𝟎𝟏, 𝟎𝟎𝟎𝟎, 𝟏𝟎𝟎𝟏𝟎𝟎…. 𝑹. 𝑬. = (𝟏∗ 𝟎𝟏∗ 𝟎𝟏∗ )∗

27. String should have odd length


𝑺𝒕𝒓𝒊𝒏𝒈𝒔: 𝟎, 𝟎𝟏𝟎, 𝟏𝟏𝟎, 𝟎𝟎𝟎, 𝟏𝟎𝟎𝟏𝟎…. 𝑹. 𝑬. = 𝟎|𝟏 ( 𝟎 𝟏 (𝟎|𝟏))∗

28. String should have even length


𝑺𝒕𝒓𝒊𝒏𝒈𝒔: 𝟎𝟎, 𝟎𝟏𝟎𝟏, 𝟎𝟎𝟎𝟎, 𝟏𝟎𝟎𝟏𝟎𝟎…. 𝑹. 𝑬. = ( 𝟎 𝟏 (𝟎|𝟏))∗

29. String start with 0 and has odd length


𝑺𝒕𝒓𝒊𝒏𝒈𝒔: 𝟎, 𝟎𝟏𝟎, 𝟎𝟏𝟎, 𝟎𝟎𝟎, 𝟎𝟎𝟎𝟏𝟎…. 𝑹. 𝑬. = 𝟎 ( 𝟎 𝟏 (𝟎|𝟏))∗
30. String start with 1 and has even length
𝑺𝒕𝒓𝒊𝒏𝒈𝒔: 𝟏𝟎, 𝟏𝟏𝟎𝟎, 𝟏𝟎𝟎𝟎, 𝟏𝟎𝟎𝟏𝟎𝟎…. 𝑹. 𝑬. = 𝟏(𝟎|𝟏)( 𝟎 𝟏 (𝟎|𝟏))∗
Regular expression examples
31. All string begins or ends with 00 or 11

𝑺𝒕𝒓𝒊𝒏𝒈𝒔: 𝟎𝟎𝟏𝟎𝟏, 𝟏𝟎𝟏𝟎𝟎, 𝟏𝟏𝟎, 𝟎𝟏𝟎𝟏𝟏 … 𝑹. 𝑬. = (𝟎𝟎|𝟏𝟏)(𝟎 | 𝟏) ∗ | 𝟎 𝟏 (𝟎𝟎|𝟏𝟏)
32. Language of all string containing both 11 and 00 as substring
𝑺𝒕𝒓𝒊𝒏𝒈𝒔: 𝟎𝟎𝟏𝟏, 𝟏𝟏𝟎𝟎, 𝟏𝟎𝟎𝟏𝟏𝟎, 𝟎𝟏𝟎𝟎𝟏𝟏 …
𝑹. 𝑬. = ((𝟎|𝟏)∗ 𝟎𝟎(𝟎|𝟏)∗ 𝟏𝟏(𝟎|𝟏)∗ ) | ((𝟎|𝟏)∗ 𝟏𝟏(𝟎|𝟏)∗ 𝟎𝟎(𝟎|𝟏)∗ )
33. String ending with 1 and not contain 00
+
𝑺𝒕𝒓𝒊𝒏𝒈𝒔: 𝟎𝟏𝟏, 𝟏𝟏𝟎𝟏, 𝟏𝟎𝟏𝟏 … . 𝑹. 𝑬. = 𝟏 𝟎𝟏
34. Language of C identifier
𝑺𝒕𝒓𝒊𝒏𝒈𝒔: 𝒂𝒓𝒆𝒂, 𝒊, 𝒓𝒆𝒅𝒊𝒐𝒖𝒔, 𝒈𝒓𝒂𝒅𝒆𝟏 … . 𝑹. 𝑬. = (_ + 𝑳)(_ + 𝑳 + 𝑫)∗
𝒘𝒉𝒆𝒓𝒆 𝑳 𝒊𝒔 𝑳𝒆𝒕𝒕𝒆𝒓 & 𝐃 𝐢𝐬 𝐝𝐢𝐠𝐢𝐭
Finite Automata
Finite Automata
• A finite automaton, or finite state machine is a 5-tuple
(𝑄, 𝛴, 𝑞0 , 𝐴, 𝛿) where
• 𝑄 is finite set of states;
• 𝛴 is finite alphabet of input symbols;
• 𝑞0 𝜖 𝑄 (initial state);
• 𝐴 ⊆ 𝑄 (the set of accepting states);
• 𝛿 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
• 𝑀 = (𝑄, 𝛴, 𝑞0 , 𝐴, 𝛿)
• 𝑄 = {𝑞0 , 𝑞1 , 𝑞2 } δ Input
• 𝛴 = {0,1} State 𝟎 𝟏
• 𝑞0 = 𝑞0 𝑞0 𝑞1 𝑞0
• 𝐴 = {𝑞2 } 𝑞1 𝑞2 𝑞0
• 𝛿 is defined as 𝑞2 𝑞2 𝑞0

1 1 0

0 0
𝑞0 𝑞1 𝑞2

1
Applications of FA
• Lexical analysis phase of a compiler.
• 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 ending with 10.

0 1

1
𝐴 𝐵 𝐶
1

0
FA Examples
• The string with number of 0’s and number of 1’s are odd

1
odd 0 odd 0
odd 1 1 even 1

0 0 0 0

1
odd 1 even 1
even 0 1 even 0
FA Examples
• The string ending in 10 or 11 1

C
0
1

1
A B 0

0
1

D
0
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
• Let 𝑀 = (𝑄, 𝛴, 𝑞0 , 𝐴, 𝛿) be an Finite Automata. We define the
function
𝛿 ∗ : 𝑄 × 𝛴∗ → 𝑄
as follows:
1. For any 𝑞 ∈ 𝑄, 𝛿 ∗ 𝑞,∧ = 𝑞
2. For any 𝑞 ∈ 𝑄, 𝑦 ∈ 𝛴 ∗ , and 𝑎 ∈ 𝛴,
𝜹∗ 𝒒, 𝒚𝒂 = 𝜹(𝜹∗ 𝒒, 𝒚 , 𝒂)

𝛿 Example
Consider FA
a b c
𝑞 𝑞1 𝑞2 𝑞3

Calculate 𝛿 ∗ (𝑞, 𝑎𝑏𝑐)


𝛿 ∗ (𝑞, 𝑎𝑏𝑐) = 𝛿(𝛿 ∗ 𝑞, 𝑎𝑏 , 𝑐)
= 𝛿(𝛿 𝛿 ∗ 𝑞, 𝑎 , 𝑏 , 𝑐)
= 𝛿(𝛿 𝛿 ∗ 𝑞, ⋀𝑎 , 𝑏 , 𝑐)
= 𝛿(𝛿(𝛿 𝜹∗ 𝒒, ⋀ , 𝑎), 𝑏 , 𝑐)
= 𝛿(𝛿(𝛿 𝒒, 𝑎), 𝑏 , 𝑐)
= 𝛿(𝛿 𝑞1 , 𝑏 , 𝑐)
= 𝛿(𝑞2 , 𝑐)
= 𝑞3

𝛿 ∗ 𝑞,∧ =𝑞
𝛿 ∗ 𝑞, 𝑦𝑎 = 𝛿(𝛿 ∗ 𝑞, 𝑦 , 𝑎)
𝐸𝑥𝑒𝑟𝑐𝑖𝑠𝑒:
Consider following FA
X Y
𝑞 𝑞1 𝑞2

1. calculate 𝛿 ∗ (𝑞, 𝑋𝑌) 𝛿 ∗ 𝑞,∧ =𝑞


𝛿 ∗ 𝑞, 𝑦𝑎 = 𝛿(𝛿 ∗ 𝑞, 𝑦 , 𝑎)
Acceptance by FA
• Let 𝑀 = (𝑄, 𝛴, 𝑞0 , 𝐴, 𝛿) be an FA. A string 𝑥 ∈ 𝛴 ∗ is accepted by 𝑀
if 𝛿 ∗ 𝑞0 , 𝑥 ∈ 𝐴. If string is not accepted, we can say it is rejected
by 𝑀. The language accepted by 𝑀, or the language recognized by
𝑀, is the set
𝐿 𝑀 = 𝑥 ∈ 𝛴 ∗ 𝑥 𝑖𝑠 𝑎𝑐𝑐𝑒𝑝𝑡𝑒𝑑 𝑏𝑦 𝑀}
• If 𝐿 is any language over 𝛴, 𝐿 is accepted or recognized by 𝑀 if and
only if 𝐿 = 𝐿(𝑀).
Union, Intersection & Complement of Languages
• Suppose 𝑀1 = (𝑄1 , 𝛴, 𝑞1 , 𝐴1 , 𝛿1 ) and 𝑀2 = (𝑄2 , 𝛴, 𝑞2 , 𝐴2 , 𝛿2 )
accepts languages 𝐿1 and 𝐿2 , respectively. Let 𝑀 be an FA defined
by 𝑀 = (𝑄, 𝛴, 𝑞0 , 𝐴, 𝛿), where
𝑄 = 𝑄1 × 𝑄2
𝑞0 = (𝑞1 , 𝑞2 )
and the transition function 𝛿 is defined by the formula
𝛿 𝑝, 𝑞 , 𝑎 = 𝛿1 𝑝, 𝑎 , 𝛿2 𝑞, 𝑎
for any 𝑝 ∈ 𝑄1 and 𝑞 ∈ 𝑄2 and 𝑎 ∈ 𝛴 then
1. if 𝐴 = 𝑝, 𝑞 𝒑 ∈ 𝑨𝟏 𝒐𝒓 𝒒 ∈ 𝑨𝟐 }, 𝑀 accepts the language 𝑳𝟏 ∪ 𝑳𝟐 ;
2. if 𝐴 = 𝑝, 𝑞 𝒑 ∈ 𝑨𝟏 𝒂𝒏𝒅 𝒒 ∈ 𝑨𝟐 }, 𝑀 accepts the language 𝑳𝟏 ∩ 𝑳𝟐 ;
3. if 𝐴 = 𝑝, 𝑞 𝒑 ∈ 𝑨𝟏 𝒂𝒏𝒅 𝒒 ∉ 𝑨𝟐 }, 𝑀 accepts the language 𝑳𝟏 − 𝑳𝟐 ;
Example
Draw Finite Automata for following languages:
1. L1={x/x 00 is not substring of x, x ∈ {0,1}*}
2. L2={x/x ends with 01, x ∈ {0,1}*}
Draw FA for 𝐿1 ∪ 𝐿2 , 𝐿1 ∩ 𝐿2 and 𝐿1 − 𝐿2

1 0,1 1 0

0 1

0 0
𝐴 𝐵 𝐶 𝑃 𝑄 𝑅
1 0
1
𝑴𝟏 𝑴𝟐
Computation for 𝐿1 ∪ 𝐿2 , 𝐿1 ∩ 𝐿2 and 𝐿1 − 𝐿2
• Here 𝑄1 = {𝐴, 𝐵, 𝐶} and 𝑄2 = 1
{𝑃, 𝑄, 𝑅}
• So, 𝑄 = 𝑄1 × 𝑄2 = {𝐴𝑃, 𝐴𝑄, 𝐴𝑅,
𝐴𝑃 𝐵𝑃 𝐶𝑃
𝐵𝑃, 𝐵𝑄, 𝐵𝑅, 𝐶𝑃, 𝐶𝑄, 𝐶𝑅}
• 𝑞0 = 𝑞1 , 𝑞2 = (𝐴, 𝑃) 0

• Computing Transition Function 𝛿


𝐴𝑄 𝐵𝑄 𝐶𝑄
𝛿 𝐴, 𝑃 , 0 = (𝛿 𝐴, 0 , 𝛿 𝑃, 0 )
= 𝐵𝑄
𝛿 𝐴, 𝑃 , 1 = (𝛿 𝐴, 1 , 𝛿 𝑃, 1 )
𝐴𝑅 𝐵𝑅 𝐶𝑅
= 𝐴𝑃

BQ
Computation for 𝐿1 ∪ 𝐿2 , 𝐿1 ∩ 𝐿2 and 𝐿1 − 𝐿2
𝛿 𝐵, 𝑄 , 0 = (𝛿 𝐵, 0 , 𝛿 𝑄, 0 ) 1
= 𝐶𝑄
𝛿 𝐵, 𝑄 , 1 = (𝛿 𝐵, 1 , 𝛿 𝑄, 1 )
= 𝐴𝑅 𝐴𝑃 𝐵𝑃 𝐶𝑃
𝛿 𝐶, 𝑄 , 0 = (𝛿 𝐶, 0 , 𝛿 𝑄, 0 ) 0
= 𝐶𝑄 0
𝛿 𝐶, 𝑄 , 1 = (𝛿 𝐶, 1 , 𝛿 𝑄, 1 ) 0
1 𝐴𝑄 𝐵𝑄 𝐶𝑄
= 𝐶𝑅
𝛿 𝐴, 𝑅 , 0 = (𝛿 𝐴, 0 , 𝛿 𝑅, 0 ) 0
1
= 𝐵𝑄 1
𝛿 𝐴, 𝑅 , 1 = (𝛿 𝐴, 1 , 𝛿 𝑅, 1 ) 𝐴𝑅 𝐵𝑅 𝐶𝑅
= 𝐴𝑃

BQ CQ AR CR
Computation for 𝐿1 ∪ 𝐿2 , 𝐿1 ∩ 𝐿2 and 𝐿1 − 𝐿2
𝛿 𝐶, 𝑅 , 0 = (𝛿 𝐶, 0 , 𝛿 𝑅, 0 ) 1 1

= 𝐶𝑄
𝛿 𝐶, 𝑅 , 1 = (𝛿 𝐶, 1 , 𝛿 𝑅, 1 ) 𝐴𝑃 𝐵𝑃 𝐶𝑃

= 𝐶𝑃 0
0 0
𝛿 𝐶, 𝑃 , 0 = (𝛿 𝐶, 0 , 𝛿 𝑃, 0 ) 0
1 𝐴𝑄 𝐵𝑄 𝐶𝑄 1
= 𝐶𝑄
0
0 1
𝛿 𝐶, 𝑃 , 1 = (𝛿 𝐶, 1 , 𝛿 𝑃, 1 ) 1
= 𝐶𝑃 𝐴𝑅 𝐵𝑅 𝐶𝑅

BQ CQ AR CR CP
Removing Unconnected States
1 1

𝐴𝑃 𝐵𝑃 𝐶𝑃

0
0 0
0 1
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 0
1 𝐵𝑄 𝐶𝑄 1
Accepting states in the
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) 0
and (B and R) will be 1 𝐵𝑄 𝐶𝑄 1
Accepting states in the 0
0 1
resultant FA. 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 0
1 𝐵𝑄 𝐶𝑄 1
should not contain R with
them will be Accepting 0
0 1
states in the resultant FA. 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 𝐿1 ∪ 𝐿2 , 𝐿1 ∩ 𝐿2 and 𝐿1 − 𝐿2 .

0 0,1 0 1

1 0

1 1
𝐴 𝐵 𝐶 𝑃 𝑄 𝑅
0 1
0
𝑴𝟏 𝑴𝟐
Nondeterministic Finite Automata (NFA)
• A nondeterministic finite automaton is a 5-tuple 𝑀 =
(𝑄, 𝛴, 𝑞0 , 𝐴, 𝛿) where 𝑄 and 𝛴 are nonempty finite sets, 𝑞0 𝜖 𝑄,
𝐴 ⊆ 𝑄 and
𝛿 ∶ 𝑄 × 𝛴 → 2𝑄
𝑄 is the set of states, 𝛴 is the alphabet, 𝑞0 is the initial state and 𝐴
is the set of accepting states.

Example of NFA for {11,110} {0}
𝑀 = (𝑄, 𝛴, 𝑞0 , 𝐴, 𝛿) δ Input
• 𝑄 = {𝑞0 , 𝑞1 , 𝑞2 , 𝑞3 , 𝑞4 } State 0 1
• 𝛴 = {0,1} 𝑞0 {𝑞4 } {𝑞1 , 𝑞2 }
• 𝑞0 = 𝑞0 𝑞1 ∅ {𝑞0 }

• 𝐴 = {𝑞4 } 𝑞2 ∅ {𝑞3 }

• 𝛿 is defined as 𝑞3 {𝑞0 } ∅

𝑞1 𝑞4 ∅ ∅

1 1

0
𝑞0 𝑞4
1 0

𝑞2 𝑞3
1

Nonrecursive Definition of 𝛿 for NFA
• For an NFA 𝑀 = 𝑄, 𝛴, 𝑞0 , 𝐴, 𝛿 , and any 𝑝 ∈ 𝑄, 𝛿 ∗ (𝑝, ⋀) = {𝑝}.
For any 𝑝 ∈ 𝑄 and any 𝑥 = 𝑎1 𝑎2 … 𝑎𝑛 ∈ 𝛴 ∗ (𝑤𝑖𝑡ℎ 𝑛 ≥

Recursive Definition of 𝛿 for NFA
• Let 𝑀 = 𝑄, 𝛴, 𝑞0 , 𝐴, 𝛿 be an NFA. The function 𝛿 ∗ : 𝑄 × 𝛴 ∗ → 2𝑄
is defined as follows.
1. For any 𝑞 ∈ 𝑄, 𝛿 ∗ (𝑞, ⋀) = {𝑞}.
2. For any 𝑞 ∈ 𝑄, 𝑦 ∈ 𝛴 ∗ , and 𝑎 ∈ 𝛴,

𝜹∗ 𝒒, 𝒚𝒂 = ራ 𝜹(𝒓, 𝒂)
𝒓∈𝜹∗ (𝒒,𝒚)
Acceptance by NFA
• Let 𝑀 = (𝑄, Ʃ, 𝑞0, 𝐴, 𝛿) be an NFA. The string 𝑥 ∈ Ʃ ∗ is accepted
by 𝑀 if 𝛿 ∗ (𝑞0, 𝑥) ∩ 𝐴 ≠ Ø . The language recognized, or
accepted, by 𝑀 is the set 𝐿(𝑀) of all string accepted by 𝑀. For any
language 𝐿 ⊆ Ʃ ∗, 𝐿 is recognized by 𝑀 𝑖𝑓 𝐿 = 𝐿(𝑀).

Example: Recursive Definition of 𝛿 in NFA
 𝑀 = (𝑄, 𝛴, 𝑞0 , 𝐴, 𝛿) δ Input
• 𝑄 = {𝑞0 , 𝑞1 , 𝑞2 , 𝑞3 } State 𝟎 𝟏
• 𝛴 = {0,1} 𝑞0 {𝑞𝑜 } {𝑞0 , 𝑞1 }
• 𝑞0 = 𝑞0 𝑞1 {𝑞2 } {𝑞2 }
• 𝐴 = {𝑞3 } 𝑞2 {𝑞3 } {𝑞3 }
• 𝛿 is defined as 𝑞3 ∅ ∅

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
𝛿 ∗ 𝑞,∧ =𝑞
𝛿∗ 𝑞0 , 1 = ራ 𝛿(𝑟, 1)
𝛿 ∗ 𝑞, 𝑦𝑎
𝑟∈𝜹∗ (𝒒𝟎 ,⋀) = ራ 𝜹(𝒓, 𝒂)
𝒓∈𝜹∗ (𝒒,𝒚)
= ራ 𝛿(𝑟, 1)
𝑟∈{𝒒𝟎 }

= 𝛿 𝑞0 , 1
= 𝑞0 , 𝑞1

Example: Recursive Definition of 𝛿 in NFA
𝛿 ∗ 𝑞,∧ =𝑞
𝛿∗ 𝑞0 , 11 = ራ 𝛿(𝑟, 1)
𝛿 ∗ 𝑞, 𝑦𝑎
𝑟∈𝜹∗ (𝒒𝟎 ,𝟏) = ራ 𝜹(𝒓, 𝒂)
𝒓∈𝜹∗ (𝒒,𝒚)
= ራ 𝛿(𝑟, 1)
𝑟∈{𝒒𝟎 ,𝒒𝟏 }

= 𝛿 𝑞0 , 1 ∪ 𝛿 𝑞1 , 1
= 𝑞0 , 𝑞1 ∪ {𝑞2 }
= 𝑞0 , 𝑞1 , 𝑞2

Example: Recursive Definition of 𝛿 in NFA
𝛿 ∗ 𝑞,∧ =𝑞
𝛿∗ 𝑞0 , 01 = ራ 𝛿(𝑟, 1)
𝛿 ∗ 𝑞, 𝑦𝑎
𝑟∈𝜹∗ (𝒒𝟎 ,𝟎) = ራ 𝜹(𝒓, 𝒂)
𝒓∈𝜹∗ (𝒒,𝒚)
= ራ 𝛿(𝑟, 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 q δ q, a δ q, b
1 {2,3} {4}
b
1 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
𝑞0 {𝑞𝑜 } {𝑞0 , 𝑞1 }
𝑞1 {𝑞2 } {𝑞2 }
𝑞2 {𝑞3 } {𝑞3 }
𝑞3 ∅ ∅

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 𝑞1 𝑞3
𝑞0 𝑞0 𝑞1

1
𝑞0 𝑞1 𝑞2
𝛿1 {𝑞0 }, 0 = {𝑞0 }
𝛿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 𝑞3
0
1
0 𝑞0 𝑞2 1

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 𝑞3
0
1
0 𝑞0 𝑞2 1
0
0 𝑞0 𝑞1 𝑞3
0
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 𝑞3
obtained, the process 1
0
stops and we need to 0 𝑞0 𝑞2 1
define the accepting 0 𝑞0 𝑞1 𝑞3 0
0
states. 1 1
• 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
𝑞0 𝑞1 𝑞2 𝑞3
states of final FA.
Nondeterministic Finite Automata with ⋀-Transitions
• A nondeterministic finite automaton with ⋀-transitions (NFA- ⋀) is
a 5-tuple 𝑀 = (𝑄, 𝛴, 𝑞0 , 𝐴, 𝛿) where 𝑄 and 𝛴 are finite sets,
𝑞0 𝜖 𝑄, 𝐴 ⊆ 𝑄 and
𝛿 ∶ 𝑄 × (𝛴 ∪ {⋀}) → 2𝑄

Nonrecursive Definition of 𝛿 for NFA- ⋀
• For an NFA - ⋀ 𝑀 = (𝑄, 𝛴, 𝑞0 , 𝐴, 𝛿), states 𝑝, 𝑞 ∈ 𝑄, and a string
𝑥 = 𝑎1 𝑎2 … 𝑎𝑛 ∈ 𝛴 ∗ , we will say 𝑀 moves from 𝑝 to 𝑞 by a
sequence of transition corresponding to 𝑥 if there exist an integer
𝑚 ≥ 𝑛, a sequence 𝑏1 , 𝑏2 , … 𝑏𝑚 ∈ 𝛴 ⋃{⋀} satisfying 𝑏1 𝑏2 … 𝑏𝑚 =
𝑥, and a sequence of states 𝑝 = 𝑝0 , 𝑝1 , … , 𝑝𝑚 = 𝑞 so that for each
𝑖 with 1 ≤ 𝑖 ≤ 𝑚, 𝑝𝑖 ∈ 𝛿(𝑝𝑖−1 , 𝑏𝑖 ).
⋀-closure of a Set of States
• Let 𝑀 = (𝑄, 𝛴, 𝑞0 , 𝐴, 𝛿) 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 𝑀 = 𝑄, 𝛴, 𝑞0 , 𝐴, 𝛿 be an NFA- ⋀. The extended transition
function 𝛿 ∗ : 𝑄 × 𝛴 ∗ → 2𝑄 is defined as follows.
1. For any 𝑞 ∈ 𝑄, 𝛿 ∗ (𝑞, ⋀) = ⋀ 𝑞 .
2. For any 𝑞 ∈ 𝑄, 𝑦 ∈ 𝛴 ∗ , and 𝑎 ∈ 𝛴,

𝜹∗ 𝒒, 𝒚𝒂 = ⋀( ራ 𝜹(𝒓, 𝒂))
𝒓∈𝜹∗ (𝒒,𝒚)
A string 𝑥 is accepted by 𝑀 if 𝛿 ∗ (𝑞0 , 𝑥)⋂𝐴 ≠ 𝜙. The language
recognized by 𝑀 is the set 𝐿(𝑀) of all strings accepted by 𝑀.

Applying Definition of 𝛿
0 1
𝛿 ∗ 𝑞0 , 𝛬 = 𝛬({𝑞0 })
1 0 = {𝑞0 , 𝑝, 𝑡}
𝑝 𝑟 𝑠

^ ^

^
𝑞0 𝑤

^ 0 ^
0
𝑡 𝑢 𝑣

1 0

Applying Definition of 𝛿
0 1
𝛿 ∗ 𝑞0 , 𝛬 = 𝛬({𝑞0 })
1 0 = {𝑞0 , 𝑝, 𝑡}
𝑝 𝑟 𝑠
𝛿 ∗ 𝑞0 , 0
^ ^

^
= 𝛬 ራ 𝛿 𝑟, 0
𝑞0 𝑤
𝑟∈𝛿 ∗ 𝑞0 ,𝛬

^ 0 0 ^ = 𝛬 ራ 𝛿 𝑟, 0
𝑡 𝑢 𝑣
𝑟∈{𝑞0 ,𝑝,𝑡}
1 0 = 𝛬(𝛿 𝑞0 , 0 ∪ 𝛿 𝑝, 0 ∪ 𝛿 𝑡, 0 )
𝛿 ∗ 𝑞,∧ = ^{𝑞} = 𝛬(𝜙 ∪ {𝑝} ∪ {𝑢})
𝛿 ∗ 𝑞, 𝑦𝑎 = 𝛬({𝑝, 𝑢})
= ^( ራ 𝜹 𝒓, 𝒂 )
𝒓∈𝜹∗ 𝒒,𝒚 = {𝑝, 𝑢}

Applying Definition of 𝛿
𝛿 ∗ 𝑞0 , 01 = 𝛬 ራ 𝛿 𝑟, 1
𝑟∈𝛿 ∗ 𝑞0 ,0

= 𝛬(𝛿 𝑝, 1 ∪ 𝛿 𝑢, 1 )
= 𝛬({𝑟})
= {𝑟}

𝛿 ∗ 𝑞0 , 010 = 𝛬 ራ 𝛿 𝑟, 0
𝑟∈𝛿 ∗ 𝑞0 ,01

= 𝛬(𝛿 𝑟, 0 )
= 𝛬({𝑠}) 𝛿 ∗ 𝑞,∧ = ^{𝑞}
𝛿 ∗ 𝑞, 𝑦𝑎
= {𝑠, 𝑤, 𝑞0 , 𝑝, 𝑡} = ^( ራ 𝜹 𝒓, 𝒂 )
𝒓∈𝜹∗ 𝒒,𝒚
NFA-^ to FA
NFA - ⋀ to FA

NFA - ⋀ NFA FA
Conversion from NFA- ^ to FA
q δ q, ^ δ q, 0 δ q, 1
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 =𝛬 ራ 𝛿 𝑟, 0
0
𝑟∈𝛿 ∗ 𝐴,^ A B D

=𝛬 ራ 𝛿 𝑟, 0 0
𝑟∈{𝐴,𝐵,𝐷}

q δ∗ q, 0 δ∗ q, 1
= 𝛬(𝛿 𝐴, 0 ∪ 𝛿 𝐵, 0 ∪ 𝛿 𝐷, 0 )
= 𝛬( 𝐴, 𝐶, 𝐷 ) A {A, B, C, D} 𝜙
= {𝐴, 𝐵, 𝐶, 𝐷} B {C, D} 𝜙
C 𝜙 {B, D}
D {D} 𝜙
Conversion from NFA- ^ to FA
𝛿 ∗ 𝐴, 1 =𝛬 ራ 𝛿 𝑟, 1 C
𝑟∈𝛿 ∗ 𝐴,^
0
0
=𝛬 ራ 𝛿 𝑟, 1
𝑟∈{𝐴,𝐵,𝐷}
0
A B D
= 𝛬 𝛿 𝐴, 1 ∪ 𝛿 𝐵, 1 ∪ 𝛿 𝐷, 1
= 𝛬(𝜙) 0

=𝜙 q δ∗ q, 0 δ∗ q, 1
A {A, B, C, D} 𝜙
B {C, D} 𝜙
C 𝜙 {B, D}
D {D} 𝜙
Conversion from NFA- ^ to FA
𝛿 ∗ 𝐵, ^ = 𝛬 𝐵 = {𝐵, 𝐷} C

𝛿 ∗ 𝐵, 0 = 𝛬 ራ 𝛿 𝑟, 0 0 0
𝑟∈𝛿 ∗ 𝐵,^ 0

=𝛬 ራ 𝛿 𝑟, 0 A
0
B
0
D
𝑟∈{𝐵,𝐷}

= 𝛬(𝛿 𝐵, 0 ∪ 𝛿 𝐷, 0 ) 0

= 𝛬( 𝐶, 𝐷 ) q δ∗ q, 0 δ∗ q, 1
A {A, B, C, D} 𝜙
= {𝐶, 𝐷}
B {C, D} 𝜙
C 𝜙 {B, D}
D {D} 𝜙
Conversion from NFA- ^ to FA
𝛿 ∗ 𝐵, 1 = 𝛬 ራ 𝛿 𝑟, 1 C
𝑟∈𝛿 ∗ 𝐵,^
0 0
0
=𝛬 ራ 𝛿 𝑟, 1
𝑟∈{𝐵,𝐷}
0 0
A B D
= 𝛬(𝛿 𝐵, 1 ∪ 𝛿 𝐷, 1 )
= 𝛬(𝜙) 0

=𝜙 q δ∗ q, 0 δ∗ q, 1
A {A, B, C, D} 𝜙
B {C, D} 𝜙
C 𝜙 {B, D}
D {D} 𝜙
Conversion from NFA- ^ to FA
𝛿 ∗ 𝐶, ^ = 𝛬 𝐶 = {𝐶} C

𝛿 ∗ 𝐶, 0 =𝛬 ራ 𝛿 𝑟, 0 0 0
𝑟∈𝛿 ∗ 𝐶,^ 0

=𝛬 ራ 𝛿 𝑟, 0 A
0
B
0
D
𝑟∈{𝐶}

= 𝛬(𝛿 𝐶, 0 ) 0

= 𝛬(𝜙) q δ∗ q, 0 δ∗ q, 1
A {A, B, C, D} 𝜙
=𝜙
B {C, D} 𝜙
C 𝜙 {B, D}
D {D} 𝜙
Conversion from NFA- ^ to FA
𝛿 ∗ 𝐶, 1 =𝛬 ራ 𝛿 𝑟, 1 C
𝑟∈𝛿 ∗ 𝐶,^
0 0
0 1 1
=𝛬 ራ 𝛿 𝑟, 1
𝑟∈{𝐶}
0 0
A B D
= 𝛬(𝛿 𝐶, 1 )
= 𝛬({𝐵}) 0

= {𝐵, 𝐷} q δ∗ q, 0 δ∗ q, 1
A {A, B, C, D} 𝜙
B {C, D} 𝜙
C 𝜙 {B, D}
D {D} 𝜙
Conversion from NFA- ^ to FA
𝛿 ∗ 𝐷, ^ = 𝛬 𝐷 = {𝐷} C

𝛿 ∗ 𝐷, 0 = 𝛬 ራ 𝛿 𝑟, 0 0 0
0
0 1 1
𝑟∈𝛿 ∗ 𝐷,^

=𝛬 ራ 𝛿 𝑟, 0 A
0
B
0
D
𝑟∈{𝐷}

= 𝛬(𝛿 𝐷, 0 ) 0

= 𝛬({𝐷}) q δ∗ q, 0 δ∗ q, 1
A {A, B, C, D} 𝜙
= {𝐷}
B {C, D} 𝜙
C 𝜙 {B, D}
D {D} 𝜙
Conversion from NFA- ^ to FA
𝛿 ∗ 𝐷, 1 = 𝛬 ራ 𝛿 𝑟, 1 C
𝑟∈𝛿 ∗ 𝐷,^
0 0
0 1 1
0
=𝛬 ራ 𝛿 𝑟, 1
𝑟∈{𝐷}
0 0
A B D
= 𝛬(𝛿 𝐷, 1 )
= 𝛬(𝜙) 0
q δ∗ q, 0 δ∗ q, 1
=𝜙
A {A, B, C, D} 𝜙
Accepting =
State { 𝐴 ∪ 𝑞0
𝐴
if 𝛬 𝑞0 ∩ 𝐴 ≠ 𝜙 in 𝑀
otherwise
B {C, D} 𝜙
C 𝜙 {B, D}

Resulting NFA D {D} 𝜙


q δ∗ q, 0 δ∗ q, 1
Conversion from NFA- ^ to FA A {A, B, C, D} 𝜙
B {C, D} 𝜙
Step 2: To convert NFA to FA
C 𝜙 {B, D}
𝛿 {𝐴}, 0 = {𝐴, 𝐵, 𝐶, 𝐷}
D {D} 𝜙
𝛿 {𝐴}, 1 = 𝜙
𝛿 {𝐴, 𝐵, 𝐶, 𝐷}, 0 = (𝛿 𝐴, 0 ∪ 𝛿 𝐵, 0 ∪ 𝛿 𝐶, 0 ∪ 𝛿 𝐷, 0)
= {𝐴, 𝐵, 𝐶, 𝐷} ∪ {C,D} ∪ {𝜙} ∪ {D} = {𝐴, 𝐵, 𝐶, 𝐷}
𝛿 {𝐴, 𝐵, 𝐶, 𝐷}, 1 = (𝛿 𝐴, 1 ∪ 𝛿 𝐵, 1 ∪ 𝛿 𝐶, 1 ∪ 𝛿 𝐷, 1)
= {𝐵, 𝐷} 0
𝛿 {𝐵, 𝐷}, 0 = (𝛿 𝐵, 0 ∪ 𝛿 𝐷, 0)
1
= {𝐶, 𝐷} ABCD BD 0

0
𝛿 {𝐵, 𝐷}, 1 = (𝛿 𝐵, 1 ∪ 𝛿 𝐷, 1)
CD
=𝜙 A
q δ∗ q, 0 δ∗ q, 1
Conversion from NFA- ^ to FA A {A, B, C, D} 𝜙
B {C, D} 𝜙
𝛿 {𝐶, 𝐷}, 0 = (𝛿 𝐶, 0 ∪ 𝛿 𝐷, 0)
C 𝜙 {B, D}
= {𝐷}
0 D {D} 𝜙
𝛿 {𝐶, 𝐷}, 1 = (𝛿 𝐶, 1 ∪ 𝛿 𝐷, 1)
= {𝐵, 𝐷}
1
𝛿 {𝐷}, 0 = {𝐷} ABCD BD
0
𝛿 {𝐷}, 1 = 𝜙 0
1
A CD

0
FA
D

0
Kleene’s Theorem Part-1
Kleene’s Theorem Part-1
Statement: Any regular language can be accepted by a finite automaton.
Proof:
• On the basis of statement, 𝐿 can be recognized by FA, NFA and NFA-^. It
is sufficient to so that every regular language can be accepted by NFA- ^.
• Set of regular language over alphabet 𝛴 contains the basic languages Ø,
{^} and 𝑎 (𝑎 ∈ 𝛴) to be closed under operation of union,
concatenation, and Kleene*.
• This allows us to prove using structural induction that every regular
language over 𝛴 can be accepted by an NFA-^.
• The basis step of the proof is to show that the three basic languages can
be accepted by NFA- ^s.
• The induction hypothesis is that 𝐿1 and 𝐿2 are languages that can be
accepted by NFA- ^s and the induction step is to show that 𝐿1 ∪ 𝐿2 , 𝐿1 𝐿2
and 𝐿∗1 can also be.
Kleene’s Theorem Part-1
• NFA-^ for the three basic languages is shown below.
a

Ø {^} {a}

• Now, suppose that 𝐿1 and 𝐿2 are recognized by the NFA-^s 𝑀1 and


𝑀2 , respectively, where for both 𝑖=1 and 𝑖 =2,
𝑀𝑖 = (𝑄𝑖 , 𝛴, 𝑞𝑖 , 𝐴𝑖 , 𝛿𝑖 )
• By renaming states if necessary, we may assume that 𝑄1 ∩ 𝑄2 = Ø.
We will construct NFA-^s 𝑀𝑢 , 𝑀𝑐 , and 𝑀𝑘 recognizing the
language 𝐿1 U 𝐿2 , 𝐿1 𝐿2 , and 𝐿∗1 , respectively.
Kleene’s Theorem Part-1
Construction of 𝑴𝒖 = 𝑸𝒖 , 𝜮, 𝒒𝒖 , 𝑨𝒖 , 𝜹𝒖
• Let 𝑞𝑢 be a new state, not in either 𝑄1 or 𝑄2 and let
𝑄𝑢 = 𝑄1 U 𝑄2 U {𝑞𝑢 }
𝑓1
𝐴𝑢 = 𝐴1 U 𝐴2
𝑞1
^
𝑓1′
𝑞𝑢

^ 𝑓2
𝑞2
𝑓2′
Kleene’s Theorem Part-1
• Now, we define 𝛿𝑢 so that 𝑀𝑢 can move from its initial state to
either 𝑞1 or 𝑞2 by a ^ transition, and then make exactly the same
moves that the respective 𝑀𝑖 would.
• Formally we define:
• 𝛿𝑢 (𝑞𝑢 , ^) = {𝑞1 , 𝑞2 }
• 𝛿𝑢 (𝑞𝑢 , 𝑎) = Ø for every 𝑎 ∈ 𝛴
and for each 𝑞 ∈ 𝑄1 U 𝑄2 and 𝑎 ∈ 𝛴 U {^},
• 𝛿𝑢 𝑞𝑢 , 𝑎 = 𝛿1 (𝑞, 𝑎) if 𝑞 ∈ 𝑄1
• 𝛿𝑢 𝑞𝑢 , 𝑎 = 𝛿2 (𝑞, 𝑎) if 𝑞 ∈ 𝑄2
Kleene’s Theorem Part-1
• For either value of 𝑖, if 𝑥 ∈ 𝐿𝑖 , then 𝑀𝑢 can process 𝑥 by moving to
𝑞𝑖 on a ^-transition and then executing the moves that cause 𝑀𝑖
to accept 𝑥.
• On the other hand, if 𝑥 is accepted by 𝑀𝑢 , there is a sequence of
transition corresponding to 𝑥, starting at 𝑞𝑢 and ending at an
element of 𝐴1 or 𝐴2 .
• The first of these transitions must be a ^-transition from 𝑞𝑢 to
either 𝑞1 or 𝑞2 , since there are no other transition from 𝑞𝑢 .
• Thereafter, since 𝑄1 ∩ 𝑄2 = Ø, either all the transition are
between of 𝑄1 or all are between elements of 𝑄2 . It follow that 𝑥
must be accepted by either 𝑀1 or 𝑀2 .
Kleene’s Theorem Part-1
Construction of 𝑴𝒄 = (𝑸𝒄 , 𝜮, 𝒒𝒄 , 𝑨𝒄 , 𝜹𝒄 )
• Let 𝑄𝑐 = 𝑄1 U 𝑄2 , 𝑞𝑐 =𝑞1 , and 𝐴𝑐 = 𝐴2 . The transition will include
all those of 𝑀1 and 𝑀2 as well as a ⋀ - transition from each state
in 𝐴1 to 𝑞2 .
• In other words, for any 𝑞 not in 𝐴1 , and 𝛼 ∈ 𝛴 ∪ {⋀}, 𝛿𝑐 (𝑞, 𝛼) is
defined to be either 𝛿1 (q,a) or 𝛿2 (q,a), depending on whether 𝑞 is
in 𝑄1 and 𝑄2 .

𝑓1 ^ 𝑓2
𝑞𝑐 = 𝑞1 𝑞2
𝑓1′ ^ 𝑓2′
Kleene’s Theorem Part-1
• For 𝑞 ∈ 𝐴1 ,
𝛿𝑐 𝑞, 𝑎 = 𝛿1 (𝑞, 𝑎) for every 𝑎 ∈ 𝛴, and 𝛿𝑐 𝑞, ⋀ = 𝛿1 (𝑞, ⋀) U {𝑞2 }
• On an input string 𝑥1 𝑥2 , where 𝑥𝑖 ∈ 𝐿𝑖 for both value of 𝑖, 𝑀𝑐 can
process 𝑥1 , arriving at a state 𝐴1 ; jump from this state to 𝑞2 by a ⋀ -
transition; and then process 𝑥2 the way 𝑀2 would, so that 𝑥1 𝑥2 is
accepted.
• Conversely, if 𝑥 is accepted by 𝑀𝑐 , there is a sequence of transition
corresponding to 𝑥 that begins at 𝑞1 and ends at an element of 𝐴2 .
• One of them must therefore be from an element of 𝑄1 to an element of
𝑄2 , and according to the definition of 𝛿𝑐 , this can only be a ⋀ - transition
from an element of 𝐴1 to 𝑞2 . Because 𝑄1 ∩ 𝑄2 = Ø, all the previous
transition are between elements of 𝑄1 and all the subsequent ones are
between elements of 𝑄2 .
• It follows that 𝑥 = 𝑥1 ∧ 𝑥2 = 𝑥1 𝑥2 , where 𝑥1 is accepted by 𝑀1 and 𝑥2
is accepted by 𝑀2 ; in other words, 𝑥 ∈ 𝐿1 𝐿2 .
Kleene’s Theorem Part-1
Construction of 𝑴𝒌 = (𝑸𝒌 , 𝜮, 𝒒𝒌 , 𝑨𝒌 , 𝜹𝒌 )
• Let 𝑞𝑘 be a new state not in 𝑄1 and let 𝑄𝑘 = 𝑄1 U {𝑞𝑘 } and 𝐴𝑘 =
{𝑞𝑘 }.
• Once again all the transitions of 𝑀1 will be allowed in 𝑀𝑘 , but in
addition there is a ⋀ - transition from 𝑞𝑘 to 𝑞1 and there is a ⋀ -
transition from each elements of 𝐴1 to 𝑞𝑘 .

𝑞1
^
𝑞𝑘 ^
𝑓1 𝑓1′
^
Kleene’s Theorem Part-1
• More precisely,
𝛿𝑘 (𝑞𝑘 , ⋀) = {𝑞1 } and 𝛿𝑘 𝑞𝑘 , 𝑎 = Ø for 𝑎 ∈ 𝛴
For 𝑞 ∈ 𝑄1 and 𝛼 ∈ 𝛴 ∪ {⋀}, 𝛿𝑘 𝑞, 𝛼 = 𝛿1 𝑞, 𝛼 unless 𝑞 ∈ 𝐴1
and 𝛼 = ⋀.
For 𝑞 ∈ 𝐴1 , 𝛿𝑘 𝑞, ⋀ = 𝛿1 𝑞, ⋀ ∪ {𝑞𝑘 }.
• Suppose 𝑥 ∈ 𝐿∗1 . If 𝑥 = ⋀ then clearly 𝑥 is accepted by 𝑀𝑘 .
Otherwise, for some 𝑚 ≥ 1, 𝑥 = 𝑥1 𝑥2 … 𝑥𝑚 , where 𝑥𝑖 ∈ 𝐿1 for
each 𝑖, 𝑀𝑘 can move from 𝑞𝑘 to 𝑞1 by a ⋀ - transition; for each 𝑖,
𝑀𝑘 moves from 𝑞1 to an element 𝑓𝑖 of 𝐴1 by a sequence of
transition corresponding to 𝑥𝑖 ; and for each 𝑖, 𝑀𝑘 then moves
from 𝑓𝑖 back to 𝑞𝑘 by a ⋀ - transition.
Kleene’s Theorem Part-1
• It follows that (⋀ 𝑥1 ⋀)(⋀ 𝑥2 ⋀)…(⋀ 𝑥𝑚 ⋀)= 𝑥 is accepted by 𝑀𝑘 .
• On the other hand, if 𝑥 is accepted by 𝑀𝑘 , there is a sequence of
transition corresponding to 𝑥 that begins and ends at 𝑞𝑘 . Since the
only transition from 𝑞𝑘 is a ⋀ - transition to 𝑞1 , and the only
transition to 𝑞𝑘 are ⋀ - transition from elements of 𝐴1 , 𝑥 can be
decomposed in the form
𝑥 = (⋀ 𝑥1 ⋀)(⋀ 𝑥2 ⋀)…(⋀ 𝑥𝑚 ⋀)
where, for each 𝑖, there is a sequence of transitions corresponding
to 𝑥𝑖 from 𝑞1 to an element of 𝐴1 . Therefore, 𝑥 ∈ 𝐿∗1 .
• Since we have constructed an NFA - ⋀ recognizing 𝐿 in each of the
three cases, the proof is complete.
Application of Kleene’s Theorem
RE to NFA-^

90
Example: Convert (00 + 1)* 1 (0 +1) to a NFA-epsilon machine.

91
RE to NFA-^

92
RE to NFA-^

93
Regular expression to NFA-^

• Convert 𝑎𝑎 + 𝑏 to NFA-^

a ^ a

b
Regular expression to NFA-^

• Convert 𝑎𝑎 + 𝑏 to NFA-^

a ^ a
^
^

b
^

^
Regular expression to NFA-^
• Convert 00 + 1 ∗ (10)∗ to NFA-^

0 ^ 0

1
Regular expression to NFA-^
• Convert 00 + 1 ∗ (10)∗ to NFA-^
0 ^ 0
^

1
^

0 ^ 0
^
^

1
^

^
Regular expression to NFA-^
• Convert 00 + 1 ∗ (10)∗ to NFA-^
^

^ 1 ^ 0
Regular expression to NFA-^
• Convert 00 + 1 ∗ (10)∗ to NFA-^ ^

0 ^ 0
^
^

1
^

^
^
^

^ 1 ^ 0
Exercise (RE to NFA-^)
1. 00
2. 00+1
3. (00+1)*
4. (0+1)*
5. (111)*
6. (10+01)*
7. (0+1)*(11+00)*11
8. (10+110)*(0+1)*1
9. (00+1)*(10)*
10. (a+b)(a+b)*
11. (aab)*b*(a+b)*
DFA to RE
The two popular methods for converting a given DFA to its regular expression are-

101
State Elimination Method-
 Step-01:
If there exists any incoming edge to the initial state, then create a
new initial state having no incoming edge to it.

102
State Elimination Method-
 Step-02:
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.

103
State Elimination Method-
 Step-03:
If there exists any outgoing edge from the final state, then create a
new final state having no outgoing edge from it.

104
State Elimination Method-
 Step-04:
• 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.

105
Find regular expression for the following DFA-

106
Step-01:

 State D is a dead state as it does not reach to any final state.


 So, we eliminate state D and its associated edges.

The resulting DFA is-

107
Step-02:
 Initial state A has an incoming edge (self loop).
 So, we create a new initial state qi.
The resulting DFA is-

108
Step-03:
 There exist multiple final states.
 So, we convert them into a single final state.
The resulting DFA is-

109
Step-04:
 Now, we start eliminating the intermediate states.
 First, let us eliminate state C.
 There is a path going from state B to state qf via state C.
 So, after eliminating state C, we put a direct path from state B to
state qf having cost b.b*.∈ = bb*

110
 Eliminating state C, we get-

111
Step-05:
 Now, let us eliminate state B.
 There is a path going from state A to state qf via state B.
 So, after eliminating state B, we put a direct path from state A to
state qf having cost a.a*.(bb*+∈) = aa*(bb*+∈)
Eliminating state B, we get-

112
Step-06:
 Now, let us eliminate state A.
 There is a path going from state qi to state qf via state A.
 So, after eliminating state A, we put a direct path from state qi to
state qf having cost ∈.b*.(aa*(bb*+∈)+∈) = b*(aa*(bb*+∈)+∈)
Eliminating state A, we get-

From here,

Regular Expression = b*(aa*(bb*+∈)+∈)

113
Exercise
(1) (2)

(3) (4)

114
Finite Automata with Output
Finite automata with output
• Finite automata has limited capability of either accepting a string
or rejecting a string. Acceptance of string was based on the
reachability of a machine from starting state to final state.
• Finite automata with output do not have a final state.
• Machine generates output on every input.
• There are two types of automata with outputs:
1. Moore machine
2. Mealy machine
Moore machine & Mealy Machine
FA with Output

Moore Machine Mealy Machine

𝑀0 = (𝑄, 𝛴, 𝛥, 𝛿, 𝜆′ , 𝑞0 )
𝑶𝒖𝒕𝒑𝒖𝒕 𝒊𝒔 𝒂𝒔𝒔𝒐𝒄𝒊𝒂𝒕𝒆𝒅 𝒘𝒊𝒕𝒉 𝒔𝒕𝒂𝒕𝒆 𝑶𝒖𝒕𝒑𝒖𝒕
𝑄 : set of states 𝒊𝒔 𝒂𝒔𝒔𝒐𝒄𝒊𝒂𝒕𝒆𝒅 𝒘𝒊𝒕𝒉 𝒕𝒓𝒂𝒏𝒔𝒊𝒕𝒊𝒐𝒏
a b𝛴 : input symbols a|1 b|0

𝛥 : output symbols
b b|0
X,1 Y,0𝛿 : Transition function
X Y
𝜆′ : output function
a 𝑞0 : initial state a|1
Moore Machine
• Mathematically Moore machine is a six tuple machine and defined as
𝑀0 = (𝑄, 𝛴, 𝛥, 𝛿, 𝜆′ , 𝑞0 )
where,
𝑄 : a nonempty finite set of states in 𝑀0
𝛴 : a nonempty finite set of input symbols
𝛥 : a nonempty finite set of outputs
𝛿 : Transition function which takes two arguments as in finite automata,
one is input state and other is input symbol. The output of this
function is a single state.
𝜆′ : it is a mapping function which maps 𝑄 to 𝛥, giving the output
associated with each state.
𝑞0 : the initial state of 𝑀0 and 𝑞0 ∈ 𝑄
Example: Moore Machine
• Design a moore machine for the 1’s compliment of binary number.

1 0

0
A,0 B,1

1
Example: Moore Machine
• Design a moore machine to count occurrence of “ab” as substring.

b a

a
𝐴, 𝟎 𝐵, 𝟎 𝐶, 𝟏
a

b
Example: Moore Machine
• Construct a moore machine that takes set of all strings over {0, 1}
and produces ‘A’ if i/p ends witg ‘10’ , produces ‘B’ if i/p ends with
’11’ otherwise produces ‘C’. 10A
11B
0 1 Otherwise C

1 1
𝑥, 𝐶 𝑦, 𝐶 𝑧, 𝐵

0 1
0 0

𝑤, 𝐴
Example: Moore Machine
• Construct a moore machine that takes binary number as an i/p
and produces residue modulo ‘3’ as an output.
0 1 ∆
Input={0,1}
A A B 0
∆={0, 1, 2} B C A 1
0 C B C 2
1
Transition Table

1 0
A,0 B,1 C,2

1 0
Mealy Machine
• Mathematically Mealy machine is a six tuple machine and defined as
𝑀𝑒 = (𝑄, 𝛴, 𝛥, 𝛿, 𝜆′ , 𝑞0 )
where,
𝑄 : a nonempty finite set of states in 𝑀𝑒
𝛴 : a nonempty finite set of input symbols
𝛥 : a nonempty finite set of outputs
𝛿 : Transition function which takes two arguments as in finite automata,
one is input state and other is input symbol. The output of this
function is a single state.
𝜆′ : It is a mapping function which maps 𝑄 × 𝛴 to 𝛥, giving the output
associated with each transition.
𝑞0 : the initial state of 𝑀𝑒 and 𝑞0 ∈ 𝑄
Example: Mealy Machine
• Design a mealy machine for the 1’s compliment of binary number

0/1
1/0

A
Example: Mealy Machine
• Design a mealy machine for regular expression (0+1)*(00+11).

0|y
00y
q2 11y
Otherwise x
0|x

q1 0|x 1|x

1|x

q3

1|y
Moore to Mealy Machine
Conversion
Conversion of Moore into Mealy Machine
1
𝑞1 Moore machine
a
a
1
0 a,b
Start
𝑞0 b 𝑞3

b b
𝑞2 𝑞1
a/1 a/1
0 a a/1,b/1
Start
𝑞0 b/0 𝑞3

b/0 b/1
𝑞2
Mealy machine
a/0
Mealy to Moore Machine
Conversion
Conversion of Mealy to Moore machine
0|0 0|1

1|1 1|0
𝐴 𝐵 Mealy machine

0 0 1

1 1 Moore machine
𝐴, 0 𝐵, 1 𝐵, 0

0
Exercise: Mealy machine to Moore machine

0|y GTU- May 2016, 7 Marks


q2
b|0 a|1
0|x
a|0
𝑠0 𝑠1
q1 0|x 1|x b|1

1|x

q3 1|y
Minimization of FA
Example: Minimize FA
Final state is {6} a
4
And, Non-Final state is {1,2,3,4,5,7} a
2 b a
(6, 1), (6,2), (6, 3), (6, 4), (6, 5), (6, 7) are distinguish pairs.
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 distinguish, so (1,3) is distinguished pair.
5 X X X
Consider pair (1,4) 6 X X X X X
δ(1,a)=2 δ(1,b)=3 7 X X X X
1 2 3 4 5 6
δ(4,a)=4 δ(4,b)=5
Example: Minimize FA
Consider pair (1,5) a
4
δ(1,a)=2 δ(1,b)=3 a
δ(5,a)=6 δ(5,b)=7 2 b a
pair (2,6) is distinguish, so (1,5) is distinguished pair. a b 5
Consider pair (1,7) 1 a
b
δ(1,a)=2 δ(1,b)=3 6
b a
δ(7,a)=6 δ(7,b)=7 b
3 a
pair (2,6) is distinguish, so (1, 7) is distinguished pair.
2 b
Consider pair (2,3) 7
3 X X b
δ(2,a)=4 δ(2,b)=5
4 X
δ(3,a)=6 δ(3,b)=7
5 X X X
pair (4,6) is distinguish, so (2, 3) distinguished pair. 6 X X X X X
Consider pair (2,4) 7 X X X X
δ(2,a)=4 δ(2,b)=5 1 2 3 4 5 6
δ(4,a)=4 δ(4,b)=5
Example: Minimize FA
Consider pair (2,5) a
4
δ(2,a)=4 δ(2,b)=5 a
δ(5,a)=6 δ(5,b)=7 2 b a
pair (4,6) is distinguish, so (2,5) is distinguished pair. a b 5
Consider pair (2,7)
1 b a
δ(2,a)=4 δ(2,b)=5
δ(7,a)=6 δ(7,b)=7 b a 6
pair (4,6) is distinguish, so (2,7) is distinguished pair. 3 a b
Consider pair (3,4) b
2 7
δ(3,a)=6 δ(3,b)=7
3 X X b
δ(4,a)=4 δ(4,b)=5 4 X
pair (6,4) is distinguish, so (3,4) is distinguish pair. 5 X X X
Consider pair (3,5) 6 X X X X X
δ(3,a)=6 δ(3,b)=7 7 X X X X
δ(5,a)=6 δ(5,b)=7 1 2 3 4 5 6
Example: Minimize FA
Consider pair (3,7) a
4
δ(3,a)=6 δ(3,b)=7 a
δ(7,a)=6 δ(7,b)=7 2 b a
Consider pair (4,5) a b 5
δ(4,a)=4 δ(4,b)=5 1 a
b
δ(5,a)=6 δ(5,b)=7 6
b a
pair (6,4) is distinguish, so (4,5) is distinguish. b
3 a
Consider pair (4,7)
2 b
δ(4,a)=4 δ(4,b)=5 7
3 X X b
δ(7,a)=6 δ(7,b)=7
4 X
pair (4,6) is distinguish, so (4,7) is distinguish.
5 X X X
Consider pair (5,7) 6 X X X X X
δ(5,a)=6 δ(5,b)=7 7 X X X X
δ(7,a)=6 δ(7,b)=7 1 2 3 4 5 6
Example: Minimize FA
a
4
a b a
a 2 b a
a b
b 5
124 357 6 1 a
b
b
b a 6
a
3 a b

𝑴𝒊𝒏𝒊𝒎𝒊𝒛𝒆𝒅 𝑭𝑨 2 b
7
3 X X b
4 X
1=2 1=4 2=4 1=2=4 5 X X X
6 X X X X X
3=5 3=7 5=7 3=5=7 7 X X X X
1 2 3 4 5 6
Pumping lemma
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.
Use the pumping lemma to show that following language is
not regular: L = {ww|w ϵ {0,1}*}
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
𝑎𝑛 𝑏 𝑎𝑛 𝑏
ῳ=
ῳ ῳ
ῳ = 2𝑛 + 2 ≥ 𝑛
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 ῳ = 𝑎 𝑏𝑎 𝑏 = 𝑥 𝑦 𝑧
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.
𝑥𝑦 2 𝑧 = 𝑎 𝑠 𝑎2𝑟 𝑎𝑛−𝑠−𝑟 𝑏𝑎𝑛 𝑏 = 𝑎𝑛+𝑟 𝑏𝑎𝑛 𝑏
• 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, 𝑥𝑦 2 𝑧 Ɇ L. Hence by contradiction we can say language
is not regular.

You might also like