Download as pdf or txt
Download as pdf or txt
You are on page 1of 35

NFAs accept the Regular

Languages

A. Senthil - Professor/CSE 1
Equivalence of Machines

Definition for Automata:

Machine M1 is equivalent to machine M2

if L( M1 ) = L( M 2 )

A. Senthil - Professor/CSE 2
Example of equivalent machines
NFA M1
L(M1 ) = {10} * 0
q0 q1
1

DFA M2 0,1
L(M 2 ) = {10} * 0
q0 q1 1 q2
1
0
A. Senthil - Professor/CSE 3
We will prove:

=
Languages
Regular
accepted
Languages
by NFAs
Languages
accepted
by DFAs
NFAs and DFAs have the
same computation power
A. Senthil - Professor/CSE 4
Step 1

Languages
accepted Ê Regular
Languages
by NFAs

Proof: Every DFA is trivially an NFA

Any language L accepted by a DFA


is also accepted by an NFA
A. Senthil - Professor/CSE 5
Step 2

Languages
accepted Í Regular
Languages
by NFAs

Proof: Any NFA can be converted to an


equivalent DFA

Any language L accepted by an NFA


is also accepted by a DFA
A. Senthil - Professor/CSE 6
Convert NFA to DFA
NFA M
a
q0 a q1 l q2
b

DFA M¢
{q0 }

A. Senthil - Professor/CSE 7
Convert NFA to DFA
NFA M
a
q0 a q1 l q2
b

DFA M¢
{q0 } a
{q1, q2 }

A. Senthil - Professor/CSE 8
Convert NFA to DFA
NFA M
a
q0 a q1 l q2
b

DFA M¢
{q0 } a
{q1, q2 }
b

Æ
A. Senthil - Professor/CSE 9
Convert NFA to DFA
NFA M
a
q0 a q1 l q2
b

a
DFA M¢
{q0 } a
{q1, q2 }
b

Æ
A. Senthil - Professor/CSE 10
Convert NFA to DFA
NFA M
a
q0 a q1 l q2
b

b a
DFA M¢
{q0 } a
{q1, q2 }
b

Æ
A. Senthil - Professor/CSE 11
Convert NFA to DFA
NFA M
a
q0 a q1 l q2
b

b a
DFA M¢
{q0 } a
{q1, q2 }
b

Æ a, b
A. Senthil - Professor/CSE 12
Convert NFA to DFA
NFA M
a
q0 a q1 l q2
b
L(M ) = L(M ¢)
a
DFA M¢ b

{q0 } a
{q1, q2 }
b

Æ a, b
A. Senthil - Professor/CSE 13
NFA to DFA: Remarks

We are given an NFA M = (QN , S, d N , q0 , FN )

We want to convert it
M ¢ = (QD , S, d D ,{q0 }, FD )
to an equivalent DFA

With
L(M ) = L(M ¢)
A. Senthil - Professor/CSE 14
If the NFA has n states

QN = {q0 , q1 , q2 ,..., qn }

the DFA has 2n states in the power set of


QN
i.e.
Æ, {q0 }, {q1}, {q1, q2 }, {q3 , q4 , q7 },....

A. Senthil - Professor/CSE 15
Procedure NFA to DFA

1. Initial state of NFA: q0

Initial state of DFA: {q0 }

A. Senthil - Professor/CSE 16
Example
NFA M a
q0 a q1 l q2
b

DFA M¢
{q0 }

A. Senthil - Professor/CSE 17
Procedure NFA to DFA
2. For every DFA’s state {qi , q j ,..., qm }

Compute in the NFA


d * (qi , a ),
d * (q j , a ), = {qi¢ , q¢j ,..., qm
¢}
...
Add transition to DFA
d ({qi , q j ,..., qm }, a ) = {qi¢ , q¢j ,..., qm
¢}
A. Senthil - Professor/CSE 18
Exampe
NFA M a
q0 a q1 l q2
b
d * (q0 , a ) = {q1, q2 }
DFA M ¢

{q0 } a
{q1, q2 }

d ({q0 }, a ) = {q1, q2 }
A. Senthil - Professor/CSE 19
Procedure NFA to DFA

Repeat Step 2 for all letters in alphabet,


until
no more transitions can be added.

A. Senthil - Professor/CSE 20
Example
NFA M a
q0 a q1 l q2
b

b a
DFA M¢
{q0 } a
{q1, q2 }
b

Æ a, b
A. Senthil - Professor/CSE 21
Procedure NFA to DFA
3. For any DFA state {qi , q j ,..., qm }

If some qj is a final state in the NFA

Then, {qi , q j ,..., qm }


is a final state in the DFA

A. Senthil - Professor/CSE 22
Example
NFA M a
q0 a q1 l q2 q1 Î F
b
a
DFA M¢ b

{q0 } a
{q1, q2 }
b {q1, q2 }Î F ¢
Æ a, b
A. Senthil - Professor/CSE 23
Theorem
Take NFA M

Apply procedure to obtain DFA M¢

Then M and M¢ are equivalent :

L( M ) = L( M ¢)

A. Senthil - Professor/CSE 24
Proof

L( M ) = L( M ¢)

L( M ) Í L( M ¢) AND L( M ) Ê L( M ¢)

A. Senthil - Professor/CSE 25
First we show: L( M ) Í L( M ¢)

Take arbitrary: wÎ L(M )

We will prove: w Î L(M ¢)

A. Senthil - Professor/CSE 26
wÎ L(M )

M: q0 w qf

w = s 1s 2 !s k
s1 s2 sk
M: q0 qf

A. Senthil - Professor/CSE 27
We will show that if wÎ L(M )

w = s 1s 2 !s k
s1 s2 sk
M: q0 qf

s1 s2 sk
M¢:
{q0 } {q f ,!}
w Î L(M ¢)
A. Senthil - Professor/CSE 28
More generally, we will show that if in M:
(arbitrary string) v = a1a2 ! an
a1 a2 an
M: q0 qi qj ql qm

a1 a2 an
M¢:
{q0 } {qi ,!} {q j ,!} {ql ,!} {qm ,!}

A. Senthil - Professor/CSE 29
Proof by induction on |v|

Induction Basis: v = a1

a1
M: q0 qi

a1
M¢:
{q0 } {qi ,!}

A. Senthil - Professor/CSE 30
Induction hypothesis: 1 £| v |£ k
v = a1a2 ! ak
a1 a2 ak
M: q0 qi qj qc qd

a1 a2 ak
M¢:
{q0 } {qi ,!} {q j ,!} {qc ,!} {qd ,!}

A. Senthil - Professor/CSE 31
Induction Step: | v |= k + 1
v = a1a2 % ak ak +1 = v¢ak +1
$!#! "

a1 a2 ak
M: q0 qi qj qc qd


a1 a2 ak
M¢:
{q0 } {qi ,!} {q j ,!} {qc ,!} {qd ,!}


A. Senthil - Professor/CSE 32
Induction Step: | v |= k + 1
v = a1a2 % ak ak +1 = v¢ak +1
$!#! "

a1 a2 ak ak +1
M: q0 qi qj qc qd qe


a1 a2 ak ak +1
M¢:
{q0 } {qi ,!} {q j ,!} {qc ,!} {qd ,!} {qe ,!}


A. Senthil - Professor/CSE 33
Therefore if wÎ L(M )

w = s 1s 2 !s k
s1 s2 sk
M: q0 qf

s1 s2 sk
M¢:
{q0 } {q f ,!}
w Î L(M ¢)
A. Senthil - Professor/CSE 34
We have shown: L( M ) Í L( M ¢)

We also need to show: L( M ) Ê L( M ¢)

(proof is similar)

A. Senthil - Professor/CSE 35

You might also like