TIC 2151 – Theory of Computation
Lecture 2
Finite Automat II
TIC 2151 – Theory of Computation
3/19/202
3 1
Lecture 2 - Outline
Removing ε-transition from NFAs.
Converting an NFA to a DFA.
Minimizing a DFA.
3/19/2023 2
Main point to note
Get this point from now! DFAs and NFAs are equivalent in
power.
DFA ≡ NFA
Two machines are equivalent if they recognize the same
language
Every nondeterministic finite automaton has an equivalent
deterministic finite automaton.
A DFA is a special case of an NFA
3
Point to remember
For now we can say:
RLs: Languages that can be represented by a DFA / NFA
DFA = NFA (later it will be DFA = NFA = RE = RG)
When asked if a language L is regular, the answer must be YES if
you can represent L using a DFA / NFA
4
The formal description of An (ε-NFA)
In NFAs Epsilon means present state can go to other state without any
input.
5
ε-closure
Epsilon closure (ε-closure) is finding all the states which can be reached from the
present state on one or more epsilon transitions.
Epsilon Closure (in plain English)
The Epsilon Closure of a state is:
• The state itself
• All other states reachable from the state via the epsilon transition.
In the example:
• ECLOSE(q0) ={q0, q1, q2, q5}
• ECLOSE(q2)={q2, q5}
• ECLOSE(x)={x} for the remaining 5 states
{q1, q3, q4, q5, q6}
6
Conversion of an ε-NFA into an NFA
The state diagram of a finite automaton
In order Convert an ε-NFA into an NFA without ε
Step 1. we need to find ECLOSEδ(z0),
ECLOSEδ(z1),
ECLOSEδ(z2)!
Lets define ECLOSEδ : state => { state } for δ
ECLOSEδ(q) =Df
q ∈ ECLOSEδ(q)
if p ∈ ECLOSEδ(q) and r ∈ δ(p, ε) then r ∈ ECLOSEδ(q)
7
Conversion of an ε-NFA into an NFA
The state diagram of a finite automaton
Step 2. build a complete new table for the new transition function δN
and fill without ε
State = q, Symbol = s
Step 3. Build new state diagram (NFA) based on the new table
8
Conversion of an ε-NFA into an NFA
The state diagram of a finite automaton
Steps 1 and 2
Build the complete new table for δN: How do you obtain this?
9
Conversion of an ε-NFA into an NFA
Computing δNFA Entries
Step 1
Step 2
10
Conversion of an ε-NFA into an NFA
Computing δNFA Entries
Step 1
Step 2
11
Conversion of an ε-NFA into an NFA
Computing δNFA Entries
Step 1
Step 2
REMEMBER: if the initial state can reach final states on ε(s) the
initial state is considered as final state also.
Ex: when we build the new NFA z0 will be a final state as well because in the
state diagram above from z0 we can reach final state z2 with only ε(s)
12
Conversion of an ε-NFA into an NFA
Step 1. Find epsilon closure ECLOSEδ(z0), ECLOSEδ(z1), ECLOSEδ(z2)!
Step 2. Build a complete new transition table without ε
Step 3. Draw the new automaton NFA w/o ε
REMEMBER: in the new NFA z0 will be a final
state as well because in the state diagram above
from z0 we can reach final state z2 with only ε(s)
13
Conversion of an ε-NFA into an NFA
2: Convert the following NFA N into an NFA N' without ε-transition.
• ECLOSE(q0) ={q0, q1, q2, q5}
•ECLOSE(q2)={q2, q5}
• ECLOSE(x)={x} for the remaining 5 states
{q1, q3, q4, q5, q6}
The construction of N' begins with N as input,
and takes 3 steps:
• Make q0 an accepting state of N' iff
ECLOSE(q0) contains an accepting state of N.
• Add an arc from q to x labeled a iff there is an
arc labeled a in N from some state in
ECLOSE(q) to x.
• Delete all arcs labeled ε.
NFA N 14
Conversion of an ε-NFA into an NFA
2: Convert the following NFA N into an NFA N' without ε-transition.
ε-NFA NFA w/o ε
15
Conversion of an NFA into a DFA
The state diagram of a finite automaton (NFA)
Convert the above NFA into a DFA
ε
1. Conversion of an -NFA into an NFA (if ε is found)
2. Write down the powerset of all the states and let the transitions function operate over
this powerset.
?
16
Conversion of an NFA into a DFA ΙΙ
3. Choose a fresh variable or a representative for each
subset.(optional)
4. Draw the new automaton DFA
17
Minimization of a DFA
Two DFAs are equivalent if they accept the same language.
Equivalent DFAs may have different number of states, so we are
interested in finding the DFA with the minimal number of states.
1) Factorize the set of states by the same output.
2) Make the factorizing relation finer, if the transition
operation is not stable. Divide the instable partition.
3) Repeat 2) until the transition operation is stable.
18
Minimization of a DFA
Example
Take the given nondeterministic finite automaton and convert it into
an equivalent deterministic finite automaton. Then minimize it.
19
Minimization of a DFA Example
NFA
NFA
T.table
1. Convert the ε-NFA into an NFA (if ε is found)
NFA into DFA
2. Complete the transition Table (powerset) and re-label
This is a DFA Table
but not Minimized.
You can draw the DFA.
(not necessary)
20
Minimization of a DFA Example
NFA
Step 1 Step 2
NFA Table
Step 3
DFA Table
Minimize the DFA
1. Remove Unreachable states if any (if you can`t see them you can remove later)
2. Group the states in Table into two groups. final states (C,E,F and G) and The non-final states (Z,A,B and D).
3. For each state, we show the next state (i.e. output) for each input symbol.
Final states Non-Final states
4. Check stability for each group. G1 is stable because for all states, the same input will produce output in the
same group. G2 is not stable and needs to be broken up into two smaller groups.
21
Minimization of a DFA Example
NFA
NFA Table
DFA Table
G2 has been split into G2 and G3,
4. all groups needs to be check for stability again. G1 is still stable. However, both G2 and G3 are not stable.
split G2 and G3. The results G1 is stable, then the minimized DFA will have 5 states: G1, Z, A, B and D.
22
Minimization of a DFA Example
The minimized DFA will have 5 states: G1, Z, A, B and D.
0,1
0 0 B 1
Z
G1 0
1
0 1
D A
1
5. Remove Unreachable states if any …. Next slide 23
Minimization of a DFA Example
Unreachable states: We may simplify this machine by observing that no arrows point at states D
so it may be removed without affecting the performance of the machine. Doing so yields the
following figure.
It is preferable to check the DFA diagram or DFA transition table for Unreachable states
before starting the Minimization process to simplify the process.
0,1 0,1
0 0 B 1 0 1
Z 0 B Z
G1 0 0
1 G1 1
0 1 1
D A A
1
24
Minimization of a DFA Example 2
In this example the DFA diagram is given , we can start minimization without the
need for the transition table (optional).
G1 G3
G2 G1 G3 G3
25
Minimization of a NFA
Note, that our nice minimization algorithm cannot work for NFA,
Take a look at the following NFA. If you group the states together as usual in nonaccepting
and accepting states:
{A,C} {B}
you have to divide {A,C} further as both are different. You come out with the same
automaton as before minimization.
26
Applications of Finite Automata
1. Compiler design
2. Regular expressions in programming languages
3. Natural language processing
4. Algorithms in group theory
5. Automated software testing
27
Learning Outcomes
After completing this lecture, you must know how to:
• Compute the Epsilon Closure for a state in ε−NFA.
• Remove all ε-transitions from an ε−NFA.
• Convert NFA to DFA.
• Minimize a given DFA.
• Understand that NFAs and DFAs are equal in power.
References
1. A. V. Aho, M. S. Lam, R. Sethi, J. D. Ullman, Compilers: principles, techniques, and tools,
2nd Ed., Pearson, 2007.
2. J. E. F. Friedl, Mastering regular expressions, 3rd Ed., O'Reilly, 2006.
3. E. Roche, Y. Schabes (editors), Finite-state language processing, The MIT Press, 1997.
4. C. C. Sims, Computation with finitely presented groups, Cambridge University Press, 1994.
5. R. K. Shehady, D. P. Siewiorek, A method to automate user interface testing using variable
finite state machines. Proc. of the 27th Annual International Symposium of Fault-Tolerant
Computing, pp. 80-88, 1997.
28