大 Theta 计算

Big Theta Computation

有人可以为我指出这个问题的正确方向吗?我需要计算这个函数的 big theta 运行 时间。我知道它会 运行 sum++ (n^2)(n+2) 次,但我不确定如何计算它的大 theta。很抱歉有 n00b 个问题,但这只是最高阶的吗? n^3?

for (int i=0; i <= n+2; i++)

   for (int j=0; j < n * n; j++)

      sum++;

您可以在 Wiki Big Theta f(n) = Θ(g(n)) means that f is bounded both above and below by g asymptotically. You may also find interesting Big-θ (Big-Theta) notation at Khan Academy. In most colloquial cases Big-O and Big-Theta are the same i.e. when someone says about some algorithms Big-O actually Big-Theta is meant. See also What is the difference between Θ(n) and O(n)? 中找到一些 Big-O 和 Big-Theta 之间差异的示例

是的,在你的情况下,只获得 n

的最高功率就可以了