According to cppreference.com, the complexity of C ++ STL sorting algorithms is as follows:
sort: O (N log (N))
partial_sort: “approximately” O (N log (M)), where M is the distance (mid-first)
nth_element: "average" O (N)
However, this means that instead of executing, partial_sortyou can use nth_elementand then sort the first range to give the total complexity of O (N + M log (M)), which is slightly better than O (N log (M)). It's true? Should I avoid partial_sort?
source
share