1
爲什麼是時間複雜度,O(n)而不是O(nlogn)?你不需要將外循環的複雜性與內循環的複雜性相乘嗎?時間複雜度分析循環:
int fun(int n){
int count = 0;
for (int i = n; i > 0; i /= 2)
for (int j = 0; j < i; j++)
count += 1;
return count;
}
http://en.wikipedia.org/wiki/1/2_%2B_1/4_%2B_1/8_%2B_1/16_%2B_%E2%8B AF% – tvanfosson