0% found this document useful (0 votes)
26 views33 pages

Comp 303 Lec 6

Uploaded by

khedma anas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views33 pages

Comp 303 Lec 6

Uploaded by

khedma anas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

3/16/2020 Construction of an FA from an RE - Tutorialspoint

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 −

Case 1 − For a regular expression ‘a’, we can construct the following FA −

Case 2 − For a regular expression ‘ab’, we can construct the following FA −

Case 3 − For a regular expression (a+b), we can construct the following FA −

Case 4 − For a regular expression (a+b)*, we can construct the following FA −

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

Convert the following RA into its equivalent DFA − 1 (0 + 1)* 0


Solution

We will concatenate three expressions "1", "(0 + 1)*" and "0"

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.

Finite Automata with Null Moves (NFA-ε)


A Finite Automaton with null moves (FA-ε) does transit not only after giving input from the alphabet set but also without any input symbol. This
transition without input is called a null move.

An NFA-ε is represented formally by a 5-tuple (Q, ∑, δ, q0, F), consisting of


Q − a finite set of states
∑ − a finite set of input symbols
δ − a transition function δ : Q × (∑ ∪ {ε}) → 2Q

q0 − an initial state q0 ∈ Q
F − a set of final state/states of Q (F⊆Q).
(F⊆Q).
(F⊆

The above (FA-ε) accepts a string set − {0, 1, 01}

Removal of Null Moves from Finite Automata


If in an NDFA, there is ϵ-move between vertex X to vertex Y, we can remove it using the following steps −
Find all the outgoing edges from Y.
Copy all these edges starting from X without changing the edge labels.
If X is an initial state, make Y also an initial state.

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.

Here the outgoing edges from qf is to qf for inputs 0 and 1.


Step 2 −
Now we will Copy all these edges from q1 without changing the edges from qf and get the following FA −

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 −

Here qf is a final state, so we make q1 also a final state.


So the FA becomes −

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)*.

Solutions: (a): Start a, b

a, b a, b
(b): Start

b
a a
(c): Start
b a, b

Quiz. Find a DFA for the language of a + aa*b.


Solution: a a
a 1 2
Start 0 b b
b
4 3
a, b
2
a, b
Table Representation of a DFA
A DFA over A can be represented by a transition function T : States × A → States, where
T(i, a) is the state reached from state i along the edge labeled a, and we mark the start and
final states. For example, the following figures show a DFA and its transition table.

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

Table representation of NFA


An NFA over A can be represented by a function T : States × A ∪ {Λ} → power(States),
where T(i, a) is the set of states reached from state i along the edge labeled a, and we mark
the start and final states. The following figure shows the table for the preceding NFA.

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)*.

Solutions: (a): Start

(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 ƒ

Connect to start Connect from each


state of FA final state of 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 ƒ

Eliminate state 1 to obtain: a*a(ba*a)*


new(s, f) = ∅ + a*a(ba*a)*Λ = a*a(ba*a)*. s ƒ

Second Solution: Eliminate state 1 to obtain: a + ab


new(0, f) = ∅ + a∅*Λ = a.
Λ a
new(0, 0) = a + a∅*b = a + ab. s 0 ƒ

Eliminate state 0 to obtain:


(a + ab)*a
new(s, f) = ∅ + Λ(a + ab)*a = (a + ab)*a. s ƒ
8
Quiz. Use regular algebra to show the following equality from the previous quiz.
a*a(ba*a)* = (a + ab)*a.
Proof: a*a(ba*a)* = a*[a((ba*)a)*] · is associative
= a*[(a(ba*))*a] R(SR)* = (RS)*R
= a*[((ab)a*)*a] · is associative
= [a*((ab)a*)*]a · is associative
= (a + ab)*a R*(SR*)* = (R + S)*. QED.

Automata with Output (Mealy and Moore)


Mealy machine: Associate an output action with each a/A
i j
transition between states.
Moore machine: Associate an output action with each state. a
i/A j/B
Theorem: Mealy and Moore machines are equivalent.
Example/Quiz. Output the complement of a binary number.
1/1 0
Solutions: 0/1 0
Start 0 Start 0/Λ 0 1
1/0 1
2/0 1

Challenge: Describe a two-floor elevator system with a Mealy or Moore machine. 9


Automata Theory II B

Q. For  = {a, b} construct DFA that accepts all strings with


exactly one ‘a’ .
A.

Dept. of Computer Science & IT, FUUAST Automata Theory 2


Automata Theory II B

Q. For  = {a, b} construct DFA that accepts all strings


with at least one ‘a’ .
A.

Dept. of Computer Science & IT, FUUAST Automata Theory 3


Automata Theory II B

Q. For  = {a, b} construct DFA that accepts all strings


with no more than three a’s.
A.

Dept. of Computer Science & IT, FUUAST Automata Theory 4


Automata Theory II B

Q. For  = {a, b} construct DFA that accepts all strings


with at least one ‘a’ and exactly two b’s.
A.

Dept. of Computer Science & IT, FUUAST Automata Theory 5


Automata Theory II B

Q. Determine a DFA that accepts all strings on {0, 1}


except those containing the substring 001.
A.

Dept. of Computer Science & IT, FUUAST Automata Theory 6


Automata Theory II B

Q. Obtain the NFA for a language defined by


L = {anbm | n,m  1}
A.

Dept. of Computer Science & IT, FUUAST Automata Theory 7


Automata Theory II B

Q. Construct an NFA for the state table given below.


d 0 1
q0 {q0, q1} {q3}
q1 {q0} {q1, q3}
q2 F {q0, q2}
q3 {q0, q2, q3} q1

A.

Dept. of Computer Science & IT, FUUAST Automata Theory 8


Automata Theory II B

Q. Obtain the language recognized by the NDA shown below.

A.
L = { 0n, 0n01, 0n11 | n  0

Dept. of Computer Science & IT, FUUAST Automata Theory 9


Automata Theory II B

Q. Determine the DFA that accepts the language


L(aa* + aba* + b*)
A.

Dept. of Computer Science & IT, FUUAST Automata Theory 10


Automata Theory II B

Q. Determine the DFA that accepts the language


L(ab(a + ab*(a + aa)))

A.

Dept. of Computer Science & IT, FUUAST Automata Theory 11


Automata Theory II B

Q. Determine the regular expression for the language


accepted by the following automaton.

A. L = b*.aa*.ab*.a

Dept. of Computer Science & IT, FUUAST Automata Theory 12


Automata Theory II B

Q. Determine the regular expression for the language


accepted by the following automaton.

A. L = (aabb)* + b(bab)*.(ba)*b + (ab)*

Dept. of Computer Science & IT, FUUAST Automata Theory 13


Automata Theory II B

Q. Determine the regular expression for the language


accepted by the following automaton.

A. L = a*.ba*

Dept. of Computer Science & IT, FUUAST Automata Theory 14


3/16/2020 Automata Conversion of RE to FA - Javatpoint

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.

Step 2: Convert this NFA with ε to NFA without ε.

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

Step 3: Convert the obtained NFA to equivalent DFA.

Example 1:

Design a FA from given regular expression 10 + (0 + 11)0* 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

→q0 q3 {q1, q2}

q1 qf ϕ

q2 ϕ q3

q3 q3 qf

*qf ϕ ϕ

The equivalent DFA will be:

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

→[q0] [q3] [q1, q2]

[q1] [qf] ϕ

[q2] ϕ [q3]

[q3] [q3] [qf]

[q1, q2] [qf] [qf]

*[qf] ϕ ϕ

Example 2:

Design a NFA from given regular expression 1 (1* 01* 01*)*.

Solution: The NFA for the given regular expression is as follows:

Step 1:

Step 2:

Step 3:

Example 3:

Construct the FA for regular expression 0*1 + 10.

Solution:

We will first construct FA for R = 0*1 + 10 as follows:

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 →

Help Others, Please Share ⇧

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?

Learn Latest Tutorials

Openpyxl Tally Godot Spring Boot

Gradle UML ANN ES6

Flutter Selenium Py Firebase Cobol

Preparation

Aptitude Reasoning Verbal A. Interview

Company

Trending Technologies

AI AWS Selenium Cloud

https://www.javatpoint.com/automata-conversion-of-re-to-fa 5/6
3/16/2020 Automata Conversion of RE to FA - Javatpoint

Hadoop ReactJS D. Science Angular 7

Blockchain Git ML DevOps

B.Tech / MCA

DBMS DS DAA OS

C. Network Compiler D. COA D. Math.

E. Hacking C. Graphics Software E. Web Tech.

Cyber Sec. Automata C C++

Java .Net Python Programs

Control S. Data Mining

https://www.javatpoint.com/automata-conversion-of-re-to-fa 6/6

You might also like