sorting algorithm time

Sorting

worst time analysis Average time complexity stability space complexity
Bubble Sort O(n 2 ) O(n 2 ) Stablize O(1)
quick sort O(n 2 ) O(n*log2n) unstable O(log2n)~O(n)
selection sort O(n 2 ) O(n 2 ) Stablize O(1)
Binary tree sorting O(n 2 ) O(n*log2n) unstable O(n)

Insertion sort

O(n 2 ) O(n 2 ) Stablize O(1)
heap sort O(n*log2n) O(n*log2n) unstable O(1)
Hill sort O O unstable O(1)

 

1. Insertion sort

Compare the nth element with the previous n-1 elements, and if it is larger than one of the elements, insert it after it

 

2. Hill sort ( a more efficient and improved version of insertion sort )

First divide the entire record sequence to be sorted into several subsequences for direct insertion sorting

 

3. Selection sort

From unsorted data, find the largest (smallest element) and combine it into a new pair column

 

Fourth, bubble sort

Compare two elements at a time, swap them if they are in the wrong order

 

Five, merge sort

A very typical application of Divide and Conquer. sorted separately and then grouped together

 

6. Quick Sort

Divide and conquer method to divide a series (list) into two sub-series

 

Seven, heap sort

It refers to a sorting algorithm designed using the data structure of the heap. Stacking is a structure that approximates a complete binary tree and satisfies the properties of stacking : that is, the key value or index of a child node is always less than (or greater than) its parent node

 

8. Basis sort

is to divide the array into a finite number of buckets. Sort each bucket individually

 

 

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326798730&siteId=291194637