Hi I am using the following generic bubble sort algorithm and I would like to display the time complexity. I understand that the best/worst case for this algorithm is fixed but I was wondering, can it be specific for my array?
For example the worst case for this sort is O(n^2), can that be specific for my array?
For example, worst case can be sorting 100 of the 120 elements (thats what i mean by specific for my array).
public static <E extends Comparable<? super E>> void bubbleSort(E[] comparable) {
boolean changed = false;
do {
changed = false;
for (int a = 0; a < comparable.length - 1; a++) {
if (comparable[a].compareTo(comparable[a + 1]) > 0) {
E tmp = comparable[a];
comparable[a] = comparable[a + 1];
comparable[a + 1] = tmp;
changed = true;
}
}
} while (changed);
}