2

Minimum number states in the DFA accepting strings (base 3 i.e,, ternary form) congruent to 5 modulo 6?

I have tried but couldn't do it.

3 Answers3

4

At first sight, It seems to have 6 states but then it can be minimised further.
Let's first see the state transition table: STATE TRANSITION TABLE

Here, the states q0, q1, q2,...., q5 corresponds to the states with modulo 0,1,2,..., 5 respectively when divided by 6. q0 is our initial state and since we need modulo 5 therefore our final state will be q5

Few observations drawn from above state transition table:

  • states q0, q2 and q4 are exactly same
  • states q1, q3 and q5 are exactly same

The states which make transitions to the same states on the same inputs can be merged into a single state.

Note: Final and Non-final states can never be merged.

Therefore, we can merge q0, q2, q4 together and q1, q3 together leaving the state q5 aloof from collation.
The final Minimal DFA has 3 states as shown below: Minimal DFA

Vinay Yadav
  • 1,206
  • 1
  • 10
  • 19
1

Let's look at a few strings in the language:

 12 =              1*3 + 2 =  5 ~ 5 (mod 6)
102 =        1*9 + 0*3 + 2 = 11 ~ 5 (mod 6)
122 =        1*9 + 2*3 + 2 = 17 ~ 5 (mod 6)
212 =        2*9 + 1*3 + 2 = 23 ~ 5 (mod 6)

1002 = 1*18 + 0*9 + 0*9 + 2 = 29 ~ 5 (mod 6)

We notice that all the strings end in 2. This makes sense since 6 is a multiple of 3 and the only way to get 5 from a multiple of 3 is to add 2. Based on this, we can try to solve the problem of strings congruent to 3 modulo 6:

  10 =  3
 100 =  9
 120 = 15
 210 = 21
1000 = 27

There's not a real pattern emerging, but consider this: every base-3 number ending in 0 is definitely divisible by 3. The ones that are even are also divisible by 6; so the odd numbers whose base-3 representation ends in 0 must be congruent to 3 mod 6. Because all the powers of 3 are odd, we know we have an odd number if the number of 1s in the string is odd.

So, our conditions are:

  1. the string begins with a 1;
  2. the string has an odd number of 1s;
  3. the string ends with 2;
  4. the string can contain any number of 2s and 0s.

To get the minimum number of states in such a DFA, we can use the Myhill-Nerode theorem beginning with the empty string:

  1. the empty string can be followed by any string in the language. Call its equivalence class [e]
  2. the string 0 cannot be followed by anything since valid base-3 representations don't have leading 0s. Call its equivalence class [0].
  3. the string 1 must be followed with stuff that has an even number of 1s in it ending with a 2. Call its equivalence class [1].
  4. the string 2 can be followed by anything in the language. Indeed, you can verify that putting a 2 at the front of any string in the language gives another string in the language. However, it can also be followed by strings beginning with 0. Therefore, its class is new: [2].
  5. the string 00 can't be followed by anything to fix it; its class is the same as its prefix 0, [0]. same for the string 01.
  6. the string 10 can be followed by any string with an even number of 1s that ends in a 2; it is therefore equivalent to the class [1].
  7. the string 11 can be followed by any string in the language whatever; indeed, you can verify prepending 11 in front of any string in the language gives another solution. However, it can also be followed by strings beginning with 0. Therefore, its class is the same as [2].
  8. 12 can be followed by a string with an even number of 1s ending in 2, as well as by the empty string (since 12 is in fact in the language). This is a new class, [12].
  9. 21 is equivalent to 1; class [1]
  10. 22 is equivalent to 2; class [2]
  11. 20 is equivalent to 2; class [2]
  12. 120 is indistinguishable from 1; its class is [1].
  13. 121 is indistinguishable from [2].
  14. 122 is indistinguishable from [12].

We have seen no new equivalence classes on new strings of length 3; so, we know we have seen all the equivalence classes. They are the following:

  • [e]: any string in the language can follow this
  • [0]: no string can follow this
  • [1]: a string with an even number of 1s ending in 2 can follow this
  • [2]: same as [e] but also strings beginning with 0
  • [12]: same as [1] but also the empty string

This means that a minimal DFA for our language has five states. Here is the DFA:

      [0]
       ^
       |
       0
       |
----->[e]--2-->[2]<-\
       |        ^   |
       |        |   |
       1   __1__/   /
       |  /        /
       | |         1
       V V         |
       [1]--2-->[12]
         ^       |
         |       |
         \___0___/

(transitions not pictured are self-loops on the respective states).

Note: I expected this DFA to have 6 states, as Welbog pointed out in the other answer, so I might have missed an equivalence class. However, the DFA seems right after checking a few examples and thinking about what it's doing: you can only get to accepting state [12] by seeing a 2 as the last symbol (definitely necessary) and you can only get to state [12] from state [1] and you must have seen an odd number of 1s to get to [1]…

Patrick87
  • 27,682
  • 3
  • 38
  • 73
-1

The minimum number of states for almost all modulus problems is the base of the modulus. The general strategy is one state for every modulus, as transitions between moduli are independent of what the previous numbers were. For example, if you're in state r4 (representing x = 4 (mod 6)), and you encounter a 1 as your next input, your new modulus is 4x6+1 = 25 = 1 (mod 6), so the transition from r4 on input 1 is to r1. You'll find that the start state and r0 can be merged, for a total of 6 states.

Welbog
  • 59,154
  • 9
  • 110
  • 123