You are viewing a single comment's thread. Return to all comments →
The problem wants to demonstrate "selection algorithm". Specifically the implementation is Quickselect.
Quickselect has worst-case time complexity O(n2) same as quicksort, but practical complexity O(n).
The problem should have explained that. From the definition it's unclear what we were supposed to do. Easiest approach is to just sort the array and get the middle element. Unless you know math, it's unclear why selection is supposed to have better complexity than sort, because from simply eyeballing it it looks exactly the same.