Update KMP.md

This commit is contained in:
Aakash Panchal 2020-06-12 22:17:37 +05:30 committed by GitHub
parent 2975f082ac
commit 0602c16dc3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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$).