mirror of
https://github.com/dholerobin/Lecture_Notes.git
synced 2025-09-13 05:42:12 +00:00
Update KMP.md
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
Prefix function and KMP-algorithm
|
||||
|
||||
KMP-algorithm is a widely used **string-matching algorithm**, which is used to find a place where a string is found within a larger string. It uses the value of **prefix function** for a given string.
|
||||
KMP-algorithm is a widely used **string-matching algorithm**, which is used to find a place where a string is found within a larger string. For example, `p = "ab"` and `s = "abbbabab"`, then KMP will find us `[0,4,6]` because $s$ has 3 occurrences of `"ab"`. It uses the value of **prefix function** to do so.
|
||||
|
||||
Let's first see what is a **prefix function**.
|
||||
|
||||
@@ -214,6 +214,8 @@ int main()
|
||||
}
|
||||
```
|
||||
|
||||
Prefix function can also be used to solve various string related problems. Let's see some applications.
|
||||
|
||||
## Find a period of a string
|
||||
|
||||
Period of a string is the shortest length such that a larger string $s$ can be represented as a concatenation of one or more copies of a substring($t$).
|
||||
|
Reference in New Issue
Block a user