Automata Chapter 2 Exercises
Automata Chapter 2 Exercises
Prepared By
Noshin Tahsin
Lecturer, Department of Computer Science and Engineering
BSMRU, Kishoreganj
Exercise 1
∑ = {0, 1}
Transition Diagram:
q0 = {q0}
F = {q2}
2
Exercise 1 (Solution)
q0 = {q0}
F = {q2}
Present Next state Next State
State for Input 0 of Input 1
→q0 q0 q1
q1 q2 q1
*q2 q2 q2
3
Exercise 2
Draw the state diagram and transition table for a DFA with ∑ = {0, 1} accepts all
starting with 0.
4
Exercise 2 (Solution)
Draw the state diagram and transition table for a DFA with ∑ = {0, 1} accepts all
starting with 0.
5
Exercise 3
Draw the state diagram and transition table for a DFA with ∑ = {0, 1} accepts all
ending with 0.
6
Exercise 3 (Solution)
Draw the state diagram and transition table for a DFA with ∑ = {0, 1} accepts all
ending with 0.
7
Exercise 4
Design a FA with ∑ = {0, 1} accepts those string which starts with 1 and ends with 0.
8
Exercise 4 (Solution)
Design a FA with ∑ = {0, 1} accepts those string which starts with 1 and ends with 0.
9
Exercise 5
Design a FA with ∑ = {0, 1} accepts the only input 101.
10
Exercise 5 (Solution)
Design a FA with ∑ = {0, 1} accepts the only input 101.
11
Exercise 6
Design a FA with ∑ = {0, 1} accepts the strings with an even number of 0's followed by
single 1.
12
Exercise 6 (Solution)
Design a FA with ∑ = {0, 1} accepts the strings with an even number of 0's followed by
single 1.
13
Exercise 7
Construct the transition table for the following NFA.
14
Exercise 7 (Solution)
Construct the transition table for the following NFA.
→q0 q0, q1 q1
q1 q2 q0
*q2 q2 q1, q2
15
Exercise 8
Construct the NFA with ∑ = {0, 1} that accepts all strings of length at least 2.
16
Exercise 8 (Solution)
Construct the NFA with ∑ = {0, 1} that accepts all strings of length at least 2.
→q0 q1 q1
q1 q2 q2
*q2 ε ε
17
Exercise 9
Design an NFA for the transition table as given below:
Present 0 1
State
q1 q3 ε
q2 q2, q3 q3
→q3 q3 q3
18
Exercise 9 (Solution)
Design an NFA for the transition table as given below:
Present 0 1
State
q1 q3 ε
q2 q2, q3 q3
→q3 q3 q3
19
Exercise 10
Design an NFA with ∑ = {0, 1} accepts all strings in which the third symbol from the right end
is always 0.
20
Exercise 10 (Solution)
Design an NFA with ∑ = {0, 1} accepts all strings in which the third symbol from the right end
is always 0.
21
Exercise 11
22
Exercise 11 (Solution)
23
Exercise 12
Convert the given NFA to DFA.
24
Solution
State 0 1
→q0 q0 q1
q1 {q1, q2} q1
25
Solution Step 2: Now we will obtain δ'
transition for all the states
State 0 1
The δ' transition for state q0 is
obtained as:
→q0 q0 q1
δ'([q0], 0) = [q0]
δ'([q0], 1) = [q1]
q1 {q1, q2} q1
The δ' transition for state q1 is
obtained as:
*q2 q2 {q1, q2}
δ'([q1], 0) = [q1, q2] (new state generated)
δ'([q1], 1) = [q1]
Table: The transition table for the
NFA
26
Solution Step 2: Now we will obtain δ'
transition for all the states
State 0 1
The δ' transition for state q0 is
obtained as:
→q0 q0 q1
δ'([q0], 0) = [q0]
δ'([q0], 1) = [q1]
q1 {q1, q2} q1
The δ' transition for state q1 is
obtained as:
*q2 q2 {q1, q2}
δ'([q1], 0) = [q1, q2] (new state generated)
δ'([q1], 1) = [q1]
Table: The transition table for the
NFA The δ' transition for state q2 is
obtained as:
δ'([q2], 0) = [q2]
δ'([q2], 1) = [q1, q2]
27
Solution Step 2: Now we will obtain δ'
transition for all the states
State 0 1
Now we will obtain δ' transition on [q1, q2].
28
Solution Step 3: Construct the transition table for the DFA
State 0 1 State 0 1
29
Solution
Step 4: Draw the transition diagram
State 0 1
30
Solution
State 0 1
31
Exercise 13
Convert the given NFA to DFA.
32
Solution
Step 1: For the given transition diagram,
we will first construct the transition
table.
State 0 1
33
Step 2: Obtain transition states
Solution
Now we will obtain δ' transition for state q0.
Step 1: For the given transition diagram,
we will first construct the transition
δ'([q0], 0) = {q0, q1}
table.
= [q0, q1] (new state generated)
State 0 1
δ'([q0], 1) = {q1} = [q1]
→q0 {q0, q1} {q1} The δ' transition for state q1 is obtained as:
δ'([q1], 0) = ϕ
*q1 ϕ {q0, q1}
δ'([q1], 1) = [q0, q1]
34
Step 2: Obtain transition states
Solution
Now we will obtain δ' transition on [q0, q1].
Step 1: For the given transition diagram, δ'([q0, q1], 0) = δ(q0, 0) ∪ δ(q1,
we will first construct the transition
0)
table.
= {q0, q1} ∪ ϕ
State 0 1
= {q0, q1}
= [q0, q1]
→q0 {q0, q1} {q1}
Similarly,
δ'([q0, q1], 1) = δ(q0, 1) ∪ δ(q1, 1)
*q1 ϕ {q0, q1}
= {q1} ∪ {q0, q1}
= {q0, q1}
= [q0, q1]
35
Step 3: Construct the transition table from
Solution the transition states
Step 1: For the given transition diagram, As in the given NFA, q1 is a final state, then in DFA
we will first construct the transition wherever, q1 exists that state becomes a final state.
table. Hence in the DFA, final states are [q1] and [q0, q1].
Therefore set of final states F = {[q1], [q0, q1]}.
State 0 1 The transition table for the constructed DFA will be:
State 0 1
→q0 {q0, q1} {q1}
36
Solution Step 4: Construct the transition diagram
from the transition table
The transition table for the constructed DFA will
be:
State 0 1
37
Solution Step 4: Construct the transition diagram
Even we can change the name of the from the transition table
states of DFA.
A = [q0]
B = [q1]
C = [q0, q1]
38
Minimization of DFA
● Minimization of DFA means reducing the number of states from a given FA.
Thus, we get the FSM (finite state machine) with redundant states after
minimizing the FSM.
● We have to follow the various steps to minimize the DFA. These are as follows:
● Step 1: Remove all the states that are unreachable from the initial state via any
set of the transition of DFA.
39
Exercise 14
Minimize the following DFA.
40
Solution
Minimize the following DFA.
41
Exercise 16: Eliminating ε Transitions
Convert the following NFA with ε to NFA without ε.
42
Solution
Convert the following NFA with ε to NFA without ε.
ε-closure(q0) = {q0}
ε-closure(q1) = {q1, q2}
ε-closure(q2) = {q2}
43
Solution
Convert the following NFA with ε to NFA without ε.
Now the δ' transition on each input symbol is
obtained as:
44
Solution
Convert the following NFA with ε to NFA without ε.
Now the δ' transition on q1 is obtained as:
45
Solution
Convert the following NFA with ε to NFA without ε.
The δ' transition on q2 is obtained as:
46
Solution
Convert the following NFA with ε to NFA without ε.
Now we will summarize all the
computed δ' transitions:
47
Solution
ε-closures of q0, q1 and q2:
States a b
ε-closure(q0) = {q0}
ε-closure(q1) = {q1, q2}
→q0 {q1, q2} Ф
ε-closure(q2) = {q2}
48
Solution The NFA can be shown by the following transition
diagram:
States a b
*q1 Ф {q2}
*q2 Ф {q2}
49
Conversion from NFA with ε to DFA
Step 1: We will take the ε-closure for the starting state of NFA as a starting state of
DFA.
Step 2: Find the states for each input symbol that can be traversed from the present.
That means the union of transition value and their closures for each state of NFA
present in the current state of DFA.
Step 3: If we found a new state, take it as current state and repeat step 2.
Step 4: Repeat Step 2 and Step 3 until there is no new state present in the transition
table of DFA.
Step 5: Mark the states of DFA as a final state which contains the final state of NFA.
50
Conversion from NFA with ε to DFA
51
Conversion from NFA with ε to DFA
52
Conversion from NFA with ε to DFA
53
Conversion from NFA with ε to DFA
ε-closure {q0} = {q0, q1, q2} δ'(B, 0) = ε-closure {δ(q3, 0) }
ε-closure {q1} = {q1} =ϕ
ε-closure {q2} = {q2} δ'(B, 1) = ε-closure {δ(q3, 1) }
ε-closure {q3} = {q3}
= ε-closure {q4}
ε-closure {q4} = {q4}
= {q4} i.e. state C
Now, let ε-closure {q0} = {q0, q1, q2} be
state A.
54
Conversion from NFA with ε to DFA
δ'(B, 0) = ε-closure {δ(q3, 0) }
The partial DFA will be =ϕ
δ'(B, 1) = ε-closure {δ(q3, 1) }
= ε-closure {q4}
= {q4} i.e. state C
55
Conversion from NFA with ε to DFA
Convert the given NFA into its equivalent DFA.
56
Conversion from NFA with ε to DFA
Convert the given NFA into its equivalent DFA.
57
Conversion from NFA with ε to DFA
Convert the given NFA into its equivalent DFA.
δ'(A, 0) = A
δ'(A, 1) = B
δ'(A, 2) = C
58
Conversion from NFA with ε to DFA
Convert the given NFA into its equivalent DFA. The partial DFA will be:
δ'(A, 0) = A
δ'(A, 1) = B
δ'(A, 2) = C
59
Conversion from NFA with ε to DFA
Convert the given NFA into its equivalent DFA.
60
Conversion from NFA with ε to DFA
Convert the given NFA into its equivalent DFA.
δ'(B, 0) = ϕ
δ'(B, 1) = B
δ'(B, 2) = C
61
Conversion from NFA with ε to DFA
Convert the given NFA into its equivalent DFA.
The partial transition diagram will be
δ'(B, 0) = ϕ
δ'(B, 1) = B
δ'(B, 2) = C
62
Conversion from NFA with ε to DFA
Convert the given NFA into its equivalent DFA.
63
Conversion from NFA with ε to DFA
Convert the given NFA into its equivalent DFA.
Hence the final DFA is:
64
Conversion from NFA with ε to DFA
Convert the given NFA into its equivalent DFA.
Hence the final DFA is:
65
Resource List
1. DFA | Deterministic Finite Automata - Javatpoint
2. Examples of DFA
66