An already-sorted list is the worst case for the algorithm called quicksort: with the pivot taken at the end of the range, each partition peels off a single element and the comparison count shoots up to roughly n²/2, no better than bubble sort. Let the pivot land near the middle and the very same algorithm returns to O(n log n). Merge sort holds O(n log n) always and never reorders equal elements, at the price of a borrowed array of size n. On a sorted list, binary search halves the range at every step for O(log n), even when the value is not there at all.
An already-sorted list is the worst case for the algorithm called quicksort: with the pivot taken at the end of the range, each partition peels off a single element and the comparison count shoots up to roughly n²/2, no better than bubble sort. Let the pivot land near the middle and the very same algorithm returns to O(n log n). Merge sort holds O(n log n) always and never reorders equal elements, at the price of a borrowed array of size n. On a sorted list, binary search halves the range at every step for O(log n), even when the value is not there at all.
Related topics in Mind & Machine