Today's Question:  What does your personal desk look like?        GIVE A SHOUT

 ALL


  Find the kth smallest number in an array

This is an classical question, the general solution to this question is first using sorting algorithm to sort the array, then get the kth number in the array, the complexity is O(nlogn), we can also use selective sort or head sort to, the complexity of selective sort is O(kn) and heap sort is O(nlogk). The better solution is to use quick sort to find the kth smallest number, the complexity is O(n), the worst case cost is O(n^2). But today we introduce one more solution which has the worst case cost O(n).First let's check the quick sort solution, quick sort is to find one number, then put all n...

5,389 0       SORT SEARCH QUICK SORT SMALLEST