You are on page 1of 65

Hawassa University Daye

Campus
Department of Computer
Automata and complexity
Science
theory

Course code: CoSc3071


By: Mekonen M.
1
Unit 2
Finite State Automata
Finite State Automata
Finite state automata (AKA finite accepters ) is a mathematical
representation of a system, with discrete input and output.
Consists of a finite sets of states and a set of transitions from state
to state.
It is the Simplest form of an automation
It have no temporary storage.

Mekonen M. # CoSc3071  Unit 2 – Finite Automata 3


Finite State Automata
Hence, a finite automaton is limited in its capacity to remember
things during the computation, because its input file cannot be
rewritten.
There are two types of finite accepters
Deterministic finite state Automata (DFA)
Nondeterministic finite state Automata (NFA)

Mekonen M. # CoSc3071  Unit 2 – Finite Automata 4


Deterministic Finite State Automata
In DFA, for each input symbol, one can determine the state to which
the machine will move. As it has a finite number of states, the
machine is called Deterministic Finite Machine or Deterministic
Finite Automaton.
For every state and every alphabet symbol there is exactly one move
that the machine can make

Mekonen M. # CoSc3071  Unit 2 – Finite Automata 5


Deterministic Finite Automata
(DFA)
• A finite automaton, or finite state machine is a 5-tuple where
• is finite set of states;
• is finite alphabet of input symbols;
• (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 .

Mekonen M. #CoSc3071  Unit 2 – Finite Automata 6


Transition Graph
A labeled directed graph with designed node as a start node and
one or more final/accept nodes describes a finite automata.
Notations is a state

is a transition

is a start state

is a final state

Mekonen M. # CoSc3071  Unit 2 – Finite Automata 7


Transition Table
δ Input
State

• is defined as
1 1 0

𝑞0 0
𝑞1 0
𝑞2
1

Mekonen M. #CoSc3071  Unit 2 – Finite Automata 8


Transition Graph
Example: Draw transition diagram for the following DFA
M = ({q0, q1, q2}, {0, 1},  , q0, {q1}) where  is given as
(q0, 0) = q0, (q0, 1) = q1, (q1, 1) = q1, (q1, 0) = q2, (q2, 0) = q1,
(q2, 1) = q1

06
Mekonen M. # CoSc3071  Unit 2 – Finite Automata 9
FA Examples
• The string with next to last symbol as 0.
0

1
0 𝐶
𝐴 0
𝐵 1
1

0 𝐷
1

Mekonen M. #CoSc3071  Unit 2 – Finite Automata 10


FA Examples
• The strings ending with 10.

0 1

𝐴 1
𝐵 𝐶
1

Mekonen M. #CoSc3071  Unit 2 – Finite Automata 11


Transition Graph
Exercise: Draw transition diagram for the following DFA
M=({q0, q1, q2, q3 }, , {a, b}, q0, {q3}) where  is given as
(q0, a)=q1, (q0, b) =q2, (q1, a) = q1, (q2, b) = q2, (q1, a) = q3,
(q2, b) = q3

Mekonen M. # CoSc3071  Unit 2 – Finite Automata 12


Extended Transition Function for FA
• Let be an Finite Automata. We define the function

as follows:
1. For any
2. For any and ,

Mekonen M. #CoSc3071  Unit 2 – Finite Automata 13


Example
• Consider FA
𝑞 a
𝑞1 b
𝑞2 c
𝑞3
• Calculate

Mekonen M. #CoSc3071  Unit 2 – Finite Automata 14


Exercise
Consider following
X
FA
𝑞 𝑞1 Y
𝑞2

1. calculate

Mekonen M. #CoSc3071  Unit 2 – Finite Automata 15


Acceptance by FA
• Let be an FA. A string is accepted by if . If string is not accepted, we
can say it is rejected by . The language accepted by , or the language
recognized by , is the set

• If 𝐿 is any language over , is accepted or recognized by if and only if .

Mekonen M. #CoSc3071  Unit 2 – Finite Automata 16


String Acceptance by DFA
Note that:
DFA must have a definite input symbol to move from one state to
another state
 is total function. If  is not defined for a terminal a then  (q, a) =
D, if D is dummy state/dead state

9
Mekonen M. # CoSc3071  Unit 2 – Finite Automata 17
String Acceptance by DFA
Example: Consider the following DFA
M = ({q0, q1, q2}, {a, b}, , q0, {q1, q2} ) where (q0, a) = q1,
(q0, b) = q2, (q2, a) = q2, (q1, b) = q1, (q1, a) = q2
A. Draw transition diagram of M
B. Check if the following strings are accepted by M
i) x = abbb ii) x = abba iii) x = bab

10
Mekonen M. # CoSc3071  Unit 2 – Finite Automata 18
String Acceptance by DFA
b)
I)  *(q0, abbb) =  *(T(q0,a), bbb) =  ( *(q0,abb), b)
=  *(q1, bbb) =  (  ( (  (  *( q0, ,a),b),b), b) =  (  ( ( 
( q0,a),b),b), b) =  (  ( (  ( q0,a),b),b), b)
=  *(T(q1,b), bb) =  (  ( (q1,b),b), b)
=  *(q1, bb) =  (  (q1,b), b)
=  *(T(q1,b), b) =  ( q1, b)
= (q1, b)
= q1
So, abbb is accepted by M because q1 e {q1, q2}
 Following the same step as above it can be proved that (ii) abba is accepted and
(iii) bab is rejected

11
Mekonen M. # CoSc3071  Unit 2 – Finite Automata 19
Language Acceptance by DFA
Definition: The language accepted by DFA M = (Q, Σ, , q0, F) is the set of all
strings on Σ accepted by M. Formally,
L(M) = {w ϵ Σ * :  *(q0, w) ϵ F} and
The language which is not accepted or rejected by M is given as :
[L(M)]’ = {w ϵ Σ * :  *(q0, w) ≠ F}

Example: Given the following DFA find L(M) and [L(M)]’


M = ({q0, q1, q2}, {a, b}, , q0, {q1} ) where (q0, a) = q0, (q0, b) = q1,
(q1, a) = q2, (q1, b) = q2, (q2, a) = q2, (q2, b) = q2

Answer: L(M) = {anb: n ≥0}, [L(M)] = {a,b}*a U λ

12
Mekonen M. # CoSc3071  Unit 2 – Finite Automata 20
Language Acceptance by DFA
Example: Find a deterministic finite accepter that recognizes the set of all
strings on Σ = {a, b} starting with the prefix ab.
a,b

a
𝑞0 𝑞1 b
𝑞2

Mekonen M. # CoSc3071  Unit 2 – Finite Automata 21


Language Acceptance by DFA
Exercise 1: For  = {a, b} construct DFA’s that accepts the sets
consisting of
All strings with exactly one a.
All strings with at least one a.
All strings with no more than three a’s
All strings with at least one a and exactly two b’s.
Exercise 2: Find a DFA for the following language on  = {a, b}, L =
{w: |w|a mod 3 = 0}

Mekonen M. # CoSc3071  Unit 2 – Finite Automata 22


Nondeterministic Finite Automata (NFA)
• Unlike DFA, NFA has a set of possible transitions from a state with an
input.
• 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.
The major difference between DFA and NFA
The range of the transition function is 2Q
Empty string, λ , is allowed to be an argument of δ

Mekonen M. #CoSc3071  Unit 2 – Finite Automata 23


Example of NFA for
δ Input
State

• is defined as
𝑞1
1 1

𝑞0 0
𝑞4
1 0

𝑞2 1 𝑞3
Mekonen M. #CoSc3071  Unit 2 – Finite Automata 24
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

Mekonen M. #CoSc3071  Unit 2 – Finite Automata 25


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

Mekonen M. #CoSc3071  Unit 2 – Finite Automata 26


Example: Recursive Definition of in NFA
δ Input
State

• is defined as
0, 1

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

Mekonen M. #CoSc3071  Unit 2 – Finite Automata 27


Example: Recursive Definition of in NFA


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

Mekonen M. #CoSc3071  Unit 2 – Finite Automata 28


Example: Recursive Definition of in NFA


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

Mekonen M. #CoSc3071  Unit 2 – Finite Automata 29


Example: Recursive Definition of in NFA


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

¿{𝑞 0 , 𝑞1 } ∪ {𝑞 2 }
¿ {𝑞 0 , 𝑞1 , 𝑞 𝑞 0 2𝑞
1
}1
0, 1
𝑞2 0, 1
𝑞3

Mekonen M. #CoSc3071  Unit 2 – Finite Automata 30


Example: Recursive Definition of in NFA

¿ ¿ 𝑟 ∈ 𝜹 ( 𝒒𝟎 , 𝟎) 𝛿(𝑟 , 1)

𝛿 ( 𝑞 0 , 01 )

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

Mekonen M. #CoSc3071  Unit 2 – Finite Automata 31


Example: Recursive Definition of in NFA


𝛿 ( 𝑞 0 ,111 ) ¿ ¿ 𝑟 ∈ 𝜹 (𝒒𝟎 ,𝟏𝟏 )𝛿(𝑟 , 1)
¿ ¿ 𝑟 ∈ {𝒒 𝟎 , 𝒒𝟏 , 𝒒𝟐 }𝛿(𝑟 , 1)
¿ 𝛿 ( 𝑞0 , 1 ) ∪ 𝛿 ( 𝑞 1 , 1 ) ∪ 𝛿 ( 𝑞 2 , 1 )
0, 1
¿ {𝑞 0 , 𝑞1 , 𝑞 2 , 𝑞 3 }


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

Mekonen M. #CoSc3071  Unit 2 – Finite Automata 32


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

Mekonen M. #CoSc3071  Unit 2 – Finite Automata 33


Non-Deterministic Finite State Automata
Example: Given an NFA M = ({q0, q1, q2 , q3}, {a, b}, δ, q0, {q3})and
given in transition table, draw its transition diagram

Mekonen M. # CoSc3071  Unit 2 – Finite Automata 34


Non-Deterministic Finite State Automata
Answer

Mekonen M. # CoSc3071  Unit 2 – Finite Automata 35


String Accepted by NFA
Definition: The language accepted by a NFA M = (Q, Σ, δ, q0, F) is
defined L(M) = {w e Σ*: δ(q0, w) ϵ F ≠ 0 }
Example: Consider the following NFA M =(Q, Â, , q0, F)
Check if the following strings are accepted by M
i. baa
ii. abba
iii. aab

Mekonen M. # CoSc3071  Unit 2 – Finite Automata 36


String Accepted by NFA
i ) baa
*({q0}, baa) = *(({q0}, b), aa) = *(({q2},aa)
= *(({q2}, a), a) = (({q2, q3},a) =  (q2, a) U (q3, a)
= {q2, q3} U {q3} = {q2, q3}
But, {q2, q3} I {q3} = {q3} Î 0, Hence, baa is accepted
iii ) aab
*({q0}, baa) = *(({q0}, a), ab) = *(({q1},aa)
= *(({q1}, a), b) = (({q1, q3},b) =  (q2, b) U (q3, b)
= {q1} U 0 = {q1}
But {q1}I {q3} = 0, Hence, aab is rejected

21
Mekonen M. # CoSc3071  Unit 2 – Finite Automata 37
Conversion of NFA to DFA
In NFA, when a specific input is given to the current state, the
machine goes to multiple states. It can have zero, one or more than
one move on a given input symbol.
On the other hand, in DFA, when a specific input is given to the
current state, the machine goes to only one state. DFA has only one
move on a given input symbol.
Let, M = (Q, ∑, δ, q0, F) is an NFA which accepts the language L(M).
There should be equivalent DFA denoted by M' = (Q', ∑', q0', δ', F')
such that L(M) = L(M').

Mekonen M. # CoSc3071  Unit 2 – Finite Automata 38


Conversion of NFA to DFA using subset construction
Steps for converting NFA to DFA:
Step 1: Initially Q' = ϕ
Step 2: Add q0 of NFA to Q'. Then find the transitions from this start state.
Step 3: In Q', find the possible set of states for each input symbol. If this set of
states is not in Q', then add it to Q'.
Step 4: In DFA, the final state will be all the states which contain F(final states of
NFA)

Mekonen M. # CoSc3071  Unit 2 – Finite Automata 39


Example 1: Conversion from NFA to DFA

2
a b
1 {2,3} {4}
b 2 {} {4}
1 4
3 {4} {3}
a a 4 {} }
3
Transition Table

b
NFA

Mekonen M. #CoSc3071  Unit 2 – Finite Automata 40


Example 1: Conversion from NFA to DFA
𝛿 1 ( 1 , 𝑎 ) ={ 2 , 3 } 2
a b
𝛿 1 ( 1 , 𝑏 )= { 4 }
b
1 4
𝛿 1 ( { 2 , 3 } , 𝑎 ) = 𝛿 ( 2 , 𝑎 ) ∪ 𝛿 ( 3 , 𝑎)
¿ {4 } a a
𝛿 1 ( { 2 , 3 } , 𝑏 ) =𝛿 ( 2 , 𝑏 ) ∪ 𝛿 ( 3 , 𝑏) 3

¿ {3 , 4 } b

𝛿 1( 4 , 𝑎)= { ∅ } a b
1 2,3 3,4
𝛿 1( 4 , 𝑏)={ ∅ }
a
b

Mekonen M. #CoSc3071  Unit 2 – Finite Automata 41


Example 1: Conversion from NFA to DFA
𝛿 1 ( {3 , 4 }, 𝑎 ) = 𝛿 ( 3 , 𝑎 ) ∪ 𝛿 ( 4 , 𝑎 ) 2
¿ {4 } a b

𝛿 1 ( { 3 , 4 } , 𝑏 ) = 𝛿 ( 3 , 𝑏 ) ∪ 𝛿 (4 , 𝑏) b
1 4
¿ {3 }
𝛿 1( 3 , 𝑎)={4 } a a
3
𝛿 1( 3 , 𝑏)={3 } b
a b
1 2,3 3,4

a a
b b
a
4 3

b
Mekonen M. #CoSc3071  Unit 2 – Finite Automata 42
Example 2: Conversion from NFA to DFA
δ Input
State

0, 1

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

Mekonen M. #CoSc3071  Unit 2 – Finite Automata 43


Example 2: Conversion from NFA to DFA
0, 1

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

Mekonen M. #CoSc3071  Unit 2 – Finite Automata 44


Example 2: Conversion from NFA to DFA
𝛿 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

𝑞0 𝑞1 𝑞2 1
𝑞0 𝑞1 𝑞2 𝑞3 𝑞0 1
𝑞1 0, 1
𝑞2 0, 1
𝑞3
Mekonen M. # CoSc3071  Unit 2 – Finite Automata 45
Example 2: Conversion from NFA to DFA
𝛿 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

𝑞0 𝑞1 𝑞2 1
𝑞0 𝑞1 𝑞2 𝑞3 𝑞0 1
𝑞1 0, 1
𝑞2 0, 1
𝑞3
Mekonen M. # CoSc3071  Unit 2 – Finite Automata 46
Example 2: Conversion from NFA to DFA 0, 1

𝛿1 ( {𝑞0 ,𝑞1 ,𝑞2 ,𝑞3 },0 ) =𝛿 ( {𝑞0 } ,0 ) ∪𝛿 ( {𝑞1 } ,0 ) ∪𝛿 ( {𝑞2 } ,0 ) ∪𝛿 ( {𝑞3 } ,0 )={𝑞0 ,𝑞2 ,𝑞3 }
𝑞 0 𝑞1 1 0, 1
𝑞 2 0, 1 𝑞 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
Mekonen M. #CoSc3071  Unit 2 – Finite Automata 47
Conversion of NFA to DFA
Example: Given the following NFA, construct its equivalent DFA

Mekonen M. # CoSc3071  Unit 2 – Finite Automata 48


Conversion of NFA to DFA
Find reachable states from q0

Define DFA M’ = (Q’, Â, ’, q0’, F’)


where
• Q’ = {{qo}, {q1}, {q2}, {q1, q3},
{q3}}
• q0’ = {qo}
• F = {{q1, q3}, {q3}}
• ’ is given in the diagram in the next
slide

Mekonen M. # CoSc3071  Unit 2 – Finite Automata 49


Conversion of NFA to DFA

Exercise: Convert the following NFA to its equivalent DFA.

26
Mekonen M. # CoSc3071  Unit 2 – Finite Automata 50
Conversion of NFA with ε to DFA by ε-closure
NFA with ε move: If any FA contains ε transaction or move, the finite automata
is called NFA with ε move.
ε-closure: ε-closure for a given state A means a set of states which can be
reached from the state A with only ε(null) move including the state A itself.

• ε – closure(𝑞0) = {𝑞0, 𝑞1, 𝑞2} means self state + ε – reachable states


• ε – closure(𝑞1) = {𝑞1, 𝑞2} 𝑞1 is a self state + 𝑞1 is a state obtained from 𝑞1with ε
input.
• ε – closure(𝑞2) = {𝑞2}

Mekonen M. # CoSc3071  Unit 2 – Finite Automata 51


Conversion of NFA with ε to DFA by ε-closure
Step1: Find out all the ε transition from each state from Q, that will be called as
ε-closure(qi) where, qi ∈Q.. (find ε – closure for each states from Q) then mark
Q
Step2: Find δ’ transition (means ε – closure on δ with ε moves)
Step3: repeat step2 for each input symbol and for each state
Step4: From the resultant transition table can construct the NFA without ε

Mekonen M. # CoSc3071  Unit 2 – Finite Automata 52


Conversion of NFA with ε to DFA by ε-closure – example1
Convert the following NFA to DFA using ε-closure for (a|b)*abb
-closure(0) = {0,1,2,4,7}
-closure(1) = {1,2,4}
-closure(2) = {2}
-closure(3) = {1,2,3,4,6,7}
-closure(4) = {4}
-closure(5) = {1,2,4,5,6,7}
-closure(6) = {1,2,4,6,7}
-closure(7) = {7}
-closure(8) = {8}
-closure(9) = {9}
-closure(10) = {10}
29
Mekonen M. # CoSc3071  Unit 2 – Finite Automata 53
Conversion of NFA with ε to DFA by ε-closure – example1
Then start mark -closure(0) as a state A of the equivalent DFA is
-closure(0) = {0,1,2,4,7} = A,
The input alphabet is {a, b). Thus, our first step is to mark A and compute
δ'(A, a) = ε-closure {δ((0,1,2,4,7), a) }
= ε-closure {δ(0, a) ∪ δ(1, a) ∪ δ(2, a) ∪ δ(4, a) ∪ δ(7, a) }
= ε-closure {3 ∪ 8}
= {1,2,3,4,6,7,8} Mark this States as a B
𝐵
δ'(A, b) = ε-closure {δ((0,1,2,4,7), b) } 𝐴 a

= ε-closure {δ(0, b) ∪ δ(1, b) ∪ δ(2, b) ∪ δ(4, b) ∪ δ(7, b) }


b
𝐶
= ε-closure {5}
= {1,2,4,5,6,7} Mark this States as a C
30
Mekonen M. # CoSc3071  Unit 2 – Finite Automata 54
Conversion of NFA with ε to DFA by ε-closure – example1
δ'(B, a) = ε-closure {δ((1,2,3,4,6,7,8), a) }
= ε-closure {δ(1, a)∪ δ(2, a) ∪ δ(3, a) ∪ δ(4, a) ∪ δ(6, a) ∪ δ(7, a) ∪ δ(8, a)
}
= ε-closure {3 ∪ 8}
= {1,2,3,4,6,7,8} already marked B
δ'(B, b) = ε-closure {δ((1,2,3,4,6,7,8), a) }
= ε-closure {δ(1, b)∪ δ(2, b) ∪ δ(3, b) ∪ δ(4, b) ∪ δ(6, b) ∪ δ(7, b) ∪ δ(8, ) }
= ε-closure {5,9} a
b
𝐷
= {1,2,4,5,6,7,9} Mark this States as a D
𝐵
𝐴 a

b
𝐶 30
Mekonen M. # CoSc3071  Unit 2 – Finite Automata 55
Conversion of NFA with ε to DFA by ε-closure – example1
δ'(C, a) = ε-closure {δ((1,2,4,5,6,7), a) }
= ε-closure {δ(1, a) ∪ δ(2, a) ∪ δ(4, a) ∪ δ(5, a) ∪ δ(6, a) ∪ δ(7, a) }
= ε-closure {3 ∪ 8}
= {1,2,3,4,6,7,8} - State B
δ'(C, b) = ε-closure {δ((1,2,4,5,6,7), b) }
= ε-closure {δ(1, b) ∪ δ(2, b) ∪ δ(4, b) ∪ δ(5, b) ∪ δ(6, b) ∪ δ(7, b) }
= ε-closure {5} a
b
𝐷
= {1,2,4,5,6,7} - State C
𝐵
𝐴 a
a

b
𝐶
b 30
Mekonen M. # CoSc3071  Unit 2 – Finite Automata 56
Conversion of NFA with ε to DFA by ε-closure – example1
δ'(D, a) = ε-closure {δ((1,2,4,5,6,7,9), a) }
= ε-closure {δ(1, a)∪ δ(2, a)∪ δ(4, a) ∪ δ(5, a) ∪ δ(6, a) ∪ δ(7, a) ∪ δ(9,
a) }
= ε-closure {3 ∪ 8}
= {1,2,3,4,6,7,8} - State B
δ'(D, b) = ε-closure {δ((1,2,4,5,6,7,9), b) }
= ε-closure {δ(1, b)∪ δ(2, b) ∪ δ(4, b) ∪ δ(5, b) ∪ δ(6, b) ∪ δ(7, b) ∪ δ(9, b) }
a
= ε-closure {5,10} b
𝐷
= {1,2,4,5,6,7,10} Mark this States as a E 𝐵 a b

𝐴 a
a
𝐸
b
𝐶
b 30
Mekonen M. # CoSc3071  Unit 2 – Finite Automata 57
Conversion of NFA with ε to DFA by ε-closure – example1
δ'(E, a) = ε-closure {δ((1,2,4,5,6,7,10), a) }
= ε-closure {δ(1, a)∪ δ(2, a)∪ δ(4, a) ∪ δ(5, a) ∪ δ(6, a) ∪ δ(7, a) ∪ δ(10,
a) }
= ε-closure {3 ∪ 8}
= {1,2,3,4,6,7,8} - State B
δ'(E, b) = ε-closure {δ((1,2,4,5,6,7,10), b) }
= ε-closure {δ(1, b)∪ δ(2, b) ∪ δ(4, b) ∪ δ(5, b) ∪ δ(6, b) ∪ δ(7, b) ∪ δ(10, b) }
a
= ε-closure {5} b
𝐷
= {1,2,4,5,6,7} - State C 𝐵 a b

𝐴 a
a
a

𝐸
𝐸
𝐶
b b

b 30
Mekonen M. # CoSc3071  Unit 2 – Finite Automata 58
Conversion of NFA with ε to DFA by ε-closure – Exercise
Exercise 1: Convert the following NFA to DFA. States 2 and 4 are final states

33
Mekonen M. # CoSc3071  Unit 2 – Finite Automata 59
Conversion of NFA to DFA - exercises
Exercise 2: Convert the given NFA to its equivalent DFA

Exercise 3: Convert the given NFA to its equivalent DFA

34
Mekonen M. # CoSc3071  Unit 2 – Finite Automata 60
DFA Minimization
Questions of DFA size:
? Given a DFA, can we find one with fewer states that accepts the same language?
? What is the smallest DFA for a given language?
? Is the smallest DFA unique, or can there be more than one "smallest" DFA for the same
language?
All these questions have neat answers…
Unreachable states, like some of those introduced by the subset construction,
can obviously be eliminated
Even some of the reachable states may be redundant…
DFA minimization means converting a given DFA to its equivalent DFA but with a
minimum number of states.

35
Mekonen M. # CoSc3071  Unit 2 – Finite Automata 61
DFA Minimization using Equivalence Theorem
• If X and Y are two states in a DFA, we can combine these two states into {X, Y} if they are not
distinguishable i.e. equivalent or indistinguishable.
• Two states are equivalent states if
• δ (X, w) ∈ F and δ (Y, w) ∈ F OR
• δ (X, w) ∈ F and δ (Y, w) ∈ F
1. Delete all unreachable states from initial states
2. Draw state transition table
3. Find out equivalent set
4. Draw minimized DFA
Note:
0-equivalence set - separate non-final states from final states
n-equivalence set – we take information from previous(n-1) equivalence set. i.e. we check on
seeing on input symbol, are they going to same state or different state.
if they are in same state group in previous equivalent set – write in same group
otherwise - make separate group
• Follow this procedure until you get a point where no change in the state group

Mekonen M. # CoSc3071  Unit 2 – Finite Automata 62


DFA Minimization using Equivalence Theorem
DFA transitional table Minimized DFA transitional table
States(Q) δ (Q, a) δ (Q, b)
States(Q) δ (Q, a) δ (Q, b)
A B C
{A,C} = A B A
B B D
B B D
C B C
D B E
D B E
E B A
E B C

0 – equivalent set = [{A, B, C, D}, {E}]


1 – equivalent set = [{A, B, C}, {D}, {E}]
2 – equivalent set = [{A, C}, {B}, {D}, {E}]
3 – equivalent set = [{A, C}, {B}, {D}, {E}] No more equivalent set

Mekonen M. # CoSc3071  Unit 2 – Finite Automata 63


DFA Minimization
Exercise B)

A)

C)

Mekonen M. # CoSc3071  Unit 2 – Finite Automata 64


Chomsky Hierarchy

Mekonen M. # CoSc3071  Unit 2 – Finite Automata 65

You might also like