10. Compare quicksort and merge sort.
MediumData structures & algorithms
Technical
Show model answer
Merge sort splits the array, sorts the halves and merges them: always O(n log n), stable, but needs O(n) extra memory.
Quicksort partitions around a pivot: O(n log n) on average, in place, and fast in practice, but O(n²) in the worst case with bad pivots (mitigated by random or median-of-three pivots). Many standard libraries use hybrids such as Timsort or introsort.