KEMBAR78
Naive string matching | PPTX
NAIVE
STRING
MATCHING
PREPARED BY
 ABHISHEK KUMAR SINGH
What is a String?
In C, String is a sequence of characters
or more specifically can be regarded
as an array of characters.
String Matching
One of the most commonest
operation done with strings is
String Matching.
WHAT IS STRING MATCHING?
If we are given a string “p” which is
nothing but stream of characters
p[0],p[1],p[2]……..p[n-1] (where n is the
length of the string),then searching for a
specific pattern in the string is known as
string matching
Applications of String Matching
 Intrusion Detection
• String matching in bioinformatics
• String matching in Digital Forensics
An example of string matching
Here we discuss an example on string matching
where the given text consists of a pattern which
is to be searched for. The following figure shows
the location of pattern P in a given text T.
Algorithm For String Matching
There are many ways to do the
String Matching but here we
discuss the concept of
Naïve String Matching.
Naive string matching
Running time: O((n-m+1)m).
Problem with naive algorithm
 Whenever a character mismatch occurs
after matching of several characters, the
comparison begins by going back in T
from the character which follows the
last beginning character. This makes the
process very slow.
• Suppose p=ababc, T=cabababcd
• T: c a b a b a b c d
• P: a …
• P: a b a b c
• P: a…
• P: a b a b c
Solution to the Problem
There are many more algorithms which
work in a more efficient way than the
naive string matching and are listed
below:-
Rabin–Karp string search algorithm
Finite-state automaton
Knuth–Morris–Pratt algorithm
Boyer–Moore string search algorithm
THANK YOU

Naive string matching

  • 1.
  • 2.
    What is aString? In C, String is a sequence of characters or more specifically can be regarded as an array of characters.
  • 3.
    String Matching One ofthe most commonest operation done with strings is String Matching.
  • 4.
    WHAT IS STRINGMATCHING? If we are given a string “p” which is nothing but stream of characters p[0],p[1],p[2]……..p[n-1] (where n is the length of the string),then searching for a specific pattern in the string is known as string matching
  • 5.
    Applications of StringMatching  Intrusion Detection • String matching in bioinformatics • String matching in Digital Forensics
  • 6.
    An example ofstring matching Here we discuss an example on string matching where the given text consists of a pattern which is to be searched for. The following figure shows the location of pattern P in a given text T.
  • 7.
    Algorithm For StringMatching There are many ways to do the String Matching but here we discuss the concept of Naïve String Matching.
  • 8.
  • 9.
    Problem with naivealgorithm  Whenever a character mismatch occurs after matching of several characters, the comparison begins by going back in T from the character which follows the last beginning character. This makes the process very slow. • Suppose p=ababc, T=cabababcd • T: c a b a b a b c d • P: a … • P: a b a b c • P: a… • P: a b a b c
  • 10.
    Solution to theProblem There are many more algorithms which work in a more efficient way than the naive string matching and are listed below:- Rabin–Karp string search algorithm Finite-state automaton Knuth–Morris–Pratt algorithm Boyer–Moore string search algorithm
  • 11.