# L10 - String Matching (Chapter 32) Text T with N characters...

This preview shows pages 1–16. Sign up to view the full content.

CSIS0250 Notes 10 String Matching (Chapter 32) Text T  with N characters Pattern P  with M characters The problem: decide whether T has a substring equal to  P. Example Text: kdja;dlkjkaljdfkdjaie4nvoienflkajoienlcjoehahlek kdlajfiekhhieenflodioieatingkajkedfoehaoioenngh kdjkaoekh0envp0oe9nlannv.a;poenaka;0ocnelpaaE ncoejahoncz.olei.eoiNvleoknvnldopen;apfgnepakea lkfajofeinogjpeuapeoiaojfpoeiepagtingiapenoigioy Pattern: ting Usually, N >> M  (say N=100,000, M=100)

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
CSIS0250 Notes 10 Brute-force (naïve) string matching Example Text:   abaabcdabacd Pattern: acd a b a a b c d a b a c d a c d   matched mismatched
CSIS0250 Notes 10 Brute-force string matching Example Text:   abaabcdabacd Pattern: acd a b a a b c d a b a c d a c d

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
CSIS0250 Notes 10 Brute-force string matching Example Text:   abaabcdabacd Pattern: acd a b a a b c d a b a c d a c d
CSIS0250 Notes 10 Brute-force string matching Example Text:   abaabcdabacd Pattern: acd a b a a b c d a b a c d a c d

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
CSIS0250 Notes 10 Brute-force string matching Example Text:   abaabcdabacd Pattern: acd a b a a b c d a b a c d a c d
CSIS0250 Notes 10 Brute-force string matching Example Text:   abaabcdabacd Pattern: acd a b a a b c d a b a c d a c d

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
CSIS0250 Notes 10 Brute-force string matching Example Text:   abaabcdabacd Pattern: acd a b a a b c d a b a c d a c d
CSIS0250 Notes 10 Brute-force string matching Example Text:   abaabcdabacd Pattern: acd a b a a b c d a b a c d a c d

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
CSIS0250 Notes 10 Brute-force string matching Example Text:   abaabcdabacd Pattern: acd a b a a b c d a b a c d a c d
CSIS0250 Notes 10 Brute-force string matching Example Text:   abaabcdabacd Pattern: acd a b a a b c d a b a c d a c d

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
CSIS0250 Notes 10 Brute-force typical case pattern:  xkhthbkwy text:  No of comparisons:  N+3
CSIS0250 Notes 10 pattern: 000000001 text: Brute-force worst case We need to make M comparisons before we can move the pattern  template one position left; and we need to move the template to the position N-M+1  We need to make        M(N-M+1) = O(NM) comparisons.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
CSIS0250 Notes 10 Ideas for improvement Look at the worst case.  Why it needs O(NM) comparisons?  BACK UP many times and waste a lot of comparisons. Is BACK UP really necessary? Key observation:  If the mismatch is t[i+1] p[j+1], then, we know that        ….             j
CSIS0250 Notes 10 More observations No matter what the text is, there are only M different mismatches: Mismatch at p[1]; mismatch at p[2]; … ; mismatch at p[M]. No matter what the text is, if mismatch at p[j+1], then we must  have       ….             text P[1] P[2] P[3] P[j] ?

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## L10 - String Matching (Chapter 32) Text T with N characters...

This preview shows document pages 1 - 16. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online