1 / 45

Finite Automata

Finite Automata. Introductory Example. An automaton that accepts all legal Pascal identifiers:. Letter. 2. 2. 1. "yes". Digit. Letter or Digit. 3. "no". Letter or Digit. Deterministic Finite Automata (DFA). M = (Q,  ,  , q 0 , F) Q: finite set of internal states

brice
Download Presentation

Finite Automata

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. Finite Automata

  2. Introductory Example An automaton that accepts all legal Pascal identifiers: Letter 2 2 1 "yes" Digit Letter or Digit 3 "no" Letter or Digit

  3. Deterministic Finite Automata (DFA) M = (Q, , , q0, F) Q: finite set of internal states : finite set of symbols - input alphabet : Q    Q transition function q0Q: initial state FQ: set of final states

  4. Operational Manner Input file Control unit q0 yes/no

  5. Transition Graphs M = (Q, , , q0, F) • |Q| vertices (circles) • Edge (qi, qj) labelled a for (qi, a) = qj • Initial vertice q0 • Final vertices (double circles) in F

  6. Example 1 M = ({q0, q1, q2}, {0, 1}, , q0, {q1}) (q0, 0) = q0 (q0, 1) = q1 (q1, 0) = q0 (q1, 1) = q2 (q2, 0) = q2 (q2, 1) = q1 1 0 0 0 q0 q1 q2 1 1

  7. Extended Transition Function (q0, a) = q1 & (q1, b) = q2 *(q0, ab) = q2

  8. Extended Transition Function (q0, a) = q1 & (q1, b) = q2 *(q0, ab) = q2 *(q, ) = q *(q, wa) = (*(q, w), a)

  9. Languages and DFAs M = (Q, , , q0, F) L(M) = {w* | *(q0, w)F} L(M) = {w* | *(q0, w)F}

  10. Example 1 M = ({q0, q1, q2}, {a, b}, , q0, {q1}) L(M) = ? a a, b b a, b q0 q1 q2

  11. Example 1 M = ({q0, q1, q2}, {a, b}, , q0, {q1}) L(M) = {anb | n  0} a a, b b a, b q0 q1 q2 trap state

  12. Theorem M = (Q, , , q0, F) GM: associated transition graph w+ *(qi, w) = qj iff there is a walk labelled w from qi to qj

  13. Example 2 L(M) = {w{a, b}* | w starts with ab}

  14. Example 2 L(M) = {w{a, b}* | w starts with ab} a, b b a q0 q1 q2 a b q3 trap state a, b

  15. Example 3 L(M) = {w{0, 1}* | w does not contain 001}

  16. Example 3 L(M) = {w{0, 1}* | w does not contain 001} 0, 1 1 0 1 0 1  0 00 001 trap state 0

  17. Regular Languages L is regular iff L = L(M) for some DFA M

  18. Example 4 L = {awa | w{a, b}*}

  19. Example 4 L = {awa | w{a, b}*} b b a a q0 q2 q3 b a q1 trap state a, b

  20. Example 5 L = {awa | w{a, b}*} L2 = {aw1aaw2a | w1, w2{a, b}*}

  21. Example 5 L2 = {aw1aaw2a | w1, w2{a, b}*} b b b b a a a q0 q2 q3 q4 q5 b b a a q1 trap state a, b

  22. Nondeterministic Finite Automata (NFA) M = (Q, , , q0, F) Q: finite set of internal states : finite set of symbols - input alphabet : Q  (  {})  2Qtransition function q0Q: initial state FQ: set of final states

  23. Example 6 a a q1 q2 q3 a q0 a a q4 q5 a

  24. Example 7 0 0, 1 q0 q1 q2 1 

  25. Extended Transition Function *(qi, w) = Qj

  26. Extended Transition Function *(qi, w) contains qj iff there is a walk labelled w from qi to qj

  27. Example 8 *(q1, a) = ? *(q2, ) = ?   a q0 q1 q2

  28. Example 8 *(q1, a) = {q0, q1, q2} *(q2, ) = {q0, q2}   a q0 q1 q2

  29. Example 8 *(qi, w) = ?   a q0 q1 q2

  30. Example 8 *(qi, w) = ? Evaluate all walks of length at most  + (1 + )|w|  is the number of -edges   a q0 q1 q2

  31. Languages and NFAs M = (Q, , , q0, F) L(M) = {w* | *(q0, w)  F }

  32. Languages and NFAs 0 0, 1 q0 q1 q2 1  L(M) = ?

  33. Languages and NFAs 0 0, 1 q0 q1 q2 1  L(M) = {(10)n | n  0}

  34. Languages and NFAs 0 0, 1 q0 q1 q2 1  *(q0, 110) = (q2, 0) =  dead configuration

  35. Homework • Exercises: 1, 5, 6, 11, 14, 17, 15, 17 of Section 2.1 - Linz’s book. • Exercises: 3, 4, 6, 7, 9, 10 of Section 2.2 - Linz’s book. • Reading: Why nondeterminism - Linz’s book. • Presentation: Section 2.4 - Linz’s book (procedures mark and reduce).

  36. Equivalence of DFAs and NFAs • A class of automata may be more powerful than another. • DFA is a restricted kind of NFA. DFA: (qi, a) = qj NFA: (qi, a) = {qj}

  37. Equivalence of DFAs and NFAs • DFA and NFA are equally powerful. NFA: *(q, w) = {qi, qj, ..., qk} a label of one state

  38. Example 9 2Q = {, {q0}, {q1}, {q0, q1}} b  a q0 q1 q2 a

  39. Example 9 ({q0}, a) = {q1, q2} ({q0}, b) =  b  a q0 q1 q2 a

  40. Example 9 ({q0}, a) = {q1, q2} ({q0}, b) =  ({q1, q2}, a) = {q1, q2} ({q1, q2}, b) = {q0} b  a q0 q1 q2 a

  41. Example 9 a b {q1,q2} {q0} a b  a, b

  42. Theorem Given MN = (QN, , N, q0N, FN) there exists MD = (QD, , D, q0D, FD) such that L(MD) = L(MN)

  43. Procedure NFADFA • Create GD with vertex q0D= {q0N}. • Repeat: • Take any vertex {qi, qj, ..., qk} of GD that has a missing edge for a. • Compute *(qi, a), *(qj, a), ..., *(qk, a). • Create new {ql, qm, ..., qn} = *(qi, a)*(qj, a) ... *(qk, a). • Add {qi, qj, ..., qk} a {ql, qm, ..., qn}. • Every state of GD containing qf  FN is a final vertex. • If   L(MN) then {q0N} is also a final vertex.

  44. Example 10 0 1 0, 1 0, 1 q0 q1 q2

  45. Homework • Exercises: 3, 8, 11, 12 of Section 2.3 - Linz’s book. • Exercises: 1, 4 of Section 2.4 - Linz’s book. • Programming: Implement procedures mark and reduce (Section 2.4) (Submission: 15/October).

More Related