18

Click here to load reader

NFA to DFA

Embed Size (px)

DESCRIPTION

This is demo of how to convert from NFA to DFA

Citation preview

Page 1: NFA to DFA

NFA to DFA

Page 2: NFA to DFA

DFA

• For every string x, there is a unique path from initial state and associated with x.

x is accepted if and only if this path ends at a final state.

x

Page 3: NFA to DFA

NFA

• For any string x, there may exist none or more than one path from initial state and associated with x.

Page 4: NFA to DFA

NFA DFA

• Consider an NFA M=(Q, Σ, δ, s, F). • For x in Σ*, define [x] = {q in Q | there exists a path s q}• Define DFA M’=(Q’, Σ, δ’, s’, F’}: Q’ = { [x] | x in Σ* }, δ ([x], a) = [xa] for x in Σ* and a in Σ, s’ = [ε], F’ = { [x] | x in L(M) }

x

Page 5: NFA to DFA

Construction of M’

Special Case: M has no ε-move.

• [ε] = {s}

• Suppose [x] is known. How to get [xa] for

a in Σ?

Page 6: NFA to DFA

From [x] to [xa]

• [xa] = { p | there exists a path q p for

some q in [x] }

= { p | there exists q in [x],

q p }

= U

a

a

q in [x]

δ(q,a)

edge

path

Page 7: NFA to DFA

Construction of M’

• F’ = {[x] | x in L(M)}

= {[x] | [x] ∩ F ≠ Ǿ }

Page 8: NFA to DFA

Example 1

• Construct DFA to accept 00(0+1)*

p0 0

0

1

s q s p q0 0

1

Ǿ

1

0,1

0, 1

Page 9: NFA to DFA

Example 2

• Design DFA to accept (0+1)*11

s p1 1

0

1

q s1 s

p

01 s

q

1

0

p

0

Page 10: NFA to DFA

Example 3

• Design DFA to accept 00(0+1)*11

s p q r0 1 10

0

1

t

s 0 p

1

Ǿ 0,1

1

0 q

0

1 q

r

1 qr

t0

0

1

Page 11: NFA to DFA

Example 4

• Construct DFA M for L(M)=ε.

s Is this a DFA?

s0

Ǿ

1

0,1

Page 12: NFA to DFA

Example 5

• Construct DFA M for L(M)=Ǿ.

s Is it a DFA?

s0

Ǿ 0,11

0,1

Page 13: NFA to DFA

Construction of M’

• For q in Q, define

ε-closure(q) = {p | there exists a path q p}

• [ε] = {q | there is a path s q}

= ε-closure(s)

• Suppose [x] is known. How to get [xa] for

a in Σ?

ε

εpath

path

Page 14: NFA to DFA

From [x] to [xa]

• [xa] = { p | there exists a path q p for

some q in [x] }

= { p | there exists q in [x],

q r p }

= { p | for some q in [x] and r in δ(q,a),

p in ε-closure(r) }

= U U ε-closure(r)

a

a ε

q in [x] r in δ(q,a)

edge path

path

Page 15: NFA to DFA

Construction of M’

• F’ = {[x] | x in L(M)}

= {[x] | [x] ∩ F ≠ Ǿ }

Page 16: NFA to DFA

Example 6

• Construct DFA M for L(M)=(0+1)*.0,1

ε ε

s p q

spq

0 pq

1

0,10,1

Page 17: NFA to DFA

Example 7

• Convert the following NFA to DFA.

s

p

0

ε0 ε

0

1

1

ε

0

r

srp

0 qrp

1

s

q, r, p

0

1

0

1

q

Page 18: NFA to DFA

a

s

dcbs

0,1

0

0 0 0 0

1 1 1 1 e

0 s,a

1

s,a,b0 0 s,a,b,c 0 s,a,b,c,d 0 s,a,b,c,d,e

1

s,b1

s,c

1

s,d

1s,e

How many states? 2 =325

How many final states? 2 = 164

Can we simplify it? No, it is minimum!