Data Structures & AlgorithmsHardTCS NQT Digital · Product Company SDE

Problem: What is the average-case and worst-case time complexity of the quickselect algorithm for finding the k-th smallest element?

  1. A. O(log n) average and worst case
  2. B. O(n) always, with no worst case
  3. C. O(n log n) average and worst case
  4. D. O(n) average case, O(n^2) worst case

Correct answer: D. O(n) average case, O(n^2) worst case

Like quicksort, quickselect partitions around a pivot but only recurses into the side containing the target rank, giving O(n) expected time; an adversarial pivot choice (e.g. always picking the smallest/largest) degrades it to O(n^2).

More Coding Interview Problems questions

Exams that ask this topic