Repeater wrote: |
---|
The C++ standard does not dictate what sorting algorithm must be used by std::sort. It makes the following demands: |
...which demands basically mean “Introsort”.
Introsort was created specifically for the C++ Standard Library. After that the required performance characteristics were updated to reflect what Introsort offered.
Properly implemented, it is a combination of
three different sort algorithms:
• insertion sort — the de facto fastest sort for N ≤ sizeof(L1)
• quicksort — the de facto fastest sort (typically) for N > sizeof(L1)
• heap sort — a typically high-performing sort
Long ago I wrote the FAQ for it:
http://www.cplusplus.com/faq/sequences/sequencing/sort-algorithms/introsort/
Read it for all the gory details, see that page — it will flesh out the reason behind some of the details already mentioned in this thread, including the performance trick with the insertion sort at the end.
@
Niccolo
The number of elements to leave unsorted for the insertion sort to handle is properly supposed to be tuned to the hardware that the quicksort is running on — default library implementations are typically rather conservative, and a lot of extant code has not (IFAIK) been properly updated to handle modern hardware capabilities... alas.
But only seven elements, LOL. That’s stupidly small even for a Z80...
You old man. :->