Sorting of nonlinear time comparison classes
First, Exchange class sort: bubble sort and quick sort
Bubble sort: Starts with the first number in the array, compares the next number with the second and then exchanges the number smaller than itself until the last number. If an interchange occurs, continue with the following steps, and if the interchange does not occur, the array is ordered and the sort ends.
Average time complexity: N-side
Space complexity: 1
If you save 10 data in 5 seconds, how long does 20 data take? The complexity of time is N-square
10*10=100 20*20=400 400/100=4 4*5=20
Quick sort: Quick sort, also known as partition Exchange Sort, is the improvement of bubble sort, and the idea of quick sorting is the thought of dividing and treating.
Select a record (usually the first record) from the N records to be sorted as the partition standard;
Move all records smaller than the column to the left, move all records larger than the sorting code to the right, and place the selected records in the middle, called the first order;
Then repeat the process for each of the previous two sub-sequences until all the records are sorted.
Time complexity: Log with base n logarithm of 2
Complexity of space: log2n~n
Second, insert class sort: Direct insert sort and shell sort
Direct Insert sort: Starts with the second record in the N records to be sorted, compares the previous record and looks for the inserted position, and inserts the current number into the appropriate position at the end of each outer loop.
Complexity of Time: N-side
Space complexity: 1
Third, select class sort: Simple Selection sort (direct selection sort) Heap sort merge sort
Simple selection Sorting: Select the smallest data element from all records to exchange with the first position, and then in the remaining records, find the smallest and second-position record exchange, and loop to the last data element left.
Complexity of Time: N-side
Space complexity: 1
Linear time non-comparative class ordering
One, counting sort
Second, the base sort
Third, the bucket sort
Sorting algorithm and complexity of time space