0% found this document useful (0 votes)
134 views

Automata and Formal Languages

This document is a tutorial on formal languages and automata theory. It discusses epsilon-NFAs and how to convert them to NFAs by replacing epsilon transitions with equivalent paths. An example is provided to illustrate the process. Regular expressions are also discussed, including how to construct a regular expression from a DFA using recursive rules. Finally, exercises are provided on proving properties of regular languages, such as whether they are closed under certain operations like taking the minimum or initial strings.

Uploaded by

Sri Sriniketh
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
134 views

Automata and Formal Languages

This document is a tutorial on formal languages and automata theory. It discusses epsilon-NFAs and how to convert them to NFAs by replacing epsilon transitions with equivalent paths. An example is provided to illustrate the process. Regular expressions are also discussed, including how to construct a regular expression from a DFA using recursive rules. Finally, exercises are provided on proving properties of regular languages, such as whether they are closed under certain operations like taking the minimum or initial strings.

Uploaded by

Sri Sriniketh
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 24

Tutorial 02

-- CSC3130 : Formal Languages


and Automata Theory
Tu Shikui ([email protected])
SHB 905, Office hour: Thursday 2:30pm-3:30pm
2008-09-12

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)
NFA:

NFA:

q0

,b
a

q0

a a, b
a

q1

q1
a, b

q2

q2

From NFA to NFA


-- an example from Lecture notes (2/8)
NFA:

q0

,b
a

q1

q2

(1) States stay the same


(2) Start

NFA:

q0

state
q1

stays the same

q2

From NFA to NFA


-- an example from Lecture notes (3/8)
NFA:
Path in NFA:

,b
a

q0

qi

qk
qi

Equivalent Path in NFA:

q1

a q
m

q2

a q
j

?
NFA:

q0

q1
?

q2

qj

From NFA to NFA


-- an example from Lecture notes (4/8)
NFA:
Path in NFA:

,b
a

q0

q0

q1

q1
a

q0

Equivalent Path in NFA:

q2

q0
q0

a
NFA:

q0

q1
?

q2

From NFA to NFA


-- an example from Lecture notes (5/8)
NFA:
Path in NFA:

,b
a

q0

q0

Equivalent Path in NFA:

NFA:

q0

q1
q0

q1
a
a

a a, b

q2

q1

q0

q1

q1

q0

q1

q1
?

q2

From NFA to NFA


-- an example from Lecture notes (6/8)
NFA:
Path in NFA:

,b
a

q0

q0

Equivalent Path in NFA:

NFA:

q0

q1

q1 a q1 q2
q0

a a, b

q2

q1
a, b

q2
q0 b q1 q2
b

q0

q2

q2

From NFA to NFA


-- an example from Lecture notes (7/8)
NFA:

NFA:

q0

,b
a

q0

a a, b
a

q1

q1
a, b

q2

q2

From NFA to NFA


-- an example from Lecture notes (8/8)
NFA:

q0

,b
a

q1

q2

(4) The accepting states of the NFA are all states that can reach
some accepting state of NFA using only -transitions

NFA:

q0

a a, b
a

q1
a, b

q2

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 )

Rij0 = ai + ai + + ai
1

(all qi qj)

qi

if i j
qi

ai1,ai2,,ait
ai1,ai2,,ait

qj

Rijk = Rijk-1 + Rikk-1(Rkkk-1)*Rkjk-1


(for k > 0)

qk
qi

a path in M qj

From DFA to RE
-- an example (1/3)
1

q
1

q2

R110 = {, 1} = 1
+

R120 = {0} = 0
R21 = {0} = 0

q2

q2

q
0

1
q2

R
From DFA to RE
-- an example (2/3)
1

q1

0
0

ij

= Rijk-1 + Rikk-1(Rkkk-1)*Rkj

1
q2

R110 = {, 1} = 1 + ;
R120 = {0} R111 = {, 1, 11,
111, ...}
=0
= 1*
10
0
01
0
R
=
R
+
R
= {0} = 0;
R2222 = {,
R21
22
12 = R12 +
R210(R110)*R120
1}
1 11
+0)*R
120
R11=0(R
1
1
1
R122=
=0R+
+ R12)1+(R
12 (1+
0 22 )*R22 = (1 + ) + 0(1+
)*+
0 (1+ )+0) ((1 + ) +
= (0 + (1+ )+0) + (0
0(1+ )*0)+
= (0 + (1+ )+0) ((1 + ) + 0(1+ )*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 + R1j2n + .. +
1
q1

R1jtn
0
0

1
q2

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?
Example(1). L = { 00, 001, 0011, 101 };
min(L) = ?

{ 00, 001, 0011, 101 }


0

Main idea:

Example(2).

n,m = 0,1,2,

L = { a, a(bc)n, baa, cbma }; min(L)


=?

w=ux

A DFA for L:

qj

qk

Cut the transitions going out of


each accepting state.

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!

You might also like