Skip to content
Advertisement

The Running Time For Arrays.Sort Method in Java

Does anyone know the running time in big O notation for the arrays.sort java method? I need this for my science fair project.

Advertisement

Answer

From official docs

I’ve observed that there are primarily two approaches. So, it depends on what you are sorting and what overloaded method from sort family of methods you are calling.

Docs mention that for primitive types such as long, byte (Ex: static void sort(long[])):

The sorting algorithm is a tuned quicksort, adapted from Jon L. Bentley and M. Douglas McIlroy’s “Engineering a Sort Function”, Software-Practice and Experience, Vol. 23(11) P. 1249-1265 (November 1993). This algorithm offers n*log(n) performance on many data sets that cause other quicksorts to degrade to quadratic performance.

For Object types: (Ex: void sort(Object list[]))

Guaranteed O(nlogn) performance

The sorting algorithm is a modified mergesort (in which the merge is omitted if the highest element in the low sublist is less than the lowest element in the high sublist). This algorithm offers guaranteed n*log(n) performance.

Hope that helps!

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement