Lecture21

Lecture21 - Algorithms in Systems Engineering IE170 Lecture...

Info iconThis preview shows pages 1–5. 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: 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 Knuth-Morris-Pratt Algorithm By being a little smarter, we can get a string-matching algorithm linear run time. The Knuth-Morris-Pratt Algorithm is based on the pre-computation 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

Page1 / 7

Lecture21 - Algorithms in Systems Engineering IE170 Lecture...

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

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