From f9a8c881cc5886a86d5537d5d6f9f3d1bc5776da Mon Sep 17 00:00:00 2001 From: Oleksii Trekhleb Date: Tue, 24 Apr 2018 21:36:47 +0300 Subject: [PATCH] Add Rabin. --- README.md | 4 ++-- src/algorithms/string/rabin-karp/README.md | 24 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 src/algorithms/string/rabin-karp/README.md diff --git a/README.md b/README.md index f1de421b..a21fe9b0 100644 --- a/README.md +++ b/README.md @@ -41,8 +41,8 @@ * **String** * [Levenshtein Distance](https://github.com/trekhleb/javascript-algorithms/tree/master/src/algorithms/string/levenshtein-distance) - minimum edit distance between two sequences (DP approach) * [Hamming Distance](https://github.com/trekhleb/javascript-algorithms/tree/master/src/algorithms/string/hamming-distance) - number of positions at which the symbols are different - * [Knuth–Morris–Pratt algorithm](https://github.com/trekhleb/javascript-algorithms/tree/master/src/algorithms/string/knuth-morris-pratt) - substring search - * Rabin Karp + * [Knuth–Morris–Pratt Algorithm](https://github.com/trekhleb/javascript-algorithms/tree/master/src/algorithms/string/knuth-morris-pratt) - substring search + * [Rabin Karp Algorithm](https://github.com/trekhleb/javascript-algorithms/tree/master/src/algorithms/string/rabin-karp) - substring search * Longest common subsequence * longest common substring * **Search** diff --git a/src/algorithms/string/rabin-karp/README.md b/src/algorithms/string/rabin-karp/README.md new file mode 100644 index 00000000..40d29a55 --- /dev/null +++ b/src/algorithms/string/rabin-karp/README.md @@ -0,0 +1,24 @@ +# Rabin Karp Algorithm + +In computer science, the Rabin–Karp algorithm or Karp–Rabin algorithm +is a string searching algorithm created by Richard M. Karp and +Michael O. Rabin (1987) that uses hashing to find any one of a set +of pattern strings in a text. + +## Complexity + +For text of length `n` and `p` patterns +of combined length `m`, its average and best case running time is +`O(n + m)` in space `O(p)`, but its worst-case time is `O(n * m)`. + +## Application + +A practical application of the algorithm is detecting plagiarism. +Given source material, the algorithm can rapidly search through a paper +for instances of sentences from the source material, ignoring details +such as case and punctuation. Because of the abundance of the sought +strings, single-string searching algorithms are impractical. + +## References + +[Wikipedia](https://en.wikipedia.org/wiki/Rabin%E2%80%93Karp_algorithm)