Question: Horspool s algorithm / / Fills the shift table used by Horspool s and Boyer - Moore algorithms / / Input: Pattern P [ 0
Horspools algorithm
Fills the shift table used by Horspools and BoyerMoore algorithms
Input: Pattern Pm and an alphabet of possible characters
For your assignment the set of characters are the ASCII characters
Output: Tablesize indexed by the alphabets characters and
filled with shift sizes computed by formula
ShiftTableneedle m
for i to size do Tableim
for j to m do Tableneedlej m j
printShiftTable
return Table
Implements Horspools algorithm for string matching
Input: Pattern needlem and text haystackn
Output: The index of the left end of the first matching substring
or if there are no matches
HorspoolMatchingneedlem haystackn
ShiftTableneedlem generate Table of shifts
printfs
haystack;
i m position of the patterns right end
while i n do
knumber of matched characters
while k m and needlem k haystacki k do
kk
if k m
printfssfound
im needle;
return i m Except for your code, do not return. Start looking for the next occurance from here.
else
printfss
im needle;
i i Tablehaystacki
printfMatches found at locations:";
fori ; i matchNum; i
printfd matchesi;
printf
;
return
#define MAXALPHABET
#define TABLEROWLENGTH
#define MINWRITEABLE
Print out the shift table starting at the first writable character space
void printShiftTableint table
int i start;
forstart MINWRITEABLE; start MAXALPHABET; startTABLEROWLENGTH
fori start; i startTABLEROWLENGTH; i
printfct i;
printf
;
fori start; i startTABLEROWLENGTH; i
printfdt tablei;
printf
;
Ouput:
abaabcbabcbabcbabbbabcbaabbcbabcabc
abc
abc
abcfound
abc
abcfound
abc
abcfound
abc
abc
abc
abc
abcfound
abc
abc
abc
abc
abcfound
abcfound
Matches found at locations:
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
