cs 461 – aug. 31

12
CS 461 – Aug. 31 Section 1.2 – Nondeterministic FAs • How to trace input • NFA design makes “union” operation easier • Equivalence of NFAs and DFAs

Upload: illiana-hamilton

Post on 03-Jan-2016

36 views

Category:

Documents


0 download

DESCRIPTION

CS 461 – Aug. 31. Section 1.2 – Nondeterministic FAs How to trace input √ NFA design makes “union” operation easier Equivalence of NFAs and DFAs. NFA’s using “or”. Can you draw NFA for: { begin with 0 or end with 1 } ?. Old start 1. ε. New start. Old start 2. ε. Amazing fact. - PowerPoint PPT Presentation

TRANSCRIPT

CS 461 – Aug. 31

Section 1.2 – Nondeterministic FAs

• How to trace input √

• NFA design makes “union” operation easier

• Equivalence of NFAs and DFAs

NFA’s using “or”

• Can you draw NFA for:

{ begin with 0 or end with 1 } ?

New start

Old start 1

Old start 2

ε

ε

Amazing fact

• NFA = DFA• In other words, the two kinds of machines have

the same power.• Proof idea: we can always convert a DFA into

an NFA, or vice versa. Which do you think is easier to do?

Formal NFA def’n

• The essential difference with DFA is in the transition function:

DFA δ: Q x Σ Q

NFA δ: Q x Σε P(Q)

• Thus, converting DFA NFA is easy. We already satisfy the definition!

NFA DFA construction

1. When creating DFA, states will be all possible subsets of states from NFA.

– This takes care of “all possible destinations.”– In practice we won’t need whole subset: only create

states as you need them.– “empty set” can be our dead state.

2. DFA start state = NFA’s start state or anywhere you can begin for free. Happy state will be any subset containing NFA’s happy state.

3. Transitions: Please write as a table. Drawing would be too cluttered. When finished, can eliminate useless states.

Example #1

• NFA transition table given to the right.

• DFA start state is {1, 3}, or more simply 13.

• DFA accept state would be anything containing 1. Could be 1, 12, 13, 123, but we may not need all these states.

inputs

state a b ε

1 - 2 3

2 2,3 3 -

3 1 - -

continued

• The resulting DFA could require 2n states, but we should only create states as we need them.

inputs

state a b ε

1 - 2 3

2 2,3 3 -

3 1 - -

Let’s begin:

If we’re in state 1 or 3, where do we go if we read an ‘a’ or a ‘b’?

δ(13, a) = 1, but we can get to 3 for free.

δ(13, b) = 2. We need to create a new state “2”.

Continue the construction by considering transitions from state 2.

answer

NFA

DFA

inputs

state a b ε

1 - 2 3

2 2,3 3 -

3 1 - -

inputs

state a b

13 13 2

2 23 3

23 123 3

123 123 23

3 13

Notice that the DFA is in fact deterministic: it has exactly one destination per transition. Also there is no column for ε.

Example #2

• NFA transition table given to the right.

• DFA start state is A.

• DFA accept state would be anything containing D.

inputs

State 0 1 ε

A A A,C -

B D - C

C - B -

D B D -

continued

Let’s begin.

δ(A, 0) = A

δ(A, 1) = AC

We need new state AC.

δ(AC, 0) = A

δ(AC, 1) = ABC

Continue from ABC…

inputs

State 0 1 ε

A A A,C -

B D - C

C - B -

D B D -

answer

NFA DFA

inputs

State 0 1 ε

A A A,C -

B D - C

C - B -

D B D -

inputs

State 0 1

A A AC

AC A ABC

ABC AD ABC

AD ABC ACD

ACD ABC ABCD

ABCD ABCD ABCD

final thoughts

• NFAs and DFAs have same computational power.

• NFAs often have fewer states than corresponding DFA.

• Typically, we want to design a DFA, but NFAs are good for combining 2+ DFAs.

• After doing NFA DFA construction, we may see that some states can be combined.– Later in chapter, we’ll see how to simplify FAs.