Sorting Algorithms Summarize

Swap sort

1. Bubble sort (n*n)

The range of the first round of exchange is 0~N-1, the largest number is placed in the N-1th position.
1. The first number is compared with the second number, who will put it later,
.2. Then the second number and the third number Number comparison, who will put the largest number behind
. 3. Swap in sequence, the largest number is placed at the end of the array The
second round of exchange interval 0~N-2, the largest number is enlarged at the N-2th position
...
The last round determines the first and third 2-bit value

Sort by selection

1. Direct selection sort (n*n)

The first round selects the interval 0~N-1, selects the smallest value, and puts it in position 0.
The second round selects the interval 1~N-1, selects the smallest value, and puts it in the position 1
...
The last round interval N-2 ~N-1, the smallest number (largest in the array) is placed in position N-1

merge sort

1. Merge sort (n*logN)

The first step is to make each number in the array an independent interval. The
second step is to merge adjacent intervals of length one to form an ordered sequence
of length 2 ...
The last step is to combine two adjacent lengths of n/2. The intervals are merged to form an ordered sequence of length n.

Insertion sort

1. Direct insertion class sorting (n*n)

The first time the interval 0~0 is inserted, if the element is smaller than the element at position 0, it is placed at position 0.
The second time the interval 0-1 is inserted, the comparison starts from 1~0, until the position of the element less than the position 2 is found, and it is inserted after it.
...
The last time the interval 0-N-2 is inserted, starting from N-2~-0 Compare until you find the position of the element less than position N-1, and insert it after it.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324737407&siteId=291194637