Solution 1:We can sort this out-of-order array in descending order, and then retrieve the first K, with the total time complexity of O (N * logn + k ).
Solution 2:Select sorting or interactive sorting to obtain the maximum K number after K selections. The total time complexity is O (n * K)
Solution 3: using the fast sorting idea, we randomly find an element x from array S and divide the array into two parts: SA and Sb. The element in SA is greater than or equal to X, and the element in Sb is less than X. There are two situations:
1. If the number of elements in SA is smaller than K, the K-| sa | element in Sb is the k-th number;
2. If the number of elements in SA is greater than or equal to K, the maximum K number in SA is returned. The time complexity is approximately O (n)
Solution 4:Binary [Smin, Smax] lookup result X, counts X in the array, and the number of larger than X in the array is the number of K-1, that is, the K number. The average time complexity is O (n * logn)
Solution 5:Use the O (4 * n) method to set up the maximum heap of the original number, and then pop it out K times. Time Complexity: O (4 * n + K * logn)
Solution 6:Maintain a minimum heap of K size. For each element in the array judgment and heap top size, if the heap top is large, no matter. Otherwise, the heap top is displayed, insert the current value to the heap. Time complexity O (N * logk)
Solution 7:Using hash to save the number of times the element Si appears in the array, using the counting sorting idea, in the process of linear scanning from large to small, the first number of k-1 is the K number, average time complexity O (N)