Post by Maros HluskaWhat should be changed in the pseudocode? The "while i < n" to "while i
< n - m" ?
Not quite. In this algorithm, i is the index that we are currently
looking at in the text, so certainly we want to allow i=n-1 for instance
to check the last character of the text against the last character of
the pattern.
Instead, that condition (on line 4, slide 23, module 8) should be
changed to "i < n AND i-j <= n-m". This is because i-j is the guess
index, and valid guesses are from 0 up to n-m inclusive (see slide 17).
Actually, since we know that j < m at any given point, we could simplify
the condition of the while loop to just "n-i >= m-j". But I think this
makes the logic a little less clear.
-Dan Roche
CS 240 Instructor, Section 003