本体が次の関数を考えてみましょう。
sum = 0;
for (i = 1; i <= f(n); i++)
sum += i;
ここで、f(n) は関数呼び出しです。次の仮定の下で、n の関数として、この関数の実行時間にシンプルでタイトな大きな上限を与えます。
a) The running time of f(n) is O(n), and the value of f(n) is n!
b) The running time of f(n) is O(n), and the value of f(n) is n
c) The running time of f(n) is O(n²), and the value of f(n) is n
d) The running time of f(n) is O(1), and the value of f(n) is 0
自分が正しい軌道に乗っていることを確認したいだけです。私の答え:
a) O(n²)
b) O(n²)
c) O(n³)
d) O(1)