Since C++11
, the C++ Standard Library (c.f. Section 25.4.1.1 of a draft verion of the standard) requires the std::sort
algorithm to have asymptotic worst case execution time O(n log n)
instead of average case.
Following the change, for example the quicksort
algorithm does not comply the specification anymore. This was pointed out in a bugreport for LLVM's libc++
. Instead, the algorithms introsort
or pdqsort
, which have worst case running time O(n log n)
, are used usually.
Is there any documentation on the motivation for that change? Is there some anecdote or incident that lead to that change?
std::sort
quadratic? – Slacksstd::sort
(from the bug report): gcc.godbolt.org/z/KdfT3rY1K – Pettis