Presentation is loading. Please wait.

Presentation is loading. Please wait.

Tutorial 02 -- CSC3130 : Formal Languages and Automata Theory Tu Shikui ( ) SHB 905, Office hour: Thursday 2:30pm-3:30pm 2008-09-12.

Similar presentations


Presentation on theme: "Tutorial 02 -- CSC3130 : Formal Languages and Automata Theory Tu Shikui ( ) SHB 905, Office hour: Thursday 2:30pm-3:30pm 2008-09-12."— Presentation transcript:

1 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

2 Outline From  NFA to NFA From DFA to RE Closed operators for Regular Languages

3 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

4 From  NFA to NFA -- an example from Lecture notes (1/8) q0q0 q1q1 q2q2 ,b a a   NFA: NFA: q0q0 q1q1 q2q2 a, b a a a a

5 From  NFA to NFA -- an example from Lecture notes (2/8) q0q0 q1q1 q2q2 ,b a a   NFA: q0q0 q1q1 q2q2 NFA: (1) States stay the same (2) Start state stays the same

6 From  NFA to NFA -- an example from Lecture notes (3/8) q0q0 q1q1 q2q2 ,b a a   NFA: NFA: q0q0 q1q1 q2q2 Path in  NFA : qiqi qkqk qjqj …… qmqm a  Equivalent Path in NFA : qjqj a qiqi ? ? ?

7 From  NFA to NFA -- an example from Lecture notes (4/8) q0q0 q1q1 q2q2 ,b a a   NFA: NFA: q0q0 q1q1 q2q2 Path in  NFA : q0q0 q1q1 q0q0 a  Equivalent Path in NFA : q0q0 a q0q0 a ? ?

8 From  NFA to NFA -- an example from Lecture notes (5/8) q0q0 q1q1 q2q2 ,b a a   NFA: NFA: Path in  NFA : q0q0 q1q1 q1q1 a  Equivalent Path in NFA : q1q1 q0q0 q0q0 q1q1 q2q2 a, b ? a q1q1 b q0q0 a q1q1 b q0q0

9 From  NFA to NFA -- an example from Lecture notes (6/8) q0q0 q1q1 q2q2 ,b a a   NFA: NFA: Path in  NFA : Equivalent Path in NFA : q0q0 q1q1 q2q2 a, b a q0q0 q1q1 q1q1 a  q2q2 q0q0 q1q1 b q0q0 a q2q2 b q0q0 q2q2  q2q2 

10 From  NFA to NFA -- an example from Lecture notes (7/8) q0q0 q1q1 q2q2 ,b a a   NFA: NFA: q0q0 q1q1 q2q2 a, b a a a a

11 From  NFA to NFA -- an example from Lecture notes (8/8) q0q0 q1q1 q2q2 ,b a a   NFA: NFA: q0q0 q1q1 q2q2 a, b a a a a (4) The accepting states of the NFA are all states that can reach some accepting state of  NFA using only  -transitions

12 Outline From  NFA to NFA From DFA to RE Closed operators for Regular Languages

13 From DFA to RE -- General construction We inductively define R ij k as: R ii 0 = a i 1 + a i 2 + … + a i t +  (all loops around q i and  ) (all q i → q j ) R ij k = R ij k-1 + R ik k-1 (R kk k-1 )*R kj k-1 a path in M qiqi qkqk qjqj R ij 0 = a i 1 + a i 2 + … + a i t if i ≠ j a i 1,a i 2,…,a i t qiqi qiqi qjqj (for k > 0 )

14 From DFA to RE -- an example (1/3) 0 1 0 1 q1q1 q2q2 R 11 0 = { , 1} = 1 +  R 12 0 = {0} = 0 R 21 0 = {0} = 0 R 22 0 = { , 1} = 1 +  1 q1q1 0 q1q1 q2q2 0 q1q1 q2q2 1 q2q2

15 From DFA to RE -- an example (2/3) 0 1 0 1 q1q1 q2q2 R 11 0 = { , 1} = 1 +  ; R 12 0 = {0} = 0 R 21 0 = {0} = 0; R 22 0 = { , 1} = 1 +  R 11 1 = { , 1, 11, 111,...} = 1* R ij k = R ij k-1 + R ik k-1 (R kk k-1 )*R kj k-1 R 12 1 = R 12 0 + R 11 0 (R 11 0 )*R 12 0 = 0 + (1+  ) + 0 R 22 1 = R 22 0 + R 21 0 (R 11 0 )*R 12 0 = ( 1 +  ) + 0(1+  ) * 0 R 12 2 = R 12 1 + R 12 1 (R 22 1 )*R 22 1 = (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) *

16 From DFA to RE (3/3) -- Determine the accepted RE for DFA Suppose the DFA start state is q 1, and the accepting states are F = {q j 1  q j 2 …  q j t } Then the regular expression for this DFA is R 1j 1 n + R 1j 2 n + ….. + R 1j t n 0 0 q1q1 q2q2 11 R 12 2 =1 * 0 (1+01 * 0) *

17 Outline From  NFA to NFA From DFA to RE Closed operators for Regular Languages

18 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.

19 (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”.

20 (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: u q0q0 qjqj qkqk x 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 } 0011 1 01 Example(2). L = { a, a(bc) n, baa, cb m a }; min ( L ) = ? n,m = 0,1,2,…

21 Solution for (1) min(L) = { w | w is in L, but no proper prefix of w is in L };

22 Solution for (1) -- (cont.) min(L) = { w | w is in L, but no proper prefix of w is in L };

23 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!

24 End of this tutorial! Thanks for coming!


Download ppt "Tutorial 02 -- CSC3130 : Formal Languages and Automata Theory Tu Shikui ( ) SHB 905, Office hour: Thursday 2:30pm-3:30pm 2008-09-12."

Similar presentations


Ads by Google