Dichotomy: Average time complexity: O (log2n) int halffuntion (int a[], int length, int number) {int start = 0;int end = Length-1;int index = 0;while (Start < end){index = start + (End-start)/2if (a[index] = = number) {return index;} else if (A[index] < number) {Start = index + 1;} else{end = Index-1;}}return index; }
Bubble Sort:
/**
Average time complexity: O (n2)
Space complexity: O (1) (for Exchange)
Stability: Stable
*/
void paofuntion (int a[], int length) {
for (int i = 0; i < length-1; i++) {
for (int j = 0; J < length-1-I; j + +) {
if (A[j] > a[j+1]) {
int temp = A[j];
A[J] = a[j+1];
A[J+1] = temp;
}
}
}
}
Select Sort:
/**
Average time complexity: O (n2)
Spatial complexity: O (1) (for Exchange and record indexing)
Stability: Unstable (such as sequence "5, 5, 3" The first trip will be the first [5] with [3], causing the first 5 to move to the second 5 back)
*/
void choosefuntion (int a[],int length) {
for (int i = 0; i < length-1; i++) {
for (int j = i + 1; j < length; J + +) {
if (A[i] > A[j]) {
int temp = A[j];
A[J] = A[i];
A[i] = temp;
}
}
}
}
iOS common algorithm (binary bubble selection)