Algorithms and Data Structures · Middle · Question 4 of 75

Why is quicksort often faster than merge sort in practice despite the same O(n log n) average?

Explanation

Partitioning works inside the array with good cache locality and small constants. Its worst case is actually worse (O(n²)), and the usual in-place version is not stable.

Further reading

Problem with a question

Algorithms and Data Structures · Middle · question 4

Test yourself

Take the Algorithms and Data Structures · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz