Skip to content

Commit 8833f67

Browse files
authored
Rabin-Karp: clean up intro
#1356 (comment)
1 parent fec16e6 commit 8833f67

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/string/rabin-karp.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@ e_maxx_link: rabin_karp
66

77
# Rabin-Karp Algorithm for string matching
88

9-
This algorithm is based on the concept of hashing, so if you are not familiar with string hashing, refer to the [string hashing](string-hashing.md) article.
10-
This algorithm was authored by Rabin and Karp in 1987.
11-
12-
Problem: Given two strings - a length $m$ pattern to find in a length $n$ text, find all matches in $\Theta(m+n) = \Theta(n)$ average time.
9+
Consider the string-matching problem: Given two strings - a length $m$ pattern to find in a length $n$ text, find all matches in $\Theta(m+n) = \Theta(n)$ average time.
1310

1411
The naive solution is to simply check all length $m$ substrings in the $n$ length text, but that would take $\Theta(mn)$ time.
1512

13+
This algorithm was authored by Rabin and Karp in 1987 and is based on the concept of [string hashing](string-hashing.md).
14+
1615
The Rabin-Karp algorithm uses the concept of a "rolling hash". In it, a hash function is chosen in such a way that the hash of the first text substring of size $m$ is computed in $\Theta(m)$ time, but the computation of hashes of subsequent substrings of length $m$ is done in $O(1)$ per substring (hence the term "rolling"). Then, the hash of the pattern is compared to hashes of each text substring, and if they are the same then there is a match with high probability.
1716

1817
## The hash function

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy