What are the different sorting algorithms available in Java 6?

There are several sorting algorithms, such as sorting sorting, sorting sorting, bubble sorting, etc., which are often discussed in computer science textbooks. Given an array of integers or objects, is there a built-in Java Java API that allows me to choose to use a special sorting algorithm to sort the array instead of reinventing these wheels? If you are not embedded in Java 6, are there open source libraries that define this functionality and what are they?

+7
source share
3 answers

Arrays.sort() methods use quick sort in all arrays of primitive types.

A sorting algorithm is a customized high-speed sorting adapted from Jon L. Bentley and M. Douglas McIlroy "Engineering a Sort Function", Software-Practice and Experience, Vol. 23 (11), p. 1249-1265 (November 1993). This algorithm provides n * log (n) performance on many datasets, which lead to performance degradation in fast sectors to quadratic performance.

The Collections.sort() method uses merge sort. This view is also used in Arrays.sort(Object[]) and Arrays.sort(T[], Comparator<? super T>) .

The sorting algorithm is a modified merge system (in which the merge is omitted if the highest item in the lower sublist is less than the smallest item in the high sublist). This algorithm provides guaranteed performance n log (n). This implementation unloads the specified list into an array, sorts the array and iterates through the list, dropping each element from the corresponding position in the array. This avoids the n2 log (n) performance that would occur when trying to sort a linked list in place.

+22
source

Arrays.sort(int[] a) uses customized quicksort.

Arrays.sort[Object[] a) uses modified merging.

+5
source

Usually you cannot select (with built-in sorting, anyway). The Collections class provides a sort method that should be efficient enough for most needs.

+3
source

All Articles