Selection sorting of Java sorting algorithm summary

This paper gives an example of Java sorting algorithm summary selection sorting. Share with you for your reference. The specific analysis is as follows:

The basic operation of selective sorting is to select the smallest (or largest) element from the data elements to be sorted in each trip, and place it at the end of the ordered sequence until all the data elements to be sorted are finished. The algorithm is unstable, the additional space of O (1), the time complexity of comparison is O (n ^ 2), and the time complexity of exchange is O (n), which is not adaptive. It is not recommended in most cases. It can only be used if you want to reduce the number of exchanges. Basic idea: for the direct selection sorting of n records, the ordered results can be obtained through n-1 times of direct selection sorting: ① initial state: the disordered area is r [1.. n], and the ordered area is empty. ② In the first sorting, select the record R [k] with the smallest keyword in the unordered area R [1.. n] and exchange it with the first record R [1] in the unordered area, so that R [1.. 1] and R [2.. n] become a new ordered area with an increase in the number of records and a new unordered area with a decrease in the number of records respectively ③ Sorting of the ith pass

At the beginning of the i-th sorting, the current ordered area and unordered area are R [1.. I-1] and R (1 ≤ I ≤ n-1) respectively. This round of sorting selects the record R [k] with the smallest keyword from the current unordered area and exchanges it with the first record r of the unordered area, so that R [1.. I] and R become a new ordered area with an increase in the number of records and a new unordered area with a decrease in the number of records, respectively. In this way, the direct selection sorting of files of n records can get ordered results through n-1 times of direct selection sorting. code implementation

Like the bubble sorting method, the outermost loop still needs to be executed n-1 times, and its efficiency is still poor.

I hope this article will be helpful to your Java programming.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>