1 / 27

CSCI 3130: Formal languages and automata theory Tutorial 1

CSCI 3130: Formal languages and automata theory Tutorial 1. Lee Chin Ho. About me. Name: Chin Office: SHB 117 Office hour: Tuesday 11:00 – 12:00 Homework 1 is due on next Thursday. Finite Automata. Finite Automata Q - States S - Alphabets d - Transitions q 0 - Initial state

Download Presentation

CSCI 3130: Formal languages and automata theory Tutorial 1

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSCI 3130: Formal languagesand automata theoryTutorial 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 • Finite Automata • Q- States • S - Alphabets • d - Transitions • q0- Initial state • 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 Æ andeare regular expressions • Every ainS 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 S 2. For DFA, out degree of each state must be equal|S| e.g. S = {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 • q2 is a “die” state • After a 1 has appeared, any 0 appears afterwards will die • 0*1* 0 1 0, 1 0 1 q2 q0 q1 S= {0, 1}

  10. Exercise S = {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 qk when sum of digits = k 0 0 0 0 0 0 1 1 1 1 1 q0 q1 … q2 q4 q3 q5

  12. Idea • Need to keep track of the sum of digits • Arrive at the state qk when sum of digits = k • k divisible by 5 iff k mod 5 = 0 • Keep track of the remainder instead 0 0 0 0 0 1 1 1 1 q0 q1 q2 q4 q3 1

  13. Answer • Handle the input  1 0 0 0 0 0 1 1 1 1 0 q0 q1 qs q2 q4 q3 1

  14. Converting an NFA to a DFA 0  q0 q1 • Eliminate  for each state i for each alphabet x for each state j if i can reach j using one xand(s) add an edge from i to j with label x q2 0 q0 q1 q2 0  1 q0 q1 q2 1 q0 q1 q2 1 1 1   1 q0 q1 1 q2 q3 q0 q1 q2 q3 1

  15. Converting an NFA to a DFA • Eliminate  • Remember to consider the case when the initial state can reach accepting states on (s)  1 q0 q1 q2 1 q0 q1 q2 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 q1 1 1 q0 {q0} {q1, q2} q2 1

  17. Converting an NFA to a DFA • Empty set ∅=die S S ∅

  18. Exercise 0  q0 q1 0 1 0, 1 1 q2

  19. Eliminating -transitions • q0 can reach q0on 0 (q0 -> q1 -> q0) • q0can reach q1on 0 (q0 -> q1) • q1 can reach q0 on 0 (q1 -> q0) • q1 can reach q1 on 0 (q1 -> q1) • The rest of the transitions remain unchanged 0  q0 q1 0 1 0, 1 1 q2

  20. Eliminating -transitions • q0 is the initial state • q0 can reach an accepting state on  (i.e. q1) • therefore q0 is also an accepting state 0 0 0  0 q1 q0 q0 q1 0 0 1 0, 1 1 0, 1 1 1 q2 q2

  21. Converting NFA to DFA 0 0 0 q0 q1 0 1 0, 1 1 q2

  22. Converting NFA to DFA • Starting from initial state {q0} 0 {q0} {q0, q1} 1 {q2}

  23. Converting NFA to DFA • Check if every state has |S| outgoing transitions • No • “Fix” {q2} and {q0, q1} • {q0, q1} goes to {q0, q1} ∪{q0, q1} = {q0, q1} on 0 • {q0, q1} goes to {q2} ∪∅ = {q2} on 1 0 {q0} {q0, q1} 0 1 1 {q1} {q2} 0 1 {q1, q2}

  24. Converting NFA to DFA • Check if every state has |S| outgoing transitions • No • “Fix” {q1} and {q1, q2} • {q1, q2} goes to {q0, q1} ∪{q1} = {q0, q1} on 0 • {q1, q2} goes to ∅ ∪ {q1, q2}= {q1, q2} on 1 0 {q0} {q0, q1} 0 1 1 0 {q1} 1 {q2} 0 ∅ 1 0 {q1, q2} 1

  25. Converting NFA to DFA • Check if every state has |S| outgoing transitions • No • “Fix” ∅ • ∅ = die 0 {q0} {q0, q1} 0 1 1 0 {q1} 1 0, 1 {q2} 0 ∅ 1 0 {q1, q2} 1

  26. Converting NFA to DFA 0 0 0 q0 q1 • Check if every state has |S| outgoing transitions • Yes • Accepting states = states that contain q0 or q1 0 1 0, 1 1 q2 0 {q0, q1} {q0} 0 1 1 0 {q1} 1 0, 1 {q2} 0 ∅ 1 0 {q1, q2} 1

  27. Converting NFA to DFA • Done 0 0  {q0, q1} {q0} 0 q0 q1 1 1 0 0 {q1} 1 0, 1 1 1 0, 1 {q2} 0 ∅ q2 1 0 1 {q1, q2}

More Related