1 Chapter 2 Finite Automata (part b) Windmills in Holland.

43
1 Chapter 2 Chapter 2 Finite Automata Finite Automata (part b) (part b) Windmills in Holland

Transcript of 1 Chapter 2 Finite Automata (part b) Windmills in Holland.

11

Chapter 2 Chapter 2

Finite AutomataFinite Automata(part b)(part b)

Windmills in Holland

22

OutlineOutline

(part a --- in another PPT)(part a --- in another PPT)

2.0 Introduction2.0 Introduction

2.1 An Informal Picture of Finite Automata 2.1 An Informal Picture of Finite Automata

2.2 Deterministic Finite automata2.2 Deterministic Finite automata

2.3 Nondeterministic Finite Automata2.3 Nondeterministic Finite Automata

(part b --- in this PPT)(part b --- in this PPT)

2.4 An Application: Text Search2.4 An Application: Text Search

2.5 Finite Automata with Epsilon-Transitions2.5 Finite Automata with Epsilon-Transitions

33

2.4 An Application: Text Search2.4 An Application: Text Search

2.4.1 Finding Strings in Text2.4.1 Finding Strings in Text– Searching Google for a set of words is equivalent Searching Google for a set of words is equivalent

to just finding strings in documentsto just finding strings in documents

– TechniquesTechniques

Using Using inverted indexesinverted indexes

Using Using finite automatafinite automata

– Applications unsuitable to use inverted indexing:Applications unsuitable to use inverted indexing:

Document repository change rapidly.Document repository change rapidly.

Documents to be searched cannot be catalogued.Documents to be searched cannot be catalogued.

Keyword K

Page p1

Page p2

.

.

Page pnInverted indexing

44

2.4 An Application: Text Search2.4 An Application: Text Search

2.4.2 NFA’s for Text Search2.4.2 NFA’s for Text Search– (supplemental 1/3)(supplemental 1/3) A simple example --- find the DF A simple example --- find the DF

A equivalent to the following NFA which searches woA equivalent to the following NFA which searches words of rds of xx11 = = abab and and xx22 = = bb in long text strings in long text strings

a, b2

StartStart

bb

a, b

$20 4 aa

1 a, b

$20 3bb

55

2.4 An Application: Text Search2.4 An Application: Text Search

2.4.2 NFA’s for Text Search2.4.2 NFA’s for Text Search– (supplemental 2/3)(supplemental 2/3) A simple example (con’d) --- find A simple example (con’d) --- find

the DFA equivalent to the following NFA (note: state the DFA equivalent to the following NFA (note: state 12 means state {1, 2}, etc.)12 means state {1, 2}, etc.)

StartStart

bb

a

12 $20

b

134

aa

1 b

$2013bb

$20

a

1234

aa

bb

a

$20123 aa

bb

66

2.4 An Application: Text Search2.4 An Application: Text Search

2.4.2 NFA’s for Text Search2.4.2 NFA’s for Text Search– (supplemental 3/3)(supplemental 3/3) A simple example (con’d) --- co A simple example (con’d) --- co

mpare!!!mpare!!!

StartStart

bb

a

12 $20

a, b

134

aa

1 a, b

$2013bb

a, b2

StartStart

bb

a, b

$20 4

aa

1 a, b

$20 3bb

77

2.4 An Application: Text Search2.4 An Application: Text Search

2.4.2 NFA’s for Text Search2.4.2 NFA’s for Text Search– Example 2.14: Example 2.14: use an NFA to search two keywords “use an NFA to search two keywords “

web” and “eBay” among textweb” and “eBay” among text

Figure 2.16 (Note: there are two final states; red parts are necessary and missing in the textbook; correct your textbook!!!)

2

StartStart

3 ee

$20 4 bb

ww

1

6 7 $20 85 ee

bb aa yy

= set of all printable ASCII characters

88

2.4 An Application: Text Search2.4 An Application: Text Search

2.4.2 NFA’s for Text Search2.4.2 NFA’s for Text Search– Example 2.14 (cont’d): Example 2.14 (cont’d): how to implement NFA?how to implement NFA?

Write a simulation program like Fig. 2.10Write a simulation program like Fig. 2.10

Convert the NFA to an equivalent DFA using subset constrConvert the NFA to an equivalent DFA using subset construction and simulate the DFA.uction and simulate the DFA.

q0

q1

Stuck!

q0

q1

q2 Stuck!

q0 q0

q1

q2

Accept!

q0 q0q0 q0 q0

q1

q2Fig. 2.10

99

2.4 An Application: Text Search2.4 An Application: Text Search

2.4.3 A DFA to Recognize a Set of Keywords2.4.3 A DFA to Recognize a Set of Keywords– The converted DFA has an equal number of states of the origThe converted DFA has an equal number of states of the orig

inal NFA (an observation).inal NFA (an observation).

– The DFA states may be constructed as (may be proved):The DFA states may be constructed as (may be proved):If qIf q00 is start state of NFA, then { is start state of NFA, then {qq00} is start state of DFA} is start state of DFA

If pIf p is a state of NFA reachable (accessible) from a path is a state of NFA reachable (accessible) from a path xx = = aa11aa22……aamm, , thenthen

one state of the DFA is a set of NFA states consisting ofone state of the DFA is a set of NFA states consisting of1.1. qq00

2.2. pp

3.3. every other NFA states reachable from every other NFA states reachable from qq00 by following every subpath w by following every subpath which is a hich is a suffixsuffix ( (尾段尾段 ) of ) of xx, like , like aajjaajj+1+1……aamm..

– In the above way, all states in the DFA may be constructed, aIn the above way, all states in the DFA may be constructed, and then all transitions derived (see the next page).nd then all transitions derived (see the next page).

1010

2.4 An Application: Text Search2.4 An Application: Text Search

2.4.3 A DFA to Recognize a Set of Keywords2.4.3 A DFA to Recognize a Set of Keywords– Example 2.15 (a continuation of Example 2.14)Example 2.15 (a continuation of Example 2.14)

E.g., state 3 of the NFA becomes state 135 of the DFA E.g., state 3 of the NFA becomes state 135 of the DFA because because

start state 1 is included;start state 1 is included;

state 3 itself is reachable by the path state 3 itself is reachable by the path xx==wewe, so state 3 itself , so state 3 itself is included;is included;

xx has a suffix has a suffix ee by which states 1 and 5 are reachable from by which states 1 and 5 are reachable from start state 1. start state 1.

(for the transition diagram, see the next page)(for the transition diagram, see the next page)

1111

2.4 An Application: Text Search2.4 An Application: Text Search2.4.3 A DFA to Recognize a Set of Keywords2.4.3 A DFA to Recognize a Set of Keywords

– Example 2.15 (a continuation of Example 2.14)Example 2.15 (a continuation of Example 2.14)E.g., state 3 of the NFA becomes state 135 of the DFAE.g., state 3 of the NFA becomes state 135 of the DFA

2

StartStart

3 ee

$20 4

bb

ww

1

6 7 $20 85 ee

bb aa yy

12

Start

3 e b

w

e

b a y

135

1

16 17 1815

146

1212

2.4 An Application: Text Search2.4 An Application: Text Search

2.4.3 A DFA to Recognize a Set of Keywords2.4.3 A DFA to Recognize a Set of Keywords

– How to derive transitions ---How to derive transitions ---

For any state of the DFA of the form {For any state of the DFA of the form {qq00,, pp11, , pp22, …, , …, ppnn}, a}, a

nd for each input nd for each input symbol symbol xx, let the reached states be {, let the reached states be {rr11, , rr22, ,

…, …, rrmm}, then the next state is {}, then the next state is {qq00, , rr11, , rr22, …, , …, rrmm}.}.

If If nono rrii as above can be collected, then if the as above can be collected, then if the reached statesreached states

from the from the qq00 by by x x are {are {ss11, , ss22, …, , …, sskk}, then the next state is {}, then the next state is {qq

00,, ss11, , ss22, …, , …, sskk}.}.

1313

2.4 An Application: Text Search2.4 An Application: Text Search2.4.3 A DFA to Recognize a Set of Keywords2.4.3 A DFA to Recognize a Set of Keywords

– How to derive transitions ---How to derive transitions ---e.g., (1) for e.g., (1) for xx==bb, state 3, state 34, state 54, state 56, 6,

so state 135so state 135146146 (2) for (2) for xx==ee, state 3, state 3, state 5, state 5, but state 1, but state 15, 5, so state 135so state 1351515

12

Start

3 e

w

e

b a y

135 b

1

16 17 1815

146

e

1414

2.4 An Application: Text Search2.4 An Application: Text Search

2.4.3 A DFA to Recognize a Set of Keywords2.4.3 A DFA to Recognize a Set of Keywords

– A complete NFA to DFA conversion is shown in A complete NFA to DFA conversion is shown in

Fig. 2.17 (Fig. 2.17 ( bb ee ww, e.g., means all ASCII , e.g., means all ASCII

characters other than characters other than bb, , ee, , ww). ).

– Derive it by yourself. Derive it by yourself. Can you write it down Can you write it down

directly???directly???

– The above rules for constructing the DFA The above rules for constructing the DFA

directly may be thought as theorems!directly may be thought as theorems!

1515

2.5 Finite Automata with Epsilon-2.5 Finite Automata with Epsilon-TransitionsTransitions

2.5.1 Use of 2.5.1 Use of -transitions-transitions

– We allow the automaton to accept the empty We allow the automaton to accept the empty

string string ..

– This means that a transition is allowed to occur This means that a transition is allowed to occur

withoutwithout reading in a symbol. reading in a symbol.

– The resulting NFA is called The resulting NFA is called -NFA-NFA..

– It adds “programming (design) convenience” It adds “programming (design) convenience”

(more intuitive for use in designing FA’s)(more intuitive for use in designing FA’s)

1616

Example 2.16: Example 2.16: an an -NFA accepting decimal -NFA accepting decimal numbersnumbers like 2.15, .125, +1.4, -0.501… like 2.15, .125, +1.4, -0.501…

– To accept a number like “+5.” (nothing after the To accept a number like “+5.” (nothing after the decimal point), we have to add decimal point), we have to add qq44..

qq55

0, 1, …, 90, 1, …, 9

2.5 Finite Automata with Epsilon-2.5 Finite Automata with Epsilon-TransitionsTransitions

startstart qq00, + , -, + , - qq11 qq22

..

0, 1, …, 90, 1, …, 9

0, 1, …, 90, 1, …, 9qq33

qq44

0, 1, …, 90, 1, …, 9 ..

Figure 2.18Figure 2.18

1717

2.5 Finite Automata with Epsilon-2.5 Finite Automata with Epsilon-TransitionsTransitions

Example 2.17: a more intuitive Example 2.17: a more intuitive -NFA for -NFA for Example 2.14Example 2.14

Figure 2.19 Design an NFA with -transitions.

2

StartStart

3 ee

$2 4 bb

9

6 7 80 bb aa yy

1 ww

5 ee

1818

2.5 Finite Automata with Epsilon-2.5 Finite Automata with Epsilon-TransitionsTransitions

2.5.2 Formal Notation for an 2.5.2 Formal Notation for an -NFA-NFA

– Definition: an Definition: an -NFA -NFA AA is denoted by is denoted by AA = ( = (QQ, , , , , ,

qq00, , FF)) where the transition function where the transition function takes as argu takes as argu

ments:ments:

a state in a state in QQ, and , and

a member of a member of ∪∪{{}}

1919

2.5 Finite Automata with Epsilon-2.5 Finite Automata with Epsilon-TransitionsTransitions

2.5.2 Formal Notation for an 2.5.2 Formal Notation for an -NFA-NFA

– Notes: Notes:

cannotcannot be used as an input symbol, but can b be used as an input symbol, but can b

e accepted to yield a transition!e accepted to yield a transition!

((qqii, , ) is defined for every state ) is defined for every state qqii ( (getting into getting into

the dead state the dead state if there is no next state if there is no next state with with as as

input symbolinput symbol originally originally).).

2020

2.5 Finite Automata with Epsilon-2.5 Finite Automata with Epsilon-TransitionsTransitions

2.5.2 Formal Notation for an 2.5.2 Formal Notation for an -NFA-NFA

– Example 2.18: the Example 2.18: the -NFA of Fig. 2.18 is described as -NFA of Fig. 2.18 is described as

EE = ({ = ({qq00, , qq11, ..., , ..., qq55}, {., +, }, {., +, , 0, 1, ..., 9}, , 0, 1, ..., 9}, , , qq00, {, {qq55})})

The transitions, e.g., include The transitions, e.g., include

– ((qq00, , ) = ) = qq11

– ((qq11, , ) = ) =

See Fig. 2.20 for the complete transition table of See Fig. 2.20 for the complete transition table of E E

(next page).(next page).

2121

2.5 Finite Automata with Epsilon-2.5 Finite Automata with Epsilon-TransitionsTransitions

2.5.2 Formal Notation for an 2.5.2 Formal Notation for an -NFA-NFA

– Example 2.18 (cont’d):Example 2.18 (cont’d):

Fig. 2.20 --- the complete transition table of Fig. 2.20 --- the complete transition table of EE..

0, 1, …, 9

q0

q1

q2

q3

q4

q5

{q1}

{q5}

{q1}

{q2}

{q3}

{q1, q4}

{q3}

{q3}

2222

2.5 Finite Automata with Epsilon-2.5 Finite Automata with Epsilon-TransitionsTransitions

2.5.3 Epsilon-Closures (2.5.3 Epsilon-Closures (-closures)-closures)

– We have to define the We have to define the -closure-closure to define the extended to define the extended

transition function for the transition function for the -NFA.-NFA.

– We “We “-closure-closure” a state ” a state qq by following all transitions by following all transitions

out of out of qq that are labeled that are labeled ..

2323

2.5 Finite Automata with Epsilon-2.5 Finite Automata with Epsilon-TransitionsTransitions

2.5.3 Epsilon-Closures (2.5.3 Epsilon-Closures (-closures)-closures)

– Formal recursive definition of Formal recursive definition of the setthe set ECLOSE( ECLOSE(qq) for ) for qq::

State State qq is in ECLOSE( is in ECLOSE(qq) (including the state ) (including the state itselfitself););

If If pp is in ECLOSE( is in ECLOSE(qq), then all states accessible from ), then all states accessible from pp through through

pathspaths of of ’s’s are also in ECLOSE( are also in ECLOSE(qq).).

(“(“經經式式式式式式式式式式式式式式可到的所有可到的所有 statesstates 車站車站皆算在內”皆算在內” ))

2424

2.5 Finite Automata with Epsilon-2.5 Finite Automata with Epsilon-TransitionsTransitions

2.5.3 Epsilon-Closures2.5.3 Epsilon-Closures– -closure for a set of states -closure for a set of states SS::

ECLOSE(ECLOSE(SS)) = = ∪∪qqSS ECLOSE( ECLOSE(qq))

– Example 2.19Example 2.19

ECLOSE(1) = {1, 2, 3, 4, 6}ECLOSE(1) = {1, 2, 3, 4, 6}ECLOSE({3, 5}) = ECLOSE(ECLOSE({3, 5}) = ECLOSE(33)) ECLOSE(∪ECLOSE(∪ 55) = ) = {{33, 6}, 6}∪∪{{55, 7} = {3, 5, 6, 7}, 7} = {3, 5, 6, 7}

3 6

1

74

2

5aa

bb

2525

2.5 Finite Automata with Epsilon-2.5 Finite Automata with Epsilon-TransitionsTransitions

2.5.4 Extended Transitions & Languages for 2.5.4 Extended Transitions & Languages for -NFA-NFA’s’s– Recursive definition of extended transition function Recursive definition of extended transition function

: :

BasisBasis: (: (qq, , ) = ECLOSE() = ECLOSE(qq). ).

InductionInduction: if : if ww = = xaxa, then (, then (qq, , ww) is computed as:) is computed as:

If (If (qq, , xx) = ) = {{pp11, , pp22, …, , …, ppkk}} and and

((ppii, , aa) = {) = {rr11, , rr22, …, , …, rrmm},},

then then ((qq, , ww) = ) = ECLOSE(ECLOSE({{rr11, , rr22, …, , …, rrmm})})==ECLOSE( ECLOSE( ((ppii, , aa)))) . .

1

k

iU

1

k

iU

2626

2.5 Finite Automata with Epsilon-2.5 Finite Automata with Epsilon-TransitionsTransitions

2.5.4 Extended Transitions & Languages for 2.5.4 Extended Transitions & Languages for -NF-NFA’sA’s– InductionInduction: if : if ww = = xaxa, then (, then (qq, , ww) is computed as:) is computed as:

If (If (qq, , xx) = ) = {{pp11, , pp22, …, , …, ppkk}} and and ((ppii, , aa) = {) = {rr11, , rr22, …, , …, rrmm},},

then then ((qq, , ww) = ) = ECLOSEECLOSE(({{rr11, , rr22, …, , …, rrmm}).}).

1

k

iU

……

a (q, x)= { p1 p2 . . . pk}

x

a

a

{ r1

r2 . . . rm}

ECLOSE

{ r1,

r2, …, rm}

2727

2.5 Finite Automata with Epsilon-2.5 Finite Automata with Epsilon-TransitionsTransitions

Example 2.20 ---Computing (Example 2.20 ---Computing (qq00,, 5.6) for 5.6) for -NFA of Fig. -NFA of Fig. 2.18.2.18.

– Compute Compute ((qq00, 5), 5)= = ((qq00, , 5)5) first: first:– ((qq00, , )) = ECLOSE( = ECLOSE(qq00) = {) = {qq00, , qq11}}式 ((qq00, 5), 5)∪∪((qq11, 5) = , 5) = ∪∪{{qq11, , qq44} = {} = {qq11, , qq44}}

– ((qq00, 5), 5) = = ( (qq00, , 5)5) = ECLOSE( = ECLOSE(((qq00, 5), 5)∪∪((qq11, 5), 5)))

= ECLOSE(= ECLOSE({{qq11, , qq44}}) = E) = ECLOSE(CLOSE({{qq11}}))∪∪ECLOSE(ECLOSE({{qq44}}) )

= = {{qq11, , qq44}} (complete the rest of computations by yourself!) -(complete the rest of computations by yourself!) -

qq55

0, 1, …, 90, 1, …, 9

startstart qq00, + , -, + , - qq11 qq22

..

0, 1, …, 90, 1, …, 9

0, 1, …, 90, 1, …, 9qq33

qq44

0, 1, …, 90, 1, …, 9 ..Figure 2.18Figure 2.18

2828

2.5 Finite Automata with Epsilon-2.5 Finite Automata with Epsilon-TransitionsTransitions

2.5.5 Eliminating 2.5.5 Eliminating -Transitions-Transitions

– The The -transition is good for design of FA, but for i-transition is good for design of FA, but for i

mplementation, they have to be eliminated.mplementation, they have to be eliminated.

– Given an Given an -NFA, we can find an equivalent DFA -NFA, we can find an equivalent DFA

(a theorem seen later).(a theorem seen later).

– Let Let EE = ( = (QQEE, , , , EE, , qq00, , FFEE)) be the given be the given -NFA, the -NFA, the

equivalent DFA equivalent DFA DD = ( = (QQDD, , , , DD, , qqDD, , FFDD)) is is

constructed as follows (in the next page).constructed as follows (in the next page).

2929

2.5 Finite Automata with Epsilon-2.5 Finite Automata with Epsilon-TransitionsTransitions

– QQDD is the set of is the set of subsetssubsets of of QQEE, in which , in which each accesseach access

ibleible is an is an -closed subset of -closed subset of QQEE, i.e., are sets , i.e., are sets SS QQ

EE such that such that SS = ECLOSE( = ECLOSE(SS).).

In other words, In other words, eacheach -closed set of states, -closed set of states, SS, i, includes those states such that any ncludes those states such that any -transition out o-transition out of one of the states in f one of the states in SS leads to a state that is also in leads to a state that is also in SS..

– qqDD = ECLOSE( = ECLOSE(qq00) ) (initial state of (initial state of DD))

– FFDD = { = {SS | | SSQQDD and and SS∩∩FFEE}}

(continued in the next page)(continued in the next page)

3030

2.5 Finite Automata with Epsilon-2.5 Finite Automata with Epsilon-TransitionsTransitions

– DD((SS, , aa) is computed for each ) is computed for each aa in in and each and each SS in in QQ

DD in the following way: in the following way:

Let Let SS = { = {pp11, , pp22, ..., , ..., ppkk}}

Compute Compute ((ppii, , aa) and let this set be {) and let this set be {rr11, , rr22, …, , …, rrmm}}

Set Set DD((SS, , aa) = ECLOSE() = ECLOSE({{rr11, , rr22, …, , …, rrmm}}) )

= ECLOSE( = ECLOSE( ((ppii, , aa))))

– Technique to create accessible states in DFA Technique to create accessible states in DFA DD::

starting from the start state starting from the start state qq00 of of -NFA -NFA EE, generate ECL, generate ECL

OSE(OSE(qq00) as start state ) as start state qqDD of of D;D;

from the generated states to derive other states.from the generated states to derive other states.

1

k

iU

1

k

iU

3131

2.5 Finite Automata with Epsilon-Transitions2.5 Finite Automata with Epsilon-Transitions Example 2.21: eliminate Example 2.21: eliminate -transitions of Fig. 2.18.-transitions of Fig. 2.18.

– Start state Start state qqDD = = ECLOSE(ECLOSE(qq00) = ) = {{qq00, , qq11}}

– DD({({qq00, , qq11}, +) = ECLOSE(}, +) = ECLOSE(EE((qq00, +), +)∪∪EE((qq11, +)) , +))

= ECLOSE({= ECLOSE({qq11}}∪∪) = ECLOSE() = ECLOSE({{qq11}}) = {) = {qq11}, ...}, ...

式 DD({({qq00, , qq11}, 0) = ECLOSE(}, 0) = ECLOSE(EE((qq00, 0), 0)∪∪EE((qq11, 0)) , 0))

= ECLOSE (= ECLOSE (∪∪{{qq11, , qq44}) = ECLOSE({}) = ECLOSE({qq11, , qq44}) = {}) = {qq11, , qq44}, ...}, ...

式 DD({({qq00, , qq11}, .) = ECLOSE(}, .) = ECLOSE(EE((qq00, .), .)∪∪EE((qq11, .)) = {, .)) = {qq22}}

qq55

0, 1, …, 90, 1, …, 9

startstart qq00, + , -, + , - qq11 qq22

..

0, 1, …, 90, 1, …, 9

0, 1, …, 90, 1, …, 9qq33

qq44

0, 1, …, 90, 1, …, 9 ..Figure 2.18Figure 2.18

3232

2.5 Finite Automata with Epsilon-2.5 Finite Automata with Epsilon-TransitionsTransitions

Example 2.21: (cont’d)Example 2.21: (cont’d)

+ , -+ , -{{qq11

}}

startstart {{qq00, ,

qq11}}

Figure 2.22Figure 2.22

{{qq11, , qq44}}0, 1, …, 90, 1, …, 9

{{qq22}}..

3333

2.5 Finite Automata with Epsilon-2.5 Finite Automata with Epsilon-TransitionsTransitions

Example 2.21: (cont’d)Example 2.21: (cont’d)

式 DD({({qq11}, 0) = ECLOSE(}, 0) = ECLOSE(EE((qq11, 0)) = ECLOSE({, 0)) = ECLOSE({qq11, , qq44})})

= {= {qq11, , qq44}...}...

式 DD({({qq11}, .) = ECLOSE(}, .) = ECLOSE(EE((qq11, .)) = ECLOSE({, .)) = ECLOSE({qq22})})

= {= {qq22}}

qq55

0, 1, …, 90, 1, …, 9

startstart qq00, + , -, + , - qq11 qq22

..

0, 1, …, 90, 1, …, 9

0, 1, …, 90, 1, …, 9qq33

qq44

0, 1, …, 90, 1, …, 9 ..Figure 2.18Figure 2.18

3434

2.5 Finite Automata with Epsilon-2.5 Finite Automata with Epsilon-TransitionsTransitions

+ , -+ , -{{qq11

}}

startstart {{qq00, ,

qq11}}

{{qq11, , qq44}}0, 1, …, 90, 1, …, 9

{{qq22}}..

0, 1, …, 90, 1, …, 9

..

3535

Example 2.21: (cont’d)Example 2.21: (cont’d)

式 DD({({qq11, , qq44}, 0) = ECLOSE(}, 0) = ECLOSE(EE((qq11, 0)∪, 0)∪EE((qq44, 0)), 0))

= ECLOSE({= ECLOSE({qq11, , qq44}∪}∪) = {) = {qq11, , qq44}...}...

式 DD({({qq11, , qq44}, .) = ECLOSE(}, .) = ECLOSE(EE((qq11, .)∪, .)∪EE((qq44, .)) = , .)) =

ECLOSE({ECLOSE({qq22} {∪} {∪ qq33}) = ECLOSE(}) = ECLOSE(qq22) ECLOSE (∪) ECLOSE (∪ qq33))

= {= {qq22}∪}∪{{qq33, , qq55}} = { = {qq22, , qq33, , qq55}}

qq55

0, 1, …, 90, 1, …, 9

startstart qq00, + , -, + , - qq11 qq22

..

0, 1, …, 90, 1, …, 9

0, 1, …, 90, 1, …, 9qq33

qq44

0, 1, …, 90, 1, …, 9 ..Figure 2.18Figure 2.18

2.5 Finite Automata with Epsilon-Transitions2.5 Finite Automata with Epsilon-Transitions

3636

0, 1, …, 90, 1, …, 9

2.5 Finite Automata with Epsilon-2.5 Finite Automata with Epsilon-TransitionsTransitions

+ , -+ , -{{qq11

}}

startstart {{qq00, ,

qq11}}

{{qq11, , qq44}}0, 1, …, 90, 1, …, 9

{{qq22}}..

0, 1, …, 90, 1, …, 9

..

{{qq22, , qq33, , qq55}}..

3737

Example 2.21: (cont’d)Example 2.21: (cont’d)

式 DD({({qq22}, 0) = ECLOSE(}, 0) = ECLOSE(EE((qq22, 0)) = ECLOSE({, 0)) = ECLOSE({qq33}) = {}) = {qq33, , qq55} } ……

式 DD({({qq22, , qq33, , qq55}, 0) = ECLOSE(}, 0) = ECLOSE(EE((qq22, 0)∪, 0)∪EE((qq33, 0) ∪, 0) ∪

EE((qq55, 0))=ECLOSE({, 0))=ECLOSE({qq33} {∪} {∪ qq33}∪}∪)=ECLOSE()=ECLOSE(qq33)={)={qq33, , qq55} } ……

qq55

0, 1, …, 90, 1, …, 9

startstart qq00, + , -, + , - qq11 qq22

..

0, 1, …, 90, 1, …, 9

0, 1, …, 90, 1, …, 9qq33

qq44

0, 1, …, 90, 1, …, 9 ..Figure 2.18Figure 2.18

2.5 Finite Automata with Epsilon-Transitions2.5 Finite Automata with Epsilon-Transitions

3838

2.5 Finite Automata with Epsilon-2.5 Finite Automata with Epsilon-TransitionsTransitions

0, 1, …, 90, 1, …, 9

+ , -+ , -{{qq11

}}

startstart {{qq00, ,

qq11}}

{{qq11, , qq44}}0, 1, …, 90, 1, …, 9

{{qq22}}..

0, 1, …, 90, 1, …, 9

..

{{qq22, , qq33, , qq55}}..

{{qq33, , qq55}}0, 1, …90, 1, …9

0, 1, …90, 1, …9

3939

Example 2.21: (cont’d)Example 2.21: (cont’d)

式 DD({({qq33, , qq55}, 0) = ECLOSE(}, 0) = ECLOSE(EE((qq33, 0)∪, 0)∪EE((qq55, 0)) , 0))

=ECLOSE({=ECLOSE({qq33}∪}∪) =ECLOSE() =ECLOSE(qq33)={)={qq33, , qq55} } ……

qq55

0, 1, …, 90, 1, …, 9

startstart qq00, + , -, + , - qq11 qq22

..

0, 1, …, 90, 1, …, 9

0, 1, …, 90, 1, …, 9qq33

qq44

0, 1, …, 90, 1, …, 9 ..Figure 2.18Figure 2.18

2.5 Finite Automata with Epsilon-Transitions2.5 Finite Automata with Epsilon-Transitions

4040

0, 1, …, 90, 1, …, 9

2.5 Finite Automata with Epsilon-2.5 Finite Automata with Epsilon-TransitionsTransitions

0, 1, …, 90, 1, …, 9

+ , -+ , -{{qq11

}}

startstart {{qq00, ,

qq11}}

{{qq11, , qq44}}0, 1, …, 90, 1, …, 9

{{qq22}}..

0, 1, …, 90, 1, …, 9

..

{{qq22, , qq33, , qq55}}..

{{qq33, , qq55}}0, 1, …90, 1, …9

0, 1, …90, 1, …9

4141

Example 2.21: (cont’d)Example 2.21: (cont’d)– The dead state The dead state need be shown. need be shown.

– But according to Section 2.3.7a, the diagram in the last page But according to Section 2.3.7a, the diagram in the last page may be regarded as deterministic.may be regarded as deterministic.

0, 1, …, 90, 1, …, 9

0, 1, …, 90, 1, …, 9

0, 1, …, 90, 1, …, 9

+ , -+ , -{{qq11

}}

startstart {{qq00, ,

qq11}}

{{qq11, , qq44}}0, 1, …, 90, 1, …, 9

{{qq22}}..

0, 1, …, 90, 1, …, 9

..

{{qq22, , qq33, , qq55}}..

{{qq33, , qq55}}all symbolsall symbols

0, 1, …90, 1, …9

2.5 Finite Automata with Epsilon-Transitions2.5 Finite Automata with Epsilon-Transitions

+, -, +, -, ..

+, -, .+, -, .

+, -+, -

+, -, .+, -, .

+, -+, -

4242

2.5 Finite Automata with Epsilon-2.5 Finite Automata with Epsilon-TransitionsTransitions

Theorem 2.22 Theorem 2.22 – A language A language LL accepted by some accepted by some -NFA if and only -NFA if and only

if if LL is accepted by some DFA. is accepted by some DFA.– Proof: see the textbook yourself.Proof: see the textbook yourself.

4343

2.6 A Review2.6 A Review

3 Types of Automata 3 Types of Automata – DFA ---DFA ---good for soft/hardware implementationgood for soft/hardware implementation

– NFA ( NFA ( -NFA -NFA )) ---intermediately intuitive ---intermediately intuitive– -NFA ---most intuitive-NFA ---most intuitive

-NFA-NFA

DFADFA

-NFA-NFA

equivalentequivalent