Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "1 Finite Automata. 2 Introductory Example An automaton that accepts all legal Pascal identifiers: 1 2 3 Letter Digit Letter or Digit "yes" "no" 2."— Presentation transcript:

1 1 Finite Automata

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

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

4 4 Operational Manner Control unit q 0 Input file yes/no

5 5 Transition Graphs M = (Q, , , q 0, F) |Q| vertices (circles) Edge (q i, q j ) labelled a for  (q i, a) = q j Initial vertice q 0 Final vertices (double circles) in F

6 6 Example 1 M = ({q 0, q 1, q 2 }, {0, 1}, , q 0, {q 1 })  (q 0, 0) = q 0  (q 0, 1) = q 1  (q 1, 0) = q 0  (q 1, 1) = q 2  (q 2, 0) = q 2  (q 2, 1) = q 1 q0q0 q1q1 1 q2q2 1 0 0 0 1

7 7 Extended Transition Function  (q 0, a) = q 1 &  (q 1, b) = q 2   * (q 0, ab) = q 2

8 8 Extended Transition Function  (q 0, a) = q 1 &  (q 1, b) = q 2   * (q 0, ab) = q 2  * (q, ) = q  * (q, wa) =  (  * (q, w), a)

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

10 10 Example 1 M = ({q 0, q 1, q 2 }, {a, b}, , q 0, {q 1 }) L(M) = ? q0q0 q1q1 q2q2 a, b a b

11 11 Example 1 M = ({q 0, q 1, q 2 }, {a, b}, , q 0, {q 1 }) L(M) = {a n b | n  0} trap state q0q0 q1q1 q2q2 a, b a b

12 12 Theorem M = (Q, , , q 0, F) G M : associated transition graph w  +  * (q i, w) = q j iff there is a walk labelled w from q i to q j

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

14 14 Example 2 L(M) = {w  {a, b} * | w starts with ab} q0q0 q1q1 q2q2 b a, b b a trap state q3q3 a a, b

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

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

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

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

19 19 Example 4 L = {awa | w  {a, b} * } q0q0 q2q2 q3q3 b a b a trap state q1q1 a a, b b

20 20 Example 5 L = {awa | w  {a, b} * } L 2 = {aw 1 aaw 2 a | w 1, w 2  {a, b} * }

21 21 Example 5 L 2 = {aw 1 aaw 2 a | w 1, w 2  {a, b} * } q4q4 q5q5 ba b a trap state q1q1 a a, b b q0q0 q2q2 q3q3 b b a a b

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

23 23 Example 6 q1q1 q2q2 q3q3 a a q4q4 q5q5 a a q0q0 a a

24 24 Example 7 q0q0 q1q1 q2q2 1 0 0, 1

25 25 Extended Transition Function  * (q i, w) = Q j

26 26 Extended Transition Function  * (q i, w) contains q j iff there is a walk labelled w from q i to q j

27 27 Example 8  * (q 1, a) = ?  * (q 2, ) = ? q0q0 q1q1 q2q2 a

28 28 Example 8  * (q 1, a) = {q 0, q 1, q 2 }  * (q 2, ) = {q 0, q 2 } q0q0 q1q1 q2q2 a

29 29 Example 8  * (q i, w) = ? q0q0 q1q1 q2q2 a

30 30 Example 8  * (q i, w) = ? Evaluate all walks of length at most  + (1 +  )|w|  is the number of -edges q0q0 q1q1 q2q2 a

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

32 32 Languages and NFAs q0q0 q1q1 q2q2 1 0 0, 1 L(M) = ?

33 33 Languages and NFAs L(M) = {(10) n | n  0} q0q0 q1q1 q2q2 1 0 0, 1

34 34 Languages and NFAs  * (q 0, 110) =  (q 2, 0) =  dead configuration q0q0 q1q1 q2q2 1 0 0, 1

35 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 36 Equivalence of DFAs and NFAs A class of automata may be more powerful than another. DFA is a restricted kind of NFA. DFA:  (q i, a) = q j NFA:  (q i, a) = {q j }

37 37 Equivalence of DFAs and NFAs DFA and NFA are equally powerful. NFA:  * (q, w) = {q i, q j,..., q k } a label of one state

38 38 Example 9 2 Q = { , {q 0 }, {q 1 }, {q 0, q 1 }} q0q0 q1q1 q2q2 a b a

39 39 Example 9  ({q 0 }, a) = {q 1, q 2 }  ({q 0 }, b) =  q0q0 q1q1 q2q2 a b a

40 40 Example 9  ({q 0 }, a) = {q 1, q 2 }  ({q 0 }, b) =   ({q 1, q 2 }, a) = {q 1, q 2 }  ({q 1, q 2 }, b) = {q 0 } q0q0 q1q1 q2q2 a b a

41 41 Example 9 {q 0 } {q 1,q 2 } b a  b a a, b

42 42 Theorem Given M N = (Q N, ,  N, q 0N, F N ) there exists M D = (Q D, ,  D, q 0D, F D ) such that L(M D ) = L(M N )

43 43 Procedure NFA  DFA 1.Create G D with vertex q 0D = {q 0N }. 2.Repeat: Take any vertex {q i, q j,..., q k } of G D that has a missing edge for a . Compute  * (q i, a),  * (q j, a),...,  * (q k, a). Create new {q l, q m,..., q n } =  * (q i, a)  * (q j, a) ...  * (q k, a). Add {q i, q j,..., q k }  a  {q l, q m,..., q n }. 3.Every state of G D containing q f  F N is a final vertex. 4.If  L(M N ) then {q 0N } is also a final vertex.

44 44 Example 10 q0q0 q1q1 q2q2 0, 1 0 1

45 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).


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

Similar presentations


Ads by Google