Advanced Search

Browse by Discipline

Scientific Societies

E-print Alerts

Add E-prints

E-print Network

  Advanced Search  

CS 5050 -Program #4 -30 points KMP String Matching for binary input

Summary: CS 5050 - Program #4 - 30 points
KMP String Matching for binary input
Part 1
For this problem, write the code to do string matching as described in section 9.1 of the text. Starter
code is provided, but feel free to ignore it if it doesn't help. Variable names were selected to match
those used in the text. This is common practice when you are citing a specific algorithm.
In order to use subscripting, Strings are converted to character arrays.
This program is a modification of the KMP string matching. If the input is binary in nature (only
two symbols are used - such as x/y or 0/1), when you fail to match at x, you know you are looking
at a y. (The book describes the problem in C-9.6, but I think their formula is messed up.) I see it this
Bfail(j) = the largest k < j such that the prefix of P (P[0..k]) is a suffix of what you have seen
(P[0..j-1] Popp[j]).
where Popp[j] means the opposite character of P[j]. In other words, when you fail at position j, you
know you have seen P[0..j-1] Popp[j]. If you know how far to shift the pattern so it matches (the first
part of the desired string is what you have just seen), you don't have to check them again. It's like
you have a little helper saying to you, "Oh, you failed after matching j-1 characters, just shift the
string over X characters and try again. Since I know what you have just seen, I can tell you what X
should be."
For example, suppose you were trying to match xxyxxyxy in the input string. The "O" means you


Source: Allan, Vicki H. - Department of Computer Science, Utah State University


Collections: Computer Technologies and Information Sciences