[英]Minimum number of states in DFA
Minimum number states in the DFA accepting strings (base 3 ie,, ternary form) congruent to 5 modulo 6? DFA 中接受字符串(基数为 3,即三元形式)中与 5 模 6 一致的最小数状态?
I have tried but couldn't do it.我试过了,但做不到。
At first sight, It seems to have 6 states but then it can be minimised further.乍一看,它似乎有 6 个状态,但可以进一步最小化。
Let's first see the state transition table:我们先来看看状态转移表:
Here, the states q 0 , q 1 , q 2 ,...., q 5 corresponds to the states with modulo 0,1,2,..., 5 respectively when divided by 6. q 0 is our initial state and since we need modulo 5 therefore our final state will be q 5这里,状态 q 0 , q 1 , q 2 ,...., q 5 分别对应于模 0,1,2,..., 5 除以 6 时的状态。 q 0是我们的初始状态,由于我们需要模 5,因此我们的最终状态将是 q 5
Few observations drawn from above state transition table:从上面的状态转换表中得出的一些观察结果:
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 q 0 , q 2 , q 4 together and q 1 , q 3 together leaving the state q 5 aloof from collation.因此,我们可以将 q 0 , q 2 , q 4合并在一起,将 q 1 , q 3合并在一起,使状态 q 5远离整理。
The final Minimal DFA has 3 states as shown below :最终的最小 DFA 有 3 个状态,如下所示:
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) 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:我们注意到所有的字符串都以 2 结尾。这是有道理的,因为 6 是 3 的倍数,从 3 的倍数得到 5 的唯一方法是加上 2。基于此,我们可以尝试解决字符串的问题与 3 模 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;没有出现真正的模式,但请考虑一下:每个以 0 结尾的基数为 3 的数字肯定可以被 3 整除。偶数也可以被 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.
所以基数 3 表示以 0 结尾的奇数必须与 3 mod 6 一致。因为 3 的所有幂都是奇数,我们知道如果字符串中 1 的个数是奇数,我们就有一个奇数。
So, our conditions are:所以,我们的条件是:
To get the minimum number of states in such a DFA, we can use the Myhill-Nerode theorem beginning with the empty string:要获得此类 DFA 中的最小状态数,我们可以使用以空字符串开头的 Myhill-Nerode 定理:
We have seen no new equivalence classes on new strings of length 3;我们在长度为 3 的新字符串上没有看到新的等价类; so, we know we have seen all the equivalence classes.
所以,我们知道我们已经看到了所有的等价类。 They are the following:
它们如下:
This means that a minimal DFA for our language has five states.这意味着我们语言的最小 DFA 有五个状态。 Here is the DFA:
这是 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.注意:我希望这个 DFA 有 6 个状态,正如 Welbog 在另一个答案中指出的那样,所以我可能错过了一个等价类。 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]…
然而,在检查了几个例子并思考它在做什么之后,DFA 似乎是正确的:你只能通过将 2 作为最后一个符号(绝对必要)来接受状态 [12],并且你只能进入状态 [12]从状态 [1] 开始,您必须看到奇数个 1 才能到达 [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
.例如,如果您处于状态
r4
(代表x = 4 (mod 6)
),并且您遇到1
作为下一个输入,则您的新模数为4x6+1 = 25 = 1 (mod 6)
,因此转换从输入1
上的r4
到r1
。 You'll find that the start state and r0
can be merged, for a total of 6 states.你会发现 start state 和
r0
可以合并,总共有 6 个 state。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.