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

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

View Full Document Right Arrow Icon
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)
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 2
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
Background image of page 3

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

View Full DocumentRight Arrow Icon
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   
Background image of page 4
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   
Background image of page 5

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

View Full DocumentRight Arrow Icon
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
Background image of page 6
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
Background image of page 7

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

View Full DocumentRight Arrow Icon
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
Background image of page 8
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    
Background image of page 9

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

View Full DocumentRight Arrow Icon
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  
Background image of page 10
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         
Background image of page 11

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

View Full DocumentRight Arrow Icon
CSIS0250 Notes 10 Brute-force typical case pattern:  xkhthbkwy text:  No of comparisons:  N+3
Background image of page 12
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.
Background image of page 13

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

View Full DocumentRight Arrow Icon
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
Background image of page 14
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] ?
Background image of page 15

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

View Full DocumentRight Arrow Icon
Image of page 16
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 85

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 Right Arrow Icon
Ask a homework question - tutors are online