From 0602c16dc34b87a9d977a6226d8e30dbf7022092 Mon Sep 17 00:00:00 2001 From: Aakash Panchal <51417248+Aakash-Panchal27@users.noreply.github.com> Date: Fri, 12 Jun 2020 22:17:37 +0530 Subject: [PATCH] Update KMP.md --- articles/Akash Articles/md/KMP.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/articles/Akash Articles/md/KMP.md b/articles/Akash Articles/md/KMP.md index 96ca9e6..588045f 100644 --- a/articles/Akash Articles/md/KMP.md +++ b/articles/Akash Articles/md/KMP.md @@ -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$).