【发布时间】:2014-09-28 01:41:22
【问题描述】:
所以我知道如果两个while循环只是while(x
int result = 0;
int x = 0;
while (x < n / 2){
result += arr[x];
x += 1;
while (x >= n / 2 && x < n){
result += arr[x];
x += 1;
}
}
printf("%d\n", result);
【问题讨论】:
-
为什么不把外循环的代码改写成
while (x < n),去掉内循环呢?它将是O(n)。 -
我应该按原样评估它,而不是重写它
-
提示:线性函数和常数的乘积仍然是线性函数。
标签: c performance algorithm big-o