Analysis of the STL sort sort

I wrote relatively fast discharge and sorting algorithm efficiency in fast row

I wonder, have been quick sort sorting algorithm is very fast, and why and sorting algorithm libraries difference so far.
Here Insert Picture Description

Access to online information and library source code that

Sorting algorithm is not bare in the library to use quick-sort, and to the use of a combination of more than one sort mode, the control for the size of the entire ordered sequence of the sort.

  • First, the STL sort function uses three sorting techniques, are quick sort, heap sort, insertion sort three ways, and quick sort manner recursive call.
  • Secondly, the sort order is: amount data using quick sort , to a large data segment, when a certain small threshold amount of data is reduced to reduce the efficiency of quicksort recursive call, so the use of insertion sort way each piece of data Sort; when a recursive call to the number of layers reaches a certain critical value, it will use heap sort of way sort.
    Here Insert Picture Description
    Why use heap sort: the sort heap because of a constant time complexity nlogn
    Why use insertion sort: because insertion sort is more efficient in the face of near-ordered data.
Published 52 original articles · won praise 26 · views 3403

Guess you like

Origin blog.csdn.net/weixin_43796685/article/details/104451725