BUBBLE SORT METHOD
public String bubbleSortCalc (float[] arr) {
float[] b = deepCopy(arr);
long start = System.nanoTime();
boolean turnOn = false;
do {
turnOn = false;
for (int i = 0; i < b.length - 1; i++) {
if (b[i] > b[i + 1]) {
swap(b, i, i + 1);
turnOn = true;
}
}
} while (turnOn);
long end = System.nanoTime();
return end - start + "ns";
}
INPUT ARRAY Element: Random float values | Length = 100 | Try: 3 times
BEST CASE | AVERAGE | WORST CASE |
---|---|---|
9300ns | 316900ns | 830800ns |
6000ns | 477300ns | 684800ns |
21000ns | 1252800ns | 1079600ns |
I just don't understand how average case sometimes takes longer time than worst case. Thank you for answering my question!
I've tried with length 1000, 10000, 100000 also. I expected average case to be faster than worst case. Maybe something got in the way. And I tried to search for the answer but didn't find any hint.