This is an old revision of the document!


5. Minimal DFAs

Consider the following DFAs:

DFA 1:

DFA 2:

The first DFA is the solution to exercise 4.3.4 from Lab4.

5.1.1. Identify a pair of states which are indistinguishable. (Solve the exercise for the 2 given DFAs.)

Click to display ⇲

Click to hide ⇱

DFA 1

States 2 and 5 are indistinguishable.

Looking at the DFA we can see that states 2 and 5 both go to state 6 on “1” and to 3 on “0”.

Click to display ⇲

Click to hide ⇱

DFA 2

States 1 and 2 are indistinguishable.

Looking at the DFA we can see that states 1 and 2 both go to state 2 on “a” and to 5 on “b”.

5.1.2. Identify a pair of final or non-final states which are distinguishable. The pair must be distinguished by a word different from the empty word. (Solve the exercise for the 2 given DFAs.)

Click to display ⇲

Click to hide ⇱

DFA 1

States 4 and 5 are distinguishable because we can accept “1” from 4, but not from 5.

Click to display ⇲

Click to hide ⇱

DFA 2

States 0 and 5 are distinguishable because from 0 we can accept word “b”, but not from 5.

5.1.3. Compute the table of indistinguishable states for the DFA. (Solve the exercise for the 2 given DFAs.)

Click to display ⇲

Click to hide ⇱

DFA 1

1 2 3 4 5
1 - - - - -
2 X - - - -
3 X - - -
4 X - -
5 X X X -
6 X X X X X

Initially marked pairs of (final, non-final) states:

  • (1, 6)
  • (2, 6)
  • (3, 6)
  • (4, 6)
  • (5, 6)

Predecessors for (6, 1):

  • 0: -
  • 1: -

Predecessors for (6, 2):

  • 0: -
  • 1: (2, 1), (5, 1) ⇒ mark them on the table

Predecessors for (6, 3):

  • 0: -
  • 1: -

Predecessors for (6, 4):

  • 0: -
  • 1: -

Predecessors for (6, 5):

  • 0: -
  • 1: (2, 3), (5, 3), (2, 4), (5, 4) ⇒ mark them on the table

Predecessors for (2, 1):

  • 0: -
  • 1: -

Predecessors for (5, 1):

  • 0: -
  • 1: -

Predecessors for (3, 2):

  • 0: -
  • 1: -

Predecessors for (4, 2):

  • 0: -
  • 1: -

Predecessors for (5, 3):

  • 0: -
  • 1: -

Predecessors for (5, 4):

  • 0: -
  • 1: -

The partitions of undistinguishable states are given by the missing marks:

  • (5, 2)
  • (3, 1), (4, 3), (4, 1)

⇒ The partitions are: {2, 5} and {1, 3, 4}

Click to display ⇲

Click to hide ⇱

DFA 2

0 1 2 3 4
0 - - - - -
1 X - - - -
2 X - - -
3 X X - -
4 X X -
5 X X X X X

Initially marked pairs of (final, non-final) states:

  • (0, 1)
  • (0, 2)
  • (0, 4)
  • (3, 1)
  • (3, 2)
  • (3, 4)
  • (5, 1)
  • (5, 2)
  • (5, 4)

Predecessors for (5, 4):

  • a: -
  • b: (3, 4), (3, 1), (3, 2), (3, 5) ⇒ mark them on the table

Predecessors for (5, 1):

  • a: -
  • b: (5, 0) ⇒ mark it on the table

Predecessors for (3, 1):

  • a: -
  • b: -

Predecessors for (3, 2):

  • a: (0, 1), (0, 2), (0, 4) ⇒ already marked
  • b: -

Predecessors for (5, 2):

  • a: (5, 1), (5, 2), (5, 4) ⇒ already marked
  • b: -

Predecessors for (3, 4):

  • a: -
  • b: -

Predecessors for (0, 1):

  • a: -
  • b: -

Predecessors for (0, 2):

  • a: (3, 1), (3, 2), (3, 4) ⇒ already marked
  • b: -

Predecessors for (0, 4):

  • a: -
  • b: -

Predecessors for (0, 5):

  • a: (3, 5) ⇒ mark it on the table
  • b: -

Predecessors for (3, 5):

  • a: (0, 5) ⇒ already marked
  • b: -

The partitions of undistinguishable states are given by the missing marks:

  • (0, 3)
  • (4, 1), (4, 2), (2, 1)

⇒ The partitions are: {0, 3} and {1, 2, 4}

5.2.1. Minimise the DFA. (Solve the exercise for the 2 given DFAs.)

Click to display ⇲

Click to hide ⇱

DFA 1

Click to display ⇲

Click to hide ⇱

DFA 2

5.2.2. How can we algorithmically determine if two minimal DFAs accept the same language?

Click to display ⇲

Click to hide ⇱

  • assume the states are labeled as integers starting with 0, and that 0 is the unique initial state of both DFAs (this can be easily obtained from any previous transformation).
  • give an ordering to the symbols of the alphabet. Write $ \delta$ as a string by the following rules:
    • we sort each transition $ \delta(q,c)=q'$ , by $ q$ first and by $ c$ , second. We append each transition given this ordering (smaller states first, then for each state, output the order of the $ \delta(q,c)$ transitions according to $ c$ .
  • two minimal DFAs accept the same language iff:
    • they have the same string representation of $ \delta$ and
    • have the same final states.

Another more elegant approach is to use state equivalence. We can treat two (not necessarily minimal) DFAs as one and the same, and compute the (in)distinguishability table over all states, in a single go. Finally, the DFAs accept the same language iff their initial states are indistinguishable.

5.2.3. Determine if the following regexes are equivalent: $ (1\cup\epsilon)(00^*1)^*0^*$ and $ (10\cup 0)^*(01 \cup 1)^*(0 \cup \epsilon)$

5.2.4. Remeber exercise 3.3.4 from Lab3. Show that the two regexes are equivalent: $ E1 = ((ab^*a)^+b)^* $ and $ E2 = (a(b\mid aa)^*ab)^* $

5.2.5. (extra) Apply the Brzozowski minimisation algorithm on DFA 1.

Brzozowski minimisation: minDfa(A) = toDfa(reverse(toDfa(reverse(A))))

Click to display ⇲

Click to hide ⇱

Step 1: Reverse(A)

  • reverse transitions
  • the initial state becomes final in Reverse(A)
  • the final state becomes initial in Reverse(A), but here we have more final states:
    • normally, to compute Reverse(A) we should add a new initial state in Reverse(A); the final states in A become non-final in Reverse(A); then add $\varepsilon$ - transitions from the new initial state of Reverse(A) to the former final states of A
    • for Brzozowski's minimization algorithm however, we will not add this new initial state and, instead, we will start the subset construction in Step 2 from the set of final states that were in A, that now become “multiple” initial states in Reverse(A)
  • we can also not include the sink state in the reversal of the DFA
  • the set of initial states is: {1, 2, 3, 4, 5}

Step 2: toDfa(Reverse(A))

Step 3: Reverse(toDfa(Reverse(A)))

  • we can ignore the sink state
  • we rename the subsets as follows: {1,2,3,4,5} → 1 and {1,3,4} → 2
  • as previously, we remember a set of initial states: {1,2}

Step 4: toDfa(Reverse(toDfa(Reverse(A))))

  • This is minDfa(A)
Now we can do a complete transformation of a regex into a minimal DFA.
  • Regex → NFA (Thomson's algorithm)
  • NFA → DFA (Subset Construction)
  • DFA → minDfa

We advise you to use this conversion when solving the project.