下面search函数的平均时间复杂度为( )。
1 int search(int n, int * p, int target) { 2 int low = 0, high = n; 3 while (low <= high) { 4 int middle = (low + high) / 2; 5 if (target == p[middle]) { 6 return middle; 7 } else if (target > p[middle]) { 8 low = middle + 1; 9 } else { 10 high = middle - 1; 11 } 12 } 13 return -1; 14 }
0(n)
0(log(n))
0 (1)
可能⽆法返回