Question: public static int brute _ force ( String text, String pattern ) { int n = text.length ( ) ; int m = pattern.length (
public static int bruteforceString text, String pattern
int n text.length;
int m pattern.length;
for int i ; i n m; i
int j ;
while j m && pattern.charAtj text.charAti j
j;
if j m
return i;
return ;
public static int shifttableString pattern
int m pattern.length;
int table new int; Assuming ASCII characters
Arrays.filltable m;
for int i ; i m ; i
tablepatterncharAti m i;
return table;
public static int horspoolString text, String pattern
int n text.length;
int m pattern.length;
int table shifttablepattern;
int i m ;
while i n
int k ;
while k m && pattern.charAtm k text.charAti k
k;
if k m
return i m ;
else
i tabletextcharAti;
return ;
public static void mainString args
String text "ABABDABACDABABCABAB";
String pattern "ABABCABAB";
int index bruteforcetext pattern;
System.out.printlnBrute Force: index;
index horspooltext pattern;
System.out.printlnHorspools: index;
Consider the following code above, now put into consideration this modification and see what appropriate changes can be done:
"The data structures HashSet or Setfor getting distinct characters present in the textand HashTable or HashMapfor creating shift tableshould be used in Horspool algorithm".
Show full java code.
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
