While using std::sort to sort a range is reasonably fast, it is still wasteful if you only require the top few elements. The std::partial_sort will only sort the top k elements with O(n*logk) time complexity and will even outperform std::nth_element if k is small compared to n. Compiler Explorer link: https://lnkd.in/edv7PH6A #cpp #cplusplus #coding #programming #dailybiteofcpp
What is the use case for partial_sort? Never understood it.
Northern Trust•625 followers
2yDo you think checking `std::is_sorted` before `std::sort` adds some value to the code performance if the vector has elements in random order?