Common iOS algorithms (Binary bubble selection)
Bipartite: 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)/2 if (a [index] = number) {return index ;} else if (a [index] <number) {start = index + 1;} else {end = index-1 ;}} return index ;}
Bubble Sorting:
/**
Average time complexity: O (n2)
Space complexity: O (1) (used for exchange)
Stability: Stability
*/
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) (used for exchange and record indexing)
Stability: unstable (for example, in sequence [5, 5, 3], the first step is to exchange the first [5] with [3], resulting in the first 5 moving to the second 5)
*/
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;
}
}
}
}