The Rabin-Karp algorithm is a string-searching algorithm that uses hashing to find patterns in strings.
The Rabin-Karp algorithm makes use of hash functions and the rolling hash technique.
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Rabin Karp ppt
1. R A B I N -
K A R P
A L G O R I T H
M
F O R PAT T E R N S E A R C H I N G
B Y:
S H R E YA S B H A R A D W A J B . A
M . T E C H 1 S T S E M
B M S I T
3. INTRODUCTION
• Michael O. Rabin
• Richard M. Karp
Proposed In 1987
• By Hashing
Improved Naïve String Matching
4. A string is an abstract data
type that consists of a sequence of
characters.
Letters, words, sentences, and
more can be represented as
strings.
String matching is a very important
application of computer science. If
you’ve ever searched through a
document for a particular word,
then you have benefitted from
string-matching technology.
5. D E F I N I T I O
N O F
R A B I N
K A R P
A L G O R I T H M
The Rabin-Karp algorithm is
a string-searching algorithm
that uses hashing to find
patterns in strings.
The Rabin-Karp algorithm
makes use of hash
functions and the rolling
hash technique.
6. Hashing and Rolling hash
Hashing is a way to associate values using a hash
function to map an input to an output. The purpose of a
hash is to take a large piece of data and be able to be
represented by a smaller form.
A rolling hash allows an algorithm to calculate a hash
value without having to rehash the entire string.
7. HOW RABIN
KARP WORKS
• The Rabin-Karp string matching
algorithm calculates a hash value for
the pattern, as well as for each M-
character subsequence's of text to be
compared.
• If the hash values are unequal, the
algorithm will determine the hash value
for next M-character sequence.
• If the hash values are equal, the
algorithm will analyse the pattern and
the M-character sequence.
• In this way, there is only one
comparison per text subsequence, and
character matching is only required
when the hash values match.
16. Limitations of
Rabin-Karp
Algorithm
Spurious Hit
• When the hash value of the pattern matches
with the hash value of a window of the text
but the window is not the actual pattern then
it is called a spurious hit.
• Spurious hit increases the time complexity of
the algorithm. In order to minimize spurious
hit, we use modulus. It greatly reduces the
spurious hit.
•
17. Rabin-Karp Algorithm Complexity
The average case and
best case complexity of
Rabin-Karp algorithm
is O(m + n) and the
worst case complexity
is O(mn).
The worst-case
complexity occurs
when spurious hits
occur a number for all
the windows.