Tutorial 02-- CSC3130 : Formal Languages
and Automata Theory
Outline
From NFA to NFA From DFA to RE Closed operators for Regular Languages
From NFA to NFA
-transitions is the empty string, “it contains no alphabets”; It makes a state transition when seeing . It makes a state transition without receiving an input
symbol (from alphabet); It makes a state transition unconditionally;
NFA NFA + Allows -transitions; It brings “programming convenience”; Closely related to regular expressions
From NFA to NFA -- an example from Lecture notes (1/8)
q0 q1 q2,b a
aNFA:
NFA: q0 q1 q2a, b a
aa
a, b
a
From NFA to NFA -- an example from Lecture notes (2/8)
q0 q1 q2,b a
aNFA:
q0 q1 q2NFA:
(1) States stay the same
(2) Start state stays the same
From NFA to NFA -- an example from Lecture notes (3/8)
q0 q1 q2,b a
aNFA:
NFA: q0 q1 q2
Path in NFA:
qi qk qj… …qma
Equivalent Path in NFA:
qjaqi
?
?
?
From NFA to NFA -- an example from Lecture notes (4/8)
q0 q1 q2,b a
aNFA:
NFA: q0 q1 q2
Path in NFA:
q0 q1 q0a
Equivalent Path in NFA:
q0aq0
a
?
?
From NFA to NFA -- an example from Lecture notes (5/8)
q0 q1 q2,b a
aNFA:
NFA:
Path in NFA:
q0 q1 q1a
Equivalent Path in NFA:
q1q0
q0 q1 q2a, b
?
a
q1bq0
a q1bq0
From NFA to NFA -- an example from Lecture notes (6/8)
q0 q1 q2,b a
aNFA:
NFA:
Path in NFA:
Equivalent Path in NFA:
q0 q1 q2a, b
a, b
a
q0 q1 q1a
q2q0
q1bq0
a q2bq0
q2 q2
From NFA to NFA -- an example from Lecture notes (7/8)
q0 q1 q2,b a
aNFA:
NFA: q0 q1 q2a, b a a
a, b
a
a
From NFA to NFA -- an example from Lecture notes (8/8)
q0 q1 q2,b a
aNFA:
NFA: q0 q1 q2a, b a
aa
a, b
a
(4) The accepting states of the NFA are all states that can reach some accepting state of NFA using only -transitions
Outline
From NFA to NFA From DFA to RE Closed operators for Regular Languages
From DFA to RE -- General construction
We inductively define Rijk as:
Rii0 = ai1
+ ai2 + … + ait
+
(all loops around qi and )
(all qi → qj)
Rijk = Rij
k-1 + Rikk-1(Rkk
k-1)*Rkjk-1
a path in Mqi
qk
qj
Rij0 = ai1
+ ai2 + … + ait
if i ≠ j
ai1,ai2
,…,ait qi
qi qj
ai1,ai2
,…,ait
(for k > 0)
From DFA to RE -- an example (1/3)
0
1
0
1
q1
q2
R110 = {, 1} = 1
+
R120 = {0} = 0
R210 = {0} = 0
R220 = {, 1} = 1
+
1q1
0q1
q2
0q1
q2
1
q2
From DFA to RE -- an example (2/3)
0
1
0
1
q1 q2
R110 = {, 1} = 1 + ; R12
0 = {0} = 0
R210 = {0} = 0; R22
0 = {, 1} = 1 +
R111 = {, 1, 11,
111, ...} = 1*
Rijk = Rij
k-1 + Rikk-1(Rkk
k-1)*Rkjk-1
R121 = R12
0 + R11
0(R110)*R12
0
= 0 + (1+ )+0
R221 = R22
0 + R21
0(R110)*R12
0
= (1 + ) + 0(1+ )*0
R122 = R12
1 + R121(R22
1)*R221
= (0 + (1+ )+0) + (0 + (1+ )+0) ((1 + ) + 0(1+ )*0)+
= (0 + (1+ )+0) ((1 + ) + 0(1+ )*0)*
= (1+ )*0 ((1 + ) + 01*0)*
= 1*0 (1 + 01*0)*
From DFA to RE (3/3) -- Determine the accepted RE for DFA
Suppose the DFA start state is q1, and the accepting states are F = {qj1
qj2 … qjt
}
Then the regular expression for this DFA is
R1j1n + R1j2
n + ….. +
R1jtn
0
0q1 q2
11
R122=1*0
(1+01*0)*
Outline
From NFA to NFA From DFA to RE Closed operators for Regular Languages
Closed operators for Regular Languages -- An Exercise
Prove or disprove the regular languages are closed under the following operations: (1). min(L) = { w | w is in L, but no proper
prefix of w is in L }; (2). max(L) = { w | w is in L and for no x other
than εis wx in L }; (3). init(L) = { w | for some x, wx is in L }
Hint: Start with a DFA for L and perform a construction to
get the desired language.
(1). min(L) = { w | w is in L, but no proper prefix of w is in L };
What is “proper prefix”?
For example, suppose the alphabet is { 0, 1 }, then:
(1) “011”, “01” are proper prefixes of “0110001”;
(2) “0110001” is a prefix of “0110001”, but not a proper prefix;
(3) “” (i.e., ε) is not a proper prefix of “0110001”.
(1). min(L) = { w | w is in L, but no proper prefix of w is in L };
What does min(L) look like?
Main idea:
uq0
qj qkx
w=ux
A DFA for L:
Cut the transitions going out of each accepting state.
Example(1). L = { 00, 001, 0011, 101 }; min(L) = ?
{ 00, 001, 0011, 101 }
0 0 1 1
1 0 1
Example(2).
L = { a, a(bc)n, baa, cbma }; min(L) = ?
n,m = 0,1,2,…
Solution for (1)min(L) = { w | w is in L, but no proper prefix of w is in L };
Solution for (1) -- (cont.)min(L) = { w | w is in L, but no proper prefix of w is in L };
Properties of Regular Languages -- An Exercise Prove or disprove the regular languages are
closed under the following operations: (1). min(L) = { w | w is in L, but no proper
prefix of w is in L }; (2). max(L) = { w | w is in L and for no x other
than εis wx in L }; (3). init(L) = { w | for some x, wx is in L }
Hint: Start with a DFA for L and perform a construction to
get the desired language.
Left as exercises at home!
End of this tutorial!Thanks for coming!