简体   繁体   English

非确定性有限自动机(NFA)校正

[英]Nondeterministic finite automata (NFA) correction

I am trying to solve a question about NFA. 我正在尝试解决有关NFA的问题。 The instructions are as following: Alphabet {a, b, c}. 说明如下:字母{a,b,c}。 • L1 is all strings that their last character is the same as their fifth-last character. •L1是所有最后一个字符与第五个最后一个字符相同的字符串。 For instance, the string aaacbacbca should be accepted, because the fifth-last character and the last character are both a. 例如,字符串aaacbacbca应该被接受,因为倒数第二个字符和最后一个字符都是a。 The string ccaab should be rejected because the fifth-last character is c and the last character is b. 字符串ccaab应该被拒绝,因为倒数第二个字符是c,最后一个字符是b。 Here is with what I came up, but I am really beginner in this topic and I am not sure whether is correct or not: 这是我的想法,但我确实是该主题的初学者,并且不确定是否正确: 在此处输入图片说明

The automata you have at the moment accepts only the strings that end with acbca . 您目前拥有的自动机仅接受以acbca结尾的字符串。 Here are steps to arrive to the solution: 以下是到达解决方案的步骤:

  • change the automata you have such that it would accept all strings which have last and five-to-last symbol a 更改您拥有的自动机,使其可以接受所有具有倒数和倒数第五个符号a字符串
  • do the same for the symbols b , c 对符号bc
  • combine the 3 automata 结合3个自动机

You were almost right, but the automata you drew was only to accept strings ending in acbca . 您几乎是正确的,但是您绘制的自动机只接受以acbca结尾的acbca This one will accept the strings you want 这将接受您想要的字符串

a,b,c     a      a,b,c   a,b,c   a,b,c    a     a,b,c
,--->[q0]--->[q1]--->[q2]--->[q3]--->[q4]--->{q5}----+>[q16]-----.
|    /|   b      a,b,c   a,b,c   a,b,c    b     a,b,c|   ^ a,b,c |
`---´ +----->[q6]--->[q7]--->[q8]--->[q9]--->{q10}---+   `-------´
      |   c      a,b,c   a,b,c   a,b,c    c     a,b,c|
      `----->[q11]-->[q12]-->[q13]-->[q14]-->{q15}---´

States like {q5} are accepting states, while states like [q0] are not accepting. {q5}这样的状态正在接受状态,而像[q0]这样的状态则不在接受状态。 The meaning of q16 is to make sure that strings that have two equal letters distant 4 characters but not ending there, sink to a non accepting state. q16的含义是确保两个相等的字母的字符串相距4个字符,但不以该字符结尾,该字符串陷入非接受状态。 Same might be for letters b,c in state [q4] , for letters a,c in state [q9] , and for letters a,b in state [q14] , but for clarity of the drawing, I have omitted them. 同样可能是字母b,c状态[q4]对于字母a,c状态[q9]并为字母a,b状态[q14]但为了绘图清楚起见,我省略了它们。

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

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