Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSCI 3130: Formal languages and automata theory Tutorial 1 Lee Chin Ho.

Similar presentations


Presentation on theme: "CSCI 3130: Formal languages and automata theory Tutorial 1 Lee Chin Ho."— Presentation transcript:

1 CSCI 3130: Formal languages and automata theory Tutorial 1 Lee Chin Ho

2 About me Name: Chin Office: SHB 117 Office hour: Tuesday 11:00 – 12:00 Homework 1 is due on next Thursday

3 Finite Automata 1. Q - States 2.  - Alphabets 3.  - Transitions 4. q 0 - Initial state 5. F - Final state(s) / Accepting state(s)

4 Deterministic Finite Automata There must be a transition corresponding to each alphabet at each state

5 Nondeterministic Finite Automata Can be at multiple states at the same time Can go to multiple states on one alphabet May have no transitions on an alphabet (die)

6 Regular Expression The symbols  and  are regular expressions Every a in  is a regular expression If R and S are regular expressions, so are R+S, RS and R* Remember for R*, * could be 0

7 Regular Languages Languages that can be represented by a DFA / NFA / RE DFA = NFA = RE When asked if a language L is regular, represent L using a DFA / NFA / RE

8 Checklist 1. Always pay attention to  2. For DFA, out degree of each state must be equal |  | e.g.  = { 0, 1, 2 }, L = {w: w begins with 01 } 3. For NFA, pay attention to  -transitions 4. Remember to specify the initial state 5. Make sure you have considered the input  e.g. L = {w: w contains even number of 01 }

9 Example in Lecture q0q0 q1q1 0 1 1 0 q2q2 0, 1  = {0, 1} 1.q 2 is a “die” state 2.After a 1 has appeared, any 0 appears afterwards will die 3.0*1*

10 Exercise  = { 0, 1 } L = {w: w is non-empty and the sum of the digits in w is divisible by 5}

11 Idea Need to keep track of the sum of digits Arrive at the state q k when sum of digits = k q0q0 q1q1 0 0 1 q2q2 0 1 q3q3 0 1 1 q4q4 0 q5q5 0 1 …

12 Idea Need to keep track of the sum of digits Arrive at the state q k when sum of digits = k k divisible by 5 iff k mod 5 = 0 Keep track of the remainder instead q0q0 q1q1 0 0 1 q2q2 0 1 q3q3 0 1 1 q4q4 0 1

13 Answer Handle the input  q0q0 q1q1 0 0 1 q2q2 0 1 q3q3 0 1 1 q4q4 0 1 qsqs 0 1

14 Converting an NFA to a DFA Eliminate  for each state i for each alphabet x for each state j if i can reach j using one x and  (s) add an edge from i to j with label x q0q0 q1q1 0 q2q2  q0q0 q1q1  q2q2 1 q0q0 q1q1 0 q2q2 0 q0q0 q1q1 q2q2 1 1 q0q0 q1q1  q2q2 1 q0q0 q1q1 q2q2 1 1 q3q3  q3q3 11

15 Converting an NFA to a DFA Eliminate  Remember to consider the case when the initial state can reach accepting states on  (s) q0q0 q1q1  q2q2 1 q0q0 q1q1 q2q2 1 1

16 Converting an NFA to a DFA Every possible subsets of Q is a state in the DFA Going to multiple states at the same time in the NFA = going to a subset of Q, which is now a state in the DFA q0q0 q1q1 1 q2q2 1 {q 0 }{q 1, q 2 } 1

17 Converting an NFA to a DFA Empty set ∅ = die ∅  

18 Exercise q0q0 q1q1 0  0 q2q2 1 0, 1 1

19 Eliminating  -transitions q 0 can reach q 0 on 0 (q 0 -> q 1 -> q 0 ) q 0 can reach q 1 on 0 (q 0 -> q 1 ) q 1 can reach q 0 on 0 (q 1 -> q 0 ) q 1 can reach q 1 on 0 (q 1 -> q 1 ) The rest of the transitions remain unchanged 01 q0q0 q 0, q 1 q2q2 q1q1 q2q2 q1q1 q 1, q 2 q0q0 q1q1 0  0 q2q2 1 0, 1 1

20 Eliminating  -transitions q0q0 q1q1 0 0 q2q2 1 0, 1 1 0 0 01 q0q0 q 0, q 1 q2q2 q1q1 q2q2 q1q1 q 1, q 2 q0q0 q1q1 0  0 q2q2 1 0, 1 1 q 0 is the initial state q 0 can reach an accepting state on  (i.e. q 1 ) therefore q 0 is also an accepting state

21 Converting NFA to DFA 01 {q 0 }{q 0, q 1 }{q 2 } {q 1 }{q 0, q 1 } ∅ {q 2 }{q 1 }{q 1, q 2 } q0q0 q1q1 0 0 q2q2 1 0, 1 1 0 0

22 Converting NFA to DFA 01 {q 0 }{q 0, q 1 }{q 2 } {q 1 }{q 0, q 1 } ∅ {q 2 }{q 1 }{q 1, q 2 } Starting from initial state {q 0 } {q 0 } {q 0, q 1 } 0 {q 2 } 1

23 Converting NFA to DFA 01 {q 0 }{q 0, q 1 }{q 2 } {q 1 }{q 0, q 1 } ∅ {q 2 }{q 1 }{q 1, q 2 } Check if every state has |  | outgoing transitions No “Fix” {q 2 } and {q 0, q 1 } {q 0, q 1 } goes to {q 0, q 1 } ∪ {q 0, q 1 } = {q 0, q 1 } on 0 {q 0, q 1 } goes to {q 2 } ∪ ∅ = {q 2 } on 1 {q 0 } {q 0, q 1 } 0 {q 2 } 1 0 {q 1 } 0 {q 1, q 2 } 1 1

24 Converting NFA to DFA 01 {q 0 }{q 0, q 1 }{q 2 } {q 1 }{q 0, q 1 } ∅ {q 2 }{q 1 }{q 1, q 2 } Check if every state has |  | outgoing transitions No “Fix” {q 1 } and {q 1, q 2 } {q 1, q 2 } goes to {q 0, q 1 } ∪ {q 1 } = {q 0, q 1 } on 0 {q 1, q 2 } goes to ∅ ∪ {q 1, q 2 } = {q 1, q 2 } on 1 {q 0 } {q 0, q 1 } 0 {q 2 } 1 0 {q 1 } 0 {q 1, q 2 } 1 1 0 0 1 ∅ 1

25 Converting NFA to DFA 01 {q 0 }{q 0, q 1 }{q 2 } {q 1 }{q 0, q 1 } ∅ {q 2 }{q 1 }{q 1, q 2 } Check if every state has |  | outgoing transitions No “Fix” ∅ ∅ = die 0, 1 {q 0 } {q 0, q 1 } 0 {q 2 } 1 0 {q 1 } 0 {q 1, q 2 } 1 1 0 0 ∅ 1 1

26 Converting NFA to DFA 01 {q 0 }{q 0, q 1 }{q 2 } {q 1 }{q 0, q 1 } ∅ {q 2 }{q 1 }{q 1, q 2 } Check if every state has |  | outgoing transitions Yes Accepting states = states that contain q 0 or q 1 q0q0 q1q1 0 0 q2q2 1 0, 1 1 0 0 {q 0 } {q 0, q 1 } 0 {q 2 } 1 0 {q 1 } 0 {q 1, q 2 } 1 1 0 0 ∅ 1 1

27 Converting NFA to DFA Done q0q0 q1q1 0  0 q2q2 1 0, 1 1 {q 0 } {q 0, q 1 } 0 {q 2 } 1 0 {q 1 } 0 {q 1, q 2 } 1 1 0 0 ∅ 1 1


Download ppt "CSCI 3130: Formal languages and automata theory Tutorial 1 Lee Chin Ho."

Similar presentations


Ads by Google