Chapter 2 Part 2
Chapter 2 Part 2
(NDFA or NFA)
• NFAs can have more than one transition leaving a state on the
same symbol.
• NFAs may have transitions with empty string label
– May move to new state without consuming character
• It is easy to construct NFA than DFA for a given regular
language.
• Every NFA is not DFA, but each NFA can be translated into
DFA. This is because
– DFA is only one path for specific input
– NFA is having many paths for specific input
• NFA is defined in the same way as DFA but with two
exception.
i. It contains multiple next state
1
ii. It contains transition
Cont…
• The nondeterministic finite automaton is a variant of
finite automaton with two characteristics:
– -transition: state transition can be made without
reading a symbol;
– Non-determinism: zero or more than one possible
value may exist for state transition.
2
Formal Definition of an NDFA
• An NDFA can be represented by a 5-tuples of M= (Q,
Σ, δ, q0, F) where:
– Q: is a finite set of states.
– Σ: is a finite set of symbols called the alphabets.
– : is the transition function where , NFA has
multiple state.
– q0: is the initial state from where any input is processed
(q0 ∈ Q).
– F: is a set of final state/states of Q (F ⊆ Q)
3
Graphical Representation of an
NDFA
• It is same as DFA
• An NDFA is represented by digraphs called state diagram.
– The vertices represent the states.
– The arcs labeled with an input alphabet show the
transitions.
– The initial state is denoted by an empty single incoming
arc.
– The final state is indicated by double circles.
4
• Let M = (Q, Σ, δ,q0,F) be an NFA-ε and let w be in Σ*. Then
w is accepted by M iff δ({q0}, w) contains at least one state in
F.
5
More example
1. M=(Q = {q0, q1, q2}, ∑ = {0, 1}, q0 = {q0}, F = {q2})
– Transition diagram
→q0 q1 q1
• Transition table q1 q2 q2
*q2 ε ε
8
Difference b/n NFA and DFA
SR.NO
. DFA NFA
1 DFA stands for Deterministic Finite Automata. NFA stands for Nondeterministic Finite Automata.
2 DFA cannot use Empty String transition. NFA can use Empty String transition.
6 Time needed for executing an input string is less. Time needed for executing an input string is more.
8 DFA requires more space. NFA requires less space than DFA.
9
Convert NFA to Equivalent DFA
• The following steps are followed to convert a given NFA to a
DFA-
Step-01:
– Let Q’ be a new set of states of the DFA. Q’ is null in the starting.
– Let T’ be a new transition table of the DFA.
• Step-02:
– Add start state of the NFA to Q’.
– Add transitions of the start state to the transition table T’.
– If start state makes transition to multiple states for some input
alphabet, then treat those multiple states as a single state in the
DFA.
– In NFA, if the transition of start state over some input alphabet is
null,
– then perform the transition of start state over that input alphabet
to a dead state in the DFA.
10
• Step-03:
– If any new state is present in the transition table T’,
– Add the new state in Q’.
– Add transitions of that state in the transition table T’.
• Step-04:
– Keep repeating Step-03 until no new state is present
in the transition table T’.
– Finally, the transition table T’ so obtained is the
complete transition table of the required DFA.
11
• Convert the following Non-Deterministic Finite
Automata (NFA) to Deterministic Finite
Automata (DFA)-
12
• Transition table for the given Non-Deterministic
Finite Automata (NFA) is-
State / Alphabet a b
→q0 q0 q0, q1
q1 – *q2
*q2 – –
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.
13
• Step-02:
• Add transitions of start state q0 to the
transition table T’.
State / Alphabet a b
→q0 q0 {q0, q1}
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 / Alphabet a b
→q0 q0 {q0, q1}
{q0, q1} q0 {q0, q1, q2}
14
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 / Alphabet a b
15
Step-05:
• Since no new states are left to be added in the transition table
T’, so we stop.
• States containing q2 as its component are treated as final states
of the DFA.
• Finally, Transition table for Deterministic Finite Automata (DFA)
is-
State / Alphabet a b
16
Now, Deterministic Finite Automata (DFA) may be drawn as-
17
Problem 2: Convert the following Non-Deterministic Finite Autom
ata (NFA) to Deterministic Finite Automata (DFA)-
Solution
18
Problem 3: Convert the following Non-Deterministic Finite Autom
ata (NFA) to Deterministic Finite Automata (DFA)-
Solution
19
• When there are unreachable states invloved
– Unreachable states are the states that are not
reachable from the initial state of the DFA, for any
input string. These states can be removed.
– Example
– Solution
20
• Important Points-
– It is important to note the following points when converting a given NFA
into a DFA-
– 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.
• 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 NFA
• In the resulting DFA, all those states that contain the final state(s) of
NFA are treated as final states.
• Dead states are the states from which no final state is reachable. These
states can be removed unless the automaton is required to
be complete.
• Nondistinguishable states are those that cannot be distinguished from
one another for any input string. These states can be merged.
21
22
Minimization of DFA
• MINIMIZATION OF DFA is the procedure through
which we can obtain minimized DFA which consists
of a minimum number of states.
• There are two classes of states that can be removed or
merged from the original DFA without affecting the
language it accepts to minimize it.
1. Unreachable states are the states that are not reachable
from the initial state of the DFA, for any input string.
2. Non-distinguishable states are those that cannot be
distinguished from one another for any input string.
23
DFA minimzation 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. Two states are
distinguishable, if there is at least one string S, such that one of δ (X, S)
and δ (Y, S) is accepting and another is not accepting. Hence, a DFA is
minimal if and only if all the states are distinguishable.
• Step 1 − All the states Q are divided in two partitions − final
states and non-final states and are denoted by P0. All the states in a
partition are 0th equivalent. Take a counter k and initialize it with 0.
• Step 2 − Increment k by 1. For each partition in Pk, divide the states
in Pk into two partitions if they are k-distinguishable. Two states
within this partition X and Y are k-distinguishable if there is an
input S such that δ(X, S) and δ(Y, S) are (k-1)-distinguishable.
• Step 3 − If Pk ≠ Pk-1, repeat Step 2, otherwise go to Step 4.
• Step 4 − Combine kth equivalent sets and make them the new states
of the reduced DFA.
24
Let us consider the
following DFA −
q δ(q,0) δ(q,1)
a b c
b a d
c e f
d e f
e e f
f f f 25
• Let us apply the above Q δ(q,0) δ(q,1)
26
DFA Minimization using Myphill-Nerode
Theorem
• Step 1 − Draw a table for all pairs of states (Qi, Q j) not
necessarily connected directly [All are unmarked
initially]
• Step 2 − Consider every state pair (Qi, Q j) in the DFA
where Qi ∈ F and Q j ∉ F or vice versa and mark them.
[Here F is the set of final states]
• Step 3 − Repeat this step un l we cannot mark
anymore states −
• If there is an unmarked pair (Qi, Q j), mark it if the pair
{δ (Qi, A), δ (Qi, A)} is marked for some input alphabet.
• Step 4 − Combine all the unmarked pair (Qi, Q j) and
make them a single state in the reduced DFA.
27
• Example: DFA shown below.
28
• Step 1 − We draw a table for all pair of states.
a b c d e f
29
• Step 2 − We mark the state pairs.
a b c d e f
c x x
d x x
e x x
f x x x
30
• Step 3: We will try to mark the state pairs, with green colored check mark,
transitively. If we input 1 to state ‘a’ and ‘f’, it will go to state ‘c’ and ‘f’ respectively.
(c, f) is already marked, hence we will mark pair (a, f). Now, we input 1 to state ‘b’
and ‘f’; it will go to state ‘d’ and ‘f’ respectively. (d, f) is already marked, hence we
will mark pair (b, f).
a b c d e f
c x x
d x x
e x x
f x x X x x
31
• After step 3, we have got state combinations {a, b} {c, d} {c, e}
{d, e} that are unmarked.
• We can recombine {c, d} {c, e} {d, e} into {c, d, e}
• Hence we got two combined states as − {a, b} and {c, d, e}
• So the final minimized DFA will contain three states {f}, {a, b}
and {c, d, e}
32
Exercise
Minimize this DFA using by two
methods
33
• Now it is the transition table of minimized
DFA.
34
35