简体   繁体   English

我的转换函数正确吗(与有限自动机匹配的字符串)

[英]Is my transition function correct (String matching with finite automata)

I am learning String matching with finite automata from CLRS . 我正在从CLRS学习具有有限自动机的字符串匹配。 I am solving some exercise problems .For the exercise problem 32.3-1 , 我正在解决一些运动问题。对于运动问题32.3-1,

Construct the string-matching automaton for the pattern P = aabab and illustrate its operation on the text string T = aaababaabaababaab. 构造模式P = aabab的字符串匹配自动机,并说明其在文本字符串T = aaababaabaababaab上的操作。

the following is my transition function , 以下是我的转换函数,

states   a   b
 0       1   0
 1       2   0
 2       2   3
 3       4   3
 4       4   5
 5       ?   ?

Is my transition function correct ? 我的转换函数正确吗? And how do i fill the last row ? 那我怎么填最后一行呢? Any help 任何帮助

I assume you are creating a Finite Automata which accepts a string containing the pattern aabab . 我假设您正在创建一个有限自动机,该自动机接受包含模式aabab的字符串。

There are two mistakes in your finite automata, 有限自动机有两个错误,

on state 3 and state 4, 在状态3和状态4,

For state 3 , if the input is b , you have to go back to state 0 . 对于状态3 ,如果输入为b ,则必须返回状态0 For example the pattern aabb will force you back to state 0 . 例如, aabb模式将迫使您返回状态0 Here you have to start all over again from state 0 . 在这里,您必须从状态0重新开始。

For state 4 , if the input is a , you have to go back to state 2 because you have the pattern aa . 对于状态4 ,如果输入为a ,则必须返回状态2因为您具有模式aa For example the pattern aabaa will force you back to state 2 . 例如,模式aabaa将迫使您返回状态2

The corrected Finite Automaton is given below, 修正后的有限自动机如下所示,

states   a   b
 0       1   0
 1       2   0
 2       2   3
 3       4   0
 4       2   5
 5       5   5

Here 5 is your Accepting state. 这里5是您的接受状态。 You will reach this state only when you have found the required pattern in a string. 仅当在字符串中找到所需的模式时,您才会达到此状态。 Once a pattern is found no matter what the string remains in the accepting state. 一旦找到模式,无论什么字符串保持接受状态。 Hence for both inputs a and b on state 5 remains on 5 itself. 因此,对于状态5输入ab ,状态5本身都保持不变。

The transition function is that of an fa accepting a string with sub string ' aabab '. 过渡函数是fa接受带有子字符串“ aabab ”的字符串的函数 If you are going back to state 1 for a and 0 for b , then the transition function accepts strings ending with the sub string ' aabab '. 如果你想回到状态1a0b ,那么转换函数接受与子串“aabab的 ”结尾的字符串。 Given that only state 5 is the accepting state. 假定只有状态5是接受状态。

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

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