sortingcomparisonquicksortradix-sort

Is there a good library for sorting a large array of numbers in C?


If I have a large array of integers or floats, what is a good algorithm/ implementation for sorting (in C)?

It is a bit late in the game for an edit... but I am looking for correctness and speed.


Solution

  • For sorting arrays of numbers, consider a radix sort algorithm. When properly engineered, these sorts should provide better performance than GLIBC qsort().

    The usort library contains type-specific implementations for all the major C numeric types.

    https://github.com/setjmp/usort

    The speed advantage of radix sort over GLIBC qsort is about 2.5x for double precision floating point numbers at N=1000000 on my 64 bit intel laptop. However, as N grows the advantage should be even greater since radix sort is a linear time algorithm requiring constant number of passes through the data.

    For very small N, the same code dispatches to an introsort or insertion sort.