Common internal sorting algorithms are: insert sort, hill sort, select sort, bubble sort, merge sort, quick sort, heap sort, cardinality sort , etc.
Summarize with a picture:
Select sort
Select Sort is a simple and intuitive sorting algorithm, which is the time complexity of O (N2) Regardless of what data goes in. So when it's used, the smaller the data, the better. The only advantage might be that you don't take up extra memory space. In layman's terms, who is the youngest of you, standing on the last side of the queue, and then continue to the rest of the unordered array of the smallest of you who will be out of line, stand to the last side of the queue, until the last one, continue to stand to the last side, so that the array has a sequence, from small to large.
1. Algorithm steps
- First find the smallest (large) element in the unordered sequence, and place it at the beginning of the sort sequence
- Then continue looking for the smallest (large) element from the remaining unsorted elements and place it at the end of the sorted sequence.
- Repeat the second step until all the elements are sorted.
2. Dynamic Diagram Demonstration
3. JavaScript Code Implementation
function Selectionsort (arr) {varLen =arr.length; varMinindex, temp; for(vari =0; I < Len-1; i++) {Minindex=i; for(varj = i +1; J < Len; J + +) { if(Arr[j] < Arr[minindex]) {//Find the smallest numberMinindex = j;//Save the index of the minimum number}} Temp=Arr[i]; Arr[i]=Arr[minindex]; Arr[minindex]=temp; } returnarr;}
4.
Python
Code Implementation
def Selectionsort (arr): for in range (len (arr)-1): as in range (I+1, Len (arr)): if Arr[j] < arr[i]: = arr[j], arr[i] return arr
5. Java Code Implementation
Public Static voidSelectsort (int[] numbers) { intsize = Numbers.length;//Array Length inttemp = 0;//Intermediate Variables for(inti = 0; i < size; i++){ intK = i;//location to be determined//Select the number that should be in the first position for(intj = size-1; J > i; j--){ if(Numbers[j] <Numbers[k]) {k=J; } } //Exchange two numberstemp =Numbers[i]; Numbers[i]=Numbers[k]; NUMBERS[K]=temp; } }
6. Go Code Implementation
Func Selectionsort (arr []int) []int { length:= len (arr) for I: = 0; i < length-1; i++ { min:= i for J: = i + 1; j < length; J + + { if ar R[min] > arr[j] { = j } } = arr[min], arr[i] } return arr}
Hope to communicate with the technology, there is interest can add QQ invite into the group: 525331804 full stack technology development QQ Group: 581993430
"Quick sort" of JavaScript, Python, Java, go algorithm series