Sorting algorithms
Characteristics of common sorting algorithms
Time complexity and spatial complexity of common sorting method
Insert sort (direct insert, Hill Sort)
Select sort (' Simple select sort, heap sort ')
Swap sort (bubble sort, quick sort)
Merge sort
Base sort
Direct Insert Sort
First start with the first number, each time you select, the next data in the sorted data is inserted into the sorted data
Hill sort
Jump select two data, and according to the size of the exchange position, after completion, and then reduce the jumping interval, until the jump zero.
Select sort
First find the element, the smallest element, find it, put it in the first place, and then in the remaining sequence, find the smallest element and put it in the second place ... Until it's all done.
Heap sort of a complete binary tree
Is in the tree, must be from top to bottom, from left to right, in turn, or reduce
Examples:
1. Read the question we know, build the Big Top heap is, above is the biggest
2. Then start from the last layer of the final layer from the right-to-left node, that is, 56, she and her child nodes, 84, 84 large, so the two swap positions
3. Again to the left a node to see, that is, 79, we see that 79 is larger than her two nodes, so 79 positions do not move
4. This layer is over, look at the above layer, 46,46 two nodes, 84 large, so 84 replace 46
Then repeat the process until the heap cannot be changed.
The result is the following:
So his initial heap is 84 79 56 38 40 46 Select B
In fact, what we need is not this initial heap, but the final sort, so the following steps are
Swap the topmost vertex and the last one, and disconnect 84 and 56, forming a new heap,
Repeat the above heap steps until all is successful
Bubble Sort:
Start with the smallest element, compare it to the previous element, and move the small element forward, then the smallest
Then, starting with the penultimate element, proceed to the previous steps until all the elements are complete
Quick Sort
1 Select a keyword, then use all the elements and this keyword to compare, small put front, big put back
2 There are two small collections, and then in these two small sets, each one of the other keywords, continue the first step
Until it's all done.
Merge sort
Base sort (I don't think I'm going to test it)
1. Start sorting from each digit
2. Then the 10-bit
3. Hundred ...
Thinking of sorting algorithm
What sort of algorithms are stable
Find Order Lookup
From the beginning of the table, followed by the words that need to be looked up,
Two-point Search
Require a sequence to be searched for ordered series
- First, divide the gross position data by 2 to get the central element.
- Then make a comparison, large, starting from the right sequence, small from the left sequence,
- Take the first step
Block Lookup
is the improvement of the sequential lookup
2-Algorithm Basics