Select Sorting Algorithm and Sorting Algorithm
The idea of selecting a sorting algorithm is similar to Bubble sorting. the maximum or minimum values are selected from the sequence that is not sorted each time, and placed in the header or tail of the array. However, the algorithm is not compared to the bubble algorithm, but an unordered array in each loop. It finds the index of the maximum or minimum value and exchanges it with the header or tail of the unordered array. The sorting ends when only one unordered array is left. Java code implementation is as follows:
Public static void SelectionSort (int [] array) {for (int I = 0; I <array. length; I ++) {int min = array [I]; int key = I; for (int j = I + 1; j <array. length; j ++) {if (min> array [j]) {min = array [j]; key = j ;}} int temp = array [I]; array [I] = min; array [key] = temp ;}}
Select the time complexity of sorting as O (n ^ 2) and space complexity as O (1 ).