0% found this document useful (0 votes)
6 views39 pages

5. Section 2.3

The document discusses the equivalence of Non-deterministic Finite Automata (NFA) and Deterministic Finite Automata (DFA), stating that both accept the same regular languages. It outlines the process for converting an NFA to an equivalent DFA and includes a minimization technique for reducing the number of states in a DFA. Additionally, it provides examples and homework exercises related to the concepts presented.

Uploaded by

Chiranjib Patra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views39 pages

5. Section 2.3

The document discusses the equivalence of Non-deterministic Finite Automata (NFA) and Deterministic Finite Automata (DFA), stating that both accept the same regular languages. It outlines the process for converting an NFA to an equivalent DFA and includes a minimization technique for reducing the number of states in a DFA. Additionally, it provides examples and homework exercises related to the concepts presented.

Uploaded by

Chiranjib Patra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 39

CS 3186

Equivalence of NFA & DFA


Section 2.3

1
Equivalence of Machines

Definition for Automata (DFA or NFA):

Machine M1 is equivalent to machine M 2

if L M1   L M 2 

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
3
We will prove:


Languages
Regular
accepted
Languages
by NFAs
Languages
accepted
by DFAs
NFAs and DFAs have the
same computation power
4
NFA to DFA: Remarks

We are given an NFA M

We want to convert it
to an equivalent DFA M 

With LM   L(M )


5
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
6
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
7
Proof by construction: Convert NFA to DFA
NFA M
a
q 0
a q 1
 q 2
b

Construct a DFA M  such that the


language accepted by this DFA is the
same language as accepted by the
given NFA M. i.e., LM   L(M )

8
Procedure to convert NFA to DFA

Step 1.
Initial state of NFA: q0

Initial state of DFA: q0 


(A state in the constructed DFA is a subset of the
states Q in the given NFA)

9
Procedure NFA to DFA
Step 2. For every DFA’s state
{qi , q j ,..., qm }
Compute in the NFA
 * qi , a ,
 * q j , a ,  {qi , qj ,..., qm
}
...
Add transition to DFA
 {qi , q j ,..., qm }, a   {qi , qj ,..., qm
}
10
Procedure NFA to DFA

Repeat Step 2 for all symbols in alphabet,


until
no more transitions can be added.

11
Procedure NFA to DFA
Step 3.
For any DFA state {qi , q j ,..., qm }

If some q jis a final state in the NFA


Then{qi , q j ,..., qm } is a final state in the DFA

If  is in the language accepted by NFA,


then q0  , the initial state, also becomes a
final state in the DFA
12
If the NFA has states

q0 , q1, q2 ,...

the DFA has states in the powerset

, q0 , q1, q1, q2 , q3 , q4 , q7 ,....

13
Example (Step 1)
NFA M a
q0 a q1
 q 2
b

DFA M
q0 

14
Example (Step 2)
NFA M a
q0 a q  q
1 2
b
 * (q0 , a )  {q1, q2 }

DFA M 

q0  a
q1, q2 

 q0 , a   q1, q2 
15
Example (step 2)
NFA M a
q0 a q  q
1 2
b

a
DFA M b

q0  a
q1, q2 
b

 a, b
16
Example (step 3)
NFA M a
q0 a q  q
1 2 q1  F
b
a
DFA M b

q0  a
q1, q2 
b q1, q2  F 
 a, b
17
By the process of construction,
If there exists a walk on a string, w,
from q0 to in the NFA M,

then there exists a walk from q0 to


on the string w in the DFA M’

If is a final state in M, then


is a final state in M’.
Thus any string w accepted by M is also
accepted by M’
18
Theorem
Take NFA M

Apply procedure to obtain DFA M

Then M and M are equivalent :


L M   L M  
If w L (M ) then w  L(M ) and vice versa
19
Another Example
NFA M

Construct DFA M 

20
Another Example
DFA M 

21
22
Homework 2.3
I) Do exercises : #1, #2, #3, #4

II) Convert the following NFAs to DFAs

23
CS3186
Reduction in number of
states of a DFA
Section 2.4

24
Equivalent or Indistinguishable States
Definition: Two states p and q are equivalent (or
indistinguishable), if, for every string w   * ,
transition *( p , w ) ends in an accepting state if and
only if *( q , w) does. There are efficient algorithms
available for computing the sets of equivalent states
of a given DFA.

Property: If p and q are indistinguishable and if q and r


are indistinguishable, then p and r are also
indistinguishable. i.e., all three states p, q, r are
indistinguishable.

25
Minimization Technique for DFA

The number of states of an automaton has direct


affect to the size of the machine realizing the
automaton. Hence, it is very important to reduce the
number of states, if possible.

The procedure to reduce the states of a DFA is


based on finding and combining equivalent states.

This procedure uses the set partitioning technique.


The technique is similar to one that they use for
partitioning people into groups (each having certain
preferences) based on their responses to
questionnaire.

26
DFA-> Minimum DFA
Minimization Algorithm:
Step 0: Remove from M1 the dead states and the
states not reachable from the start state, if there
are any. Any transitions to a dead state become
undefined.
A state is a dead state if it is not an accepting state
and has no out-going transitions except to itself.

Step 1: We will divide Q (set of states) into two sets.


One set will contain all final states and other set will
contain non-final states. This partition is called P0.

Step 2: Initialize k = 1

27
Step 3: Find Pk by partitioning the different
sets of Pk-1. In each set of Pk-1, we will take
all possible pair of states. If two states of a
set are distinguishable, we will split the sets
into different sets in Pk.
Note: Two states ( qi, qj ) are distinguishable in partition Pk if
for any input symbol a, δ ( qi, a ) and δ ( qj, a ) are in different
sets in partition Pk-1.
Step 4: Stop when Pk = Pk-1 (No change in
partition)
Step 5: All states of one set are merged into
one state. No. of states in minimized DFA
will be equal to no. of sets in Pk.
Note: The initial state will be the set that contains the given
initial state. Similarly the sets that contain any of the initial
final states will be the final state of the minimal DFA 28
Example

29
Example
Step 1. P0 will have two sets of states. One set will
contain q1, q2, q4 which are final states of DFA and
another set will contain remaining states.
So P0 = { { q1, q2, q4 }, { q0, q3, q5 } }.

Step 2. To calculate P1, we will check whether sets


of partition P0 can be partitioned or not:

30
i) For set { q1, q2, q4 } :

δ ( q1, 0 ) = δ ( q2, 0 ) = q2 and


δ ( q1, 1 ) = δ ( q2, 1 ) = q5,
So q1 and q2 are not distinguishable.(can remain in the
same partition)

Similarly, δ ( q1, 0 ) = δ ( q4, 0 ) = q2 and


δ ( q1, 1 ) = δ ( q4, 1 ) = q5, So q1 and q4 are not
distinguishable.

Since, q1 and q2 are not distinguishable and q1 and q4 are


also not distinguishable, So q2 and q4 are not
distinguishable. So, { q1, q2, q4 } set will remain in the
same partition in P1.

31
ii) For set { q0, q3, q5 } :

δ ( q0, 0 ) = q3 and δ ( q3, 0 ) = q0


δ ( q0, 1) = q1 and δ( q3, 1 ) = q4
Moves of q0 and q3 on input symbol 0 are q3 and q0
respectively which are in same set in partition P0 .
Similarly, Moves of q0 and q3 on input symbol 1 are q1 and q4
which are in same set in partition P0 . So, q0 and q3 are not
distinguishable.

δ ( q0, 0 ) = q3 and δ ( q5, 0 ) = q5 and


δ ( q0, 1 ) = q1 and δ ( q5, 1 ) = q5
Moves of q0 and q5 on input symbol 1 are q3 and q5
respectively which are in different set in partition P0. So, q0
and q5 are distinguishable. So, set { q0, q3, q5 } will be
further partitioned into { q0, q3 } and { q5 }.
32
We have now determined the partition P1:
P1 = { { q1, q2, q4 }, { q0, q3}, { q5 } }

To calculate the next partition P2, we will


check similarly whether sets of partition
P1 can be partitioned or not:

33
iii)For set { q1, q2, q4 } :

δ ( q1, 0 ) = δ ( q2, 0 ) = q2 and δ ( q1, 1 ) = δ ( q2, 1 )


= q5, So q1 and q2 are not distinguishable.
Similarly, δ ( q1, 0 ) = δ ( q4, 0 ) = q2 and δ ( q1, 1 )
= δ ( q4, 1 ) = q5, So q1 and q4 are not
distinguishable.
Since, q1 and q2 are not distinguishable and q1 and
q4 are also not distinguishable, So q2 and q4 are
not distinguishable.

So, { q1, q2, q4 } set will not be partitioned in P2.

34
iv)For set { q0, q3 } :

δ ( q0, 0 ) = q3 and δ ( q3, 0 ) = q0


δ ( q0, 1 ) = q1 and δ ( q3, 1 ) = q4
Moves of q0 and q3 on input symbol 0 are q3 and q0 respectively which
are in same set in partition P1. Similarly, Moves of q0 and q3 on input
symbol 1 are q3 and q0 which are in same set in partition P1.

So, q0 and q3 are not distinguishable.

35
v) For set { q5 }:
Since we have only one state in this set, it can’t
be further partitioned.

So, the next partition is


P2 = { { q1, q2, q4 }, { q0, q3 }, { q5 } }

Since, P1=P2, this is the final partition.

Partition P2 means that q1, q2 and q4 states are


equivalent and can be merged into one. Similarly,
q0 and q3 are merged into one.

The initial state is the merged state { q0, q3 }


The final state is the merged state{ q1, q2, q4 }
36
Minimized DFA for this example is given below

37
Homework 2.4
I) Do exercises : #1, #2

II) Convert the following DFAs to minimal DFAs

38
Homework 2.4
II)

39

You might also like