Algorithms and Data Structures · Senior · Question 16 of 75

What is the average complexity of quickselect for finding the k-th smallest element?

Explanation

Like quicksort it partitions, but it recurses only into the side that contains position k, so the work is n + n/2 + n/4 + ... ≈ 2n. The worst case is O(n²); median of medians guarantees O(n) with a bigger constant.

Further reading

Problem with a question

Algorithms and Data Structures · Senior · question 16

Test yourself

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

Take this quiz