You are on page 1of 31

Single Accepting

State for NFAs

Fall 2005 Costas Busch - RPI 1


Any NFA can be converted

to an equivalent NFA

with a single accepting state

Fall 2005 Costas Busch - RPI 2


Example
a
NFA
a b

a Equivalent NFA

a b

b 

Fall 2005 Costas Busch - RPI 3
In General
NFA

Equivalent NFA
 Single
 accepting

state
Fall 2005 Costas Busch - RPI 4
Extreme Case

NFA without accepting state

Add an accepting state


without transitions

Fall 2005 Costas Busch - RPI 5


Properties of
Regular Languages

Fall 2005 Costas Busch - RPI 6


For regular languages L1 and L2
we will prove that:

Union: L1  L2
Concatenation: L1L2
Star: L1 * Are regular
Languages
Reversal: R
L1
Complement: L1
Intersection: L1  L2
Fall 2005 Costas Busch - RPI 7
We say: Regular languages are closed under

Union: L1  L2
Concatenation: L1L2
Star: L1 *
Reversal: R
L1
Complement: L1
Intersection: L1  L2
Fall 2005 Costas Busch - RPI 8
Regular language L1 Regular language L2

L M1   L1 L M 2   L2

NFA M1 NFA M2

Single accepting state Single accepting state

Fall 2005 Costas Busch - RPI 9


Example
M1
n0
a
n
L1  {a b} b

M2
a
L2   ba b

Fall 2005 Costas Busch - RPI 10


Union
NFA for L1  L2
M1

 M2

Fall 2005 Costas Busch - RPI 11


Example
n
NFA for L1  L2  {a b}  {ba}
n
L1  {a b}
a
b

 L2  {ba}
b a
Fall 2005 Costas Busch - RPI 12
Concatenation

NFA for L1L2

M1 M2
 

Fall 2005 Costas Busch - RPI 13


Example

n n
NFA for L1L2  {a b}{ba}  {a bba}

n
L1  {a b}
a L2  {ba}
b  b a 

Fall 2005 Costas Busch - RPI 14


Star Operation
NFA for L1 * w  w1w2  wk
 wi  L1
M1
  L1 *
 


Fall 2005 Costas Busch - RPI 15
Example

n
NFA for L1*  {a b} *

n
L1  {a b}
a
 b 


Fall 2005 Costas Busch - RPI 16
Reverse
R
NFA for L1
L1 M1 M1

1. Reverse all transitions

2. Make initial state accepting state


and vice versa
Fall 2005 Costas Busch - RPI 17
Example
M1
a
n
L1  {a b} b

M1
a
R n
L1  {ba } b

Fall 2005 Costas Busch - RPI 18


Complement

L1 M1 L1 M1

1. Take the DFA that accepts L1

2. Make final states non-final,


and vice-versa
Fall 2005 Costas Busch - RPI 19
Example
M1
a a, b
n b a, b
L1  {a b}

M1
n a a, b
L1  {a, b} * {a b}
b a, b

Fall 2005 Costas Busch - RPI 20


Intersection

L1 regular
We show L1  L2
L2 regular regular

Fall 2005 Costas Busch - RPI 21


DeMorgan’s Law: L1  L2  L1  L2

L1 , L2 regular
L1 , L2 regular
L1  L2 regular
L1  L2 regular
L1  L2 regular
Fall 2005 Costas Busch - RPI 22
Example

n
L1  {a b} regular
L1  L2  {ab}
L2  {ab, ba} regular regular

Fall 2005 Costas Busch - RPI 23


Another Proof for Intersection Closure

Machine M1 Machine M2
FA for L1 FA for L2

Construct a new FA M that accepts L1  L2

M simulates in parallel M1 and M 2


Fall 2005 Costas Busch - RPI 24
States in M

qi , p j

State in M1 State in M2

Fall 2005 Costas Busch - RPI 25


FA M1 FA M2

q1 a q2 p1 a p2
transition transition

FA M

q1, p1 a q2 , p2
New transition
Fall 2005 Costas Busch - RPI 26
FA M1 FA M2

q0 p0
initial state initial state

FA M

q0 , p0
New initial state
Fall 2005 Costas Busch - RPI 27
FA M1 FA M2

qi pj pk

accept state accept states

FA M
qi , p j qi , pk

New accept states

Both constituents must be accepting states


Fall 2005 Costas Busch - RPI 28
Example:

n0 m0
L1  {a b} n m
L2  {ab }
M1 M2
a b
q0 b q1 p0 a p1
a, b b a
q2 p2
a, b a, b
Fall 2005 Costas Busch - RPI 29
Automaton for intersection
n n
L  {a b}  {ab }  {ab}
a, b

q0 , p0 a q0 , p1 b q1, p1 a q2 , p2

b a b a
q1, p2 b q0 , p2 q2 , p1

a b
a, b
Fall 2005 Costas Busch - RPI 30
M simulates in parallel M1 and M 2
M accepts string w if and only if

M1 accepts string w and


M 2 accepts string w

L ( M )  L ( M1 )  L ( M 2 )

Fall 2005 Costas Busch - RPI 31

You might also like