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

Chapter 2 Finite State Automata Part 1

This document provides an overview of finite state automata (FSA) and deterministic finite automata (DFA), including their definitions, components, and applications in language recognition. It outlines the structure of FSAs and DFAs, including transition functions, state diagrams, and transition tables, along with examples of designing DFAs for specific string patterns. The document emphasizes the importance of finite automata in computer science and data networking.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views97 pages

Chapter 2 Finite State Automata Part 1

This document provides an overview of finite state automata (FSA) and deterministic finite automata (DFA), including their definitions, components, and applications in language recognition. It outlines the structure of FSAs and DFAs, including transition functions, state diagrams, and transition tables, along with examples of designing DFAs for specific string patterns. The document emphasizes the importance of finite automata in computer science and data networking.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 97

Course Instructor

ANUJ GHIMIRE
DISCLAIMER
 This document does not claim any originality and
cannot be used as a substitute for prescribed textbooks.
 The information presented here is merely a collection
from various sources as well as freely available material
from internet and textbooks.
 The ownership of the information lies with the
respective authors or institutions.
Chapter 2

Finite State Automata


Automata
 Automata is a Greek word which means
“self computing”.
 Automata theory is a branch of the theory of
computation which deals with the study of abstract
machines and their capacities for computation.
 An abstract machine is called the automata which
includes the design and analysis of the computing
devices.
 Automata are the mathematical models that can
perform computations on strings of symbols according
to a set of rules.
Automata
 These computational devices are mainly used to solve
language recognition problems.
 Language recognition problems are whose which are
used to determine whether a word belongs to a
language.
 Simply, finite automata (FA) are good models of
computers with a extremely limited amount of
memory.
Finite Automata / FSM
 Finite Automata (FA) is the simplest machine to
recognize patterns.
 Finite automata or Finite State Machine (FSM) is the
model of computation that accepts / rejects regular
languages therefore it is also called as language
recognizer.
 It captures all possible states and transition that a
machine can take while responding to a sequence of
input symbols
 It has a finite set of states, edge that lead from one
state to another and edge labelled with a symbol.
Finite Automata / FSM
 It has a set of states and rules for moving from one
state to another but it depends on applied input
symbol.
 A finite automata consists of five tuples
(components) as: (S, I, O, F, G) where:
S: Set of finite number of states.
I : Set of finite input symbols.
O : Finite set of outputs
F : State Relation or Transition Function
G: Output Relation
Finite Automata / FSM
 A state relation (F) is of the form:
(current state, input) → next state
 A output relation (G) is of the form
(current state, input) → (next state, output)
 ON/OFF switch as FSM:
M=(S, I, O, F, G) is a FSM where:
S={ON, OFF} F Consist of:
I={Press}, (ON, Press) → OFF
O={Device ON, Device OFF} (OFF, Press) → ON
G Consist of:
(ON, Press) → (OFF, Device OFF)
(OFF, Press) → (ON, Device ON)
Finite Automata / FSM
Press/Device
OFF

ON OFF

Press/ Device
ON

Fig: State Diagram or Transition Diagram


Finite Automata / FSM
 The finite state machines are applicable in computer
science and data networking.
 For example:
 Finite-state machines are basis for programs for spell
checking, indexing, grammar, searching large bodies of
text, transforming text using markup languages such as
XML and HTML.
 Network protocols that specify how computers
communicate.
Deterministic Finite Automata (DFA)
 A Deterministic Finite Automata (DFA) is a finite
automata, in which for each input symbol there is exactly
one and only transition for each state.
 In DFA null (∈) string is not allowed i.e., DFA cannot
change state without any character.
 Formally, DFA is defined by five tuples:
M= (Q, ∑, δ, q0, F) where:
Q: Set of finite number of states.
∑ : Set of finite input symbols.
q0 : Initial /Starting State (q0 Є Q)
F: Set of Final States (F  Q)
Deterministic Finite Automata (DFA)
δ : Transition Function of the form
Q∑→Q
 This is the function which describes the change of states
during the transition.
 This mapping is usually represented by a transition table or a
transition diagram.
Representation of DFA
 DFA or any Finite Automata (FA) can be represented
using:
 Transition Diagram and
 Transition Table
 The Transition Diagram is a directed labelled graph
in which each vertex or node represents a state.
 The directed edges of the graph show the transition of
a state and every edges are labelled with input.
Representation of DFA
 The notations used in transition diagram are:

Normal States

Initial / Starting States

Represents the transition from one state to another

Terminating States
Representation of DFA
 Let us consider a DFA as
M= (Q, ∑, δ, q0, F)
Q= {q0, q1 q2 q3}
∑ ={ a,b}
δ : Transition Function of the form Q  ∑ → Q are:

(q0,a) → q1 (q1,b) → q1 (q3,a) → q2


(qo,b) → q2 (q2,a) → q1 (q3,b) → q1
(q1,a) → q3 (q2,b) → q0
q0 : q0
F: q3
Representation of DFA
 Transition Diagram of given DFA
b
a
q0 q1

a a
b b b

q2 a q3
Representation of DFA
 A Transition Table is a tabular representation of a
transition function of finite automata.
 The rows of the table correspond to the states, and the
columns correspond to the input.
 The intersection of each row and the column i.e. each
cell corresponding to the next state.
 Here the initial state or starting state is marked with
arrow head and the final state are marked with
( * ) symbol
Representation of DFA
 Let us consider a DFA as
M= (Q, ∑, δ, q0, F)
Q= {q0, q1 q2 q3}
∑ ={ a,b}
δ : Transition Function of the form Q  ∑ → Q are:

δ(q0,a) → q1 δ(q1,b) → q1 δ(q3,a) → q2


δ(qo,b) → q2 δ(q2,a) → q1 δ(q3,b) → q1
δ(q1,a) → q3 δ(q2,b) → q0
q0 : q0
F: q3
Representation of DFA
 A Transition Table of given DFA

Q/∑ a b
qo q1 q2
q1 q3 q1
q2 q1 q0
* q3 q2 q1
Processing of String
 For processing any string by an automata, it has three
blocks: a a b a b …. ….. ….. ….
 Input Tape Input Tape
 Reading Head
 Finite Control Finite Control
Reading Head q0, q1, q2,…..
 Input Tape of automata is responsible for storing the
symbol of input string.
 It is divided into number of square cell, each cell stores
the symbol of input string.
Processing of String
 Reading Head scans the symbol from the input tape,
each cell at a time in one direction only, either from
left to right or right to left.
 The processing of FA is re controlled by Finite
Control i.e. all the states, current state, next state
obtained after each transition function must be
defined in the finite control.
 Finite control is also responsible for giving next state
regularly and the state obtained after each transition is
tracked by finite control.
Processing of String
 Initially the reading head is placed at the left must cell
of input tape and then it scans each cell in the defined
direction.
 When the input string becomes empty and it the finite
control gives one of the defined final states as the next
state, the string is said to be accepted otherwise
rejected.
Processing of String
 Consider the following DFA and check whether the
string w=001110100 is accepted or rejected

0
1 q2
q1

1 1 0

q3

0
Processing of String
 Solution,
The transition function of given DFA is written as:
δ(q1,0) → q1 δ(q2,0) → q3
δ(q1,1) → q2 δ(q2,1) → q1
δ(q3,0) → q3
δ(q3,1) → q2

Given string w=001110100


Processing of String
Now,
δ(q1, 001110100) → δ(q1, 01110100)
→ δ(q1, 1110100)
→ δ(q2, 110100)
→ δ(q1, 10100)
→ δ(q2, 0100)
→ δ(q3, 100)
→ δ(q2, 00)
→ δ(q3, 0)
→ δ(q3, ε)
Here, after processing each of the input string the DFA is in the final state
hence the given string w=001110100 is accepted by given DFA.
Designing DFA
 Procedure for Designing DFA
 Analyze the set of strings i.e. language which is accepted
by the DFA.
 Draw the transition diagram as per the string that the
language generates.
 Confirm that every state is check for the output state for
every input symbol.
 Confirm that no state have two different output state for
a single input symbol.
 Confirm that there is only one initial state and at least
one final state in transition diagram of DFA.
Designing DFA (Example_1)
 Design DFA over ∑{a,b} that accepts the string with zero or
more a .
Solution,
We need to construct the DFA as M= (Q, ∑, δ, q0, F) where:
Q: Set of finite number of states.
∑ : Set of finite input symbols.
q0 : Initial /Starting State (q0 Є Q)
F: Set of Final States (F  Q)
δ : Transition Function of the form
Q∑→Q
Set of string that the DFA accepts are:
{ε, a, aa, aaa, aaaa, aaaaa……….}
Designing DFA (Example_1)
a a

q1 b q2

Figure: DFA that accepts the string with zero or more a


Designing DFA (Example_1)
 Now the required DFA is
M= (Q, ∑, δ, q0, F)
Q= {q1, q2 }
∑ ={ a,b}
δ : Transition Function of the form Q  ∑ → Q are:
(q1,a) → q1
(q1,b) → q2
(q2,a) → q2
(q2,b) → q2
q0: q1
F: q1
Designing DFA (Example_2)
 Design DFA over ∑{a,b} that accepts the string ending with
bab and check w=baabbbababbab is accepted or not.
Solution,
We need to construct the DFA as M= (Q, ∑, δ, q0, F) where:
Q: Set of finite number of states.
∑ : Set of finite input symbols.
q0 : Initial /Starting State (q0 Є Q)
F: Set of Final States (F  Q)
δ : Transition Function of the form
Q∑→Q
Set of string that the DFA accepts are:
{bab, abab, abbab, aabab, bbabbab, babaabab,……….}
Designing DFA (Example_2)
a

a
b
b a b q4
q1 q2 q3

Figure: DFA over the {a,b} that accepts the string ending with bab
Designing DFA (Example_2)
 Now the required DFA is
M= (Q, ∑, δ, q0, F)
Q= {q1, q2 q3 q4}
∑ ={ a,b}
δ : Transition Function of the form Q  ∑ → Q are:

(q1,a) → q1 (q2,b) → q2 (q4,a) → q3


(q1,b) → q2 (q3,a) → q1 (q4,b) → q2
(q2,a) → q3 (q3,b) → q4
q0 : q1
F: q4
Designing DFA (Example_2)
Now, check for w=baabbbababbab
δ(q1, baabbbababbab) → δ(q2, aabbbababbab)
→ δ(q3, abbbababbab)
→ δ(q1, bbbababbab)
→ δ(q2, bbababbab)
→ δ(q2, bababbab)
→ δ(q2, ababbab)
Here, after processing → δ(q3, babbab)
each of the input → δ(q4, abbab)
string the DFA is in → δ(q1, bbab)
the final state hence → δ(q2, bab)
the given string → δ(q2, ab)
w=baabbbababbab is → δ(q3, b)
accepted by given → δ(q4, ε)
DFA.
Designing DFA (Example_3)
 Design DFA over ∑{0,1} that accepts the string that starts
with 110.
Solution,
We need to construct the DFA as M= (Q, ∑, δ, q0, F) where:
Q: Set of finite number of states.
∑ : Set of finite input symbols.
q0 : Initial /Starting State (q0 Є Q)
F: Set of Final States (F  Q)
δ : Transition Function of the form
Q∑→Q
Set of string that the DFA accepts are:
{110, 11011, 11000, 1101011, 1100111, 11000110,……….}
Designing DFA (Example_3)
0

1 1 0 q4
q1 q2 q3
1
0 0

q5
0,1

Figure: DFA over the {a,b} that accepts the string starting with 110
Designing DFA (Example_3)
 Now the required DFA is
M= (Q, ∑, δ, q0, F)
Q= {q1, q2 q3 q4 ,q5}
∑ ={ 0,1}
δ : Transition Function of the form Q  ∑ → Q are:
(q1,0) → q5 (q2,1) → q3 (q4,0) → q4
(q1,1) → q2 (q3,0) → q4 (q4,1) → q4
(q2,0) → q5 (q3,1) → q5 (q5,0) → q5
(q5,1) → q5
q0 : q1
F: q4
Designing DFA (Example_4)
 Design DFA over {0,1} that accepts the string with even
number of 0 and odd number of 1.
Solution,
We need to construct the DFA as M= (Q, ∑, δ, q0, F) where:
Q: Set of finite number of states.
∑ : Set of finite input symbols.
q0 : Initial /Starting State (q0 Є Q)
F: Set of Final States (F  Q)
δ : Transition Function of the form
Q∑→Q
Set of string that the DFA accepts are:
{1, 001, 111, 01011, 01101, 1001010, 110111000, 00101010110,……….}
Designing DFA (Example_4)
0
q1 q2

1 1 1 1

q4 0 q3

Figure: DFA over the {0,1} that accepts the string with even 0 and odd 1
Designing DFA (Example_4)
 Now the required DFA is
M= (Q, ∑, δ, q0, F)
Q= {q1, q2 q3 q4 }
∑ ={ 0,1}
δ : Transition Function of the form Q  ∑ → Q are:
(q1,0) → q2 (q2,1) → q3 (q4,0) → q3
(q1,1) → q4 (q3,0) → q4 (q4,1) → q1
(q2,0) → q1 (q3,1) → q2

q0 : q1
F: q4
Designing DFA (Example_5)
 Design a deterministic finite automaton M that accepts the
language L= {w є {a, b} * : w does not contain three
consecutive b's }
Solution,
We need to construct the DFA as M= (Q, ∑, δ, q0, F) where:
Q: Set of finite number of states.
∑ : Set of finite input symbols.
q0 : Initial /Starting State (q0 Є Q)
F: Set of Final States (F  Q)
δ : Transition Function of the form
Q∑→Q
Set of string that the DFA accepts are:
{a, bb, aab, aabb, aabba, babbab, bbabbaba,……….}
Designing DFA (Example_5)
a
a a

b b b q4
q1 q2 q3

Figure: DFA that accepts the language L= {w є {a, b} * : w does not


contain three consecutive b's }
Designing DFA (Example_5)
 Now the required DFA is
M= (Q, ∑, δ, q0, F)
Q= {q1, q2 q3 q4}
∑ ={ a,b}
δ : Transition Function of the form Q  ∑ → Q are:

(q1,a) → q1 (q2,b) → q3 (q4,a) → q4


(q1,b) → q2 (q3,a) → q1 (q4,b) → q4
(q2,a) → q1 (q3,b) → q4
q0 : q1
F: {q1, q2, q3}
Non-Deterministic Finite Automata
(NFA)
 In NFA the for a particular input symbol machine can
move to any combination of states.
 In other word the exact state to which the machine
moves cannot be determined in non deterministic
finite automata.
 The automaton, as it reads the input string, may
choose at each step to go into anyone of these legal
next states; the choice is not determined by anything
in our model, and is therefore said to be non-
deterministic.
 NFA does not contain any dead state.
Non-Deterministic Finite Automata
(NFA)
 Formally, NFA is defined by five tuples (similar to
DFA):
M= (Q, ∑, δ, q0, F) where:
Q: Set of finite number of states.
∑ : Set of finite input symbols.
q0 : Initial /Starting State (q0 Є Q)
F: Set of Final States (F  Q)
δ : Transition Function of the form
Q  ∑ → 2Q
Non-Deterministic Finite Automata
(NFA)
 The difference between DFA and the NFA is in the type
of transition function (δ).
 In NFA, δ is a function that takes a state and input
symbol as arguments and returns a set of zero, one, or
more states as output but in case of DFA exactly only
one state is returned an output.
 In fact every DFA is a NFA but not every NFA is a DFA.
But there may exists an equivalent DFA for every
NFA.
Non-Deterministic Finite Automata
(NFA)
 Consider a NFA as:
M= (Q, ∑, δ, q0, F)
Q= {q1, q2 q3 q4}
∑ ={ a,b}
δ : Transition Function of the form Q  ∑ → 2Q are:
(q1,a) → {q1, q2} (q2,b) → ф (q4,a) → {q4, q2}
(q1,b) → q3 (q3,a) → ф (q4,b) → {q1, q3}
(q2,a) → q3 (q3,b) → {q3, q4}

q0 : q1
F: q4
Non-Deterministic Finite Automata
(NFA)
a

a
b a
a a b q4
q1 q2 q3
b

Figure: NFA
Non-Deterministic Finite Automata
(NFA)
 A Transition Table of given NFA

Q/∑ a b
q1 {q1,q2} q3
q2 q3 ф
q3 ф {q3,q4}
* q4 {q2,q4} {q1,q3}
Non-Deterministic Finite Automata
(NFA)
 Consider the language L = (ab+aba)*, and draw its DFA

a b q3 a q4
q1 q2

b
b a

a q5
b Figure: DFA that accepts the language
L = (ab+aba)*
Non-Deterministic Finite Automata
(NFA)
 For this language L = (ab+aba)*, we can have the NFA as
b

q1 q2

b
a

q3
Figure: NFA that accepts the
language L = (ab+aba)*
Non-Deterministic Finite Automata
(NFA)_Example_1
 Construct an NDFA for the language
(ba)*  (bab)*.
Solution,
We need to construct the NDFA as M= (Q, ∑, δ, q0, F) where:
Q: Set of finite number of states.
∑ : Set of finite input symbols.
q0 : Initial /Starting State (q0 Є Q)
F: Set of Final States (F  Q)
δ : Transition Function of the form
Q  ∑ → 2Q
Set of string that the DFA accepts are:
{ε, ba, bab, babbabbab, babbabbabbab, bababa..……….}
Non-Deterministic Finite Automata
(NFA)_Example_1
 For this language L = (ba)*  (bab)*, we can have the NFA
as
a

q1 q2

a
b

q3
Figure: NFA that accepts the
language L = (ba)*  (bab)*
Non-Deterministic Finite Automata
(NFA)_Example_1
 Consider a NFA as:
M= (Q, ∑, δ, q0, F)
Q= {q1, q2 q3}
∑ ={ a,b}
δ : Transition Function of the form Q  ∑ → 2Q are:

(q1,a) → ф (q2,b) → ф
(q1,b) → q2 (q3,a) → ф
(q2,a) →{q1, q3} (q3,b) → q1
q0 : q1
F: q1
Non-Deterministic Finite Automata
(NFA)
 Here we can see that the complex DFA can be
described with the simple NFA.
 Non-deterministic finite automata can be a much
more convenient device to design than a deterministic
finite automata.
 Nondeterministic devices are not meant as realistic
models of computers.
 They are simply a useful notational generalization of
finite automata, as they can greatly simplify the
description of these automata.
Extended Transition Function of
NFA
 The extended transition function of NFA, denoted
by is a transition function that takes two arguments as
input, a state q Є Q & a string w and returns a set of
states that the NFA is in, if it starts in q & processes the
string w.
 It describes what happens when we start in any state
and follow any sequence of inputs.
Extended Transition Function of
NFA_Example
Conversion of NFA to DFA
 Remember that every DFA is an special NFA but not vice
versa.
 But there is an equivalent DFA for every NFA.
 We use sub-set construction method to convert NFA into
DFA
 Steps are:
 Construct a transition table of given NFA.
 Identify all the new states from the transition table.
 Find the transition for each new states in term of input
symbols.
 The process is continued until transition for all the new states
are identified.
 Finally draw a transition diagram by using all states obtained.
Conversion of NFA to DFA_Example(1)
 Convert the following NFA into DFA
0 1
0 q2
q1

1 1

q3
0
Conversion of NFA to DFA_Example(1)
 Solution,
The transition table of the given NFA is given by:

Q/∑ 0 1
q1 {q1,q2} q3
q2 ф {q2,q3}
*q3 q3 ф

Let δ’ be the transition function of the DFA being


constructed.
Conversion of NFA to DFA_Example(1)
Now we need to find the transition for all the states in the
transition table for each input symbol.
Since q1 is the initial state of given NFA so the starting state
of DFA will be also q1.
Step 1: Find the transition for initial state
δ’ ({q1},0)→ δ (q1,0)→ {q1,q2} (new state)
δ’ ({q1},1)→ δ (q1,1)→ {q3} (new state)
Step 2: Find the transition for new state
δ’ ({q1,q2},0)
→ δ (q1,0)  δ (q2,0)
→ {q1,q2}  {ф}
{q1,q2}
Conversion of NFA to DFA_Example(1)
δ’ ({q1,q2},1)
→ δ (q1,1)  δ (q2,1)
→ {q3}  {q2,q3}
{q2,q3} (new state)
δ’ ({q2,q3},0)
→ δ (q2,0)  δ (q3,0)
→ {ф}  {q3}
{q3}
Conversion of NFA to DFA_Example(1)
δ’ ({q2,q3},1)
→ δ (q2,1)  δ (q3,1)
→ {q2,q3}  {ф}
{q2,q3}
δ’ ({q3},0)→ δ (q3,0)→ {q3}
δ’ ({q3},1)→ δ (q3,1)→ {ф} In DFA there cannot be empty
state so we need to define the dead state.
So,
δ’ ({q3},1)→ δ (q3,1)→ {A} here A is dead state.
Conversion of NFA to DFA_Example(1)
Now the DFA is: 0

{q1 ,q2 }
1 1
0

{q1 } {q2 ,q3 }


0
1
0
{A} {q3 }
1
1
0
Conversion of NFA to DFA_Example(1)
This DFA can be redrawn as :
0

Q
0 1

P S
1
0
1 0 {q1 }=P
T R {q1 ,q2 }=Q
1
1
{q2 ,q3 }=S
0 {q3 }=R
{A}=T
Conversion of NFA to DFA_Example(2)
 Convert the following NFA into DFA
1

1
0, 1 0, 1
A B C

1 0
D
Conversion of NFA to DFA_Example(2)
 Solution,
The transition table of the given NFA is given by:
Q/∑ 0 1
A {B,D} B
B C {B,C}
C D A
*D Ф A

Let δ’ be the transition function of the DFA being


constructed.
Conversion of NFA to DFA_Example(2)
Now we need to find the transition for all the states in the
transition table for each input symbol.
Since A is the initial state of given NFA so the starting state of
DFA will be also A.
Step 1: Find the transition for initial state
δ’ ({A},0)→ δ (A,0)→ {B,D} (new state)
δ’ ({A},1)→ δ (A,1)→ {B} (new state)
Step 2: Find the transition for new state
δ’ ({B,D},0)
→ δ (B,0)  δ (D,0)
→ {C}  {ф}
{C} (new state)
Conversion of NFA to DFA_Example(2)
δ’ ({B,D},1)
→ δ (B,1)  δ (D,1)
→ {B,C}  {A}
{A,B,C} (new state)

δ’ ({B},0)→ δ (B,0)→ {C}


δ’ ({B},1)→ δ (B,1)→ {B,C} (new state)

δ’ ({C},0)→ δ (C,0)→ {D} (new state)


δ’ ({C},1)→ δ (C,1)→ {A} (old state)
Conversion of NFA to DFA_Example(2)
δ’ ({A,B,C},0)
→ δ (A,0)  δ (B,0)  δ (C,0)
→ {B,D}  {C}  {D}
{B,C,D} (new state)
δ’ ({A,B,C},1)
→ δ (A,1)  δ (B,1)  δ (C,1)
→ {B}  {B,C}  {A}
{A,B,C} (old state)
Conversion of NFA to DFA_Example(2)
δ’ ({B,C},0)
→ δ (B,0)  δ (C,0)
→ {C}  {D}
{C,D} (new state)
δ’ ({B,C},1)
→ δ (B,1)  δ (C,1)
→ {B,C}  {A}
{A,B,C} (old state)
Conversion of NFA to DFA_Example(2)
δ’ ({D},0)→ δ (D,0)→ {ф} In DFA there cannot be empty
state so we need to define the dead state.
So,
δ’ ({D},0)→ δ (D,1)→ {Q} here Q is dead state.
δ’ ({D},1)→ δ (D,1)→ {A} (old state)

δ’ ({B,C,D},0)
→ δ (B,0)  δ (C,0)  δ (D,0)
→ {C}  {D}  {ф}
{C,D}
Conversion of NFA to DFA_Example(2)
δ’ ({B,C,D},1)
→ δ (B,1)  δ (C,1)  δ (D,1)
→ {B,C}  {A}  {A}
{A,B,C} (old state)

δ’ ({C,D},0)
→ δ (C,0)  δ (D,0)
→ {D}  {ф}
{D} (old state)
δ’ ({C,D},1)
→ δ (C,1)  δ (D,1)
→ {A}  {A}
{A} (old state)
Conversion of NFA to DFA_Example(2)
 Final DFA is: 1

0 1
A {B,D} {A,B,C}

1 1 0 1

1 1 1
B {B,C} {B,C,D}

0 0 0 1

C {C, D} 0
0 0

0 Q 0, 1
D
Conversion of NFA to DFA_Example(3)
 Convert the following NFA into DFA

Try Yourself
ε-Non-Deterministic Finite
Automata (ε -NFA)
 If there is a transition for ε (empty input) then the
automata is called ε-NFA.
 This is another extension of finite automata that
allows a transition on ε, the empty string which
means it can switches to new states without reading an
input symbol.
 This capability does not expand the class of languages
that can be accepted by finite automata, but it does
give some added “programming convenience”.
ε-Non-Deterministic Finite
Automata (ε -NFA)
 Formally, ε-NFA is defined by five tuples (similar to
DFA and NFA):
M= (Q, ∑, δ, q0, F) where:
Q: Set of finite number of states.
∑ : Set of finite input symbols.
q0 : Initial /Starting State (q0 Є Q)
F: Set of Final States (F  Q)
δ : Transition Function of the form
Q  ∑  {ε} → 2Q
ε-Non-Deterministic Finite
Automata (ε -NFA)
 ε-NFA can be shown as:
1
q1 q2

ε 1 1

q4 ε q3

0
Figure: ε-NFA
ε-Closure of a State (ε*)
 Epsilon closure of a state q is the set that contains the
state q itself and all other states that can be reached
from state q by following ε transitions.
 Epsilon closure of a state q denoted by ε-closure (q) is
the set of states that can be reached without reading any
input symbol from state q.
 To obtain ε-closure (q), follow all transitions out of q
that are labelled ε.
 After we get to another state by following ε, follow the ε-
transitions out of those states & so on, eventually
finding every state that can be reached from q along any
path whose arcs are all labeled.
ε-Closure of a State (ε*)
 Formally, we can define ε-closure of the state q as;
 Basis: state q is in ε-closure (q).
 Induction: If state p is reached with ε-transition from
state q, p is in ε-closure (q) and if there is an arc from p
to r labeled ε, then r is in ε-closure (q) and so on.
ε-Closure of a State (ε*) a

q2 ε q4 b q6
ε

q1 ε
a ε a
a

q3 q5 q7
a ε

ε-closure (q1)={q1,q2,q4,q5,q7,q6}
ε-closure (q2)={q2,q4,q5,q7,q6} ε-closure (q6)={q6}
ε-closure (q3)={q3} ε-closure (q7)={q7,q6}
ε-closure (q4)={q4,q5,q7,q6}
ε-closure (q5)={q5,q7,q6}
(ε -NFA) Representation
1
q1 q2

ε 1 1

q4 ε q3

0
Figure: ε-NFA
(ε -NFA) Representation
 Given ε - NFA as can be defined as:
M= (Q, ∑, δ, q0, F)
Q= {q1, q2, q3, q4}
∑ ={ 0, 1}
δ : Transition Function of the form Q  ∑ → 2Q are:
(q1,0) → q2 (q2,1) → {q1, q3}
(q1,1) → ф (q3, ε) → {q3, q4}
(q2, ε) → q2
(q1, ε) → {q1, q4} (q4,0) → q3
(q3,0) → ф
(q2,0) → ф (q4,1) → ф
(q3,1) → q2
(q4, ε) → q4
q0 : q1
F: q4
(ε -NFA) Representation
 A Transition Table of given ε-NFA
Q/∑ 0 1 ε
q1 q2 ф {q1, q4}
q2 ф {q1,q3} q2
Q3 ф q2 {q3, q4}
* q4 q3 ф q4
• Keep in mind that all states contains ε and every state on getting ε
as input goes to itself. i.e. if ε is not given then then goes to itself.
• If ε is given then transition will be on itself as well as other state
where transition is given
Extended Transition Function of
(ε -NFA)
 The extended transition function of ε -NFA denoted by 𝛿መ is
defined by;
መ ε) = ε -closure (q)
 Basis Step: 𝛿(q,
 Inductive Step: Let w = xa be a string, where x is substring
of w without last symbol a and a Є ∑ but a ≠ ε
 Let 𝛿መ (q, x)= {p1,p2,p3………pk} i.e. pi's are the states that can be
reached from q following path labeled x which can end with
many ε & can have many ε.
 Also let,
‫=𝑖𝑘ڂ‬1 δ(𝑝𝑖, 𝑎)= {r1,r2,……….rm}
Then, δ 𝑞, 𝑥 = ‫𝑚ڂ‬ 𝑗=1 ε −closure (rj)
Extended Transition Function of
(ε -NFA)
 To compute 𝛿መ (q, w), first find the ε -closure of starting
state.
 Then read the first symbol of w and determine the states of
NFA after reading first symbol and take the union of ε -
closure of these states.
 Again read the second symbol and determine the states of
NFA after reading second symbol from the union of ε -
closure of states found in previous step.
 Continue this process until the last symbol is read and
finally compute the ε -closure of states that are reached
after reading last symbol.
Extended Transition Function of
(ε -NFA)_Example
ε b q6 ε
q2 q4 q8
a
ε
q1 q10
ε
ε
q3 q5 q7 q9
b a b

Find the extended transition for string ba.


Extended Transition Function of
(ε -NFA)_Example
 Step-1:
Compute the extended transition for starting state.
መ 1, ε)= ε-closure(q1)={q1, q2, q3, q4}
i.e. 𝛿(q
 Step-2: Compute the transition for b as:
δ q1, 𝑏  δ q2, 𝑏  δ q3, 𝑏  δ q4, 𝑏
= ф  ф  {q5}  {q6}
={q5,q6}
Compute the extended transition for the newly obtained
state {q5,q6}.
Extended Transition Function of
(ε -NFA)_Example
The extended transition for {q5,q6} is:
መ 5, ε)  𝛿(q
i.e. 𝛿(q መ 6, ε)= ε-closure(q5)  ε-closure(q6)
= {q5}  {q6,q8}
= {q5,q6,q8}
Now Compute the transition for a as:
δ q5, 𝑎  δ q6, 𝑎  δ q8, 𝑎
= {q7}  ф  {q10}
={q7,q10}
Extended Transition Function of
(ε -NFA)_Example
Lastly,
The extended transition for {q7,q10} is:
መ 7, ε)  𝛿(q
i.e. 𝛿(q መ 10, ε)= ε-closure(q7)  ε-closure(q10)
= {q7}  {q10}
= {q7,q10}
Here the final set of state i.e. {q7,q10} contains one of the final
state so the string ba is accepted.
Removing ε-Transition Function
from ε -NFA
 This process is also considered as the conversion of ε –
NFA to NFA.
 We use the concept of ε-closure to remove the
ε-transition.
 The procedure for converting any ε -NFA to its
equivalent NFA is as follows:
 Step-1:
 For each state we have to check that where does the state goes
on ε*. (ε* 1s the set of all states that can be reached from a
particular state only by seeing the ε symbol)
Removing ε-Transition Function
from ε -NFA
 Step-2:
 Now set of states that we got in step-1, have to be checked on
which state they go on getting a particular input.
 Step-3:
 Again the set of states that we got in step-2 are again checked
on to which state do they go on ε* again.
Removing ε-Transition Function
from ε -NFA
Example
1
0 0, 1
ε ε
A B C

Here we are removing ε-Transition from above ε-NFA i.e.


converting ε –NFA to NFA.
starting state = {A}
input symbol are {0, 1}
Removing ε-Transition Function
from ε -NFA
Let, δN be the transition function of NFA.
Now we process for each state and input as follows:-
δN(A, 0) = ε-closure(δ(ε-closure(A),0)
δ(A,0)  δ(B,0)  δ(C,0)
= ε-closure(δ({A,B,C},0) {A} ф {C}= {A,C}
= ε-closure({A,C})
= ε-closure(A)  ε-closure(C)
= {A,B,C}  {C}
= {A,B,C}
Removing ε-Transition Function
from ε -NFA
δN(A, 1) = ε-closure(δ(ε-closure(A),1) δ(A,1)  δ(B,1)  δ(C,1)
= ε-closure(δ({A,B,C},1) ф {B} {C}= {B,C}

= ε-closure({B,C})
= ε-closure(B)  ε-closure(C)
= {B,C}  {C}
= {B,C}
Removing ε-Transition Function
from ε -NFA
δN(B, 0) = ε-closure(δ(ε-closure(B),0)
δ(B,0)  δ(C,0)
= ε-closure(δ({B,C},0) ф {C}= {C}
= ε-closure(C)
= {C}
δN(B, 1) = ε-closure(δ(ε-closure(B),1)
δ(B, 1)  δ(C, 1)
= ε-closure(δ({B,C},1) {B} {C}= {B, C}
= ε-closure({B, C})
= ε-closure(B)  ε-closure(C)
= {B, C}  {C}
= {B, C}
Removing ε-Transition Function
from ε -NFA
δN(C, 0) = ε-closure(δ(ε-closure(C),0)
= ε-closure(δ(C,0))
= ε-closure(C)
= {C}
δN(C, 1) = ε-closure(δ(ε-closure(C),1)
= ε-closure(δ(C, 1)
= ε-closure(C)
= {C}
Removing ε-Transition Function
from ε -NFA
Final NFA
0
1
0, 1
0, 1 0
A B C
1

0, 1
Here A, B and C all are final states in NFA because the final
states are those state from where we can reach to the final
state of ε –NFA only by ε – input.

You might also like