Sie sind auf Seite 1von 43

Chapter 2

Finite Automata (part a)

Hokkaido, Japan
1

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 Epsilon2

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. implementations. The latter is more efficient for descriptions of applications of FA.
3

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
4

2.2 Deterministic Finite Automata


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

Start

$0

$5 $10 $10 $20

2.2 Deterministic Finite Automata 2.2.1 Definition of DFA


5 A DFA A consists of 5-tuples (1/2): a finite (nonempty) set of states Q; a finite (nonempty) set of input symbols 7; a (state) transition function H such that
H q , a ) = p means

automaton A, in state q, takes input a and enters state p;


6

2.2 Deterministic Finite Automata 2.2.1 Definition of DFA


5 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 5A = (Q, 7, H, q0, F). (Q
7

2.2 Deterministic Finite Automata 2.2.1 Definition of DFA


graphic model for a DFA
tape

0 1 1 0 1 0 0
tape reader finite control

4.2
8

2.2 Deterministic Finite Automata


2.2.2 How a DFA processes strings
Given an input string x = a1a2an, if H(q0, a1) = q1, H(q1, a2) = q2, , H qi1, ai) = qi, ..., H(qn1, an) = qn, and qn F, then x is accepted; otherwise, rejected. accepted; rejected. Every transition is deterministic. deterministic.
9

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 0s and 1s}. {x01y 1s}. Examples of strings in L: 01, 11010, 100011 01, 11010, 100011

10

2.2 Deterministic Finite automata


Example 2.1
Transitions: H q0, 1) = q0, H(q0, 0) = q2, H(q2, 1) = q1, H(q2, 0) = q2, H q1, 0) = q1, H q1, 1) = q1 5-Tuple: A = ({q0, q1, q2}, {0, 1}, H, q0, {q1}) ({q {q
11

2.2 Deterministic Finite automata


2.2.3 Simpler Notations for DFAs
Transition diagram --1 0 0

Start

q0

q2

q1

0, 1

12

2.2 Deterministic Finite automata


2.2.3 Simpler Notations for DFAs
Transition table --0 p q0 *q1 q2 q2 q1 q2 1 q0 q1 q1

p: initial state; *: final state


13

2.2 Deterministic Finite automata


2.2.4 Extending transition function to strings
Extended transition function H If x = a1a2an and His such that His

H(p, a1) = q1, H(q1, a2) = q2, , H qi1, ai) = qi, ..., H(qn1, an) = q,
then we define H to be H (p , x ) = q .
14

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

2.2 Deterministic Finite automata


2.2.4 Extending Transition Function to Strings
A graphic diagram for the following concept: Induction: Induction: if w = xa (a is the last symbol of w), then
(q H(q, w) = H (H (q, x), a).

H (q, x)

a H

0, 1 (q, Hq1 w=xa)

16

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 | H(q0, w) is in F}. {w (q

If L is L(A) for some DFA A, then we say L is a regular language. language.

17

2.3 Nondeterministic Finite Automata


2.3.1 An informal view of NFAs
Review of a previous example of DFA (of Example 2.1)
1 0 0

Start

q0

q2

q1 $20

0, 1

An NFA version of above DFA (more intuitive!) (more intuitive!)


0, 1

Start

q0

q2

q1 $20

0, 1
18

2.3 Nondeterministic Finite Automata


Some properties of NFAs
0, 1 0 1

Start

q0

q2

q1 $20

0, 1

Some transitions may die, like H q2, 0). die, 0). Some transitions have multiple choices, like H(q0, 0) = q0 and q2.
19

2.3 Nondeterministic Finite Automata


Example 2.6
Design an NFA accepting the following language L = {w | w{0, 1}* and ends in 01}. {w
0, 1

Start

q0

q1

q2 $20

Nondeterminism creates many transition paths, but state, if there is one path leading to a final state, then the input is accepted.
20

2.3 Nondeterministic Finite Automata


Example 2.6 (contd)
0, 1

Start

q0

q1

q2 $20

When input x = 00101, the NFA processes x in the following way:


q0 q0 q1 Stuck!
Fig. 2.10

q0 q1

q0

q0 q1

q0

q2 Stuck!

q2 Accept!
21

2.3 Nondeterministic Finite Automata


2.3.2 Definition of NFA
An NFA A is a 5-tuple A = (Q, 7, H, q0, F) where 5(Q Q = a finite (nonempty) set of states; 7!a 7!a finite (nonempty) set of input symbols; q0 = a start state; F = a set of (nonempty) final or accepting states;

22

2.3 Nondeterministic Finite Automata


2.3.2 Definition of NFA
An NFA A is a 5-tuple A = (Q, 7, H, q0, F) where 5(Q H!a (state) transition function such that H!a H q, a) = {p1, p2, , pm}
which means

y y

automaton A, in state q, takes input a and enters one of the states p1, p2, , pm.
23

2.3 Nondeterministic Finite Automata


Example 2.7
Transition table of NFA of the last example --0, 1

Start

q0

q1

q2 $20

0 p q0 q1 *q2 {q0, q1} J J

1 {q0} {q2} J
24

2.3 Nondeterministic Finite Automata


2.3.3 Extended Transition Function
Recursive definition of H (with string as input) Basis: (q Basis: H (q, I) = {q}. {q Induction: if w = xa (a is the last symbol of w), Induction: {p H (q, x) = {p1, p2, , pk}, and {r U H(pi, a) = {r1, r2, , rm} then
i!1 k

{r H (q, w) = {r1, r2, , rm}.


25

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), Induction: {r {p H (q, x) = {p1, p2, , pk}, and H(pi, a) = {r1, r2, , rm} then H (q, w) = {r1, r2, , rm}. {r H (q, x)=

{ p1 p2 . . . p k}

a a a H

H (q, w=xa)
= {r1 r2 . . . rm }

26

2.3 Nondeterministic Finite Automata


Example 2.8 -- For the input w = 00101, we have {q 1. H(q0, I) = {q0}. 2. H(q0, I 0) = H(q0, 0) = {q0, q1}. (q {q (q 3. H (q0, 00) = H(q0, 0) H(q1, 0) = {q0, q1} J!{q0, q1} {q J!{
Start
0, 1

q0

q1

q2 $20

27

2.3 Nondeterministic Finite Automata


2.3.4 The Language of an NFA
Definition --If A = (Q, 7, H, q0, F) is an NFA, then the language (Q accepted by A is L(A) = {w H (q0, w) F { J}. {w | (q That is, as long as a final state is reached, which is among possibly many, the input is accepted.
28

2.3 Nondeterministic Finite Automata


2.3.5 Equivalence of DFA and NFA
NFAs are more intuitive to construct for many languages. DFAs are easier for use in software and hardware implementations.

29

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

2.3 Nondeterministic Finite Automata


2.3.5 Equivalence of DFA and NFA
Subset construction: each state of DFA is a subset construction: of NFA Given an NFA N = (QN, 7, H2, q0, FN), we (Q construct a DFA D = (QD, 7, HD, q0', FD) such that: (Q
The two alphabets are identical; QD is 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)
31

2.3 Nondeterministic Finite Automata


2.3.5 Equivalence of DFA and NFA
(contd) q0' = {q0}; {q

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 { J). For each subset S of QN and for each input symbol a, define HD(S, a) = U HN(p, a) a) a)
pS
32

2.3 Nondeterministic Finite Automata


Example 2.10 -- For the NFA of Example 2.6 below:
0, 1

Start

q0

q1

q2 $20

The power set of QN = {q0, q1, q2} is QD = _J, {q0}, {q1}, {q2}, {q0, q1}, {q0, q2}, _J, {q {q {q {q {q {q1, q2}, {q0, q1, q2}}. {q }}.
33

2.3 Nondeterministic Finite Automata


Example 2.10 (contd)
0, 1

Start

q0

q1

q2 $20
0 1 J {q0} {q2} J {q0, q2} {q0} {q2} {q0, q2}
34

The transition table is

J p{q0} {q1} *{q2} {q0, q1} *{q0, q2} *{q1, q2} *{q0, q1, q2}

J {q0, q1} J J {q0, q1} {q0, q1} J {q0, q1}

2.3 Nondeterministic Finite Automata


Example 2.10 (contd)
Change names of the states, we get
0 A pB C *D E *F *G *H A E A A E E A E 1 A B D A F B D F
35

2.3 Nondeterministic Finite Automata


Example 2.10 (contd)
Checking accessible states from the start state as red ones; the others are inaccessible.
0 A pB C *D E *F *G *H A E A A E E A E 1 A B D A F B D F
36

Figure 2.13

2.3 Nondeterministic Finite Automata


Example 2.10 (contd) (supplemental) solved by Lazy evaluation using table: Lazy evaluation
starting from the start state, only accessible states are evaluated, in order to avoid generation of inaccessible states.
0, 1

Start

q0

q1

q2 $20

The transition table is

J p{q0} 0 {q1} 1 *{q2} 2 {q0, q1} 0 1 *{q0, q2} 0 2 *{q1, q2} 1 2 *{q0, q1, q2} 0 1 2

0 J {q0, q1} 0 1 J J {q0, q1} 0 1 {q0, q1} 0 1 J {q0, q1} 0 1

1 J {q0} 0 {q2} 2 J {q0, q2} 0 2 {q0} 0 {q2} 2 {q0, q2} 0 2

37

2.3 Nondeterministic Finite Automata


Example 2.10 (contd) ---

solved by Lazy evaluation using diagram: Lazy evaluation


starting from the start state, only accessible states are evaluated, in order to avoid generation of inaccessible states.
1 0

Start

{q0}

{q0, q1}

1 0

{q0, q2}

Figure 2.14

1
38

2.3 Nondeterministic Finite Automata


Theorem 2.11
If DFA D = (QD, 7, HD, {q0}, FD) is constructed (Q {q from NFA N = (QN, 7, H2, q0, FN) by subset (Q construction, then L(D) = L(N). Proof. See the textbook.

39

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.

40

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.
41

2.3 Nondeterministic Finite Automata


2.3.7a Regarding NFAs as DFAs
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.
t h e n

start

th

the

then

42

2.3 Nondeterministic Finite Automata


2.3.7a Regarding NFAs as DFAs
But it is deterministic in nature --- either getting into a next state or becoming dead (getting into a dead dead state).
start
t t h th e the n then

Such a kind of NFA has at most one transition out of any state on any symbol, and may be regarded symbol, as a DFA.
43

Das könnte Ihnen auch gefallen