470 likes | 643 Views
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
E N D
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, , , q0, F) Q: finite set of internal states : finite set of symbols - input alphabet : Q Q transition function q0Q: initial state FQ: set of final states
Operational Manner Input file Control unit q0 yes/no
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
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
Extended Transition Function (q0, a) = q1 & (q1, b) = q2 *(q0, ab) = q2
Extended Transition Function (q0, a) = q1 & (q1, b) = q2 *(q0, ab) = q2 *(q, ) = q *(q, wa) = (*(q, w), a)
Languages and DFAs M = (Q, , , q0, F) L(M) = {w* | *(q0, w)F} L(M) = {w* | *(q0, w)F}
Example 1 M = ({q0, q1, q2}, {a, b}, , q0, {q1}) L(M) = ? a a, b b a, b q0 q1 q2
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
Theorem M = (Q, , , q0, F) GM: associated transition graph w+ *(qi, w) = qj iff there is a walk labelled w from qi to qj
Example 2 L(M) = {w{a, b}* | w starts with ab}
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
Example 3 L(M) = {w{0, 1}* | w does not contain 001}
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
Regular Languages L is regular iff L = L(M) for some DFA M
Example 4 L = {awa | w{a, b}*}
Example 4 L = {awa | w{a, b}*} b b a a q0 q2 q3 b a q1 trap state a, b
Example 5 L = {awa | w{a, b}*} L2 = {aw1aaw2a | w1, w2{a, b}*}
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
Nondeterministic Finite Automata (NFA) M = (Q, , , q0, F) Q: finite set of internal states : finite set of symbols - input alphabet : Q ( {}) 2Qtransition function q0Q: initial state FQ: set of final states
Example 6 a a q1 q2 q3 a q0 a a q4 q5 a
Example 7 0 0, 1 q0 q1 q2 1
Extended Transition Function *(qi, w) = Qj
Extended Transition Function *(qi, w) contains qj iff there is a walk labelled w from qi to qj
Example 8 *(q1, a) = ? *(q2, ) = ? a q0 q1 q2
Example 8 *(q1, a) = {q0, q1, q2} *(q2, ) = {q0, q2} a q0 q1 q2
Example 8 *(qi, w) = ? a q0 q1 q2
Example 8 *(qi, w) = ? Evaluate all walks of length at most + (1 + )|w| is the number of -edges a q0 q1 q2
Languages and NFAs M = (Q, , , q0, F) L(M) = {w* | *(q0, w) F }
Languages and NFAs 0 0, 1 q0 q1 q2 1 L(M) = ?
Languages and NFAs 0 0, 1 q0 q1 q2 1 L(M) = {(10)n | n 0}
Languages and NFAs 0 0, 1 q0 q1 q2 1 *(q0, 110) = (q2, 0) = dead configuration
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).
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}
Equivalence of DFAs and NFAs • DFA and NFA are equally powerful. NFA: *(q, w) = {qi, qj, ..., qk} a label of one state
Example 9 2Q = {, {q0}, {q1}, {q0, q1}} b a q0 q1 q2 a
Example 9 ({q0}, a) = {q1, q2} ({q0}, b) = b a q0 q1 q2 a
Example 9 ({q0}, a) = {q1, q2} ({q0}, b) = ({q1, q2}, a) = {q1, q2} ({q1, q2}, b) = {q0} b a q0 q1 q2 a
Example 9 a b {q1,q2} {q0} a b a, b
Theorem Given MN = (QN, , N, q0N, FN) there exists MD = (QD, , D, q0D, FD) such that L(MD) = L(MN)
Procedure NFADFA • 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.
Example 10 0 1 0, 1 0, 1 q0 q1 q2
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).