This preview shows pages 1–5. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Algorithms in Systems Engineering IE170 Lecture 21 Dr. Ted Ralphs IE170 Lecture 21 1 References for Todays Lecture Required reading CLRS Chapter 32 IE170 Lecture 21 2 The KnuthMorrisPratt Algorithm By being a little smarter, we can get a stringmatching algorithm linear run time. The KnuthMorrisPratt Algorithm is based on the precomputation a prefix function for the pattern. The prefix function looks ahead and tells us something about the validity of upcoming shifts by examining how well the current shift matches the pattern. Example : IE170 Lecture 21 3 The Naive KMP Algorithm In this simplified algorithm, we keep track of two pointers s and r . The pointer s is the start of the shift we are investigating. At all times, we maintain r such that P [0 ..r s ] = T [ s..r ] . The Simple KMP Algorithm 1. Set s = 0 and r = 1 . 2. While s < n m If r s = m 1 , then s is a valid shift. Increase s by at least 1 until P [0 ..r s ] = T...
View
Full
Document
 Spring '07
 Ralphs
 Systems Engineering

Click to edit the document details