C#: Efficient algorithm to find greatest m elements in an N x N matrix -
I would like to know whether there is an efficient algorithm for finding the largest M elements in the N xn matrix with one method Headers like this:
double [] largest value (double [] [] matrix, int number profiles); Any ideas?
If you treat N xn as an array of matrix n xn items you One of the following technologies can apply:
Direct application of the Quick Sort Based Selection Algorithm Find the Smallest or Largest Element of Quick Sort Based Selection Algorithm Can be used to find the smallest elements of measurable Use the intermediate base to get the smallest element. After the partition, the most important element is found, smaller elements are present than all the small elements which are left of the elements and all the elements will be presented as the smallest element of the smallest element. Thus, from 1 to all element elements are the smallest elements to include. The complexity of time is linear in n, the total number of elements.
Data structure based solutions Another simple method is to add each element of the order to the set set structures, such as a heap or self-balance binary search tree, in which Most K-elements are whenever whenever the data is greater than the elements of the structure, we remove the largest element, which can be done in the time of the (log) time. Each convergence operation also takes time (o log), which results in the overall form of O (NLLP) time.
It is possible to change the list Θ (n) into a heap in time, and then using a modified fourth-first search algorithm, a heap which is a priority queue (rather than normal Qi which is commonly used in BFS ), And actually ends the scan after crossing the elements. Since the queue size o (k) lives in the whole traversal, it requires time to complete o (klog k), so that o (n + klog k) is timed on this algorithm.
Comments
Post a Comment