Download as pdf or txt
Download as pdf or txt
You are on page 1of 40

Unit: 1.

2
Topic
DFA & NDFA

CST- 3 TOC BY: SRABANTI


CHAKRABORTY HOD, CST ; EIEM
CONTENTS
• Definition of DFA

• Definition of NDFA

• The equivalence of DFA and NDFA

• A theorem on equivalence of DFA and NDFA

CST- 3 TOC BY: SRABANTI CHAKRABORTY HOD, CST ; EIEM


DFA
(Deterministic Finite Automaton )

DFA refers to A Finite Automata(FA) is


said to be deterministic, if
corresponding to an input symbol,
there is single resultant state i.e. there
is only one transition.

CST- 3 TOC BY: SRABANTI CHAKRABORTY HOD, CST ; EIEM


CHARACTERISTICS OF
DFA
• The finite automata are called deterministic finite
automata if the machine is read an input string one
symbol at a time.
• In DFA, there is only one path for specific input from the
current state to the next state.
• DFA refers to deterministic finite automata.
Deterministic refers to the uniqueness of the
computation.
• DFA does not accept the null move, i.e., the DFA cannot
change state without any input character.
• DFA can contain multiple final states. It is used in Lexical
Analysis in Compiler.

CST- 3 TOC BY: SRABANTI CHAKRABORTY HOD, CST ; EIEM


Formal Definition of
DFA
A DFA is a collection of 5-tuples
• Q: finite set of states
• ∑: finite set of the input symbol
• q0: initial state
• F: final state
• δ: Transition function
Q x ∑→Q

CST- 3 TOC BY: SRABANTI CHAKRABORTY HOD, CST ; EIEM


Graphical Representation of
DFA

• A DFA can be represented by digraphs called


state diagram. In which:
• The state is represented by vertices.
• The arc labelled with an input character show
the transitions.
• The initial state is marked with an arrow.
• The final state is denoted by a double circle.

CST- 3 TOC BY: SRABANTI CHAKRABORTY HOD, CST ; EIEM


•Q = {q0, q1, q2}
•∑ = {0, 1}
•q0 = {q0}
•F = {q2}
Example
CST- 3 TOC BY: SRABANTI CHAKRABORTY HOD, CST ; EIEM
Transition Diagram:

CST- 3 TOC BY: SRABANTI CHAKRABORTY HOD, CST ; EIEM


Transition Table:
Present State Next state for Next State of
Input 0 Input 1
→q0 q0 q1
q1 q2 q1
*q2 q2 q2
CST- 3 TOC BY: SRABANTI CHAKRABORTY HOD, CST ; EIEM
DFA with ∑ = {0, 1}
accepts all
starting with 0.

CST- 3 TOC BY: SRABANTI CHAKRABORTY HOD, CST ; EIEM


Explanation:
In the given diagram:
On given 0 as input to DFA in state q0 the DFA changes
state to q1 and always go to final state q1 on starting input
0.

It can accept 00, 01, 000, 001....etc. It can't accept any


string which starts with 1, because it will never go to final
state on a string starting with 1.

CST- 3 TOC BY: SRABANTI CHAKRABORTY HOD, CST ; EIEM


NDFA
(Non-Deterministic finite
automata)
Non-Deterministic Finite Automata
(NDFA / NFA) is an automata in which
for some current state and input
symbol, there exists more than one
next output states.

CST- 3 TOC BY: SRABANTI CHAKRABORTY HOD, CST ; EIEM


CHARACTERISTICS OF
NDFA
• The finite automata are called NFA when there exist many
paths for specific input from the current state to the next
state.
• Every NFA is not DFA, but each NFA can be translated into
DFA.
• NDFA stands for non-deterministic finite automata. It is
easy to construct an NFA than DFA for a given regular
language.
• NFA is defined in the same way as DFA but with the
following two exceptions, it contains multiple next states,
and it contains ε transition.

CST- 3 TOC BY: SRABANTI CHAKRABORTY HOD, CST ; EIEM


Formal definition of NDFA:

• Q: finite set of states


• ∑: finite set of the input symbol
• q0: initial state
• F: final state
• δ: Transition function
Q x ∑ →2Q
CST- 3 TOC BY: SRABANTI CHAKRABORTY HOD, CST ; EIEM
Graphical Representation of
NDFA

An NDFA can be represented by digraphs called state


diagram. In which:
• The state is represented by vertices.
• The arc labelled with an input character show the
transitions.
• The initial state is marked with an arrow.
• The final state is denoted by the double circle.

CST- 3 TOC BY: SRABANTI CHAKRABORTY HOD, CST ; EIEM


EXAMPLE : 1
•Q = {q0, q1, q2}
∑ = {0, 1}
q0 = {q0}
F = {q2}
CST- 3 TOC BY: SRABANTI CHAKRABORTY HOD, CST ; EIEM
Transition Diagram

CST- 3 TOC BY: SRABANTI CHAKRABORTY HOD, CST ; EIEM


Transition table
Present Next state Next State
State for Input 0 of Input 1
→q0 q0, q1 q1
q1
Transition
q2 q0
Table:
*q2 q2 q1, q2

CST- 3 TOC BY: SRABANTI CHAKRABORTY HOD, CST ; EIEM


In the above diagram,
When the current state is q0, on input 0:
the next state will be q0 or q1,
on 1 input
the next state will be q1.
When the current state is q1, on input 0:
the next state will be q2
on 1 input:
the next state will be q0.
When the current state is q2, on 0 input
the next state is q2,
on 1 input:
the next state will be q1 or q2.

EXPLANATION
CST- 3 TOC BY: SRABANTI CHAKRABORTY HOD, CST ; EIEM
The equivalence
of
DFA & NDFA

CST- 3 TOC BY: SRABANTI CHAKRABORTY HOD, CST ; EIEM


PROBLEMS ON CONVERTING
NDFA TO DFA:
Problem-01:

Convert the following Non-Deterministic Finite


Automata (NFA) to Deterministic Finite
Automata (DFA)-

CST- 3 TOC BY: SRABANTI CHAKRABORTY HOD, CST ; EIEM


FIG : NDFA M1
CST- 3 TOC BY: SRABANTI CHAKRABORTY HOD, CST ; EIEM
Solution-

Transition table for the given Non-


Deterministic Finite Automata (NFA)
is-

State /
a b
Alphabet
→q0 q0 q0, q1

q1 – *q2

*q2 – –

CST- 3 TOC BY: SRABANTI CHAKRABORTY HOD, CST ; EIEM


Step-01:
Let Q’ be a new set of states of the Deterministic Finite Automata (DFA).
Let T’ be a new transition table of the DFA.

Step-02:
Add transitions of start state q0 to the transition table T’.

State /
a b
Alphabet

→q0 q0 {q0, q1}


CST- 3 TOC BY: SRABANTI CHAKRABORTY HOD, CST ; EIEM
Step-03:
New state present in state Q’ is {q0, q1}.
Add transitions for set of states {q0, q1}
to the transition table T’.

State /
a b
Alphabet
→q0 q0 {q0, q1}
{q0, q1,
{q0, q1} q0
q2}
CST- 3 TOC BY: SRABANTI CHAKRABORTY HOD, CST ; EIEM
Step- 04
New state present in state Q’ is {q0, q1, q2}.
Add transitions for set of states {q0, q1, q2} to the transition table T’.

State /
a b
Alphabet

→q0 q0 {q0, q1}


{q0, q1,
{q0, q1} q0
q2}
{q0, q1,
{q0, q1, q2} q0
CST- 3 TOC BY: SRABANTI CHAKRABORTY HOD, CST ; EIEM
q2}
Step-05
• Since no new states are left to be
added in the transition table T’,

• Do have to stop.

• States containing q2 as its component


are treated as final states of the DFA.
CST- 3 TOC BY: SRABANTI CHAKRABORTY HOD, CST ; EIEM
Finally, Transition table
for Deterministic Finite
Automata (DFA) is-

State /
a b
Alphabet
→q0 q0 {q0, q1}
*{q0, q1,
{q0, q1} q0
q2}
*{q0, q1,
*{q0, q1, q2} q0
q2}
CST- 3 TOC BY: SRABANTI CHAKRABORTY HOD, CST ; EIEM
Final Deterministic Finite Automata
(DFA)

FIG : DFA of the NDFA M1


CST- 3 TOC BY: SRABANTI CHAKRABORTY HOD, CST ; EIEM
rules while convert
ndfa to dfa

CST- 3 TOC BY: SRABANTI CHAKRABORTY HOD, CST ; EIEM


Note-01:
• After conversion, the number of states in the resulting
DFA may or may not be same as NFA.
• The maximum number of states that may be present in the
DFA are 2Number of states in the NFA.

CST- 3 TOC BY: SRABANTI CHAKRABORTY HOD, CST ; EIEM


Note-02:
In general, the following relationship exists between
the number of states in the NFA and DFA- 1 <=
n <= 2m
Here,
n = Number of states in the DFA
m = Number of states in the NDFA

CST- 3 TOC BY: SRABANTI CHAKRABORTY HOD, CST ; EIEM


Note-03:
In the resulting DFA, all those states
that contain
the final state(s) of NFA are treated
as final states.

CST- 3 TOC BY: SRABANTI CHAKRABORTY HOD, CST ; EIEM


CST- 3 TOC BY: SRABANTI CHAKRABORTY HOD, CST ; EIEM
Q / A SESSION
?

CST- 3 TOC BY: SRABANTI CHAKRABORTY HOD, CST ; EIEM


ASSIGNMENT #2

CST- 3 TOC BY: SRABANTI CHAKRABORTY HOD, CST ; EIEM


QUESTIONS :

1. Draw DFA with ∑ = {0, 1}


accepts all ending with 0.

CST- 3 TOC BY: SRABANTI CHAKRABORTY HOD, CST ; EIEM


QUESTIONS:
2. Convert the following NDFA to DFA.

CST- 3 TOC BY: SRABANTI CHAKRABORTY HOD, CST ; EIEM


QUESTIONS:
3. Convert the following NDFA to DFA.

CST- 3 TOC BY: SRABANTI CHAKRABORTY HOD, CST ; EIEM


CST- 3 TOC BY: SRABANTI CHAKRABORTY HOD, CST ; EIEM

You might also like