转换 RE ->全国期货协会
我有一个关于将正则表达式转换为非确定性有限状态自动机的问题:
将 (a*|b*)* 转换为 NFA。我的尝试如下:
我完全偏离目标了吗?或者说有一点?
NB E => ε
I have a question regarding the conversion of regular expressions to non-deterministic finite state automata:
Convert (a*|b*)* to NFA. My attempt is as follows:
Am I completely off the mark? Or somewhat there?
NB E => ε
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的 NFA 与
(a*|b*)*
匹配相同的语言,因此答案是正确的。但是,有许多 NFA 匹配相同的语言,在您的情况下,可以删除至少三个 epsilon 箭头。尽管如此,它不会比你的建议更正确。
正则表达式
(a*|b*)*
也可以在不改变语义的情况下进行简化。例如,(a|b)*
相当于(a*|b*)*
。如果你仔细想想,FA 可以像这样简单:Your NFA matches the same language as
(a*|b*)*
, so the answer is correct.However, there are many NFAs that match the same language and in your case it would be possible to remove at least three epsilon arrows. Still, it will not be more correct than your suggestion.
The regex
(a*|b*)*
can also be simplified, without changing the semantics. E.g.(a|b)*
is equivalent to(a*|b*)*
. And if you think about it, the FA can be as simple as this: