algorithm - 显示找到算法总操作的步骤

标签 algorithm big-o

下面是这个问题的一些 Java 代码:

int total1 = 0;
int total2 = 0;
for (int x = 0; x <= n; x++)
    total1 = total1 + x;
for (int y = 1; y < n; y++)
    total2 += total1 * y;

根据上面的问题,我做了如下的回答。请帮我检查我的答案是对还是错。感谢您的帮助。

Operation        Number of operations
-------------------------------------
Assignment       n² + 1
Addition         n²
Multiplication   n²
Total Operation  3n² + 1

最佳答案

让我们从这个开始:为什么你认为有 n^2 + 1 次赋值?

关于algorithm - 显示找到算法总操作的步骤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3675081/

相关文章:

algorithm - 有多个推销员的旅行推销员,每个推销员的城市数量有限制吗?

algorithm - 从多边形计算对偶图

algorithm - 为什么执行 N/2 步的代码被认为是 O(N)?

while-loop - while 循环的大 O 表示法,每次迭代时对索引进行平方

algorithm - 子集概率(同余变化)

algorithm - 寻找部分有序集合的最大元素的高效算法

检查给定数字的算法是给定数组中组合的总和

algorithm - 一小部分输入的比较排序下限?

algorithm - 如何证明 theta(log n)=o(log n)?

python - Objective-C 中非常慢的两个和解决方案的变体