47
CS311: CS311: Computational Computational Theory Theory Lecture 2: Regular Languages– Ch 1 Lecture 2: Regular Languages– Ch 1 Dr. Manal Helal, Spring 2014. Dr. Manal Helal, Spring 2014. http://moodle.manalhelal.com http://moodle.manalhelal.com

CS311: Computational Theory

Embed Size (px)

DESCRIPTION

CS311: Computational Theory. Lecture 2: Regular Languages– Ch 1. Dr. Manal Helal, Spring 2014. http:// moodle.manalhelal.com. Lecture Learning Objectives. Design automata for simple problems Study languages recognized by finite automata . Discuss the concepts of finite state machines. - PowerPoint PPT Presentation

Citation preview

Page 1: CS311: Computational Theory

CS311: CS311: Computational Computational

TheoryTheory

Lecture 2: Regular Languages– Ch 1Lecture 2: Regular Languages– Ch 1

Dr. Manal Helal, Spring 2014.Dr. Manal Helal, Spring 2014.http://moodle.manalhelal.comhttp://moodle.manalhelal.com

Page 2: CS311: Computational Theory

Lecture Learning ObjectivesLecture Learning Objectives

1.1. Design automata for simple problemsDesign automata for simple problems

2.2. Study languages recognized by finite Study languages recognized by finite

automata.automata.

3.3. Discuss the concepts of finite state machines.Discuss the concepts of finite state machines.

4.4. Design a deterministic finite state machine to Design a deterministic finite state machine to

accept a specified language.accept a specified language.

5.5. Design Non-Deterministic finite state Design Non-Deterministic finite state

machine, and transform NFA, to DFA.machine, and transform NFA, to DFA.

Page 3: CS311: Computational Theory

Recognizing Finite LanguagesRecognizing Finite Languages

• Just need a lookup table and a search Just need a lookup table and a search

algorithmalgorithm

• Problem – cannot express infinite sets, e.g. Problem – cannot express infinite sets, e.g.

odd integersodd integers

Page 4: CS311: Computational Theory

Finite AutomataFinite Automata

• The simplest machine that can recognize an infinite The simplest machine that can recognize an infinite

language.language.

““Read once”, “no write” procedure.Read once”, “no write” procedure.

• Useful for describing algorithms also. Used a lot in Useful for describing algorithms also. Used a lot in

network protocol description.network protocol description.

• Remember: DFA’s can accept finite languages as Remember: DFA’s can accept finite languages as

well.well.

Page 5: CS311: Computational Theory

A Simple Automaton (0)A Simple Automaton (0)

Page 6: CS311: Computational Theory

A Simple Automaton (1)A Simple Automaton (1)

on input “0110”, the machine goes:

q1

→q1

→q2

→q2

→q3

=“reject”

Page 7: CS311: Computational Theory

A Simple Automaton (2)A Simple Automaton (2)

on input “101”, the machine goes:

q1 →q2 →q3 →q2 =“accept”

Page 8: CS311: Computational Theory

A Simple Automaton (3)A Simple Automaton (3)

on input “101”, the machine goes:

q1 →q2 →q3 →q2 =“accept”

Page 9: CS311: Computational Theory

9

Finite Automaton (FA)Finite Automaton (FA)Informally, a state diagram that comprehensively captures Informally, a state diagram that comprehensively captures

all possible states and transitions that a machine can take all possible states and transitions that a machine can take while responding to a stream or sequence of input while responding to a stream or sequence of input symbolssymbols

Recognizer for Recognizer for ““Regular LanguagesRegular Languages””

Deterministic Finite Automata (DFA)Deterministic Finite Automata (DFA)

The machine can exist in only one state at any given timeThe machine can exist in only one state at any given time

Non-deterministic Finite Automata (NFA)Non-deterministic Finite Automata (NFA)

The machine can exist in multiple states at the same timeThe machine can exist in multiple states at the same time

Page 10: CS311: Computational Theory

10

Deterministic Finite Automata - Deterministic Finite Automata - DefinitionDefinition

A Deterministic Finite Automaton (DFA) consists A Deterministic Finite Automaton (DFA) consists of:of:

Q ==> a finite set of statesQ ==> a finite set of states

∑ ∑ ==> a finite set of input symbols (alphabet)==> a finite set of input symbols (alphabet)

qq00 ==> a start state ==> a start state

F ==> set of final statesF ==> set of final states

δδ ==> a transition function, which is a mapping between Q x ∑ ==> a transition function, which is a mapping between Q x ∑ ==> Q==> Q

A DFA is defined by the 5-tuple: A DFA is defined by the 5-tuple:

{Q, ∑ , q{Q, ∑ , q00,F, ,F, δδ } }

Page 11: CS311: Computational Theory

ExampleExample

We can describe M1 formally by writing M1 = (Q, Σ, δ, q1 , F ), where1.Q = {q1,q2,q3},

2.Σ = {0,1},

3.δ is described as

4.q1 is the start state, and

5.F = {q2}.

0 1

q1 q1 q2

q2 q3 q2

q3 q2 q2

Page 12: CS311: Computational Theory

12

What does a DFA do on reading What does a DFA do on reading an input string?an input string?

Input:Input: a word w in ∑* a word w in ∑*

Question:Question: Is w acceptable by the DFA? Is w acceptable by the DFA?

Steps:Steps:

Start at the Start at the ““start statestart state”” q q00

For every input symbol in the sequence w doFor every input symbol in the sequence w doCompute the next state from the current state, given the Compute the next state from the current state, given the

current input symbol in w and the transition functioncurrent input symbol in w and the transition function

If after all symbols in w are consumed, the current state is If after all symbols in w are consumed, the current state is one of the final states (F) then accept w; one of the final states (F) then accept w;

Otherwise, reject w.Otherwise, reject w.

Page 13: CS311: Computational Theory

13

Regular LanguagesRegular Languages

Let L(A) be a language recognized by a DFA A. Let L(A) be a language recognized by a DFA A.

Then L(A) is called a Then L(A) is called a ““Regular LanguageRegular Language””..

Locate regular languages in the Chomsky Locate regular languages in the Chomsky

HierarchyHierarchy

Page 14: CS311: Computational Theory

Recursively-enumerable

(TM)

Context-sensitive

(LBA)

Context-free

(PDA)

14

The Chomsky HierarchyThe Chomsky Hierarchy

Regular(DFA)

• A containment hierarchy of classes of formal languages

Page 15: CS311: Computational Theory

15

Example #1Example #1Build a DFA for the following language:Build a DFA for the following language:

L = {w | w is a binary string that contains 01 as a substring}L = {w | w is a binary string that contains 01 as a substring}

Steps for building a DFA to recognize L:Steps for building a DFA to recognize L:∑ ∑ = {0,1}= {0,1}

Decide on the states: QDecide on the states: Q

Designate start state and final state(s)Designate start state and final state(s)

δδ: : Decide on the transitions: Decide on the transitions:

Final states == same as Final states == same as ““accepting statesaccepting states””

Other states == same as Other states == same as ““non-accepting statesnon-accepting states””

Page 16: CS311: Computational Theory

16

DFA for strings containing 01DFA for strings containing 01

q0

startq1

0

Regular expression: (0+1)*01(0+1)*

1 0,10

1

q2

Finalstate

• What if the language allows empty strings?

• What makes this DFA deterministic?

• Q = {q0,q1,q2}

• ∑ = {0,1}

• start state = q0

• F = {q2}

• Transition table

q2q2*q2

q2q1q1

q0q1q0

10st

ate

ssymbols

Page 17: CS311: Computational Theory

17

Example #2Example #2

Clamping Logic: Clamping Logic: A clamping circuit waits for a A clamping circuit waits for a ””11”” input, and turns on forever. However, input, and turns on forever. However,

to avoid clamping on spurious noise, weto avoid clamping on spurious noise, we’’ll design a DFA that waits for ll design a DFA that waits for two consecutive 1s in a row before clamping on.two consecutive 1s in a row before clamping on.

Build a DFA for the following language:Build a DFA for the following language:L = { w | w is a bit string which contains the substring L = { w | w is a bit string which contains the substring

11}11}

State Design:State Design:qq00 : start state (initially off), also means the most recent input was not : start state (initially off), also means the most recent input was not

a 1a 1

qq11: has never seen 11 but the most recent input was a 1: has never seen 11 but the most recent input was a 1

qq22: has seen 11 at least once: has seen 11 at least once

Page 18: CS311: Computational Theory

18

Example #3Example #3

Build a DFA for the following language:Build a DFA for the following language:

L = { w | w is a binary string that has even L = { w | w is a binary string that has even

number of 1s and even number of 0s}number of 1s and even number of 0s}

??

Page 19: CS311: Computational Theory

19

Extension of transitions (Extension of transitions (δδ) to ) to Paths (Paths (δδ))

δδ (q,w) = destination state from state q on input (q,w) = destination state from state q on input string wstring w

δδ (q,wa) = (q,wa) = δ (δδ (δ(q,w), a)(q,w), a)

Work out example #3 using the input Work out example #3 using the input sequence w=10010, a=1:sequence w=10010, a=1:

δδ (q (q00,wa) = ?,wa) = ?

Page 20: CS311: Computational Theory

20

Language of a DFALanguage of a DFA

A DFA A accepts string w if there is a path from A DFA A accepts string w if there is a path from qq00 to an accepting (or final) state that is labeled to an accepting (or final) state that is labeled by wby w

i.e., L(A) = { w | i.e., L(A) = { w | δδ(q(q00,w) ,w) F F }}

i.e., L(A) = all strings that lead to a final state i.e., L(A) = all strings that lead to a final state from qfrom q00

Page 21: CS311: Computational Theory

21

Non-deterministicNon-deterministic Finite Finite Automata (NFA)Automata (NFA)

A Non-deterministic Finite Automaton (NFA) A Non-deterministic Finite Automaton (NFA)

is of course is of course ““non-deterministicnon-deterministic””

Implying that the machine can exist in more Implying that the machine can exist in more

than one state at the same timethan one state at the same time

Transitions could be non-deterministicTransitions could be non-deterministic

qi

1

1

qj

qk

• Each transition function therefore maps to a set of states

Page 22: CS311: Computational Theory

22

Non-deterministicNon-deterministic Finite Automata Finite Automata ((NFANFA))

A A Non-deterministic Non-deterministic Finite Automaton (Finite Automaton (NFANFA)) consists of:consists of:Q ==> a finite set of statesQ ==> a finite set of states∑ ∑ ==> a finite set of input symbols (alphabet)==> a finite set of input symbols (alphabet)

qq00 ==> a start state ==> a start stateF ==> set of final states F ==> set of final states δδ ==> a transition function, which is a mapping between ==> a transition function, which is a mapping between

Q x ∑ ==> Q x ∑ ==> subset ofsubset of Q Q

An NFA is also defined by the 5-tuple: An NFA is also defined by the 5-tuple: {Q, ∑ , q{Q, ∑ , q00,F, ,F, δδ } }

Page 23: CS311: Computational Theory

23

How to use an NFA?How to use an NFA?Input:Input: a word w in ∑* a word w in ∑*

Question:Question: Is w acceptable by the NFA? Is w acceptable by the NFA?

Steps:Steps:

Start at the Start at the ““start statestart state”” q q00

For every input symbol in the sequence w doFor every input symbol in the sequence w do

Determine Determine all possible next states from all current statesall possible next states from all current states, given , given the current input symbol in w and the transition functionthe current input symbol in w and the transition function

If after all symbols in w are consumed If after all symbols in w are consumed andand if at least if at least one ofone of the the current states is a final state then accept w;current states is a final state then accept w;

Otherwise, reject w.Otherwise, reject w.

Page 24: CS311: Computational Theory

24

NFANFA for strings containing 01 for strings containing 01

q0

startq1

0

0,1 0,1

1

q2Finalstate

• Q = {q0,q1,q2}

• = {0,1}

• start state = q0

• F = {q2}

• Transition table

{q2}{q2}*q2

{q2}Φq1

{q0}{q0,q1}q0

10st

ate

ssymbols

What will happen if at state q1 an input of 0 is received?

Why is this non-deterministic?

Regular expression: (0+1)*01(0+1)*

Page 25: CS311: Computational Theory

25

What is a What is a ““dead statedead state””??

A DFA for recognizing the key word A DFA for recognizing the key word ““whilewhile””

An NFA for the same purpose:An NFA for the same purpose:

q0

wq1

hq2

iq3

lq4

eq5

qdead

Any other input symbol

q0

wq1

hq2

iq3

lq4

eq5

Any symbol

Note: Explicitly specifying dead states is just a matter of design convenience(one that is generally followed in NFAs), and

this feature does not make a machine deterministic or non-deterministic.

Transitions into a dead state are implicit

Page 26: CS311: Computational Theory

26

Example #2Example #2

Build an NFA for the following language:Build an NFA for the following language:

L = { w | w ends in 01}L = { w | w ends in 01}

??

Other examplesOther examples

Keyword recognizer (e.g., if, then, else, while, for, Keyword recognizer (e.g., if, then, else, while, for,

include, etc.)include, etc.)

Strings where the first symbol is present somewhere Strings where the first symbol is present somewhere

later on at least oncelater on at least once

Page 27: CS311: Computational Theory

27

Extension of Extension of δδ to NFA to NFA PathsPaths

Basis:Basis: δδ (q, (q,) = {q}) = {q}

Induction:Induction:

LetLet δδ (q (q00,w) = {p,w) = {p11,p,p22…,p…,pkk}}

δδ (p (pii,a) = S,a) = Si i for i=1,2...,kfor i=1,2...,k

Then, Then, δδ (q (q00,wa) = S,wa) = S1 1 U SU S2 2 U … U SU … U Sk k

Page 28: CS311: Computational Theory

28

Language of an NFALanguage of an NFA

An NFA accepts w if there exists at least one An NFA accepts w if there exists at least one

path from the start state to an accepting (or path from the start state to an accepting (or

final) state that is labeled by wfinal) state that is labeled by w

L(N) = { w | L(N) = { w | δδ(q(q00,w) ,w) ∩ F ≠ ∩ F ≠ Φ Φ }}

Page 29: CS311: Computational Theory

29

Advantages & Caveats for NFAAdvantages & Caveats for NFA

Great for modeling regular expressions Great for modeling regular expressions

String processing - e.g., grep, lexical analyzerString processing - e.g., grep, lexical analyzer

Could a non-deterministic state machine be Could a non-deterministic state machine be

implemented in practice?implemented in practice?

A parallel computer could exist in multiple A parallel computer could exist in multiple ““statesstates”” at the at the

same timesame time

Probabilistic models could be viewed as extensions of Probabilistic models could be viewed as extensions of

non-deterministic state machines non-deterministic state machines

(e.g., toss of a coin, a roll of dice)(e.g., toss of a coin, a roll of dice)

Page 30: CS311: Computational Theory

30

Differences: DFA vs. NFADifferences: DFA vs. NFADFADFA1.1. All transitions are deterministicAll transitions are deterministic

Each transition leads to exactly one Each transition leads to exactly one statestate

2.2. For each state, transition on all For each state, transition on all possible symbols (alphabet) possible symbols (alphabet) should be definedshould be defined

3.3. Accepts input if the last state is Accepts input if the last state is in Fin F

4.4. Sometimes harder to construct Sometimes harder to construct because of the number of statesbecause of the number of states

5.5. Practical implementation is Practical implementation is feasiblefeasible

NFANFA1.1. Some transitions could be non-Some transitions could be non-

deterministicdeterministicA transition could lead to a subset of A transition could lead to a subset of

statesstates

2.2. Not all symbol transitions need Not all symbol transitions need to be defined explicitly (if to be defined explicitly (if undefined will go to a dead state undefined will go to a dead state – this is just a design – this is just a design convenience, not to be confused convenience, not to be confused with with ““non-determinismnon-determinism””))

3.3. Accepts input if one of the last Accepts input if one of the last states is in Fstates is in F

4.4. Generally easier than a DFA to Generally easier than a DFA to constructconstruct

5.5. Practical implementation has to Practical implementation has to be deterministic (convert to be deterministic (convert to DFA) or in the form of DFA) or in the form of parallelismparallelism

But, DFAs and NFAs are equivalent in their power to capture langauges !!

Page 31: CS311: Computational Theory

31

Equivalence of DFA & NFAEquivalence of DFA & NFA

Theorem 1.39Theorem 1.39::Every nondeterministic finite automaton has an Every nondeterministic finite automaton has an

equivalent deterministic finite automaton.equivalent deterministic finite automaton.

Page 32: CS311: Computational Theory

32

ProofProof

Let N = (Q, Σ, δ, qLet N = (Q, Σ, δ, q00, , , , F ) be the F ) be the NFA NFA recognizing some language A. We recognizing some language A. We

construct a construct a DFA DFA M =(Q’, Σ, δ’, qM =(Q’, Σ, δ’, q00’, F ) recognizing A. Before doing the ’, F ) recognizing A. Before doing the

full construction, let’s first consider the easier case where in N has no full construction, let’s first consider the easier case where in N has no

ε arrows. Later we take the ε arrows into account.ε arrows. Later we take the ε arrows into account.

1. Q’ 1. Q’ ′ ′ = P(Q).= P(Q).

Every state of M is a set of states of N. Recall that P(Q) is the set of Every state of M is a set of states of N. Recall that P(Q) is the set of

subsets of Q.subsets of Q.

2. For R Q ∈2. For R Q ∈ ′ ′ and a Σ, let δ∈and a Σ, let δ∈ ′′(R, a) = {q Q| q δ(r, a) for some r ∈ ∈ ∈(R, a) = {q Q| q δ(r, a) for some r ∈ ∈ ∈

R}. If R is a state of M, it is also a set of states of N. When M reads a R}. If R is a state of M, it is also a set of states of N. When M reads a

symbol a in state R, it shows where a takes each state in R. Because symbol a in state R, it shows where a takes each state in R. Because

each state may go to a set of states, we take the union of all these each state may go to a set of states, we take the union of all these

sets. Another way to write this expression issets. Another way to write this expression is

Page 33: CS311: Computational Theory

33

Proof – Cont’dProof – Cont’d

3. q0′ = {q0}.

M starts in the state corresponding to the

collection containing just the start state of N .

4. F′ = {R Q′| R contains an accept state of N}.∈The machine M accepts if one of the possible

states that N could be in at this point is an

accept state.

Page 34: CS311: Computational Theory

Proof – Cont’dProof – Cont’d

To include ε ε , we set up an extra bit of notation.

For any state R of M, we define E(R) to be the

collection of states that can be reached from

members of R by going only along ε arrows,

including the members of R themselves.

Formally, for R Q let⊆

E(R) = {q| q can be reached from R by traveling

along 0 or more ε arrows}.34

Page 35: CS311: Computational Theory

35

NFA to DFA construction: ExampleNFA to DFA construction: Example

L = {w | w ends in 01}L = {w | w ends in 01}

q0 q1

0

0,1

q2

1

NFA:

δN 0 1

q0 {q0,q1} {q0}

q1 Ø {q2}

*q2 Ø Ø

DFA:

δD 0 1

Ø Ø Ø

{q0} {q0,q1} {q0}

{q1} Ø {q2}

*{q2} Ø Ø

{q0,q1} {q0,q1} {q0,q2}

*{q0,q2} {q0,q1} {q0}

*{q1,q2} Ø {q2}

*{q0,q1,q2} {q0,q1} {q0,q2}

1. Determine transitions

δD 0 1

{q0} {q0,q1} {q0}

{q0,q1} {q0,q1} {q0,q2}

*{q0,q2} {q0,q1} {q0}

{q0}

1

0{q0,q1}

1{q0,q2}

0

0

1

Idea: To avoid enumerating all of power set, do

“lazy creation of states”

2. Retain only those states reachable from {q0}

0. Enumerate all possible subsets

Page 36: CS311: Computational Theory

36

NFA to DFA: Repeating the example NFA to DFA: Repeating the example using using LAZY CREATIONLAZY CREATION

L = {w | w ends in 01}L = {w | w ends in 01}

q0 q1

0

0,1

q2

1

NFA:

δN 0 1

q0 {q0,q1} {q0}

q1 Ø {q2}

*q2 Ø Ø

DFA:

δD 0 1

{q0} {q0,q1} {q0}

{q0,q1} {q0,q1} {q0,q2}

*{q0,q2} {q0,q1} {q0}

{q0}

1

0{q0,q1}

1{q0,q2}

0

0

1

Main Idea: Introduce states as you go

(on a need basis)

Page 37: CS311: Computational Theory

37

Correctness of subset constructionCorrectness of subset construction

Theorem:Theorem: If D is the DFA constructed from NFA If D is the DFA constructed from NFA

N by subset construction, then L(D)=L(N)N by subset construction, then L(D)=L(N)

Proof:Proof:

Show that Show that δδDD({q({q00},w) ≡ },w) ≡ δδNN(q(q00,w} , for all w,w} , for all w

Using induction on wUsing induction on w’’s length:s length:

Let w = xaLet w = xa

δδDD({q({q00},xa) ≡ },xa) ≡ δδDD( ( δδNN(q(q00,x}, a ) ≡ ,x}, a ) ≡ δδNN(q(q00,w},w}

Page 38: CS311: Computational Theory

38

Applications Applications Text indexing Text indexing

inverted indexinginverted indexing

For each unique word in the database, store all locations For each unique word in the database, store all locations

that contain it using an NFA or a DFAthat contain it using an NFA or a DFA

Find pattern P in text TFind pattern P in text T

Example: Google queryingExample: Google querying

Extensions of this idea:Extensions of this idea:

PATRICIA tree, suffix tree PATRICIA tree, suffix tree

Page 39: CS311: Computational Theory

A few subtle properties A few subtle properties of DFAs and NFAsof DFAs and NFAs

The machine never really terminates. The machine never really terminates.

It is always waiting for the next input symbol or making transitions.It is always waiting for the next input symbol or making transitions.

The machine decides when to The machine decides when to consumeconsume the next symbol from the input the next symbol from the input

and when to and when to ignoreignore it. it.

(but the machine can never (but the machine can never skip skip a symbol)a symbol)

=> A transition can happen even without really consuming an input => A transition can happen even without really consuming an input

symbol (think of consuming symbol (think of consuming as a free token) – if this happens, then it as a free token) – if this happens, then it

becomes an becomes an -NFA (see next few slides).-NFA (see next few slides).

A single transition cannot consume more than one (nonA single transition cannot consume more than one (non--) ) symbol.symbol.

39

Page 40: CS311: Computational Theory

40

FA with FA with -Transitions -Transitions We can allow We can allow explicitexplicit -transitions in finite automata-transitions in finite automata

i.e., a transition from one state to another state without i.e., a transition from one state to another state without

consuming any additional input symbol consuming any additional input symbol

Makes it easier sometimes to construct NFAsMakes it easier sometimes to construct NFAs

Definition:Definition: -NFAs are those NFAs with at least -NFAs are those NFAs with at least

one explicit one explicit -transition defined.-transition defined.

-NFAs have one more column in their transition -NFAs have one more column in their transition

tabletable

Page 41: CS311: Computational Theory

41

Example of an Example of an -NFA-NFAL = {w | w is empty, or if non-empty will end in 01}

δE 0 1 *q’0 Ø Ø {q’0,q0}

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

q1 Ø {q2} {q1}

*q2 Ø Ø {q2}

ECLOSE(q’0)

ECLOSE(q0)

-closure of a state q, -closure of a state q,

ECLOSE(q)ECLOSE(q), is the set of , is the set of

all states (including itself) all states (including itself)

that can be reached from q that can be reached from q

by repeatedly making an by repeatedly making an

arbitrary number of arbitrary number of --

transitions. transitions.

start

q0 q1

0

0,1

1q2

q ’0

ECLOSE(q1)

ECLOSE(q2)

Page 42: CS311: Computational Theory

42

Example of an Example of an -NFA-NFA

δE 0 1 *q’0 Ø Ø {q’0,q0}

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

q1 Ø {q2} {q1}

*q2 Ø Ø {q2}

ECLOSE(q’0)

ECLOSE(q0)

Simulate for w=101:Simulate for w=101:

start

q0 q1

0

0,1

1q2

q ’0

q0’

q0q0’

q1

0

q2

1

q0

1

Ø

1

x

To simulate any transition:Step 1) Go to all immediate destination states.

Step 2) From there go to all their -closure states as well.

L = {w | w is empty, or if non-empty will end in 01}

Page 43: CS311: Computational Theory

43

Example of Another Example of Another -NFA-NFA

δE 0 1 *q’0 Ø Ø {q’0,q0,q3}

q0 {q0,q1} {q0} {q0,q3}

q1 Ø {q2} {q1}

*q2 Ø Ø {q2}

q3 Ø {q2} {q3}

Simulate for w=101:Simulate for w=101:

??

start

q0 q1

0

0,1

1q2

q ’0

q3

1

To simulate any transition:Step 1) Go to all immediate destination states.

Step 2) From there go to all their -closure states as well.

Page 44: CS311: Computational Theory

44

Equivalency of DFA, NFA, Equivalency of DFA, NFA, -NFA-NFA

Theorem:Theorem: A language L is accepted by some A language L is accepted by some --

NFA if and only if L is accepted by some DFANFA if and only if L is accepted by some DFA

Implication:Implication:

DFA ≡ NFA ≡ DFA ≡ NFA ≡ -NFA-NFA

(all accept Regular Languages)(all accept Regular Languages)

Page 45: CS311: Computational Theory

45

Eliminating Eliminating -transitions-transitions Let E = {QLet E = {QEE,∑,δ,∑,δEE,q,q00,F,FEE}} be an be an -NFA-NFA

Goal:Goal: To bTo build uild DFA DFA D={D={QQDD,∑,δ,∑,δDD,{q,{qDD},F},FDD} s.t. L(D)=L(E)} s.t. L(D)=L(E)

Construction:Construction:

– QQDD= all = all reachable reachable subsets of Qsubsets of QE E factoring in factoring in -closures-closures

– qqDD = ECLOSE(q = ECLOSE(q00))

– FFDD=subsets S in Q=subsets S in QDD s.t. S s.t. S∩F∩FEE≠≠ΦΦ

– δδDD: for each subset S of Q: for each subset S of QEE and for each input symbol a and for each input symbol a∑: ∑:

Let R= Let R= UU δ δEE(p,a)(p,a) // go to destination states// go to destination states

δδDD(S,a)(S,a) = = UU ECLOSE(r) ECLOSE(r) // from there, take a union// from there, take a unionof all their of all their -closures-closures

Page 46: CS311: Computational Theory

46

Example: Example: -NFA -NFA DFA DFAL = {w | w is empty, or if non-empty will end in 01}

start

q0 q1

0

0,1

1q2

q ’0

δE 0 1 *q’0 Ø Ø {q’0,q0}

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

q1 Ø {q2} {q1}

*q2 Ø Ø {q2}

δD 0 1

*{q’0,q0}

Page 47: CS311: Computational Theory

47

Example: Example: -NFA -NFA DFA DFA

start

q0 q1

0

0,1

1q2

q ’0

δE 0 1 *q’0 Ø Ø {q’0,q0}

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

q1 Ø {q2} {q1}

*q2 Ø Ø {q2}

δD 0 1

*{q’0,q0} {q0,q1} {q0}

{q0,q1} {q0,q1} {q0,q2}

{q0} {q0,q1} {q0}

*{q0,q2} {q0,q1} {q0}

{q’0, q0}

0

start

{q0,q1} {q0,q2}1

0

q0

11

0

0

1

unionunion

L = {w | w is empty, or if non-empty will end in 01}