Question: The repository contains code to load a file with the target string, ExactStringMatchingDriver, and an intended class structure for the online algorithms via an abstract
The repository contains code to load a file with the target
string, ExactStringMatchingDriver, and an intended class
structure for the online algorithms via an abstract
class StringMatcher, which has the abstract methods
void setTargetString target sets the target to
search within
void setPatternString pattern sets the pattern to
search for
int match searches for the pattern in target, returns
the index of the first match or if there is no match
int getNumberOfSteps returns the number of steps
performed during a match
Your task is to extend the abstract StringMatcher class and
override these methods to implement the online string matching
algorithms. StringMatcher contains other methods that times
the execution of the setTarget, setPattern and match
methods timed These timing methods are called from
ExactStringMatchingDriver class to perform the searching.
You are also provided with a sample implementation
of StringMatcher called StringMatcherBuiltin that uses
the String class method indexOf. Examine its contents to see
how the above methods should be implemented.
The first line of standard input specifies a command. The first
command argument specifies the name of the file that contains
the text to search, the target string. The repaper.txt file
contains the target from the tutorials and you can attempt to
search for REPAPER.
The second command argument specifies the algorithm to
use, by default this is "builtin" and uses the
StringMatcherBuiltin class. The switch statement takes this
parameter and instantiates the corresponding class that
represents an implementation of an algorithm: builtin,
bruteforce, bm or kmp It is your job to implement
bruteforce ch bm ch and kmp ch
For example, run the ExactStringMatchingDriver class to
use the builtin string matching and enter REPAPER as the
pattern user input indicated with user input:
java jar ExactStringMatchingDriver
Enter command: repaper.txt builtin, verbose user input
Enter search term: REPAPER user input
index: comp: Target: ms Pattern:
ms Match: ms
Total: ms
Enter search term: REPAPER
index: comp: Target: ms Pattern: Ems
Match: ms
Total: ms
Enter search term: user input
The program terminates when an empty line is entered.
Note that the runtime will be different on your own machine and
that the first search time maybe inaccurate or at least longer
Note that the number of comparisons is as the builtin
implementation is a blackbox. For your implementation you
should provide the number of character comparisons
made by the algorithm.
There are a number of other target text files in the data
directory that should be familiar from the lectures and you can
evaluate the runtime and number of comparisons on those files
as well.
Checkpoints
Checkpoint L Brute Force
The task for Checkpoint is to implement your own version of
the brute force algorithm and compare it to the builtin
indexOf of the Java String class. Create a new class that
extends the StringMatcher and overrides the required methods
to implement the brute force algorithm.
You should instantiate your new class for the bruteforce
case of the algorithm switch statement, for example, you should
change
case "bruteforce":
matcher null; TODO: Checkpoint
break;
to
case "bruteforce":
matcher StringMatcherBruteForce; Checkpoint
break;
For reference, the brute force text search algorithm:
T target search string
P pattern to search for
n length of T
m length of P
for int i ; i n m ; i
int j ;
while j m && T i j P j
j;
if j m
return i;
return ;
Test your program on several known input files including the
ones already in data It may be easier to debug your program
if you use a smaller target text where you can calculate the
correct position of the pattern and the number of steps youre
your algorithm should be performing. Remember to test with
both short and long patterns and also patterns that do not exist.
You can always make use of the builtin implementation to find
out the correct position of the pattern but not the number of
steps
The automated test will test your implementation of the brute
force algorithm on various target and pattern texts, running in
nonverbose mode.
Can you beat the Java builtin string comparison!!!??
Checkpoint L Better String Matching with BoyerMoore
Implement the BoyerMoore algorithm as discussed in
lectures. You should attempt to implement the algorithm
yourself, but you are allowed use the wonders of the Internet as
a resource and the lecture slides, there is pseudo code
there However, please do include the reference to the source
of your implementation and it must conform to the
implementation above and include the number of character
comparisons.
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
