Bubble Sorting is a simple sort. In this sort, the "Bubble Policy" is used to move the maximum element to the rightmost. During the bubble process, two adjacent elements are compared. If the left side is greater than the right side, two elements are exchanged. After such a bubble, you can ensure that the maximum is on the rightmost side. Then, execute n bubbles and then sort them.
The program code is as follows:
// BubbleSort. cpp: defines the entry p
Quick sorting
void quick_sort(int array[], int begin, int end){if(end > begin){int pivot = begin;int last_small = begin;int i = end;while(last_small != i){if(array[i]
Heap sorting
void adjust_heap(int[], int, int);void build_heap(int array[], int size)//build the max-heap{for(int i = size - 1; i >= 0; i--){adjust_heap(array, size, i);}}void adjust_heap(int array[], int size, int element)//adjust the max
# Include
/* Select sorting
Basic Idea: Find the smallest one from the back and put it to the last one sorted in the front.
Features: time complexity O (N ^ 2)
*/
Void selectsort (INT array [], int N ){
Int I, J;
Int temp = 0, flag = 0;
For (I = 0; I
Temp = array [I];
Flag = I;
For (j = I + 1; j
If (array [J]
Temp = array [J];
Flag = J;
}
}
// Avoid assigning values. In extreme cases, values 1, 2, 3, 4, and 5 are ordered.
If (flag! = I ){
Arra
Sixth chapter Heap SortingMinimum heap and maximum heap: approximate complete binary treeA[parent (i)]Build heap complexity O (n)Sort O (NLGN)In practical applications, fast sorting is generally better than heap sorting. Can be used for priority queues and so on.In a heap containing n elements, all priority queue operations can be done in O (LGN) time.Seventh Chapter Quick SortDivide and conquer the same so
1. Summary of the complexity of internal sorting1) Complexity of timeThe average time complexity of 4 sorts is O (nlog2n), "Get back Faster with nlog2n" (Fast, hill Sort, merge, heap sort)In the worst case, the time complexity of the n*n is O (2) Complexity of spaceO (log2n) Quick-lineO (n) MergeO (RD) CardinalityAll the others are O (1)3) StabilityUnstable: "Review the pain Ah, emotional instability, quickly choose a bunch of friends to chat" (Quick row, hill, simple selection
Sorting and sorting algorithms
-- Sorting problems, such as numbers 1, 2, 3, 4, 5, and 6 -- ideas: (1) if 1 is changed to 5, that is, 1 is directly changed to, 2, 3, 4, and 5, respectively, minus 1 and 6 unchanged -- (2) if 5 is changed to 3, 5 is directly changed to and 2, 3, 4 minus 1, 6 unchanged -- (3) for example:
is calledInternal sorting(Inner sorting); otherwise, if the data needs to be exchanged between internal and external storage, it is calledExternal sorting.Note:① Inner sorting applies to small files with a small number of records② External sorting is suitable for large files with too many records that cannot be stored
Seven classical sorting algorithms based on python (recommended) and seven types of python
I. Basic concepts and classifications of sorting
Sorting is an operation that sorts a string of records in ascending or descending order based on the size of one or more keywords. Sorting
. In other words, the selection of benchmarks is important. The selection of the datum determines the length of the two two sub-sequences, which has a decisive effect on the efficiency of the whole algorithm.Ideally, the chosen benchmark would be able to divide the ordered sequence into two equal-length sub-sequences.Method one: Fixed datum element (Basic quick Sort)Thought: Takes the first or last element of a sequence as a datum element.Note: Basic quick sort selects the first or last element
Heap sorting and heap sorting algorithms
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.
# Include
Void swap (Int A, Int B ){
Int temp;
Temp =;
A = B;
B = temp;
}
/* Bubble sort
Basic Idea: first bubble to get a record with the smallest keyword, and second to get the second small value... for each record: the key words of the two adjacent records, if the reverse order is exchanged until there is no reverse order.
Features: time efficiency, a total of N-1 trip bubbles, a trip to the table of J records bubble needs to J-1 keyword comparison, space efficiency: Only one auxiliary
Quick sorting and quick sorting algorithms
# Include Using namespace std;Void paixu (int, int );Int a [101];Int main () // This function uses the number 1{Int n, I;Cin> n;For (I = 1; I Paixu (1, n );For (I = 1; I Cout }Void paixu (int l, int r) // This function uses the letter l{Int I, j, p, mid;I = l;J = r;Mid = a [(l + r)/2];Do // here the do while loop is use
time. Then, the data on both sides of the K, and then the process is divided into the above, until no further grouping. Note: The first time quick sort does not directly get the final result, only the number smaller than K and K is divided into the two sides of K. To get the final result, you need to perform this step again on an array of subscript 22 edges, and then decompose the array until the array is no longer decomposed (only one data) to get the correct result. The code is as follows:vo
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.