lec19 - Outline • String matching definitions and terms...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

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

Unformatted text preview: Outline • String matching: definitions and terms • The na¨ ıve algorithm • Rabin-Karp algorithm • Boyer-Moore algorithm • String matching and finite automata Lecture 19, String Matching p. 1 Definitions and Terms • Given: – text: an array T [1 ..n ] of length n – pattern: an array P [1 ..m ] of length m ≤ n – Output: whether P occurs with shift s in text T • Applications • Useful terms – shift s : P occurs beginning at position s + 1 in text T . – alphabet Σ, where characters from P and T are drawn from – prefix: for example ”ba” is a prefix of ”banana” – suffix: for example ”nana” is a suffix of ”ba- nana” Lecture 19, String Matching p. 2 The Na¨ ıve algorithm Naive( T [1 ..n ] ,P [1 ..m ]) for s ← 0 to n- m do // compare P with T [ s + 1 ..s + m ] found ← true for j ← 1 to m do if T [ s + j ]! = P [ j ] then found ← false if found then return s is a valid shift Running time: O (( n- m + 1) m ) Lecture 19, String Matching p. 3 Pre-computing for string matching...
View Full Document

Page1 / 8

lec19 - Outline • String matching definitions and terms...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online