Algorithms and Data Structures · Middle · Question 3 of 75

What is the worst case of quicksort and when does it happen?

Explanation

If the pivot is always the smallest or largest element (for example, the first element of a sorted array), each partition removes only one element. Random pivots or median-of-three make this unlikely; the average is O(n log n).

Further reading

Problem with a question

Algorithms and Data Structures · Middle · question 3

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