Solution 1: We can sort the random ordinal group in order from big to small, then remove the front k large, the total time complexity is O (N*logn + k).
Solution 2: use the choice of sorting or interactive sorting, K-time selection can get the number k large. Total time complexity O (n*k)
Solution 3: Using the idea of fast ordering, we randomly find an element x from the array s and divide the array into two parts SA and SB. The element in the SA is greater than or equal to the element less than x in X,SB. There are two kinds of situations:
1. The number of elements in the SA is less than K, then the first k-| in SB The sa| element is the number k large;
2. The number of elements in the SA greater than or equal to K returns the number of K in the SA. Time complexity is approximately o (n)
Solution 4: binary [Smin,smax] Find the result x, the statistic x appears in the array, and the number that is larger than X in the whole array is k-1 K. Time complexity average is O (N*LOGN)
Solution 5: use O (4*n) method to build the largest heap of the original number, and then pop out K-time. Time Complexity of O (4*n + k*logn)
Solution 6: maintain a k size of the smallest heap, for each element in the array to determine the size of the top of the heap, if the top of the heap is larger, regardless, otherwise, pop-up heap top, the current value into the heap. Time complexity O (n * logk)
Solution 7: using the hash to save the number of elements si in the array, using the idea of counting, linear from large to small scanning process, the number of k-1 in front of the number is K large, the average time complexity O (n)