Quickselect: Finding the K-th Smallest Element

Coding · Medium · Free problem
You have an unsorted array of $n$ elements and you want the $k$-th smallest one -- not the whole sorted array, just that one element. Describe the Quickselect algorithm. What is its average-case time complexity, and what is the worst case? How can you guarantee the worst case doesn't happen?

Open the full interactive solver, hints, and worked solution →