What is the time complexity of std::sort() in the C++ standard library?

后端 未结 6 796
暗喜
暗喜 2020-12-23 11:57

What is the complexity of std::sort() in the C++ Standard Library? Which sort is applied? Is there any rule of applying any particular sorting algorithm there?<

6条回答
  •  心在旅途
    2020-12-23 12:03

    http://en.wikipedia.org/wiki/Sort_(C%2B%2B)

    The specific sorting algorithm is not mandated and may vary across implementations. The GNU Standard C++ library, for example, uses a hybrid sorting algorithm: introsort is performed first, to a maximum depth given by 2×log2 n, where n is the number of elements, followed by an insertion sort on the result.[1] Whatever the implementation, the complexity should be O(n log n) comparisons on the average. [2]

提交回复
热议问题