简体   繁体   English

创建确定性有限自动机

[英]Creating a deterministic finite automata

I need to create a non-empty DFA over the language {a,b,c} with the following properties:我需要通过具有以下属性的语言 {a,b,c} 创建一个非空 DFA:

  1. First symbol is a.第一个符号是a。
  2. Has an even number of b's.有偶数个b。
  3. Last symbol is a c.最后一个符号是 c。

I was just wondering, should I create 3 seperate automatas, and then combine them using intersections, or should I just create the one, and if that is the case, how can it has an even number of b's?我只是想知道,我应该创建 3 个单独的自动机,然后使用交叉点将它们组合起来,还是应该只创建一个,如果是这样,它怎么会有偶数个 b? I know I can alternate the states, but not sure how to do it with it all combined.我知道我可以交替使用这些状态,但不知道如何将它们结合起来。

Thanks谢谢

Here's your automaton (assuming that 0 is even and therefor 0 b's is ok): 这是您的自动机(假设0是偶数,因此0 b可以):

[start](a) -> [1]
[start](b,c,<eoi>) -> [reject]

[1](a) -> [1]
[1](<eoi>) -> [reject]

[1](c) -> [2]
[1](b) -> [3]

[2](<eoi>) -> [accept]
[2](c) -> [2]
[2](a) -> [1]
[2](b) -> [3]

[3](<eoi>) -> [reject]
[3](a,c) -> [3]
[3](b)->[1]

Where is "end-of-input". “输入结束”在哪里。

State 1: even number of b's, the last symbol processed not c. 状态1:b的偶数,最后处理的符号不是c。 State 2: even number of b's, the last symbol processed is c. 状态2:b的偶数,最后处理的符号是c。 State 3: odd number of b's. 状态3:b的奇数。

[enter image description here][1] Your required DFA is shown in the attached image [1]: https://i.stack.imgur.com/1K3Xw.jpg [在此处输入图片描述][1] 您需要的 DFA 显示在附图 [1] 中: https://i.stack.imgur.com/1K3Xw.jpg

Now let us try to understand how the DFA is constructed.现在让我们尝试了解 DFA 是如何构建的。 Initial state- 'q0' Now we take a on 'q0' for making the starting symbol of string 'a'.初始状态- 'q0' 现在我们在'q0' 上取a 来制作字符串'a' 的起始符号。 After that we want to construct our DFA which contains even number of 'b's' for that we take b on 'q1','q2'.之后,我们要构建包含偶数个“b”的 DFA,因为我们在“q1”、“q2”上取 b。 And our required DFA has last symbol is a 'c'.我们所需的 DFA 的最后一个符号是“c”。 So we take 'c' on 'q3'.所以我们在'q3'上取'c'。 The final state is 'q4'.最终的 state 是“q4”。 Now we see transition of each state.现在我们看到每个 state 的转换。 On 'q0' we take string symbol 'a' for starting symbol and we goes to state 'q1'.在“q0”上,我们将字符串符号“a”作为起始符号,然后转到 state“q1”。 If we take string symbols 'b' and 'c' on state 'q0' we goes to the state 'q5'.如果我们在 state 'q0' 上使用字符串符号 'b' 和 'c',我们将转到 state 'q5'。 If we take 'a','c' on state 'q1' then we stay in the same state 'q1'.如果我们在 state 'q1' 上取 'a','c',那么我们将留在同一个 state 'q1' 中。 Now we take 'b' on 'q1' then we goes to the state 'q2'.现在我们在“q1”上取“b”,然后我们转到 state“q2”。 In the constructing DFA we have odd number of 'b's' ie 1. But we take even number of 'b's'.在构造 DFA 中,我们有奇数个“b”,即 1。但我们取偶数个“b”。 If we take 'a','c' on state 'q2' then we stay in the same state 'q2'.如果我们在 state 'q2' 上取 'a','c',那么我们将留在同一个 state 'q2' 中。 If we take string symbol 'b' on state 'q2' then we goes to the state 'q3'.如果我们在 state 'q2' 上使用字符串符号 'b',那么我们将转到 state 'q3'。 If we take 'a'on state 'q3' then we stay in the same state 'q3'.如果我们在 state 'q3' 上取 'a',那么我们将留在同一个 state 'q3' 中。 If we take string symbol 'b' on state 'q3' then we goes to the state 'q2'.如果我们在 state 'q3' 上取字符串符号 'b',那么我们将转到 state 'q2'。 If we take string symbol 'c' on state 'q3' then we goes to the state 'q4' which is final state.如果我们在 state 'q3' 上取字符串符号 'c' ,那么我们将转到 state 'q4' ,这是最终的 state。 Because in that DFA we follow the properties which we required.因为在那个 DFA 中,我们遵循我们需要的属性。 If we take string symbol 'b' on state 'q4' then we goes to the state 'q2'.如果我们在 state 'q4' 上取字符串符号 'b',那么我们将转到 state 'q2'。 If we take string symbol 'a' on state 'q4' then we goes to the state 'q3'.如果我们在 state 'q4' 上取字符串符号 'a',那么我们将转到 state 'q3'。 This is our required DFA.这是我们需要的 DFA。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM