Professional Documents
Culture Documents
Introduction To Finite Automata: Dfas and Nfas: Rahul Banerjee
Introduction To Finite Automata: Dfas and Nfas: Rahul Banerjee
Rahul Banerjee
Computer Science and Information Systems Group,
Birla Institute of Technology & Science, Pilani (India)
Home: http://www.bits-pilani.ac.in/~rahul/
E-mail: rahul@bits-pilani.ac.in
2 An Initial State qo
5
A DFA may be therefore A Set ofas
represented Final States
a five-tuple: F (F is a subset of Q)
A = (Q, ∑ , δ, qo ,F)
Each state, can be, in turn described by using an appropriate set of State
descriptors.
However, this step adds to the clarity of the problem-definition and later helps to map the Automaton into a
programmed solution as well.
1 0 0 0,1
1,0
1 qo q2 q1
q3
Each state is represented by a ‘node’ (represented by a circle) and each ‘pair
of concentric circles’ represents an ‘accepting state’ (i.e. a member of ‘F’).
δ (qn-1 ,an)
Current State | Inputs
0 1
qo q2 qo
q1 q1 q1
q2 q1 q3
q3 q3 q3
In Transition Table, ‘states’ are represented in rows and ‘inputs’ are shown in
columns. Here, arrow shows the ‘start’ state and asterisk shows the
‘accepting’ state(s).
C 3 6 2
P L C C
Only two Data Structures ‘a single variable’ (for State Number / ID) and
‘a two-dimensional Array’ (for the Transition Function) are adequate for
modeling this Finite State Machine (FSM).
Copyright (2002): Rahul Banerjee, BITS, Pilani (India) 26
The Non-deterministic Finite
Automaton (NFA) and Its Use
The term NFA and its basic significance have been discussed in slides 3-5.
This slide attempts to expand with that backdrop.
Salient Features of NFA:
• Non-determinism yet finiteness of the automaton,
• Ability to ‘predict’ / ‘guess’ its ‘input’ in a certain sense,
• Ease of mapping onto the High-Level Language constructs,
• Capability to ‘accept’ the ‘Regular languages’ (just like the DFA
does so!);
• The single reason that forms the basis for all other features is the
NFA’s capability to be in several states at any given point of time.
• NFAs are easier to design than the DFAs.
• NFA-to-DFA conversion is always possible, though at times, it may
not be necessarily simple.
2 An Initial State qo
An NFA may be, therefore, represented as a five-tuple, just like the DFA:
A = (Q, ∑ , δ, qo ,F)
The primary difference between the NFA and DFA lies here in the
‘type of the value’ returned by the Transition Function δ.
δ, in case of an NFA, returns a ‘set of states’ instead of a ‘single state’.
ε
C S C 3 6 2
0 9 12
10 11
P L C C
Copyright (2002): Rahul Banerjee, BITS, Pilani (India) 34
Modeling … into a DFA
A DFA may be seen as an NFA with two restrictions:
• No state can have an outgoing Epsilon Transition
• Only one outgoing Transition from any state carrying the same Label is
permissible
0 1 2
C S
ε 0 1 2 3 4
ε C S I S
0 ε 0 1 2 5 6 7 8
ε
C S C 3 6 2
0 9 12
10 11
P L C C
Copyright (2002): Rahul Banerjee, BITS, Pilani (India) 35
Modeling … into a DFA
Therefore, let us try generating a DFA out of this NFA now!
Step-1: Remove Epsilon Transitions and corresponding states.
1 2
1 2 3 4
0 1 2 5 6 7 8
9 9 10 11
1 2 3 4
0 5 6 7 8
9 9 10 11
1 2 3 4
0 5 6 7 8
9 10 11 12
This is your resultant DFA. (Compare it with your Slide No. 26.)
Copyright (2002): Rahul Banerjee, BITS, Pilani (India) 38
Copyright (2002): Rahul Banerjee, BITS, Pilani (India) 39
Copyright (2002): Rahul Banerjee, BITS, Pilani (India) 40