-10
public long seriesLoop() {
long answer = a;
for (long i = 1; i < n; i++) {
long delta = a;
for (long j = 0; j < i; j++) {
delta *= r;
}
answer += delta;
}
return answer;
}
public long seriesClosedForm() {
return (long) (a * (1 - Math.pow(r, n))/(1 - r));
}
這兩種方法的Big-O符號是什麼? 爲什麼?我們如何計算算法的大O?如何計算Big-O?
我投票結束這個問題作爲題外話,因爲這是家庭作業轉儲。 – Guy
你根據循環計算大O.一個循環= O(n)。嵌套循環= O(n^2) –
@ j.pei請仔細閱讀此stackoverflow [線程](https://stackoverflow.com/questions/3255/big-o-how-do-you-calculate-approximate-it) 。這會給你清晰的想法。大O. –