Unit-1 Part-1
Unit-1 Part-1
In the above example, q2 is a trap or dead state because it can’t reach the final state.
Example
Construct transition table of DFA for a given diagram.
Q= {q0,q1,q2}
Σ ={0,1}
q0= {q0}
F= {q2}
Transition diagram
The transition diagram is as follows −
Transition Table
The transition table is as follows −
Present state Next state for input 0 Next state for input 1
->q0 q0 q1
q1 q2 q1
*q2 q2 q2
Explanation
Step 1 − In the above table q0 is the initial state, on input ‘0’ the q0 state goes to
itself and on input ‘1’ it goes to state q1.
Step 2 − q1 is the intermediate state, on input ‘0’ q1 goes to q2 state and on input
‘1’, q1 goes to itself.
Step 3 − q2 is the final state, q2 on ‘0’ goes to q2 itself and input ‘1’ goes to q2
itself.
In the following image, we can see that from state q0 for input a, there are two next
states q1 and q2, similarly, from q0 for input b, the next states are q0 and q1. Thus it
is not fixed or determined that with a particular input where to go next. Hence this
FA is called non-deterministic finite automata.
δ: Q x ∑ →2Q
where,
Q = {a, b, c}
∑ = {0, 1}
q0 = {a}
F = {c}
The transition function δ as shown below −
Present State Next State for Input 0 Next State for Input 1
A a, b b
B c a, c
C b, c c
Example 1:
1. Q = {q0, q1, q2}
2. ∑ = {0, 1}
3. q0 = {q0}
4. F = {q2}
Solution:
Transition diagram:
Transition Table:
→q0 q0, q1 q1
q1 q2 q0
*q2 q2 q1, q2
In the above diagram, we can see that when the current state is q0, on input 0, the
next state will be q0 or q1, and on 1 input the next state will be q1. When the current
state is q1, on input 0 the next state will be q2 and on 1 input, the next state will be
q0. When the current state is q2, on 0 input the next state is q2, and on 1 input the
next state will be q1 or q2.
Example 2:
NFA with ∑ = {0, 1} accepts all strings with 01.
Solution:
Transition Table:
q1 ε q2
*q2 q2 q2
Example 3:
NFA with ∑ = {0, 1} and accept all string of length atleast 2.
Solution:
Transition Table:
→q0 q1 q1
q1 q2 q2
*q2 Ε ε
DFA NFA
DFA stands for Deterministic Finite NFA stands for Nondeterministic Finite
Automata. Automata.
DFA NFA
DFA cannot use Empty String transition. NFA can use Empty String transition.
Time needed for executing an input Time needed for executing an input string
string is less. is more.
DFA requires more space. NFA requires less space then DFA.
δ: QxΣ -> Q i.e. next possible state δ: QxΣ -> 2^Q i.e. next possible state
belongs to Q. belongs to power set of Q.
DFA allows only one move for single There can be choice (more than one
input alphabet. move) for single input alphabet.
Problem Statement
Let X = (Qx, ∑, δx, q0, Fx) be an NDFA which accepts the language L(X). We have to design
an equivalent DFA Y = (Qy, ∑, δy, q0, Fy) such that L(Y) = L(X). The following procedure
converts the NDFA to its equivalent DFA −
Algorithm
Input − An NDFA
Output − An equivalent DFA
Step 1 − Create state table from the given NDFA.
Step 2 − Create a blank state table under possible input alphabets for the equivalent DFA.
Step 3 − Mark the start state of the DFA by q0 (Same as the NDFA).
Step 4 − Find out the combination of States {Q0, Q1,... , Qn} for each possible input alphabet.
Step 5 − Each time we generate a new DFA state under the input alphabet columns, we have
to apply step 4 again, otherwise go to step 6.
Step 6 − The states which contain any of the final states of the NDFA are the final states of
the equivalent DFA.
Example 1
Let us consider the NDFA shown in the figure below.
Q δ(q,0) δ(q,1)
A {a,b,c,d,e} {d,e}
B {c} {e}
C ∅ {b}
D {e} ∅
E ∅ ∅
Using the above algorithm, we find its equivalent DFA. The state table of the DFA is shown
in below.
Q δ(q,0) δ(q,1)
[d,e] [e] ∅
[e] ∅ ∅
[c, e] ∅ [b]
[c] ∅ [b]
Example 2:
Convert the given NFA to DFA.
Solution: For the given transition diagram we will first construct the transition table.
State 0 1
→q0 q0 q1
q1 {q1, q2} q1
1. δ'([q0], 0) = [q0]
2. δ'([q0], 1) = [q1]
1. δ'([q2], 0) = [q2]
2. δ'([q2], 1) = [q1, q2]
The state [q1, q2] is the final state as well because it contains a final state q2. The
transition table for the constructed DFA will be:
State 0 1
Example 3:
Convert the given NFA to DFA.
Solution: For the given transition diagram we will first construct the transition table.
State 0 1
1. δ'([q1], 0) = ϕ
2. δ'([q1], 1) = [q0, q1]
Similarly,
As in the given NFA, q1 is a final state, then in DFA wherever, q1 exists that state
becomes a final state. Hence in the DFA, final states are [q1] and [q0, q1]. Therefore
set of final states F = {[q1], [q0, q1]}.
State 0 1
Suppose
1. A = [q0]
2. B = [q1]
3. C = [q0, q1]