0% found this document useful (0 votes)
54 views

Module 2 Finite Automata Single File

1. A finite automaton is a model of computation that consists of a finite set of states, transitions between those states, and input symbols. 2. It reads an input string one symbol at a time and changes states according to its transition function until it reaches an accepting or rejecting state. 3. The document provides examples of finite automata, their components like states, transitions, accepting states, and defines the language accepted by a finite automaton as all strings that bring it to an accepting state.

Uploaded by

Sindhu P
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views

Module 2 Finite Automata Single File

1. A finite automaton is a model of computation that consists of a finite set of states, transitions between those states, and input symbols. 2. It reads an input string one symbol at a time and changes states according to its transition function until it reaches an accepting or rejecting state. 3. The document provides examples of finite automata, their components like states, transitions, accepting states, and defines the language accepted by a finite automaton as all strings that bring it to an accepting state.

Uploaded by

Sindhu P
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 177

Finite Automata

1
Finite Automaton

Input
String
Output
“Accept”
Finite
or
Automaton
“Reject”

2
Transition Graph
a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4

initial accepting
state state
transition
state
3
Initial Configuration
Input String
a b b a

a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4

4
Reading the Input

a b b a

a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4

5
a b b a

a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4

6
a b b a

a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4

7
a b b a

a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4

8
Input finished

a b b a

a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4

accept
9
Rejection

a b a

a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4

10
a b a

a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4

11
a b a

a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4

12
a b a

a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4

13
Input finished

a b a

a, b

reject
q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4

14
Another Rejection

a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4

15

a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4

reject
16
Another Example

a a b

a a, b

q0 b q1 a, b q2

17
a a b

a a, b

q0 b q1 a, b q2

18
a a b

a a, b

q0 b q1 a, b q2

19
a a b

a a, b

q0 b q1 a, b q2

20
Input finished

a a b

a a, b
accept

q0 b q1 a, b q2

21
Rejection Example

b a b

a a, b

q0 b q1 a, b q2

22
b a b

a a, b

q0 b q1 a, b q2

23
b a b

a a, b

q0 b q1 a, b q2

24
b a b

a a, b

q0 b q1 a, b q2

25
Input finished

b a b

a a, b

q0 b q1 a, b q2

reject

26
Languages Accepted by FAs
FA M

Definition:
The language LM  contains
all input strings accepted by M

LM  = { strings that bring M


to an accepting state}

27
Example
LM   abba M

a, b

q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4
accept

28
Example
LM    , ab, abba M

a, b

q5
b a a a, b
b
q0 a q1 b q2 b q3 a q4
accept accept accept

29
Example

LM   {a b : n  0}
n

a a, b

q0 b q1 a, b q2

accept trap state

30
Formal Definition
Finite Automaton (FA)

M  Q, ,  , q0 , F 
Q : set of states
 : input alphabet

 : transition function
q0 : initial state

F : set of accepting states


31
TYPES OF FINITE AUTOMATA

1.Deterministic Finite Automata - DFA


2.Non Deterministic Finite Automata - NFA
3. Non Deterministic Finite Automata with
epsilon moves - ϵ NFA

• DFA – DFA is an FA which can have only one


transition for one input symbol
• Also all symbols from the ∑ should be
defined from each state

32
33
Input Alphabet 

  a, b

a, b

q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4

34
Set of States Q
Q  q0 , q1, q2 , q3 , q4 , q5 

a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4

35
Initial State q0

a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4

36
Set of Accepting States F

F  q4 

a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4

37
Transition Function 

 :Q  Q

a, b

q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4

38
 q0 , a   q1

a, b

q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4

39
 q0 , b   q5

a, b

q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4

40
 q2 , b   q3

a, b

q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4

41
Transition Function 
 a b
q0 q1 q5
q1 q5 q2
q2 q5 q3
q3 q4 q5 a, b

*q4 q5 q5
q5 q5 q5 q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4

42
Formal Definition
Deterministic Finite Automaton (FA)

M  Q, ,  , q0 , F 
Q : set of states
 : input alphabet

 : transition function  :Q  Q
q0 : initial state

F : set of accepting states


43
Extended Transition Function  *

 * : Q  *  Q

a, b

q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4

44
 * q0 , ab  q2

a, b

q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4

45
 * q0 , abba  q4

a, b

q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4

46
 * q0 , abbbaa  q5

a, b

q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4

47
Check the string acceptance of aba
δ*(qo,aba)= δ(δ*(q0,ab) , a)
= δ(δ (δ*(q0,a),b) , a)
= δ(δ (δ (δ*(q0, λ),a),b) , a)
= δ(δ (δ ( q0,a),b) , a)
=δ(δ (q1,b) , a)
=δ(q2 , a)
=q5
=q5 Є F
String aba is rejected as q5 is a non final
state
48
Check the string acceptance of abba
δ*(qo,abba)= δ(δ*(q0,abb) , a)
= δ(δ (δ*(q0,ab),b) , a)
= δ(δ (δ (δ*(q0,a),b),b) , a)
= δ(δ (δ (δ (δ*(q0,λ),a),b),b) , a)
= δ(δ (δ (δ (q0,a),b),b) , a)
=δ(δ (δ (q1,b),b) , a)
=δ(δ (q2,b) , a)
=δ(q3, a)
=q4 Є F
String abba is accepted as q4 is a final state
49
Observation: if there is a walk from q to q
with label w then

 *  q , w   q

q w q

w   1 2  k
1 2 k
q q

50
Example: There is a walk from q0 to q5
with label abbbaa

 * q0 , abbbaa  q5
a, b

q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4

51
Recursive Definition
 * q ,    q
 * q, w    ( * (q, w), )

q w q1  q

 *  q , w   q
 * q, w    (q1, )
 (q1, )  q
 * q, w    ( * (q, w), )
 * q, w  q1

52
 * q0 , ab  
  * (q0 , a ), b  
   * q0 ,  , a , b  
  q0 , a , b  
 q1 , b  
q2 a, b

q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4
53
Language Accepted by DFAs
M  Q, ,  , q0 , F 
For a FA
M
Language accepted by :
LM   w  * :  * q0 , w  F 

q0 w q q  F

54
Observation
Language rejected by M :

LM   w  * :  * q0 , w  F 

q0 w q q  F

55
Example
LM  = { all strings with prefix ab }
a, b

q0 a q1 b q2

b a accept

q3 a, b

56
Example
LM  = { all strings without
substring 001 }

1 0 0,1
1

 0 1
0 00 001

0
57
Example

L( M )  awa : w  a, b*


a
b
b
q0 a q2 q3

b a
q4

a, b
58
Regular Languages
Definition:
A language L is regular if there is
FA M such that L  LM 

Observation:
All languages accepted by FAs
form the family of regular languages

59
Examples of regular languages:

abba  , ab, abba


awa : w  a, b* {a nb : n  0}
{ all strings with prefix ab }
{ all strings without substring 001 }

There exist finite automata that accept these


Languages
60
There exist languages which are not Regular:

Example: L {a b : n  0}
n n

There is no FA that accepts such a language

(we will prove this later in the class)

61
DFA - Starts with b , ∑={a,b}

L= { b,ba,bb,baa,bab,bba,….}
a,b

b
q0 q1

a
q2

a,b
62
DFA- strings STARTS WITH 1
L= { 1, 10,11,111,111,…}

0,1
1
q0 q1

0
q2 0,1

63
DFA - Starts with ab, ∑={a,b}

L= { ab,aba,abb,….}

a,b
a b
q0 q1 q2
b a
q3

a,b
64
DFA - Starts with bb , ∑={a,b}
L = { bb, bba,bbb,…}
a,b

b b
q0 q1 q2

a
a
q3
a,b
65
DFA - Starts with ba , ∑={a,b}
L ={ ba,baa,bab,…}
a,b

b a
q0 q1 q2

a b

q3
a,b
66
DFA - Starts with aa , ∑={a,b}
L = { aa,aab,aaba,….}
a,b

a
q0 a q1 q2

b
b
q3
a,b

67
DFA - Starts with aba , ∑={a,b}

L={ aba,abaa,abab,abaaa,…}

a,b
a b a
q0 q1 q2 q3

a
b b

q4
a,b
68
DFA - Starts with aaa , ∑={a,b}

DFA - Starts with 000 , ∑={0,1}

69
DFA - Starts with 101 , ∑={0,1}
L={ 101,1010,1011,101101,…}

0,1
1 0 1
q0 q1 q2 q3

1
0 0

q4
0, 1
70
Ends with a
L={a,aa,ba,aaa,aba,…}

b a

a q1
q0

71
L={ 1,01,11,…}
0 1

1
q0 q1

72
Ends with ab
L={ab,aab,bab,aaab,bbbbab,abab,…}

b a

a b
q0 q1 q2
a

73
Ends with ba
L= { ba,aba,bba,aaaba,bbbbba,……}
a b

b a
b

74
Ending with bab
b
a
b

q0 b a b
q1 q2 q3

a
a

75
76
DFA – Ends with 101, ∑={ 0,1}
L={ 101,0101,1101,000101,111101,…}
1
0 1 0

0 1
1 q1 q3
q0 q2

77
DFA – Ends with 111 , ∑={ 0,1}
L= { 111,0111,11111,…}
0
0 1
1 1
1 q1 q2 q3
q0

0 0

78
Dfa for – strings end with 1011

79
DfA – Substring 101
L={ 101,0101,1101,1010,1011,00010111,…}

0 1 0,1

1 0 1
q0 q1 q2 q3

80
DFA- Contains 111
L={ 111,0111,1111,000111000,11111000,..}

0 0,1

1 1 1
q0 q1 q2 q3

0
0

81
Substring /contains 1011
L ={ 1011,01011,11011,….}

Hw
1. Ends with 1100
2. Substring 1100
3. Ends with abab
4. Substring abab

82
DFA- Even no of 0s, ∑={ 0,1} or
n0(w)mod2=0
L={ λ,
1,1111,00,0000,11100,1110000,0000111,..}
1 1
Transiti o 1
0 on

q0 q1 *->q0 q1 q0
q1 qo q1

83
n1(w)mod2=1

0 0

84
DFA – Odd no of 0’s , ∑={ 0,1} or
n0(w)mod2=1
L={ 0,01,1110,000,000001111,…}
1 1

0
q0 q1

85
DFA - na(w)mod3=0, ∑={ a,b}
Or number of a is a multiple of 3
L={ λ,bbbb,aaabbb,aaaaaabbb,….}
b b b

a a

86
DFA- nb(w)mod4 > 2 , ∑={ a,b}

a a a
a

b b b

87
DfA – n1(w)mod3=2, ∑={ 0,1}

0 0 0

1 1

88
89
Dfa –lwlmod2=0, or length of the string
is a multiple of 2 or even length strings

a,b

a,b

90
DfA – lwlmod2=1 or odd length strings

L={a,b,aaa,aba,aab,baa,bbb,bab
a,bba,….

a,b

a,b

91
DFA –lwlmod3 = 2 , ∑={ a,b}

a,b a,b

a,b

92
DFA –lwlmod3 = 0 , ∑={ a,b} Or
length of the string is a multiple of
3

a,b a,b

a,b

93
|w|mod 4 <3 , { 0,1}

0,1 0,1 0,1

0,1

94
1.No of a’s is even and no of b’s odd-eo
L={ b,aab,baa,……..}

2.No of a’s is odd and no of b’s odd-oo

3.No of a’s is odd and no of b’s even=oe

4.No of a’s is even and no of b’s even-ee

95
No of a’s is even and no of b’s odd-eo
a

ee a oe

b b b b

a
eo oo

a
96
no of b’s even and No of a’s is odd =oe

ee a oe

b b b b

a
eo oo

a
97
No of a’s is odd and no of b’s odd-oo
a

ee a oe

b b b b

a
eo oo

a
98
No of a’s is even and no of b’s even-ee

ee a oe

b b b b

a
eo oo

a
99
DFA Example
Design DFA that accepts language L= { w : |w| mod 3 =
0 }
over ∑ = {a, b}
Solution
Strings accepted= {ϵ, aaa, bbb, aba, aab, bab, aaabbb, ababab, …}
Strings rejected= {a, b, ab, ba, abab, baba, bbaa, aaabb, …}
Transition Diagram

q0 a, b q1 a, b q4
a, b

2/5/2021 100
DFA Example
 Consider Sample String : aab

a, b
q0 q1 a, b q4
a, b

2/5/2021 101
DFA Example
 Consider Sample String : aab

a, b
q0 a, b q
1 q4
a, b

2/5/2021 102
DFA Example
 Consider Sample String : aab

q0 a, b q a, b
1 q4
a, b

2/5/2021 103
DFA Example
 Consider Sample String : aab
 String is accepted

Acceptance State

q0 a, b q a, b
1 q4
a, b

2/5/2021 104
DFA Example
 Consider Another Sample String : baba

a, b
q0 q1 a, b q4
a, b

2/5/2021 105
DFA Example
 Consider Another Sample String : baba

a, b
q0 a, b q
1 q4
a, b

2/5/2021 106
DFA Example
 Consider Another Sample String : baba

q0 a, b q a, b
1 q4
a, b

2/5/2021 107
DFA Example
 Consider Another Sample String : baba

q0 a, b q a, b
1 q4
a, b

2/5/2021 108
DFA Example
 Consider Another Sample String : baba
 String is rejected

Rejection State

q0 a, b q a, b
1 q2

a, b

2/5/2021 109
DFA Example
DFA Tuples M=(Q, Σ, 𝜹, q0, F)
 Q= { q0, q1, q2}
 Σ= {a, b}
𝜹 = Transition function represented by
Transition table
 q0= Initial State
F= {q0}  Acceptance State

2/5/2021 110
DFA Example
Transition Table

Σ
a b
Q
*q0 q1 q1
q1 q2 q2
q2 q0 q0

2/5/2021 111
Non Deterministic Finite Automata
An NFA is a finite automata in which
there can be 0,1, or more no: of
transitions for the same input symbols
from one state
O,1
1 1,0
q1 q2
q0

2/5/2021 112
Non Deterministic Finite Automata –
Formal Definition

2/5/2021 113
NFA – starts with 101, ∑ = {0,1}
L= { 101,1010,1010,..}
0,1

1 0 1

2/5/2021 114
NFA – substring with aba, ∑ = {a,b}
L= { aba,ababa,ababbaba,..}
a, b a, b

a b a

2/5/2021 115
NFA – ends with 101, ∑ = {0,1}
L= { 101,0101,1101,..}

0,
1
1 0 1

2/5/2021 116
NFA – substring with 101, ∑ = {0,1}
L= { 101,0101,1101,..}

0, 0,
1 1
1 0 1

2/5/2021 117
Design NFA
Starts with aabb
Ends with aabb
Substring aabb

2/5/2021 118
NFA Example
Design NFA that accepts language of strings ending with
ab/ba over ∑ = {a, b}
Solution
Strings accepted= {ab, ba, abab, baba, bbab, aaaba, …}
Strings rejected= {ϵ, a, b, aa, bb, aaa, abb, aaabbb, …}
Transition Diagram

a, b a q1 b q2
q0
b q3 a q4

2/5/2021 119
NFA to DFA Conversion Example
Convert NFA to DFA that accepts language of strings
ending with ab/ba over ∑ = {a, b}
Solution
Draw NFA for given language
Convert that NFA into DFA using subset construction method

a, b a q1 b q2
q0
b q3 a q4

2/5/2021 120
NFA to DFA Conversion Example
 Using Subset Construction Method NF a b
 Consider {q0} as Start State A
 𝜹([q0], a)=[q0 q1] newly formed state q0 {q0, q1} {q0,
 𝜹([q0, q1], a)= 𝜹(q0, a)ᴜ 𝜹({q1, a}) q3}
={q0, q1} ᴜ {Ø}
=[q0 q1] q1 - {q2}
 𝜹({q0 q1}, b)= 𝜹(q0, b)ᴜ 𝜹({q1, b}) q2 - -
={q0, q3} ᴜ {q2} q3 {q4} -
={q0 q2 q3}
DFA q4 a - b -
[q0] [q0 q1] [q0 q3]
[q0 q1] [q0 q1] {q0 q2
q3}

2/5/2021 121
NFA to DFA Conversion Example
 Using Subset Construction Method NF a b
 Consider {q0} as Start State A
 𝜹(q0, a)={q0 q1} newly formed state q0 {q0, q1} {q0,
 𝜹({q0 q1}, a)= 𝜹(q0, a)ᴜ 𝜹({q1, a}) q3}
={q0, q1} ᴜ {Ø}
={q0 q1} q1 - {q2}
 𝜹({q0 q1}, b)= 𝜹(q0, b)ᴜ 𝜹({q1, b}) q2 - -
={q0, q3} ᴜ {q2} q3 {q4} -
={q0 q2 q3}
 {q0 q2 q3} is newly formed state DFA q4 a- b-
 𝜹({q0 q2 q3}, a)= 𝜹(q0, a) ᴜ 𝜹({q2, a}) ᴜ 𝜹 q0 {q0 q1} {q0 q3}
({q3, a}) {q0 q1} {q0 q1} {q0 q2
={q0, q1} ᴜ {Ø} ᴜ q3}
{q4}
={q0 q1 q4} {q0 q2 {q0 q1 {q0 q3}
 𝜹({q0 q2 q3}, b)= 𝜹(q0, b)ᴜ 𝜹({q2, b}) ᴜ 𝜹 q3) q4}
({q3, b})
={q0, q3} ᴜ {Ø} ᴜ
{Ø} ={q0 q3}
2/5/2021 122
NFA to DFA Conversion Example
 {q0 q3} is newly formed state NF a b
 𝜹({q0 q3}, a)= 𝜹(q0, a)ᴜ 𝜹({q3, a}) A
={q0, q1} ᴜ {q4} q0 {q0, q1} {q0,
={q0 q1 q4} q3}
 𝜹({q0 q3}, b)= 𝜹(q0, b)ᴜ 𝜹({q3, b})
={q0, q3} ᴜ {Ø} q1 - {q2}
={q0 q3} q2 - -
q3 {q4} -
DFA q4 a- b-
q0 {q0 q1} {q0 q3}
{q0 q1} {q0 q1} {q0 q2
q3}
{q0 q2 {q0 q1 {q0 q3}
q3) q4}
{q0 q3} {q0 q1 {q0 q3}
q4}
2/5/2021 123
NFA to DFA Conversion Example
 {q0 q3} is newly formed state NF a b
 𝜹({q0 q3}, a)= 𝜹(q0, a)ᴜ 𝜹({q3, a}) A
={q0, q1} ᴜ {q4} q0 {q0, q1} {q0,
={q0 q1 q4} q3}
 𝜹({q0 q3}, b)= 𝜹(q0, b)ᴜ 𝜹({q3, b})
={q0, q3} ᴜ {Ø} q1 - {q2}
={q0 q3} q2 - -
 {q0 q1 q4} is newly formed state q3 {q4} -
 𝜹({q0 q1 q4}, a)= 𝜹(q0, a) ᴜ 𝜹({q1, a}) ᴜ 𝜹
({q4, a}) DFA q4 a- b-
={q0, q1} ᴜ {Ø} ᴜ q0 {q0 q1} {q0 q3}
{Ø} {q0 q1} {q0 q1} {q0 q2
={q0 q1} q3}
 𝜹({q0 q1 q4}, b)= 𝜹(q0, b)ᴜ 𝜹({q1, b}) ᴜ 𝜹
({q4, b}) {q0 q2 {q0 q1 {q0 q3}
={q0, q3} ᴜ {q2} ᴜ q3) q4}
{Ø} {q0 q3} {q0 q1 {q0 q3}
={q0 q2 q3} q4}
2/5/2021 {q0 q1 {q0 q1} {q0 q2
124
NFA to DFA Conversion Example
DFA a b
q0 {q0 q1} {q0 q3}
{q0 q1} {q0 q1} {q0 q2
q3}
a
*{q0 q2 {q0 q1 {q0 q3}
q3) q4}
{q0 q3} {q0 q1 {q0 q3} b
q4} q0q1 q0q2q3
*{q0 q1 {q0 q1}
a
{q0 q2 b
q4} q0 q3} b a
a b
b q0 q3 q0 q1q4
a

2/5/2021 125
2/5/2021 126
ϵ-NFA Example 1
Design ϵ-NFA that accepts language of strings ending
with ab/ba over ∑ = {a, b}
Solution
Strings accepted= {ab, ba, abab, baba, bbab, aaaba, …}
Strings rejected= {ϵ, a, b, aa, bb, aaa, abb, aaabbb, …}
Transition Diagram

a, b q1 a q2 b q3

q0
 q4 b q5 a q6

2/5/2021 127
ϵ-NFA Example 2

2/5/2021 128
ϵ- Closure of a state
ϵ- Closure of a state q denoted as E CLOSE(q) is the
set of all states which are reachable from q on ϵ
transitions
ϵ- Closure (q0) ={q0,q1,q2}
ϵ- Closure (q1) ={q1,q2}
ϵ- Closure (q2) ={q2}

2/5/2021 129
• ϵ- Closure (0) ={ 0} ϵ- Closure (5) ={5,8,3,4,6,9}
• ϵ- Closure (1) ={1} ϵ- Closure (6) ={6}
• ϵ- Closure (2) ={2,3,4,6,9} ϵ- Closure (7) ={7,8,9,3,4,6}
• ϵ- Closure (3) ={3,4,6} ϵ- Closure (8) ={8,9,3,4,6}
• ϵ- Closure (4) ={4} ϵ- Closure (9) ={9}

2/5/2021 130
ϵ-NFA to DFA Conversion Example
Convert the following ϵ-NFA to DFA
Solution
Find ϵ-closure of each state
Convert that ϵ-NFA into DFA using subset construction method

b, 
a
a
a q1 b q2
q0

2/5/2021 131
ϵ-NFA- ϵ closure

ϵ-closure of state is define as


a set of states that includes States ϵ-closure
- that state itself q0 {q0}
- set of states reachable from
state Q over ϵ-transaction q1 {q1, q2}
- set of states reachable from
q2 {q2}
existing states in ϵ-closure
over ϵ-transaction and so on..

2/5/2021 132
ϵ-NFA to DFA Conversion Example

 Using Subset Construction Method DFA a b


 Consider ϵ-closure of {q0}= {q0} as -> [q0] [q0 q1 q2] [D]
Start State
 a-successor of {q0}
= ϵ-closure (𝜹(q0, a))
= ϵ-closure ({q0,q1})
= ϵ-closure (q0) ᴜ ϵ-closure (q1)
= {q0} ᴜ {q1, q2}
={q0,q1,q2}
 b-successor of {q0}
= ϵ-closure (𝜹(q0, b))={Ø}

2/5/2021 133
ϵ-NFA to DFA Conversion Example
 Using Subset Construction Method
 Consider {q0 q1 q2} as a new state
DFA a b
 a-successor of {q0 q1 q2} {q0} {q0 q1 {Ø}
= ϵ-closure (𝜹(q0, a)ᴜ𝜹(q1, a)ᴜ𝜹(q2, a)) q2}
= ϵ-closure ({q0 q1}ᴜ{Ø}ᴜ{q2}) {q0 q1 {q0 q1 {q1 q2}
= ϵ-closure ({q0 ,q1 ,q2}) q2} q2}
= ϵ-closure (q0) ᴜ ϵ-closure (q1) ᴜ ϵ-closure (q2)
= {q0} ᴜ {q0, q1} ᴜ {q2}={q0,q1,q2}
 b-successor of {q0 q1 q2}
ϵ-closure (𝜹(q0, b)ᴜ𝜹(q1, b)ᴜ𝜹(q2, b))
= ϵ-closure ({Ø}ᴜ{q1 q2}ᴜ{Ø})
= ϵ-closure ({q1 q2})
= ϵ-closure (q1) ᴜ ϵ-closure (q2) = {q1 q2} ᴜ {q2}={q1 q2}

2/5/2021 134
ϵ-NFA to DFA Conversion Example
 Using Subset Construction Method
 Consider {q1 q2} as a new state DFA a b
 a-successor of {q1 q2}
= ϵ-closure (𝜹(q1, a)ᴜ𝜹(q2, a)) {q0} {q0 q1 {Ø}
q2}
= ϵ-closure ({Ø}ᴜ{q2})
= ϵ-closure ({q2}) {q0 q1 {q0 q1 {q1 q2}
= {q2} q2} q2}
 b-successor of {q1 q2} {q1 q2 ) {q2} {q1 q2}
ϵ-closure (𝜹(q1, b)ᴜ𝜹(q2, b))
= ϵ-closure ({q1 q2}ᴜ{Ø})
= ϵ-closure ({q1 q2})
= ϵ-closure (q1) ᴜ ϵ-closure (q2) = {q1 q2} ᴜ {q2}={q1 q2}

2/5/2021 135
ϵ-NFA to DFA Conversion Example
 Using Subset Construction Method
 Consider {q2} as a new state DFA a b
 a-successor of {q2}
= ϵ-closure (𝜹(q2, a)) {q0} {q0 q1 [D]
q2}
= ϵ-closure ({q2})
= {q2} {q0 q1 {q0 q1 {q1 q2}
 b-successor of {q2} q2} q2}
=ϵ-closure (𝜹(q2, b)) {q1 q2 ) {q2} {q1 q2}
= ϵ-closure ({Ø}) {q2} {q2} [D]
={Ø}

2/5/2021 136
ϵ-NFA to DFA Conversion Example
DFA a b
->{q0} [q0 q1 q2] {Ø}
*{q0 q1 {q0 q1 q2} {q1 q2}
q2} a b
*{q1 q2 ) {q2} {q1 q2}
*{q2} {q2} {Ø}
b q1q2
q0 q1q2
a
q0 a, b a a
b b
 q2

2/5/2021 137
ϵ-NFA to DFA

a b c

𝜀 𝜀
q0 q1 q2

2/5/2021 138
q0 {q0,q1,q2}
q1 {q1,q2}
q2 {q2}

a b c
->q0 {q0} Ф Ф

q1 Ф {q1} Ф

q2 Ф Ф {q2}

2/5/2021 139
States a b c

->* [ [q0,q1,q2] [q1,q2] [q2]


q0,q1,q2]

* [q2] [D] [D] [q2]

*[q1,q2] [D] [q1,q2] [q2]

[D] [D] [D] [D]

2/5/2021 140
a c

b
[q0,q1, [q1,q [q2]
q2] 2]

a
a,b
[D]

2/5/2021 141
Minimization of DFA Example
Minimize the following DFA
DFA 0 1
A B C
B B D
C B C
0
0
D B E
E* B C 1 D
B
0
0 1
A 1 0
1 0
C E

2/5/2021 142
Minimization of DFA Example
Minimize the following DFA
Use State Equivalence Method DFA 0 1
Write 0’Equivalence as A B C
{A, B, C, D} {E} B B D
C B C
Write 1’Equivalence
D B E
{A,B,C} { D} {E}
E* B C
Write 2’Equivalence
{ A,C} { B} {D}{E}
Write 3’Equivalence
{ A ,C} {B}{D}{E}

2/5/2021 143
Minimization of DFA Example
Minimize the following DFA DFA 0 1
Use State Equivalence Method A,C B C
Write 0’Equivalence as B B D
D B E
{A, B, C, D} {E}
E* B C
Write 1’Equivalence
{A, B, C} {D} {E} 0 0
Write 2’Equivalence 1
B D
{A, C} {B} {D} {E}
0
Write 3’Equivalence 1 1
{A, C} {B} {D} {E} 0
A, C 1
E

2/5/2021 144
Agenda
 Basic Concepts in FA
DFA
Language of DFA
 NFA
Why non-determinism in NFA?
 ϵ-NFA Examples
 NFA to DFA Conversion Examples
 ϵ-NFA to DFA Conversion Examples
 Minimization of DFA Examples
2/5/2021 Ms Dakhole Dipali K 145
Basic Concepts in FA
1. Transition Diagram : It is graphical representation of Finite
Automata, consisting of –
 Start State
 Acceptance State
 Intermediate States
 Transitions

q0 a, b q1 a, b q2
a, b

2/5/2021 Ms Dakhole Dipali K 146


Basic Concepts in FA
1. Transition Table : It is representation of Finite Automata in
Table format as Σ a b
Q
q0 q1 q1

q1 q2 q2

q2* q0 q0

q0 a, b q1 a, b q2
a, b

2/5/2021 Ms Dakhole Dipali K 147


DFA Example
Design DFA that accepts language L= { w : |w| mod 3 =
0 }
over ∑ = {a, b}
Solution
Strings accepted= {ϵ, aaa, bbb, aba, aab, bab, aaabbb, ababab, …}
Strings rejected= {a, b, ab, ba, abab, baba, bbaa, aaabb, …}
Transition Diagram

q0 a, b q1 a, b q4
a, b

2/5/2021 Ms Dakhole Dipali K 148


DFA Example
 Consider Sample String : aab

a, b
q0 q1 a, b q4
a, b

2/5/2021 Ms Dakhole Dipali K 149


DFA Example
 Consider Sample String : aab

a, b
q0 a, b q
1 q4
a, b

2/5/2021 Ms Dakhole Dipali K 150


DFA Example
 Consider Sample String : aab

q0 a, b q a, b
1 q4
a, b

2/5/2021 Ms Dakhole Dipali K 151


DFA Example
 Consider Sample String : aab
 String is accepted

Acceptance State

q0 a, b q a, b
1 q4
a, b

2/5/2021 Ms Dakhole Dipali K 152


DFA Example
 Consider Another Sample String : baba

a, b
q0 q1 a, b q4
a, b

2/5/2021 Ms Dakhole Dipali K 153


DFA Example
 Consider Another Sample String : baba

a, b
q0 a, b q
1 q4
a, b

2/5/2021 Ms Dakhole Dipali K 154


DFA Example
 Consider Another Sample String : baba

q0 a, b q a, b
1 q4
a, b

2/5/2021 Ms Dakhole Dipali K 155


DFA Example
 Consider Another Sample String : baba

q0 a, b q a, b
1 q4
a, b

2/5/2021 Ms Dakhole Dipali K 156


DFA Example
 Consider Another Sample String : baba
 String is rejected

Rejection State

q0 a, b q a, b
1 q4
a, b

2/5/2021 Ms Dakhole Dipali K 157


DFA Example
DFA Tuples M=(Q, Σ, ꝺ, q0, F)
 Q= (q0, q1, q4)
 Σ= (a, b)
 ꝺ= Transition function represented by
Transition table
 q0= Initial State
F= {q0}  Acceptance State

2/5/2021 Ms Dakhole Dipali K 158


DFA Example
Transition Table

Σ
a b
Q
q0* q1 q1
q1 q4 q4
q4 q0* q0*

2/5/2021 Ms Dakhole Dipali K 159


NFA Example
Design NFA that accepts language of strings ending with
ab/ba over ∑ = {a, b}
Solution
Strings accepted= {ab, ba, abab, baba, bbab, aaaba, …}
Strings rejected= {ϵ, a, b, aa, bb, aaa, abb, aaabbb, …}
Transition Diagram

a, b a q1 b q2
q0
b q3 a q4

2/5/2021 Ms Dakhole Dipali K 160


NFA to DFA Conversion Example
Convert NFA to DFA that accepts language of strings
ending with ab/ba over ∑ = {a, b}
Solution
Draw NFA for given language
Convert that NFA into DFA using subset construction method

a, b a q1 b q2
q0
b q3 a q4

2/5/2021 Ms Dakhole Dipali K 161


NFA to DFA Conversion Example
 Using Subset Construction Method NF a b
 Consider {q0} as Start State A
 ꝺ(q0, a)={q0 q1} newly formed state
q0 {q0, q1} {q0,
 ꝺ({q0 q1}, a)= ꝺ(q0, a)ᴜ ꝺ({q1, a}) q3}
={q0, q1} ᴜ {Ø}
={q0 q1} q1 - {q2}
 ꝺ({q0 q1}, b)= ꝺ(q0, b)ᴜ ꝺ({q1, b}) q2 - -
={q0, q3} ᴜ {q2} q3 {q4} -
={q0 q2 q3}
DFA q4 a- b-
q0 {q0 q1} {q0 q3}
{q0 q1} {q0 q1} {q0 q2
q3}

2/5/2021 Ms Dakhole Dipali K 162


NFA to DFA Conversion Example
 Using Subset Construction Method NF a b
 Consider {q0} as Start State A
 ꝺ(q0, a)={q0 q1} newly formed state
q0 {q0, q1} {q0,
 ꝺ({q0 q1}, a)= ꝺ(q0, a)ᴜ ꝺ({q1, a}) q3}
={q0, q1} ᴜ {Ø}
={q0 q1} q1 - {q2}
 ꝺ({q0 q1}, b)= ꝺ(q0, b)ᴜ ꝺ({q1, b}) q2 - -
={q0, q3} ᴜ {q2} q3 {q4} -
={q0 q2 q3}
 {q0 q2 q3} is newly formed state DFA q4 a- b-
 ꝺ({q0 q2 q3}, a)= ꝺ(q0, a) ᴜ ꝺ({q2, a}) ᴜ q0 {q0 q1} {q0 q3}
ꝺ({q3, a}) {q0 q1} {q0 q1} {q0 q2
={q0, q1} ᴜ {Ø} ᴜ q3}
{q4}
={q0 q1 q4} {q0 q2 {q0 q1 {q0 q3}
 ꝺ({q0 q2 q3}, b)= ꝺ(q0, b)ᴜ ꝺ({q2, b}) ᴜ q3) q4}
ꝺ({q3, b})
={q0, q3} ᴜ {Ø} ᴜ
{Ø} ={q0 q3}
2/5/2021 Ms Dakhole Dipali K 163
NFA to DFA Conversion Example
 {q0 q3} is newly formed state NF a b
 ꝺ({q0 q3}, a)= ꝺ(q0, a)ᴜ ꝺ({q3, a}) A
={q0, q1} ᴜ {q4} q0 {q0, q1} {q0,
={q0 q1 q4} q3}
 ꝺ({q0 q3}, b)= ꝺ(q0, b)ᴜ ꝺ({q3, b})
={q0, q3} ᴜ {Ø} q1 - {q2}
={q0 q3} q2 - -
q3 {q4} -
DFA q4 a- b-
q0 {q0 q1} {q0 q3}
{q0 q1} {q0 q1} {q0 q2
q3}
{q0 q2 {q0 q1 {q0 q3}
q3) q4}
{q0 q3} {q0 q1 {q0 q3}
q4}
2/5/2021 Ms Dakhole Dipali K 164
NFA to DFA Conversion Example
 {q0 q3} is newly formed state NF a b
 ꝺ({q0 q3}, a)= ꝺ(q0, a)ᴜ ꝺ({q3, a}) A
={q0, q1} ᴜ {q4} q0 {q0, q1} {q0,
={q0 q1 q4} q3}
 ꝺ({q0 q3}, b)= ꝺ(q0, b)ᴜ ꝺ({q3, b})
={q0, q3} ᴜ {Ø} q1 - {q2}
={q0 q3} q2 - -
 {q0 q1 q4} is newly formed state q3 {q4} -
 ꝺ({q0 q1 q4}, a)= ꝺ(q0, a) ᴜ ꝺ({q1, a}) ᴜ
ꝺ({q4, a}) DFA q4 a- b-
={q0, q1} ᴜ {Ø} ᴜ q0 {q0 q1} {q0 q3}
{Ø} {q0 q1} {q0 q1} {q0 q2
={q0 q1} q3}
 ꝺ({q0 q1 q4}, b)= ꝺ(q0, b)ᴜ ꝺ({q1, b}) ᴜ
ꝺ({q4, b}) {q0 q2 {q0 q1 {q0 q3}
={q0, q3} ᴜ {q2} ᴜ q3) q4}
{Ø} {q0 q3} {q0 q1 {q0 q3}
={q0 q2 q3} q4}
2/5/2021 Ms Dakhole Dipali K {q0 q1 {q0 q1} {q0 q2
165
NFA to DFA Conversion Example
DFA a b
q0 {q0 q1} {q0 q3}
{q0 q1} {q0 q1} {q0 q2
q3}
a
{q0 q2 {q0 q1 {q0 q3}
q3) q4}
{q0 q3} {q0 q1 {q0 q3} b
q4} q0q1 q0q2q3
{q0 q1 {q0 q1}
a
{q0 q2 b
q4} q0 q3} b a
a b
b q0 q3 q0 q1q4
a

2/5/2021 Ms Dakhole Dipali K 166


ϵ-NFA Example
Design ϵ-NFA that accepts language of strings ending
with ab/ba over ∑ = {a, b}
Solution
Strings accepted= {ab, ba, abab, baba, bbab, aaaba, …}
Strings rejected= {ϵ, a, b, aa, bb, aaa, abb, aaabbb, …}
Transition Diagram

a, b q1 a q2 b q3

q0
 q4 b q5 a q6

2/5/2021 Ms Dakhole Dipali K 167


ϵ-NFA to DFA Conversion Example
Convert the following ϵ-NFA to DFA
Solution
Find ϵ-closure of each state
Convert that ϵ-NFA into DFA using subset construction method

b, 
a
a
q0 a q1 b q2

2/5/2021 Ms Dakhole Dipali K 168


ϵ-NFA to DFA Conversion Example

ϵ-closure of state is define as


a set of states that includes States ϵ-closure
- that state itself q0 {q0}
- set of states reachable from
state Q over ϵ-transaction q1 {q1, q2}
- set of states reachable from
q2 {q2}
existing states in ϵ-closure
over ϵ-transaction and so on..

2/5/2021 Ms Dakhole Dipali K 169


ϵ-NFA to DFA Conversion Example

 Using Subset Construction Method DFA a b


 Consider ϵ-closure of {q0}= {q0} as {q0} {q0 q1 {Ø}
Start State q2}
 a-successor of {q0}
= ϵ-closure (ꝺ(q0, a))
= ϵ-closure ({q0,q1})
= ϵ-closure (q0) ᴜ ϵ-closure (q1)
= {q0} ᴜ {q1, q2}
={q0,q1,q2}
 b-successor of {q0}
= ϵ-closure (ꝺ(q0, b))={Ø}

2/5/2021 Ms Dakhole Dipali K 170


ϵ-NFA to DFA Conversion Example
 Using Subset Construction Method
 Consider {q0 q1 q2} as a new state
DFA a b
 a-successor of {q0 q1 q2} {q0} {q0 q1 {Ø}
= ϵ-closure (ꝺ(q0, a)ᴜꝺ(q1, a)ᴜꝺ(q2, a)) q2}
= ϵ-closure ({q0 q1}ᴜ{Ø}ᴜ{q2}) {q0 q1 {q0 q1 {q1 q2}
= ϵ-closure ({q0 q1 q2}) q2} q2}
= ϵ-closure (q0) ᴜ ϵ-closure (q1) ᴜ ϵ-closure (q2)
= {q0} ᴜ {q0, q1} ᴜ {q2}={q0,q1,q2}
 b-successor of {q0 q1 q2}
ϵ-closure (ꝺ(q0, b)ᴜꝺ(q1, b)ᴜꝺ(q2, b))
= ϵ-closure ({Ø}ᴜ{q1 q2}ᴜ{Ø})
= ϵ-closure ({q1 q2})
= ϵ-closure (q1) ᴜ ϵ-closure (q2) = {q1 q2} ᴜ {q2}={q1 q2}

2/5/2021 Ms Dakhole Dipali K 171


ϵ-NFA to DFA Conversion Example
 Using Subset Construction Method
 Consider {q1 q2} as a new state DFA a b
 a-successor of {q1 q2}
= ϵ-closure (ꝺ(q1, a)ᴜꝺ(q2, a)) {q0} {q0 q1 {Ø}
q2}
= ϵ-closure ({Ø}ᴜ{q2})
= ϵ-closure ({q2}) {q0 q1 {q0 q1 {q1 q2}
= {q2} q2} q2}
 b-successor of {q1 q2} {q1 q2 ) {q2} {q1 q2}
ϵ-closure (ꝺ(q1, b)ᴜꝺ(q2, b))
= ϵ-closure ({q1 q2}ᴜ{Ø})
= ϵ-closure ({q1 q2})
= ϵ-closure (q1) ᴜ ϵ-closure (q2) = {q1 q2} ᴜ {q2}={q1 q2}

2/5/2021 Ms Dakhole Dipali K 172


ϵ-NFA to DFA Conversion Example
 Using Subset Construction Method
 Consider {q2} as a new state DFA a b
 a-successor of {q2}
= ϵ-closure (ꝺ(q2, a)) {q0} {q0 q1 {Ø}
q2}
= ϵ-closure ({q2})
= {q2} {q0 q1 {q0 q1 {q1 q2}
 b-successor of {q2} q2} q2}
=ϵ-closure (ꝺ(q2, b)) {q1 q2 ) {q2} {q1 q2}
= ϵ-closure ({Ø}) {q2} {q2} {Ø}
={Ø}

2/5/2021 Ms Dakhole Dipali K 173


ϵ-NFA to DFA Conversion Example
DFA a b
{q0} {q0 q1 {Ø}
q2}
{q0 q1 {q0 q1 {q1 q2} a b
q2} q2}
{q1 q2 ) {q2} {q1 q2}
{q2} {q2} {Ø} b q1q2
q0 q1q2
a
q0 a, b a a
b b
 q2

2/5/2021 Ms Dakhole Dipali K 174


Minimization of DFA Example
Minimize the following DFA
DFA 0 1
A B C
B B D
C B C
0
0
D B E
E* B C 1 D
B
0
0 1
A 1 0
1 0
C E

2/5/2021 Ms Dakhole Dipali K 175


Minimization of DFA Example
Minimize the following DFA
Use State Equivalence Method DFA 0 1
Write 0’Equivalence as A B C
{A, B, C, D} {E} B B D
Write 1’Equivalence C B C
D B E
{A, B, C} {D} {E}
E* B C
Write 2’Equivalence
{A, C} {B} {D} {E}
Write 3’Equivalence
{A, C} {B} {D} {E}

2/5/2021 Ms Dakhole Dipali K 176


Minimization of DFA Example
Minimize the following DFA DFA 0 1
Use State Equivalence Method A,C B C
Write 0’Equivalence as B B D
D B E
{A, B, C, D} {E}
E* B C
Write 1’Equivalence
{A, B, C} {D} {E} 0 0
Write 2’Equivalence 1
B D
{A, C} {B} {D} {E}
0
Write 3’Equivalence 1 1
{A, C} {B} {D} {E} 0
A, C 1
E

2/5/2021 Ms Dakhole Dipali K 177

You might also like