Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Chapter 2 Finite Automata (part a) Hokkaido, Japan.

Similar presentations


Presentation on theme: "1 Chapter 2 Finite Automata (part a) Hokkaido, Japan."— Presentation transcript:

1 1 Chapter 2 Finite Automata (part a) Hokkaido, Japan

2 2 Outline (part a --- in this PPT) 2.0 Introduction 2.1 An Informal Picture of Finite Automata 2.2 Deterministic Finite automata 2.3 Nondeterministic Finite Automata (part b --- in another PPT) 2.4 An Application: Text Search 2.5 Finite Automata with Epsilon-Transitions

3 3 2.0 Introduction Two types of finite automata (FA): –Deterministic FA (DFA) –Nondeterministic FA (NFA) Both types are of the same power, –The former is easier for hardware and software implementations. –The latter is more efficient for descriptions of applications of FA.

4 4 2.1 An Informal Picture of Finite Automata A complete application example of finite automata for protocol design and verification –Read by yourself! –Involving a concept of “product of two automata”

5 5 2.2 Deterministic Finite Automata Recall the example of a vending machine selling 20-dolllar food in Chapter 0 $0 Start $5 $10 $5 $20 $15 $5 $10 $5 $10 $10 $10 $20 transition diagram

6 6 2.2 Deterministic Finite Automata 2.2.1 Definition of DFA –A DFA A consists of 5-tuples (1/2): a finite (nonempty) set of states Q; a finite (nonempty) set of states Q; a finite (nonempty) set of input symbols  ; a finite (nonempty) set of input symbols  ; a (state) transition function  such that a (state) transition function  such that  q, a) = p means means “automaton A, in state q, takes input a “automaton A, in state q, takes input a  and enters state p;”

7 7 2.2 Deterministic Finite Automata 2.2.1 Definition of DFA –A DFA A consists of 5-tuples (2/2): a start state q 0 ; a start state q 0 ; a set of (nonempty) final or accepting states F. a set of (nonempty) final or accepting states F. –A may be written as a “5-tuple” A = (Q, , , q 0, F). A = (Q, , , q 0, F).

8 8 2.2 Deterministic Finite Automata 2.2.1 Definition of DFA – graphic model for a DFA tape tape reader finite control

9 9 2.2 Deterministic Finite Automata 2.2.2 How a DFA processes strings –Given an input string x = a 1 a 2 …a n, if  (q 0, a 1 ) = q 1,  (q 1, a 2 ) = q 2, …,  q i  1, a i ) = q i,...,  (q n  1, a n ) = q n,  q i  1, a i ) = q i,...,  (q n  1, a n ) = q n, and q n  F, and q n  F, then x is “accepted”; otherwise, “rejected.” then x is “accepted”; otherwise, “rejected.” –Every transition is deterministic.

10 10 2.2 Deterministic Finite automata Example 2.1 –Design an FA A to accept the language L = {x01y | x and y are any strings of 0’s and 1’s}. –Examples of strings in L: 01, 11010, 100011… 01, 11010, 100011…

11 11 2.2 Deterministic Finite automata Example 2.1 –Transitions:  q 0, 1) = q 0,  (q 0, 0) = q 2,  (q 2, 1) = q 1,  (q 2, 0) = q 2,  q 1, 0) = q 1,  q 1, 1) = q 1 –5-Tuple: A = ({q 0, q 1, q 2 }, {0, 1}, , q 0, {q 1 }) A = ({q 0, q 1, q 2 }, {0, 1}, , q 0, {q 1 })

12 12 2.2.3 Simpler Notations for DFA’s –Transition diagram --- 2.2 Deterministic Finite automata 1 0 0, 1 q0q0 Start q2q2 0 q1 q1 1

13 13 2.2.3 Simpler Notations for DFA’s –Transition table ---  : initial state; *: final state 2.2 Deterministic Finite automata 01  q0 q0 q2q2 q0q0 *q 1 q1q1 q1q1 q 2 q2q2 q1q1

14 14 2.2 Deterministic Finite automata 2.2.4 Extending transition function to strings –Extended transition function If x = a 1 a 2 …a n and  is such that If x = a 1 a 2 …a n and  is such that  (p, a 1 ) = q 1,  (q 1, a 2 ) = q 2, …,  q i  1, a i ) = q i,...,  (q n  1, a n ) = q,  q i  1, a i ) = q i,...,  (q n  1, a n ) = q, then we define to be then we define to be (p, x) = q.

15 15 2.2 Deterministic Finite automata 2.2.4 Extending Transition Function to Strings –Also may be defined recursively as in the textbook. –Recursive definition for Basis: (q,  ) = q. Basis: (q,  ) = q. Induction: if w = xa (a is the last symbol of w), then Induction: if w = xa (a is the last symbol of w), then (q, w) =  ( (q, x), a).

16 16 2.2 Deterministic Finite automata 2.2.4 Extending Transition Function to Strings A graphic diagram for the following concept: A graphic diagram for the following concept: Induction: Induction: if w = xa (a is the last symbol of w), then if w = xa (a is the last symbol of w), then (q, w) =  ( (q, x), a). 0, 1 … q1 q1 a (q, x) x  (q, w=xa)

17 17 2.2 Deterministic Finite automata 2.2.5 The Language of a DFA –The language of a DFA A is defined as L(A) = {w | (q 0, w) is in F}. –If L is L(A) for some DFA A, then we say L is a regular language.

18 18 0, 1 2.3 Nondeterministic Finite Automata 2.3.1 An informal view of NFA’s –Review of a previous example of DFA (of Example 2.1) –An NFA version of above DFA (more intuitive!) q0q0 Start q2q2 0 $20 q1 q1 1 1 0 0, 1 q0q0 Start q2q2 0 $20 q1 q1 1 0, 1

19 19 2.3 Nondeterministic Finite Automata Some properties of NFA’s –Some transitions may “die,” like  q 2, 0). –Some transitions have multiple choices, like  (q 0, 0) = q 0 and q 2. q0q0 Start q2q2 0 $20 q1 q1 1 0, 1

20 20 2.3 Nondeterministic Finite Automata Example 2.6 –Design an NFA accepting the following language L = {w | w  {0, 1}* and ends in 01}. L = {w | w  {0, 1}* and ends in 01}. –Nondeterminism creates many transition paths, but if there is one path leading to a final state, then the input is accepted. q0q0 Start q1q1 0 $20 q2 q2 1 0, 1

21 21 2.3 Nondeterministic Finite Automata Example 2.6 (cont’d) –When input x = 00101, the NFA processes x in the following way: 0 0 1 0 1 0 0 1 0 1 q0q0 Start q1q1 0 $20 q2 q2 1 0, 1 q0q0 q1q1 Stuck! q0q0 q1q1 q2q2 q0q0 q0q0 q1q1 q2q2 Accept! q0q0 q0q0 q0q0 q0q0 q0q0 q1q1 q2q2 Fig. 2.10

22 22 2.3 Nondeterministic Finite Automata 2.3.2 Definition of NFA –An NFA A is a 5-tuple A = (Q, , , q 0, F) where Q = a finite (nonempty) set of states; Q = a finite (nonempty) set of states;  a finite (nonempty) set of input symbols;  a finite (nonempty) set of input symbols; q 0 = a start state; q 0 = a start state; F = a set of (nonempty) final or accepting states; F = a set of (nonempty) final or accepting states;

23 23 2.3 Nondeterministic Finite Automata 2.3.2 Definition of NFA –An NFA A is a 5-tuple A = (Q, , , q 0, F) where  a (state) transition function  such that  q, a) = {p 1, p 2, …, p m } which means which means  “automaton A, in state q, takes input a and enters  one of the states p 1, p 2, …, p m.”

24 24 2.3 Nondeterministic Finite Automata Example 2.7 –Transition table of NFA of the last example --- q0q0 Start q1q1 0 $20 q2 q2 1 0, 1 01  q0 q0 {q 0, q 1 }{q0}{q0} q 1 {q2}{q2} *q2 *q2

25 25 2.3 Nondeterministic Finite Automata 2.3.3 Extended Transition Function –Recursive definition of (with string as input) Basis: (q,  ) = {q}. Induction: if w = xa (a is the last symbol of w), (q, x) = {p 1, p 2, …, p k }, and  (p i, a) = {r 1, r 2, …, r m } then (q, w) = {r 1, r 2, …, r m }.

26 26 2.3 Nondeterministic Finite Automata (supplemental) 2.3.3 Extended Transition Function –A graphic diagram for the following concept: Induction: if w = xa (a is the last symbol of w), (q, x) = {p 1, p 2, …, p k }, and  (p i, a) = {r 1, r 2, …, r m } Induction: if w = xa (a is the last symbol of w), (q, x) = {p 1, p 2, …, p k }, and  (p i, a) = {r 1, r 2, …, r m } then (q, w) = {r 1, r 2, …, r m }. then (q, w) = {r 1, r 2, …, r m }. … a (q, x)= { p 1 p 2. p k } x  a a (q, w=xa) = {r 1 r 2. r m }

27 27 2.3 Nondeterministic Finite Automata Example 2.8 --- –For the input w = 00101, we have 1.(q 0,  ) = {q 0 }. 2. (q 0,  0) =  (q 0, 0) = {q 0, q 1 }. 3. (q 0, 00) =  (q 0, 0) ∪  (q 1, 0) = {q 0, q 1 } ∪  {q 0, q 1 } … q0q0 Start q1q1 0 $20 q2 q2 1 0, 1

28 28 2.3 Nondeterministic Finite Automata 2.3.4 The Language of an NFA –Definition --- If A = (Q, , , q 0, F) is an NFA, then the language accepted by A is If A = (Q, , , q 0, F) is an NFA, then the language accepted by A is L(A) = {w | (q 0, w) ∩ F   }. –That is, as long as a final state is reached, which is among possibly many, the input is accepted.

29 29 2.3 Nondeterministic Finite Automata 2.3.5 Equivalence of DFA and NFA –NFA’s are more intuitive to construct for many languages. –DFA’s are easier for use in software and hardware implementations.

30 30 2.3 Nondeterministic Finite Automata 2.3.5 Equivalence of DFA and NFA –Every NFA N has an equivalent DFA D, i.e., L(D) = L(N). L(D) = L(N). (Definition: “Two models are said to be equivalent if they have identical languages.”) (Definition: “Two models are said to be equivalent if they have identical languages.”) –The proof needs “subset construction.”

31 31 2.3 Nondeterministic Finite Automata 2.3.5 Equivalence of DFA and NFA –Subset construction: each state of DFA is a subset of NFA –Given an NFA N = (Q N, ,  , q 0, F N ), we construct a DFA D = (Q D, ,  D, q 0 ', F D ) such that: The two alphabets are identical; The two alphabets are identical; Q D is the power set of Q N (i.e., set of all subsets of Q N ); Q D is the power set of Q N (i.e., set of all subsets of Q N ); Inaccessible states in Q D should be deleted; Inaccessible states in Q D should be deleted; (continued in the next page)

32 32 2.3 Nondeterministic Finite Automata 2.3.5 Equivalence of DFA and NFA –(cont’d) q 0 ' = {q 0 }; q 0 ' = {q 0 }; Each subset S of Q N is in final state set F D if S includes at least one accepting state in F N (i.e., S ∩ F N   ). Each subset S of Q N is in final state set F D if S includes at least one accepting state in F N (i.e., S ∩ F N   ). For each subset S of Q N and for each input symbol a, define For each subset S of Q N and for each input symbol a, define  D (S, a) =  N (p, a)

33 33 2.3 Nondeterministic Finite Automata Example 2.10 --- –For the NFA of Example 2.6 below: –The power set of Q N = {q 0, q 1, q 2 } is Q D = , {q 0 }, {q 1 }, {q 2 }, {q 0, q 1 }, {q 0, q 2 }, Q D = , {q 0 }, {q 1 }, {q 2 }, {q 0, q 1 }, {q 0, q 2 }, {q 1, q 2 }, {q 0, q 1, q 2 }}. {q 1, q 2 }, {q 0, q 1, q 2 }}. q0q0 Start q1q1 0 $20 q2 q2 1 0, 1

34 34 2.3 Nondeterministic Finite Automata Example 2.10 (cont’d) –The transition table is q0q0 Start q1q1 0 $20 q2 q2 1 0, 1 01   {q 0 } {q 1 } *{q 2 } {q 0, q 1 } *{q 0, q 2 } *{q 1, q 2 } *{q 0, q 1, q 2 }  {q 0, q 1 }  {q 0, q 1 }  {q 0, q 1 }  {q 0 } {q 2 }  {q 0, q 2 } {q 0 } {q 2 } {q 0, q 2 }

35 35 2.3 Nondeterministic Finite Automata Example 2.10 (cont’d) –Change names of the states, we get 01 A  B C *D E *F *G *H AEAAEEAEAEAAEEAE ABDAFBDFABDAFBDF

36 36 2.3 Nondeterministic Finite Automata Example 2.10 (cont’d) –Checking accessible states from the start state as red ones; the others are inaccessible. 01 A  B C *D E *F *G *H AEAAEEAEAEAAEEAE ABDAFBDFABDAFBDF Figure 2.13

37 37 2.3 Nondeterministic Finite Automata Example 2.10 (cont’d) (supplemental) –solved by “Lazy evaluation” using table: starting from the start state, only accessible states are evaluated, in order to avoid generation of inaccessible states. –The transition table is q0q0 Start q1q1 0 $20 q2 q2 1 0, 1 01   {q 0 } {q 1 } *{q 2 } {q 0, q 1 } *{q 0, q 2 } *{q 1, q 2 } *{q 0, q 1, q 2 }  {q 0, q 1 }  {q 0, q 1 }  {q 0, q 1 }  {q 0 } {q 2 }  {q 0, q 2 } {q 0 } {q 2 } {q 0, q 2 } 01   {q 0 } {q 1 } *{q 2 } {q 0, q 1 } *{q 0, q 2 } *{q 1, q 2 } *{q 0, q 1, q 2 }  {q 0, q 1 }  {q 0, q 1 }  {q 0, q 1 }  {q 0 } {q 2 }  {q 0, q 2 } {q 0 } {q 2 } {q 0, q 2 } 01   {q 0 } {q 1 } *{q 2 } {q 0, q 1 } *{q 0, q 2 } *{q 1, q 2 } *{q 0, q 1, q 2 }  {q 0, q 1 }  {q 0, q 1 }  {q 0, q 1 }  {q 0 } {q 2 }  {q 0, q 2 } {q 0 } {q 2 } {q 0, q 2 }

38 38 1 2.3 Nondeterministic Finite Automata {q0}{q0} Start 0 0 1 {q 0, q 1 }{q 0, q 2 } 0 1 Example 2.10 (cont’d) --- –solved by “Lazy evaluation” using diagram: starting from the start state, only accessible states are evaluated, in order to avoid generation of inaccessible states. Figure 2.14

39 39 2.3 Nondeterministic Finite Automata Theorem 2.11 If DFA D = (Q D, ,  D, {q 0 }, F D ) is constructed from NFA N = (Q N, ,  , q 0, F N ) by subset construction, then L(D) = L(N). –Proof. See the textbook.

40 40 2.3 Nondeterministic Finite Automata Theorem 2.12 (equivalence of DFA and NFA): A language L is accepted by some DFA if and only if L is accepted by some NFA. –Proof. See the textbook.

41 41 2.3 Nondeterministic Finite Automata 2.3.6 A Bad Case of Subset Construction –The DFA constructed from an NFA usually has the same number of accessible states of the NFA. –But the worse case is m = 2 n where where m is the number of states in the DFA. n is the number of states in the NFA.

42 42 2.3 Nondeterministic Finite Automata 2.3.7a Regarding NFA’s as DFA’s –In each state of a DFA, for each input there must be a next state. –In an NFA, for a certain input there might be no next state. So the following is an NFA. start t t h th e the n then

43 43 2.3 Nondeterministic Finite Automata 2.3.7a Regarding NFA’s as DFA’s –But it is deterministic in nature --- either getting into a next state or becoming “dead” (getting into a “dead” state). –Such a kind of NFA has at most one transition out of any state on any symbol, and may be regarded as a DFA. start t t h th e the n then


Download ppt "1 Chapter 2 Finite Automata (part a) Hokkaido, Japan."

Similar presentations


Ads by Google