Exchange sorting includes bubble sorting and quick sorting. Bubble sorting is a simpler sorting algorithm in the field of computer science. The time complexity is "O(N2)", while quick sorting is An improvement on bubble sorting, the time complexity is "O(Nlog2N)".
Exchange sort
Bubble sort
Bubble Sort is a relatively simple sorting algorithm in the field of computer science.
When sorting a sequence to be sorted with N elements, a total of N-1 loops are performed. In the k-th loop, the elements from the 1st to the N-kth are compared from front to back, and the two adjacent elements are compared each time. If the former element is greater than the latter element, the two exchange positions, otherwise they remain Position unchanged
Time complexity:O(N2)
Quick sort
Quick Sorting (Quicksort) is an improvement on bubble sort.
Divide the unsorted elements into two subsequences based on a "pivot" as a benchmark. The records of one subsequence are greater than the pivot, while the records of the other subsequence are smaller than the pivot, and then recursively These two subsequences are sorted in a similar way
Time complexity:O(Nlog2N)
The above is the detailed content of What are exchange sortings?. For more information, please follow other related articles on the PHP Chinese website!