标签:following you sam situation get serve str branch represent
In the theory of computation, a branch of theoretical computer science, a deterministic finite automaton (DFA)—also known as deterministic finite acceptor (DFA), deterministic finite-state machine (DFSM), or deterministic finite-state automaton (DFSA)—is a finite-state machine that accepts or rejects a given string of symbols, by running through a state sequence uniquely determined by the string. So, the most important in it is State transition.
DFA does not directly represent a state of the string, but represents a state abstracted from the string, this is an important issue that you need to understand.
The idea of the KMP algorithm needs to be understood on the basis of violent matching, mainly focusing on the mismatch during the matching process. We assume that there is a text string Text_str and a matching string Pat_str. When using Pat_str to match a text string, Assuming that the part we match is pat_str[0] to pat_str[j], in Text_str, pat_str[i] does not match Text_str[j], then the following situation.
If we directly follow the original method of violence, we will directly move Pat_str one bit back, but while we scan to Text_str[i] we get wrong, this means that we have know the Text_str from Text_str[i-j] to Text_str[i], and we also know what Pat_str stored, so we could know this two parts‘ relationship, also it must be some complex. So let‘s consider what the relationship between Text_str[i-j] to Text_str[i] and Pat_str[0] to Pat_str[j].
In the above problem, we observed that if we return from Text_str[1], we continue to match each time, then it will match at the following position
In the above, the character after Pat_str[2] won‘t be compare. And you will notice that suffixes of Text_str[i] and prefixes of Pat_str[0] is the same, this is the most problem.
For others conditions of Pat_str and Text_str, they won‘t have Matching fields of the Prefixes of Pattern_str.
I don‘t think I could interpreter this problem clearly, so I use a picture of a book to illustrate it, First of all, you must remember what dfa[][] in the blow picture and what dfa[][] save, in the blow picture:
标签:following you sam situation get serve str branch represent
原文地址:https://www.cnblogs.com/wevolf/p/13049538.html