You are on page 1of 24

Tutorial 02

-- CSC3130 : Formal Languages and Automata Theory


Tu Shikui (sktu@cse.cuhk.edu.hk) SHB 905, Office hour: Thursday 2:30pm-3:30pm 2008-09-12

Outline
From eNFA to NFA

From DFA to RE
Closed operators for Regular Languages

From eNFA to NFA


e-transitions

e is the empty string, it contains no alphabets; It makes a state transition when seeing e. It makes a state transition without receiving an input symbol (from alphabet); It makes a state transition unconditionally;
NFA + Allows e-transitions; It brings programming convenience; Closely related to regular expressions

eNFA

From eNFA to NFA


-- an example from Lecture notes (1/8)
eNFA: q0 e,b a q1 a e q2

NFA:

q0

a, b a

q1
a, b

q2

From eNFA to NFA


-- an example from Lecture notes (2/8)
eNFA: q0 e,b a q1 a e q2

(1) States stay the same (2) Start

state q1

stays the same

NFA:

q0

q2

From eNFA to NFA


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

q0

e,b a e qi qk a

q1
a qj

e e

q2

qi

qm

qj

Equivalent Path in NFA:

?
NFA: q0 ? q1 ? q2

From eNFA to NFA


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

q0
e

e,b a q1 q0 a

q1
a

q2

q0

q0 q0

Equivalent Path in NFA:

a
NFA: q0 ? q1 ? q2

From eNFA to NFA


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

q0
e

e,b a q1 q0 a a

q1

q2
q0 q0 b b

q0

q1 q1

q1 q1

Equivalent Path in NFA:

NFA:

q0

a, b

q1

q2

From eNFA to NFA


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

q0
e

e,b a

q1

q2
q0 b q 1 e q2 q0 b q2

q0

q1 a q1 e q2 q0 a q2

Equivalent Path in NFA:

NFA:

q0

a, b

q1

q2

a, b

From eNFA to NFA


-- an example from Lecture notes (7/8)
eNFA: q0 e,b a q1 a e q2

NFA:

q0

a, b a

q1
a, b

q2

From eNFA to NFA


-- an example from Lecture notes (8/8)
eNFA: q0 e,b a q1 a e q2

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

NFA:

q0

a, b a

q1 a, b

q2

Outline
From eNFA 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 + e
(all loops around qi and e)

qi

ai1,ai2,,ait

Rij0 = ai1 + ai2 + + ait if i j


(all qi qj)

qi

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 q1 0 0 1 q2 q1 1

R110 = {e, 1} = 1 + e R120 = {0} = 0

q1 q1

0 0 1

q2 q2

R210 = {0} = 0
R220 = {e, 1} = 1 + e

q2

From DFA to RE Rijk = Rijk-1 + Rikk-1(Rkkk-1)*Rkjk-1 -- an example (2/3)


1 q1 R110 = {e, 1} = 1 + e ; R210 = {0} = 0; 0 0 1 q2

R111 = {e, 1, 11, 111, ...} R120 = {0} = 0 R220 = {e, 1} = 1 + e = 1* 1 0 0 0 0 R121 = R120 + R110(R110)*R120 R22 = R22 + R21 (R11 )*R12 +0 = (1 + e) + 0(1+ e)*0 = 0 + (1+ e)

R122 = R121 + R121(R221)*R221 = (0 + (1+ e)+0) + (0 + (1+ e)+0) ((1 + e) + 0(1+ e)*0)+ = (0 + (1+ e)+0) ((1 + e) + 0(1+ e)*0)* = (1+ e)*0 ((1 + e) + 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 + R1j2n + .. + R1jtn


1 q1 0 0 1 q2

R122=1*0 (1+01*0)*

Outline
From eNFA 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) = ? Example(2). n,m = 0,1,2,

{ 00, 001, 0011, 101 }


0 0 0 1 1 1

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

Main idea:
A DFA for L:

w=ux

q0

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