Explaning better
I have the following problem, I have source array of integer values, then I need to order the source array by suffix comparator and put it a sorted array, The problem is that I want to know which is the time complexity of constructing the suffix-array(sorting the source array)
This is the method sort:
Collections.sort(sorted, new SuffixComparator<Integer>(source));
and this is the class SuffixComparator:
public class SuffixComparator<Type extends Comparable<Type>>
implements java.util.Comparator<Integer> {
List<Type> array1;
List<Type> array2;
/**
* Constructor with a single array
*/
public SuffixComparator (ArrayList<Type> array) {
array1 = array;
array2 = array;
}
/**
* Constructor with two arrays
*/
public SuffixComparator (List<Type> a1, List<Type> a2) {
array1 = a1;
array2 = a2;
}
/**
* Constructor with two arrays
*/
public SuffixComparator (ArrayList<Type> a1, ArrayList<Type> a2) {
array1 = a1;
array2 = a2;
}
/**
* Compare two suffixes
* @param offset1 first offset
* @param offset2 second offset
*/
public int compare (Integer offset1, Integer offset2) {
int result;
if ( array1 == array2 && offset1.equals(offset2) ) {
result = 0;
} else {
int n1 = offset1;
int n2 = offset2;
while (n1 < array1.size() &&
n2 < array2.size() &&
array1.get(n1).equals(array2.get(n2))) {
++n1;
++n2;
}
if (n1 == array1.size()) {
result = (n2 < array2.size()) ? -1 : 0;
} else if (n2 == array2.size()) {
result = 1;
} else { // n1 < array1.size && n2 < array2.size
result = array1.get(n1).compareTo(array2.get(n2));
}
}
return result;
}
}
Any suggestions?
array1andarray2coming from? 2) From the javadoc forCollection.sort(): "a stable, adaptive, iterative mergesort that requires far fewer than n lg(n) comparisons when the input array is partially sorted"array1andarray2? and how do you call your sort ?