1 / 43

Chapter 2

Chapter 2. Finite Automata (part a). Hokkaido, Japan. 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

elisa
Télécharger la présentation

Chapter 2

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. Chapter 2 Finite Automata (part a) Hokkaido, Japan

  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. 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. 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. $10 $10 $5 $10 $5 $0 $5 $5 $5 Start $20 $10 $10 $20 $15 transition diagram 2.2 Deterministic Finite Automata • Recall the example of a vending machine selling 20-dolllar food in Chapter 0

  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 input symbols S; • a (state) transition function dsuch that d(q, a) = p means “automaton A, in state q, takes input a • and enters state p;”

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

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

  9. 2.2 Deterministic Finite Automata • 2.2.2 How a DFA processes strings • Given an input string x = a1a2…an, if d(q0, a1) = q1, d(q1, a2) = q2, …, d(qi1, ai) = qi, ..., d(qn1, an) = qn, and qnF, then x is “accepted”; otherwise, “rejected.” • Every transition is deterministic.

  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…

  11. 2.2 Deterministic Finite automata • Example 2.1 • Transitions: • d(q0, 1) = q0, d(q0, 0) = q2, d(q2, 1) = q1, • d(q2, 0) = q2, d(q1, 0) = q1, d(q1, 1) = q1 • 5-Tuple: A = ({q0, q1, q2}, {0, 1}, d, q0, {q1})

  12. 1 0 1 0 q1 q0 Start 0, 1 q2 2.2 Deterministic Finite automata • 2.2.3 Simpler Notations for DFA’s • Transition diagram ---

  13. 2.2 Deterministic Finite automata • 2.2.3 Simpler Notations for DFA’s • Transition table --- • : initial state; *: final state

  14. 2.2 Deterministic Finite automata • 2.2.4 Extending transition function to strings • Extended transition function If x = a1a2…an and d is such that d(p, a1) = q1, d(q1, a2) = q2, …, d(qi1, ai) = qi, ..., d(qn1, an) = q, then we define to be (p, x) = q.

  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, e) = q. Induction: if w = xa (a is the last symbol of w), then (q, w) = d( (q, x), a).

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

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

  18. 1 0 1 0 q1 q0 Start 0, 1 q2 $20 $20 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!) 1 0 q1 q0 Start 0, 1 q2

  19. $20 0, 1 1 0 q1 q0 Start 0, 1 q2 2.3 Nondeterministic Finite Automata • Some properties of NFA’s • Some transitions may “die,” like d(q2, 0). • Some transitions have multiple choices, like d(q0, 0) = q0 and q2.

  20. 0, 1 1 0 q2 q0 Start q1 $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}. • Nondeterminism creates many transition paths, but if there is one path leading to a final state, then the input is accepted.

  21. 0, 1 1 0 q2 q0 Start q1 $20 q0 q0 q0 q0 q0 q0 q0 q0 q1 q1 q1 q1 q2 q2 q2 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 q0 Stuck! Stuck! Accept! Fig. 2.10

  22. 2.3 Nondeterministic Finite Automata • 2.3.2 Definition of NFA • An NFA Ais a 5-tuple A = (Q, S, d, q0, F) where • Q = a finite (nonempty) set of states; • S = a finite (nonempty) set of input symbols; • q0 = a start state; • F = a set of (nonempty) final or accepting states;

  23. 2.3 Nondeterministic Finite Automata • 2.3.2 Definition of NFA • An NFA Ais a 5-tuple A = (Q, S, d, q0, F) where • d = a (state) transition functionsuch that d(q, a) = {p1, p2, …, pm} which means • “automaton A, in state q, takes input a and enters • one of the states p1, p2, …, pm.”

  24. 0, 1 1 0 q2 q0 Start q1 $20 2.3 Nondeterministic Finite Automata • Example 2.7 • Transition table of NFA of the last example ---

  25. 2.3 Nondeterministic Finite Automata • 2.3.3 Extended Transition Function • Recursive definition of (with string as input) • Basis: (q, e) = {q}. • Induction: if w = xa (a is the last symbol of w), (q, x) = {p1, p2, …, pk}, and • d(pi, a) = {r1, r2, …, rm} • then • (q, w) = {r1, r2, …, rm}.

  26. (q, w=xa) = {r1 r2 . . . rm} 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) = {p1, p2, …, pk}, and d(pi, a) = {r1, r2, …, rm} then (q, w) = {r1, r2, …, rm}. (q, x)= {p1 p2 . . . pk} a a x … a d

  27. 0, 1 1 0 q2 q0 Start q1 $20 2.3 Nondeterministic Finite Automata • Example 2.8 --- • For the input w = 00101, we have • (q0, e) = {q0}. 2. (q0, e 0) = d(q0, 0) = {q0, q1}. 3. (q0, 00) = d(q0, 0)∪d(q1, 0)= {q0, q1}∪f ={q0, q1} …

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

  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. 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). (Definition: “Two models are said to be equivalent if they have identical languages.”) • The proof needs “subset construction.”

  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 = (QN, S, dN, q0, FN), we construct a DFA D = (QD, S, dD, q0', FD) such that: • The two alphabets are identical; • QDis the power set of QN (i.e., set of all subsets of QN); • Inaccessible states in QD should be deleted; (continued in the next page)

  32. 2.3 Nondeterministic Finite Automata • 2.3.5 Equivalence of DFA and NFA • (cont’d) • q0' = {q0}; • Each subset S of QN is in final state set FD if S includes at least one accepting state in FN (i.e., S∩FNf). • For each subset S of QN and for each input symbol a, define dD(S, a) = dN(p, a)

  33. 0, 1 1 0 q2 q0 Start q1 $20 2.3 Nondeterministic Finite Automata • Example 2.10 --- • For the NFA of Example 2.6 below: • The power set of QN = {q0, q1, q2} is QD={f, {q0}, {q1}, {q2}, {q0, q1}, {q0, q2}, {q1, q2}, {q0, q1, q2}}.

  34. 0, 1 1 0 q2 q0 Start q1 $20 2.3 Nondeterministic Finite Automata • Example 2.10 (cont’d) • The transition table is

  35. 2.3 Nondeterministic Finite Automata • Example 2.10 (cont’d) • Change names of the states, we get

  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. Figure 2.13

  37. 0, 1 1 0 q2 q0 Start q1 $20 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

  38. 1 0 1 0 Start {q0, q2} {q0} {q0, q1} 2.3 Nondeterministic Finite Automata • 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. 0 Figure 2.14 1

  39. 2.3 Nondeterministic Finite Automata • Theorem 2.11 If DFA D = (QD, S, dD, {q0}, FD) is constructed from NFA N = (QN, S, dN, q0, FN) by subset construction, then L(D) = L(N). • Proof. See the textbook.

  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 ifL is accepted by some NFA. • Proof. See the textbook.

  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 = 2n where • m is the number of states in the DFA. • n is the number of states in the NFA.

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

  43. e t h n t th start the then 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.

More Related