Comp 303 Lec 6
Comp 303 Lec 6
Construction of an FA from an RE
We can use Thompson's Construction to find out a Finite Automaton from a Regular Expression. We will reduce the regular expression into
smallest regular expressions and converting these to NFA and finally to DFA.
Some basic RA expressions are the following −
Method
Step 1 Construct an NFA with Null moves from the given regular expression.
Step 2 Remove Null transition from the NFA and convert it into its equivalent DFA.
Problem
https://www.tutorialspoint.com/automata_theory/constructing_fa_from_re.htm 1/4
3/16/2020 Construction of an FA from an RE - Tutorialspoint
Now we will remove the ε transitions. After we remove the ε transitions from the NDFA, we get the following −
It is an NDFA corresponding to the RE − 1 (0 + 1)* 0. If you want to convert it into a DFA, simply apply the method of converting NDFA to DFA
discussed in Chapter 1.
q0 − an initial state q0 ∈ Q
F − a set of final state/states of Q (F⊆Q).
(F⊆Q).
(F⊆
https://www.tutorialspoint.com/automata_theory/constructing_fa_from_re.htm 2/4
3/16/2020 Construction of an FA from an RE - Tutorialspoint
If Y is a final state, make X also a final state.
Problem
Convert the following NFA-ε to NFA without Null move.
Solution
Step 1 −
Here the ε transition is between q1 and q2, so let q1 is X and qf is Y.
Step 3 −
Here q1 is an initial state, so we make qf also an initial state.
So the FA becomes −
https://www.tutorialspoint.com/automata_theory/constructing_fa_from_re.htm 3/4
3/16/2020 Construction of an FA from an RE - Tutorialspoint
Step 4 −
https://www.tutorialspoint.com/automata_theory/constructing_fa_from_re.htm 4/4
Section 11.2 Finite Automata
Can a machine(i.e., algorithm) recognize a regular language? Yes!
Deterministic Finite Automata
A deterministic finite automaton (DFA) over an alphabet A is a finite digraph (where
vertices or nodes are called states) for which each state emits one labeled edge for each
letter of A. One state is designated as the start state and a set of states may be final states.
Example. Either of the following alternatives is acceptable for representing a DFA, where
final states are indicated by double circles.
a b b
1 a, b 1
Start 0 b a Start 0 a
a 2 b 2 a, b
The Execution of DFA for input string w ∈ A* begins at the start state and follows a path
whose edges concatenate to w. The DFA accepts w if the path ends in a final state.
Otherwise the DFA rejects w. The language of a DFA is the set of accepted strings.
Example. The example DFA accepts the strings
a, b, ab, bb, abb, bbb, …, abn, bbn, ….
So the language of the DFA is given by the regular expression (a + b)b*. 1
Theorem (Kleene) The class of regular languages is exactly the same as the class of
languages accepted by DFAs.
Quiz. Find an DFA for each of the following languages over the alphabet {a, b}.
(a) ∅. (b) {Λ}. (c) {(ab)n | n ∈ N}, which has regular expression (ab)*.
a, b a, b
(b): Start
b
a a
(c): Start
b a, b
b T a b
a, b 1 start 0 1 1
Start 0 a
final 1 2 1
2 a, b
2 2 2
Note: T can be extended to T : States × A* → States by
T(i, Λ) = i and T(i, aw) = T(T(i, a), w) for a ∈ A and w ∈ A*.
Quiz: Calculate T(0, bba). €
Solution: T(0, bba) = T(1, ba) = T(1, a) = T(2, Λ) = 2.
Example/Quiz. Back to the problem of describing input strings over {a, b} that contain
exactly one substring bb. We observed that the strings could be described by the regular
expression (a + ba)*bb(a + ab)*. Find a DFA to recognize the language.
a b
A solution:
b a
Start a
b
b
a
a, b 3
Nondeterministic Finite Automata
A nondeterministic finite automaton (NFA) over an alphabet A is similar to a DFA except
that Λ-edges are allowed, there is no requirement to emit edges from a state, and multiple
edges with the same letter can be emitted from a state.
Example. The following NFA recognizes the language of a + aa*b + a*b.
1 a
Λ
a b
a
Start 0 2
T a b Λ
start 0 {1, 2} ∅ {1}
1 {1} {2} ∅
final 2 ∅ ∅ ∅
4
€
Theorem (Rabin and Scott) The class of regular languages is exactly the same as the
class of languages accepted by NFAs.
Quizzes. Find an NFA for each of the following languages over {a, b}.
(a) ∅. (b) {Λ}. (c) {(ab)n | n ∈ N}, which has regular expression (ab)*.
(b): Start
b
(c): Start a
ExampleQuiz. Back to the problem of describing input strings over {a, b} that contain
exactly one substring bb. We observed that the strings could be described by the regular
expression (a + ba)*bb(a + ab)*. Find an NFA to recognize the language.
A solution: a a
b b
Start
b a
a b
5
Algorithm: Transform a Regular Expression into a Finite Automaton
Start by placing the regular expression on the edge between a start and final state:
Regular expression
Start
Apply the following rules to obtain a finite automaton after erasing any ∅-edges.
R
R+S
i j transforms to i j
S
RS R S
i j transforms to i j
R
R* Λ Λ
i j transforms to i j
Quiz. Use the algorithm to construct a finite automaton for (ab)* + ba.
Answer: b a
Λ Λ
Start
b a
6
Algorithm: Transform a Finite Automaton into a Regular Expression
Connect a new start state s to the start state of the FA and connect each final state of the FA
to a new final state ƒ as shown in the figure.
Λ Given Λ
s FA ƒ
If needed, combine all multiple edges between the same two nodes into one edge with label
the sum of the labels on the multiple edges. If there is no edge between two states, assume
there is an ∅-edge.
Now eliminate each state k of the FA by constructing a new edge (i, j) for each pair of edges
(i, k) and (k, j) where i ≠ k and j ≠ k. The new label new(i, j) is defined in terms of the old
labels by the formula
new(i, j) = old(i, j) + old(i, k)old(k, k)*old(k, j)
A
Example.
A + BC*D
i B D j becomes i j
k
C 7
Quiz. Use the algorithm to transform the following NFA into a regular expression. (Half the
class eliminate state 0 then state 1 and half the class eliminate state 1 then state 0.)
a
a
Start 0 1
b
a
Solution: Connect the NFA to new a start Λ a Λ
state s and a new final state f as pictured. s 0 1 ƒ
b
First Solution: Eliminate state 0 to obtain: ba*a
new(s, 1) = ∅ + Λa*a = a*a.
new(1, 1) = ∅ + ba*a = ba*a. a*a Λ
s 1 ƒ
A.
A.
L = { 0n, 0n01, 0n11 | n 0
A.
A. L = b*.aa*.ab*.a
A. L = a*.ba*
Conversion of RE to FA
To convert the RE to FA, we are going to use a method called the subset method. This method
is used to obtain FA from the given regular expression. This method is given below:
Step 1: Design a transition diagram for given regular expression, using NFA with ε moves.
Ad closed by
Ad was
inappropriate
Stop seeing this ad
Notthis
Why interested
ad?
in this ad
Ad covered
content
Seen this ad
multiple times
Example 1:
Solution: First we will construct the transition diagram for a given regular expression.
Step 1:
Step 2:
Step 3:
https://www.javatpoint.com/automata-conversion-of-re-to-fa 1/6
3/16/2020 Automata Conversion of RE to FA - Javatpoint
Step 4:
Step 5:
Now we have got NFA without ε. Now we will convert it into required DFA for that, we will first
write a transition table for this NFA.
State 0 1
q1 qf ϕ
q2 ϕ q3
q3 q3 qf
*qf ϕ ϕ
State 0 1
⇧
https://www.javatpoint.com/automata-conversion-of-re-to-fa 2/6
3/16/2020 Automata Conversion of RE to FA - Javatpoint
[q1] [qf] ϕ
[q2] ϕ [q3]
*[qf] ϕ ϕ
Example 2:
Step 1:
Step 2:
Step 3:
Example 3:
Solution:
Step 1:
Step 2:
https://www.javatpoint.com/automata-conversion-of-re-to-fa 3/6
3/16/2020 Automata Conversion of RE to FA - Javatpoint
Step 3:
Step 4:
← prev next →
https://www.javatpoint.com/automata-conversion-of-re-to-fa 4/6
3/16/2020 Automata Conversion of RE to FA - Javatpoint
Ad closed by
Stop seeing this ad Why this ad?
Preparation
Company
Trending Technologies
https://www.javatpoint.com/automata-conversion-of-re-to-fa 5/6
3/16/2020 Automata Conversion of RE to FA - Javatpoint
B.Tech / MCA
DBMS DS DAA OS
https://www.javatpoint.com/automata-conversion-of-re-to-fa 6/6