as heapsort, partial_sort() has the better complexity, but sort() has the better runtime in most cases. The advantage of partial_sort() is that it guarantees n∗log(n) complexity in any case, so it never reaches quadratic complexity. In addition, partial_sort() has the special ability to stop sorting when only the first n elements need to be sorted. To sort all the elements, you have to pass the end of the sequence as second and last argument: