Colin Cruise

Greenhorn
+ Follow
since Feb 29, 2008
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Colin Cruise

Hey Joanne and Ulf,

Thanks for the link to the book. Very helpful. I think that I finally figured it out (after reading the Wikipedia entry several times)! For the "good suffix shift" table, it looks like the algorithm is computing a subset of the pattern string (with a negation of its mismatched character) within the original pattern string. That is confusing. Does anyone know of a good simple implementation of that "good suffix shift" table?
15 years ago
I reading the Wikipedia entry for the Boyer-Moore Algorithm for searching through strings, and I was wondering if someone can explain to me (in simple words with perhaps a simple example) of how the "good suffix shift" table is computed. I understand how the "bad character shift" table is calculated, but I can't seem to understand how the "good suffix shift" table works.

Any help would be much appreciated. I have searched the web vigorously for any sort of explanation for how the table is computed, but I honestly don't understand what they are saying. Thanks in advance.
15 years ago
I tried something like this below, but I am having problems with boundary cases, particularly where the sentence ends with a period. Somehow, I have a feeling that I am not approaching this in the right way. Any help would be much appreciated. Thanks.

public String reverseAndReplace(String original, String toBeReplaced, String replacement) {
String temp="";
String finalString="";
for(int i = 0; i < original.length(); i++) {
char c = original.charAt(i);
if(c == ' ') {
if(temp.equals(toBeReplaced)) {
finalString = replacement + " " + finalString;
} else {
finalString = temp + " " + finalString;
}
temp = "";
} else {
temp += c;
}
if(i == original.length() - 1)
if(temp.equals(toBeReplaced)) {
finalString = replacement + " " + finalString;
} else {
finalString = temp + " " + finalString;
}

}
return finalString;
}
15 years ago
It would be much appreciated if I could have some help with the following problem. I would like to write a Java function that has the following interface:
public String reverseAndReplace(String original, String toBeReplaced, String replacement) { .. }

This method would do two things:
1) Reverse the words in the string.
For example, given the string: "Wealth is the product of man's capacity to think." The method would transform this sentence to: "think. to capacity man's of product the is Wealth"
2) Replace a word in the String with another word.
For example:
public String reverseAndReplace("Wealth is the product of man's capacity to think.", "think", "act");
The method would return: "act. to capacity man's of product the is Wealth"

This method should run in linear time, and it cannot use not any of Java's built-in string manipulation functions nor any third-party packages (such as Apache's StringUtils and the String.replaceAll methods) in its implementation. For example, this is illegal:

public String reverseAndReplace(String original, String toBeReplaced, String replacement) {
return StringUtils.reverseDelimited(original.replaceAll(toBeReplaced, replacement), ' ');
}

Any help would be much appreciated and thanks in advance.
15 years ago