我们学习了大 O 表示法,但我也经常看到 T(n)。例如,
public static Comparable[] mergeSort(Comparable[] A, int low, int high) {
if (low < high) { //at least 2 elements? //cost = c
int mid = (low + high)/2; //cost = d
Comparable[] A1 = mergeSort(A, low, mid); //cost = T(n/2) + e
Comparable[] A2 = mergeSort(A, mid+1, high); //cost = T(n/2) + f
return merge(A1,A2); //cost = g n + h
}
.... //cost = i
我相信 c,d,e,... 是任意命名的常量。
T(n/2) 是什么意思?T符号与大O有什么关系?