Does the C standard require the standard-library qsort() function provide a specific level of performance? The name suggests the use of an O(n log n) algorithm such as quicksort. Could a standards-conforming library implement it using the O(n^2) insertion sort, or even the O(n!) bogosort?
Does the qsort() function provide performance guarantees?
100 views Asked by Mark At
1
According to the C89, C99, C11, and C17 standards, no particular big-O behavior is required.
This is the language from the C89 standard, under heading 7.10.5.2. The other standards contain identical language.
The standard does not specify a particular algorithm or particular speed. In fact, it goes out of its way to allow more sorting algorithms by not requiring a stable sort. I interpret this to mean that Bogosort is a standards-compliant way to implement qsort.