Sorting Algorithms
Recursion
a^b
public int pow(int a, int b){
if(b == 0){
return 1;
}
if(b == 1){
return a;
}
int halfResult = pow(a, b / 2);
if(b % 2 == 0){
return halfResult * halfResult ;
}else{
return halfResult * halfResult * a
}
}
由于不断把pow进行拆分,所以这里时间复杂度为O(log b), 空间为 O(log b)Merge Sort
Quick Sort
Last updated