The quicksort algorithm has an average time complexity of O(n*log(n)) and a worst case complexity of O(n^2).
Assuming some variant of Hoare’s quicksort algorithm, wh
To expand on what Bragboy said, instead of only running:
quicksort(array);
Run:
shuffle(array);
quicksort(array);
Where the definition of shuffle()
could be:
shuffle(array){
for(int i = array.length; i > 0; i--){
r= random number % i;
swap(array[i], array[r]);
}
}
Doing so will, likely, deal with the case of getting input which makes quicksort()
slow.