How to minimize a DFA

Introduction

Minimizing a DFA means converting a given DFA to an equivalent DFA with a minimum number of states.

We can the following two methods to minimize a DFA:

  1. The equivalence method

  2. The Myhill Nerode method

We will cover the Myhill Nerode method in this answer.

Myhill Nerode method

There are five steps included in this process:

  1. A n×nn \times n table is formed where nn is the number of states in the DFA. The table will specify all possible combinations of the states.

  Let's consider the following DFA:

g ENTRY q0 q0 ENTRY->q0 q4 q4 q1 q1 q4->q1 a q2 q2 q4->q2 b q0->q1 a q0->q2 b q1->q1 a q3 q3 q1->q3 b q2->q1 a q2->q2 b q3->q4 b q3->q1 a
Example DFA

The equivalent table for the above DFA is:

Initial table of all combination of states

The upper half of the table is crossed out as the order of the combination does not matter: (q1,q2)(q2,q1)(q_1,q_2) \equiv (q_2,q_1)

  1. Mark the states pairs (x,y)(x,y)where xx or yy must be a final state. These state pairs are called distinguishable relations.

Marked distinguishable states
  1. Now for the undistinguishable relationsThe state pairs that are of the same type i.e. both are final or both are non-final states., we take each unmarked state pair and compute δ((x,y),s))δ
    ((x,y),s))
    , where s is the set of the inputs. This function calculates the transition from an initial state to a given input. If the resultant pair from any input is already marked in the table, the state pair is also marked.

  e.g. δ((q0,q3),a))=((q0,b),(q3,b))=(q2,q4)δ
((q_0,q_3),a)) = ((q_0,b),(q_3,b))=(q_2,q_4)

  As (q2,q4)(q_2,q_4) is a marked state hence (q0,q3)(q_0,q_3) will also be marked.

Marked states calculated from δ((x,y),s)
  1. Repeat step 3 until no more relations are left that can be marked. In this case, we mark the boxes depending on the iteration number.

Repeat step 3

We see that (q2,q0)(q_2,q_0) is the only pair that cannot be marked.

  1. Check the table column-wise and see which unmarked pairs can be merged.

For example, In column 0, only q2q_2 is unmarked. Therefore, q0q_0 and q2q_2 will be merged. This step is repeated by iterating through all the columns.

g ENTRY q0q2 q0q2 ENTRY->q0q2 q4 q4 q4->q0q2 b q1 q1 q4->q1 a q0q2->q0q2 b q0q2->q1 a q1->q1 a q3 q3 q1->q3 b q3->q4 b q3->q1 a
Minimized DFA

The transitions of the merged states will have no conflict and are shown on the DFA.

Free Resources

Copyright ©2026 Educative, Inc. All rights reserved