String Matching - PowerPoint PPT Presentation

1 / 26
About This Presentation
Title:

String Matching

Description:

An efficient algorithm has a polynomial worst case time ... Brute Force,Horspool and the Berry ... less comparisons than the KMP and Brute Force algorithms. ... – PowerPoint PPT presentation

Number of Views:342
Avg rating:3.0/5.0
Slides: 27
Provided by: lau19
Category:
Tags: brute | matching | string

less

Transcript and Presenter's Notes

Title: String Matching


1
String Matching
  • Thomas Berry
  • Room 706A

2
Last Week
  • An efficient algorithm has a polynomial worst
    case time complexity. Which means that they are
    all of the form O(nk). Where k is an integer
    greater than 0. For example O(n), O(n2), etc..
  • String matching is the searching for a pattern P
    of length m in a text T of length n. Where ngtm.

3
This Week
  • Show the Horspool algorithm
  • Show Berry Ravindran

4
Theoretical evaluation
  • KMP has a time complexity of O(nm).
  • The following all have time complexities of
    O(nm)
  • Brute Force,Horspool and the Berry Ravindran.
  • So theoretically the KMP is the best algorithm
    for string matching. Is this true in practice?

5
Horspool Algorithm
  • Performs comparisons from right to left.
  • Uses one shift table to calculate the shift after
    a full match or mismatch.
  • Shift table calculates the position of the
    mismatched text character in the pattern. If the
    character is not in the pattern then we shift by
    m positions.

6
Horspool Algorithm
  • How do we construct the table?
  • The table is constructed by numbering the
    characters of the pattern from left to right
    starting with m-1.
  • If a character repeats then the lower value is
    used.
  • Example with ababcab from the KMP example.

7
Horspool Example
8
Horspool Shift Table
9
Horspool Example
10
Horspool Shift Table
11
Horspool Example
12
Horspool Example
13
Horspool Example
14
Horspool Example
15
Horspool Review
  • Horspool takes less comparisons than the KMP and
    Brute Force algorithms.
  • This is due to the larger shift when the
    algorithm mismatches.

16
Berry Ravindran
  • My own algorithm. Very simplistic?
  • Searches right to left as the Horspool.
  • Uses one shift table.
  • Shifts on the two characters after the
    text/pattern alignment.
  • Over 2 million trials with English text was the
    most efficient algorithm by 30

17
Berry Ravindran algorithm
18
B R Example
19
B R Example
20
B R Example no. 2
21
B R Example no. 2
22
B R Example no. 2
23
B R Example no. 2
24
B R Example no. 2
25
Conclusion
  • Although the theoretical evaluation claims that
    the KMP is the best algorithm for the task of
    string matching. We can see that others are
    better in practice and that the KMP is one of the
    worst in practice for searching in English text.
    This is due to us using a text and pattern that
    are not the worst case.

26
Conclusion
  • The theoretical evaluation gives an idea of the
    efficiency of the algorithm. But not until we
    have tested it in practice can we be sure of our
    claims.
Write a Comment
User Comments (0)
About PowerShow.com