[英]Build an FA that accepts only the words baa, ab, and abb and no other strings longer or shorter
I have been trying solve this problem for a while now for a university assignment.我一直在尝试解决这个问题一段时间来完成大学作业。 I'm required to build a DFA and an NFA for the above question.我需要为上述问题建立一个 DFA 和一个 NFA。 So far I have been able to solve the DFA, but can not find a solution for a proper NFA after multiple tries.到目前为止,我已经能够解决 DFA,但在多次尝试后找不到合适的 NFA 的解决方案。
My attempts for the NFA are down below.我对 NFA 的尝试如下。 I apologize for my messy handwriting but these were just rough works that I was drawing out on the go.我为我凌乱的笔迹道歉,但这些只是我在 go 上绘制的粗略作品。
There's only three words, so just make three parallel paths for your NFA, using a transition function like the following:只有三个词,所以只需为您的 NFA 创建三个并行路径,使用转换 function 如下所示:
Input State输入 State | Input Symbol输入符号 | Output States Output 状态 |
---|---|---|
[start] [开始] | a一个 | [ab], [a.bb] [ab],[a.bb] |
[start] [开始] | b b | [b.aa] [b.aa] |
[ab] [ab] | b b | [ab#] [ab#] |
[a.bb] [a.bb] | b b | [ab.b] [ab.b] |
[ab.b] [ab.b] | b b | [abb#] [abb#] |
[b.aa] [b.aa] | a一个 | [ba.a] [ba.a] |
[ba.a] [ba.a] | a一个 | [baa#] [咩#] |
Here, state names are in brackets ([..]) and state names that end with "#" are terminal.在这里,state 名称在括号 ([..]) 中,以“#”结尾的 state 名称是终端名称。
Generally it's considered easier to make an NFA than a DFA, so the usual method is to first make an NFA and then make the DFA by modifying the NFA by changing multiple output states to a single intermediate state.通常认为制作 NFA 比 DFA 更容易,因此通常的方法是先制作 NFA,然后通过将多个 output 状态更改为单个中间 state 来修改 NFA 来制作 DFA。
If you followed this method for the above NFA, then the resulting DFA would look something like this (I have appended an "*" to the intermediate state names):如果您对上述 NFA 遵循此方法,则生成的 DFA 将如下所示(我已将“*”附加到中间 state 名称):
Input State输入 State | Input Symbol输入符号 | Output State Output State |
---|---|---|
[start] [开始] | a一个 | [ab*] [ab*] |
[start] [开始] | b b | [b.aa] [b.aa] |
[ab*] [ab*] | b b | [ab.*] [ab.*] |
[ab.*] [ab.*] | (e) (e) | [ab#] [ab#] |
[ab.*] [ab.*] | b b | [abb.*] [缩写*] |
[abb.*] [缩写*] | (e) (e) | [abb#] [abb#] |
[b.aa] [b.aa] | a一个 | [ba.a] [ba.a] |
[ba.a] [ba.a] | a一个 | [baa#] [咩#] |
I've been a bit loose about all of the empty symbol/end-of-input transitons to terminal states.我对所有空符号/输入结束转换到终端状态有点松懈。 If you need me to fill al of them in, them I can do that.如果你需要我填写所有这些,我可以做到。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.