My code calculates the starting position of the intervall correctly but not the end position:
int left;
int bot = 0; int top = textLength;
while(bot != top)
{
int mid = (bot+top)/2;
if(pattern.compareTo(text.substring(suffixArray.get(mid))) > 0) bot = mid + 1;
else top = mid;
}
left = bot;
int right;
bot = left; top = textLength;
while(bot != top)
{
int mid = (bot+top)/2;
if(pattern.compareTo(text.substring(suffixArray.get(mid))) < 0) top = mid;
else bot = mid+1;
}
right = bot;
I compared it to several pseudo codes on the internet and I don't really see why it's not working. What am I missing?
The search for
right
differs only in>=
instead of>
So I would think
to point to the next higher value.
So better check first whether all is ordered: